:root {
  color-scheme: dark;
  --font: "Montserrat", Arial, sans-serif;
  --title-font: "Barlow Condensed", "Arial Narrow", sans-serif;
  --background: #101010;
  --surface: #1b1b1b;
  --text: #fafafa;
  --muted: #bdbdbd;
  --accent: var(--text);
  --on-accent: var(--background);
  --selected: #363636;
  --border: #666;
  --correct: #76d9a1;
  --miss: #ff8487;
  --primary-color: hsl(var(--primary-hue, 210) 85% 76%);
  --secondary-color: hsl(var(--secondary-hue, 258) 85% 76%);
  --rainbow: linear-gradient(90deg, #f44, #fc0, #8d4, #4dd, #48f, #c5f, #f44);
  --accent-fill: var(--accent);
  --ice: #8dc8ff;
  --violet: #c7afff;
  --gradient: linear-gradient(115deg, var(--ice), #e4b3ff);
  --control-width: 15rem;
}
:root[data-appearance="light"] {
  color-scheme: light;
  --background: #fafafa;
  --surface: #eee;
  --text: #101010;
  --muted: #555;
  --selected: #d9d9d9;
  --border: #777;
  --correct: #167346;
  --miss: #b42638;
}
:root[data-theme="gradient"] {
  --accent: #c7c4ff;
  --accent-fill: var(--gradient);
  --on-accent: #101010;
  --primary-color: var(--ice);
  --secondary-color: var(--violet);
}
:root[data-theme="gradient"][data-appearance="light"] { --accent: #513789; }
:root[data-theme="gradient"][data-appearance="light"] {
  --gradient-text: linear-gradient(115deg, #215b8e, #7739a2);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--background); color: var(--text); font: 500 1rem/1.45 var(--font); }
main { width: min(100% - 2rem, 31rem); margin: clamp(2rem, 9vh, 5rem) auto 2rem; }
#masthead { margin-bottom: 1.5rem; text-align: center; }
h1 {
  margin: 0;
  color: var(--accent);
  font: 800 clamp(4.75rem, 15vw, 7rem)/.85 var(--title-font);
  letter-spacing: -.025em;
}
:root[data-theme="custom"] {
  --gradient-text: linear-gradient(115deg, var(--primary-color), var(--secondary-color));
}
:root[data-theme="custom"][data-appearance="light"] {
  --gradient-text: linear-gradient(115deg,
    hsl(var(--primary-hue, 210) 75% 32%), hsl(var(--secondary-hue, 258) 75% 32%));
}
:root:is([data-theme="gradient"], [data-theme="custom"]) h1,
:root[data-theme="gradient"] #line {
  width: fit-content;
  margin-inline: auto;
  background: var(--gradient-text, var(--accent-fill));
  background-clip: text;
  color: transparent;
}
.mode-bar { display: grid; grid-template-columns: minmax(0, 1fr); margin-bottom: clamp(1.75rem, 5vh, 2.75rem); }
#modes, #play-tools { grid-area: 1 / 1; }
#modes {
  display: grid;
  justify-self: center;
  width: max-content;
  max-width: 100%;
  grid-template-columns: minmax(0, 1fr) max-content minmax(0, 1fr);
  gap: .2rem;
  padding: .25rem;
  border-radius: .65rem;
  background: var(--surface);
  transition: opacity 180ms ease, visibility 180ms;
}
#modes .mode-pair { display: flex; justify-content: space-between; gap: .2rem; }
#modes button {
  padding: .55rem clamp(.2rem, 1.25vw, .7rem);
  white-space: nowrap;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: clamp(.68rem, 2.65vw, .85rem);
}
@media (max-width: 23rem) {
  main:not(.playing) .mode-bar { margin-inline: -.5rem; }
  #modes button { font-size: .625rem; padding-inline: .15rem; }
}
#modes button:hover { color: var(--text); }
#modes button[aria-pressed="true"] { background: var(--selected); color: var(--text); }
.playing #modes { opacity: 0; visibility: hidden; }
#play-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  align-self: center;
  min-height: 2.5rem;
  font-size: .82rem;
  color: var(--muted);
}
#quit { padding: .35rem 0 .35rem .75rem; border: 0; background: transparent; color: inherit; }
#quit:hover { color: var(--text); text-decoration: underline; }
button, input:not([type="radio"]):not([type="checkbox"]):not([type="range"]), select {
  min-height: 2.75rem;
  padding: .55rem .8rem;
  border: 1px solid var(--border);
  border-radius: .45rem;
  color: inherit;
  background: var(--surface);
  font: inherit;
}
select, select option {
  color: var(--text);
  background-color: var(--surface);
}
button { cursor: pointer; font-weight: 700; }
:focus-visible { outline: 2px solid var(--text); outline-offset: 3px; }
.card { text-align: center; }
h2 { margin: 0; font-size: clamp(1.65rem, 6vw, 2.25rem); font-weight: 800; line-height: 1.1; }
#score, #daily-date { color: var(--muted); font-size: .9rem; font-variant-numeric: tabular-nums; }
#score:not(:has(> :not([hidden]))) { display: none; }
#score { margin-top: .45rem; }
#daily-date { margin: .5rem 0 0; }
main:not(.playing) #score:has(#record:not([hidden])) { display: none; }
#endless-setup { margin: 1.25rem auto 0; }
#endless-difficulty { width: min(100%, var(--control-width)); }
#next {
  display: block;
  width: min(100%, var(--control-width));
  margin: 1.25rem auto 0;
  border-color: var(--accent);
  background: var(--accent-fill);
  color: var(--on-accent);
}
#next:hover { filter: brightness(.9); }
main.playing { margin-top: clamp(.65rem, 3vh, 1.5rem); }
.playing .mode-bar { margin-bottom: clamp(.65rem, 2.5vh, 1.25rem); }
.playing #stage { font-size: clamp(1.6rem, 5.5vw, 2.45rem); }
.playing #score:has(#record:not([hidden])) { color: var(--text); font-size: clamp(1.9rem, 6vw, 2.75rem); font-weight: 700; line-height: 1; }
#record { display: inline-flex; align-items: center; gap: .16em; }
#wins, #losses { min-width: 1ch; text-align: center; }
#clock {
  display: flex;
  justify-content: center;
  gap: .45rem;
  width: fit-content;
  margin: clamp(.8rem, 2.5vh, 1.35rem) auto 0;
  padding: .5rem .65rem;
  border-radius: .25rem;
  background: #120b0c;
}
.clock-digit { position: relative; width: clamp(1.95rem, 6vh, 2.85rem); aspect-ratio: 17 / 31; }
.segment { position: absolute; background: #3b171b; }
.segment.lit { background: #ff4f55; }
.segment-a, .segment-d, .segment-g {
  left: 14%;
  width: 72%;
  height: 12%;
  clip-path: polygon(12% 0, 88% 0, 100% 50%, 88% 100%, 12% 100%, 0 50%);
}
.segment-b, .segment-c, .segment-e, .segment-f {
  width: 20%;
  height: 42%;
  clip-path: polygon(50% 0, 100% 12%, 100% 88%, 50% 100%, 0 88%, 0 12%);
}
.segment-a { top: 0; }
.segment-g { top: 44%; }
.segment-d { bottom: 0; }
.segment-b, .segment-f { top: 5%; }
.segment-c, .segment-e { bottom: 5%; }
.segment-b, .segment-c { right: 0; }
.segment-e, .segment-f { left: 0; }
#prompt {
  display: grid;
  gap: .18rem;
  margin: clamp(.8rem, 2.5vh, 1.4rem) 0 .65rem;
}
#subject { font-size: clamp(1.1rem, 4vw, 1.35rem); font-weight: 700; }
#stat-details { color: var(--muted); font-size: clamp(.75rem, 3vw, .9rem); }
#line, .playing #result {
  margin: 0;
  font-size: clamp(3rem, 12vw, 4.75rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
#line { color: var(--accent); }
#result:empty { display: none; }
.playing #result { color: var(--correct); }
.playing #result.miss { color: var(--miss); }
#choices {
  display: grid;
  gap: .45rem;
  width: min(100%, var(--control-width));
  margin: .85rem auto 0;
}
#higher { background: var(--accent-fill); border-color: var(--accent); color: var(--on-accent); }
#lower { background: transparent; border-color: var(--accent); color: var(--accent); }
:root:is([data-theme="gradient"], [data-theme="custom"]) #choices button {
  color: #101010;
  border-color: transparent;
}
:root:is([data-theme="gradient"], [data-theme="custom"]) #higher { background: var(--primary-color); }
:root:is([data-theme="gradient"], [data-theme="custom"]) #lower { background: var(--secondary-color); }
#higher:hover, :root:is([data-theme="gradient"], [data-theme="custom"]) #lower:hover { filter: brightness(.9); }
#lower:hover { background: var(--surface); }
footer { margin-top: 1rem; text-align: center; font-size: .8rem; }
a { color: var(--accent); }
#levels, #custom-stats { list-style: none; padding: 0; }
#levels { display: grid; gap: .5rem; margin: 1.25rem auto 0; max-width: 20rem; }
#levels button { width: 100%; }
#levels button:hover, #add-stat button:hover { background: var(--selected); }
#custom { margin-top: 1.25rem; text-align: left; }
#custom-stats li { display: flex; justify-content: space-between; flex-wrap: wrap; align-items: center; gap: .5rem; }
#custom-stats li + li { margin-top: .5rem; }
#add-stat { display: grid; justify-items: end; gap: .75rem; }
.stat-picker-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .75rem;
  width: 100%;
}
.stat-picker-grid label, #share-label, .stat-field { display: grid; gap: .3rem; min-width: 0; }
.stat-picker-grid input, .stat-picker-grid select, #share-link { width: 100%; min-width: 0; }
.stat-control {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: .45rem;
  background: var(--surface);
}
.stat-control select { border: 0; }
#stat-preview {
  min-width: 4ch;
  margin-right: .65rem;
  padding-left: .55rem;
  border-left: 1px solid var(--border);
  text-align: right;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
#add-stat button:disabled { cursor: default; opacity: .65; background: var(--surface); }
@media (max-width: 28rem) {
  .stat-picker-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (prefers-reduced-motion: reduce) { #modes { transition: none; } }

#settings { width: min(100%, 23rem); margin: 1.25rem auto 0; text-align: left; }
.theme-picker {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .5rem;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}
.theme-picker legend { margin-bottom: .5rem; font-weight: 700; }
.theme-picker label, .motion-setting {
  display: flex;
  align-items: center;
  gap: .45rem;
  min-height: 3rem;
  padding: .55rem .65rem;
  border: 1px solid var(--border);
  border-radius: .45rem;
  background: var(--surface);
  cursor: pointer;
  font-size: .83rem;
}
.theme-picker label:has(:checked) { border-color: var(--accent); }
.theme-picker input, .motion-setting input { flex: none; margin: 0; accent-color: var(--accent); }
.theme-swatch { flex: none; width: .85rem; height: .85rem; border-radius: 50%; background: #fafafa; }
[value="gradient"] + .theme-swatch { background: var(--gradient); }
.motion-setting { margin-top: 1rem; }

[value="custom"] + .theme-swatch { background: var(--rainbow); }
.color-controls { display: grid; gap: .35rem; margin-top: 1rem; font-size: .85rem; }
.color-controls label:not(:first-child) { margin-top: .35rem; }
.color-controls input {
  appearance: none;
  width: 100%;
  height: 1.5rem;
  margin: 0;
  border: 1px solid var(--border);
  border-radius: 1rem;
  background: var(--rainbow);
  cursor: pointer;
}
.color-controls input::-webkit-slider-thumb {
  appearance: none;
  width: 1.25rem;
  height: 1.25rem;
  border: 2px solid #101010;
  border-radius: 50%;
  background: #fafafa;
}
.color-controls input::-moz-range-thumb {
  width: 1rem;
  height: 1rem;
  border: 2px solid #101010;
  border-radius: 50%;
  background: #fafafa;
}

#run-results { margin: .75rem auto 0; }
#results-detail, #results-last-question, #results-last-answer { color: var(--muted); font-size: .9rem; }
#results-score { margin: .65rem 0; font-size: clamp(1.3rem, 5vw, 2rem); font-weight: 800; }
#results-overtime { margin: 0 0 1rem; font-weight: 700; }
#results-last-question { margin: 1rem 0 .25rem; }
#results-last-answer { margin: .25rem 0 0; }
.results-actions { display: flex; justify-content: center; gap: .5rem; }
.results-actions button { margin-top: 1.25rem; width: min(100%, 9rem); }
.results-actions button:hover { background: var(--selected); }
#share-status { color: var(--muted); font-size: .85rem; }
#share-text {
  width: min(100%, 24rem);
  min-height: 9rem;
  padding: .6rem;
  border: 1px solid var(--border);
  border-radius: .45rem;
  color: var(--text);
  background: var(--surface);
  font: inherit;
  font-size: .85rem;
}

main:has(#settings:not([hidden])) {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  margin: 0 auto;
  padding: clamp(2rem, 9vh, 5rem) 0 .75rem;
}
.settings-note {
  display: none;
  align-self: center;
  width: max-content;
  max-width: calc(100vw - 1.5rem);
  margin: auto 0 0;
  padding-top: 2rem;
  color: var(--muted);
  font-size: clamp(.6875rem, 1.8vw, .75rem);
  text-wrap: balance;
}
.settings-note a { white-space: nowrap; }
main:has(#settings:not([hidden])) .settings-note { display: block; }

.playing .card {
  display: grid;
  grid-template-areas: "scoreboard" "prompt" "value" "actions";
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto auto minmax(5.95rem, auto);
  grid-auto-rows: auto;
  row-gap: clamp(.75rem, 2.5vh, 1.5rem);
}
.playing .scoreboard { grid-area: scoreboard; }
.playing #court { display: contents; }
.playing #prompt { grid-area: prompt; margin: 0; }
.playing :is(#line, #result) { grid-area: value; }
.playing :is(#choices, #next) {
  grid-area: actions;
  align-self: start;
  margin: 0 auto;
}

@media (max-width: 40rem) {
  main.playing { margin-bottom: 1rem; }
  .playing .card { row-gap: clamp(.65rem, 1.8vh, 1rem); }
}

@media (max-height: 41rem) {
  main.playing { margin-top: .35rem; margin-bottom: .65rem; }
  .playing .mode-bar { margin-bottom: .35rem; }
  .playing .card { row-gap: .65rem; }
  .playing #clock { margin-top: .65rem; padding: .35rem .5rem; }
  .playing .clock-digit { width: clamp(1.45rem, 5vh, 2.25rem); }
  .playing :is(#line, #result) { font-size: clamp(2.35rem, 8vh, 4rem); }
}

@media (orientation: landscape) and (max-height: 31rem) and (min-width: 32rem) {
  .playing .card {
    grid-template-areas: "scoreboard prompt" "scoreboard value" "scoreboard actions";
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr);
    grid-template-rows: auto auto minmax(5.95rem, auto);
    column-gap: clamp(1rem, 4vw, 2rem);
  }
  .playing .scoreboard { align-self: center; }
  .playing #stage { font-size: clamp(1.4rem, 4.5vw, 2rem); }
  .playing #score:has(#record:not([hidden])) { font-size: clamp(1.65rem, 5vw, 2.5rem); }
}
