:root {
  --bg: #0E1220;
  --ring: #3A4260;
  --hand: #F5F1E6;
  --accent: #FFB347;
  --text: #E8EAF2;
  --muted: #8A90A8;
  --surface: rgba(255, 255, 255, 0.04);
  --surface-line: rgba(255, 255, 255, 0.08);
  --g-perfect: #FFD54A;
  --g-great: #4ADE80;
  --g-good: #60A5FA;
  --g-off: #FB923C;
  --g-lost: #F87171;
  --btn-text: #0E1220;
  --p1: #F472B6;
  --p2: #22D3EE;
  --result-top: 70vh;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #F6F4EE;
    --ring: #C9CCD8;
    --hand: #1B1F33;
    --accent: #D9822B;
    --text: #1B1F33;
    --muted: #5C6178;
    --surface: rgba(27, 31, 51, 0.04);
    --surface-line: rgba(27, 31, 51, 0.1);
    --g-perfect: #B8860B;
    --g-great: #15803D;
    --g-good: #1D4ED8;
    --g-off: #C2410C;
    --g-lost: #B91C1C;
    --btn-text: #F6F4EE;
    --p1: #DB2777;
    --p2: #0E7490;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

#dial {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 0;
}

/* ---------- Screens ---------- */
.screen {
  position: fixed;
  inset: 0;
  z-index: 1;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 200ms ease-out, visibility 0s linear 200ms;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
           max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.screen.active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transition: opacity 200ms ease-out, visibility 0s;
}

button {
  font: inherit;
  cursor: pointer;
  border: 0;
  color: inherit;
  background: none;
}
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.primary {
  background: var(--accent);
  color: var(--btn-text);
  font-weight: 600;
  font-size: 1.1rem;
  padding: 14px 32px;
  border-radius: 999px;
  min-width: 220px;
  transition: transform 150ms ease-out, filter 150ms;
}
.primary:hover { filter: brightness(1.06); }
.primary:active { transform: scale(0.97); }
.secondary {
  border: 1.5px solid var(--ring);
  padding: 12px 28px;
  border-radius: 999px;
  font-weight: 600;
  min-width: 220px;
}
.text-btn { color: var(--muted); padding: 10px 20px; text-decoration: underline; text-underline-offset: 3px; }

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: inline-grid;
  place-items: center;
  color: var(--muted);
}
.icon-btn:hover { color: var(--text); background: var(--surface); }
.icon-btn svg {
  width: 24px; height: 24px;
  fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.icon-btn svg .ico-fill { fill: currentColor; stroke: none; }
.icon-btn[aria-pressed="true"] .ico-off,
.icon-btn[aria-pressed="false"] .ico-on { display: none; }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.caps { text-transform: uppercase; letter-spacing: 0.12em; }
.amber { color: var(--accent); font-weight: 600; }
.lost { color: var(--g-lost); font-weight: 600; }

/* ---------- Home ---------- */
#home { display: flex; flex-direction: column; align-items: center; justify-content: space-between; text-align: center; }
.corner { position: absolute; top: max(8px, env(safe-area-inset-top)); right: max(8px, env(safe-area-inset-right)); display: flex; gap: 4px; }
.home-top { margin-top: 4vh; }
h1 { font-size: clamp(2rem, 6vw, 3rem); font-weight: 700; letter-spacing: -0.02em; margin: 0 0 8px; }
.tagline { margin: 0; color: var(--muted); font-size: 1rem; max-width: 30ch; margin-inline: auto; }
.home-bottom { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-top: auto; margin-bottom: 24px; }
.modes {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  width: min(780px, 100%);
}
@media (min-width: 640px) {
  .modes { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 639px) {
  .mode-card { padding: 10px 16px; }
  .mode-desc { font-size: 0.85rem; }
}
.mode-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  text-align: left;
  padding: 14px 18px;
  border-radius: 16px;
  background: var(--surface);
  border: 1.5px solid var(--surface-line);
  transition: border-color 150ms ease-out, transform 150ms ease-out, background 150ms;
}
.mode-card:hover { border-color: var(--accent); }
.mode-card:active { transform: scale(0.98); }
.mode-name { font-size: 1.2rem; font-weight: 700; }
.mode-desc { color: var(--muted); font-size: 0.9rem; line-height: 1.35; }
.mode-meta { color: var(--accent); font-size: 0.85rem; font-weight: 600; font-variant-numeric: tabular-nums; min-height: 1.2em; }
#btn-endless .mode-name::after { content: " →"; color: var(--accent); }
#btn-duel .mode-name::after,
#btn-timer .mode-name::after { content: " →"; color: var(--accent); }

/* ---------- Players (Duel) ---------- */
.p1 { color: var(--p1); }
.p2 { color: var(--p2); }
.turn { font-weight: 600; }
.result-sub .p1, .result-sub .p2 { font-weight: 600; }
.duel-turns { margin: 6px 0 0; display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 16px; font-variant-numeric: tabular-nums; }

.duel-headline { font-size: clamp(2rem, 9vw, 2.8rem); font-weight: 700; margin: 0; line-height: 1.1; }
.duel-score { font-size: 1.4rem; font-weight: 600; margin: 8px 0 0; font-variant-numeric: tabular-nums; }
.duel-rows { display: grid; gap: 10px; margin-top: 22px; text-align: left; }
.duel-row {
  background: var(--surface);
  border: 1px solid var(--surface-line);
  border-radius: 14px;
  padding: 12px 14px;
}
.duel-row-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.duel-row-head strong { font-size: 1.05rem; }
.duel-row-head span { color: var(--muted); font-size: 0.85rem; font-variant-numeric: tabular-nums; }
.duel-row .squares { justify-content: flex-start; margin: 10px 0 0; max-width: none; }

.setup-label { margin: 16px 0 10px; font-weight: 600; }
.setup-choices { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-bottom: 8px; }
.setup-choices .primary, .setup-choices .secondary { min-width: 140px; }
.overlay-card > p.muted { margin: 0; line-height: 1.45; }

/* ---------- Play ---------- */
#play {
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  cursor: pointer;
}
.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  height: 44px;
  font-size: 0.95rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.topbar .hud { white-space: nowrap; }
.hearts { letter-spacing: 2px; color: var(--g-lost); font-size: 1.05rem; }
.hearts .empty { color: var(--ring); }
.streak { color: var(--g-great); }
.points { margin-left: auto; color: var(--text); font-weight: 600; }

.caption {
  position: absolute;
  left: 16px; right: 16px;
  top: 64px;
  margin: 0;
  text-align: center;
  color: var(--accent);
  font-weight: 600;
  animation: rise 250ms ease-out;
}
.hint {
  position: absolute;
  left: 16px; right: 16px;
  top: var(--result-top);
  margin: 0;
  text-align: center;
  color: var(--muted);
  animation: rise 250ms ease-out;
}
/* When a result is on screen, the hint sits underneath it instead of on top of it. */
.result.show ~ .hint { top: calc(var(--result-top) + 70px); }
.result {
  position: absolute;
  left: 16px; right: 16px;
  top: var(--result-top);
  text-align: center;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
}
.result.show { opacity: 1; transform: none; transition: opacity 250ms ease-out, transform 250ms ease-out; }
.result-line {
  margin: 0;
  font-size: clamp(20px, 5vw, 24px);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.result-sub { margin: 6px 0 0; color: var(--muted); font-variant-numeric: tabular-nums; }

@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Summary ---------- */
#summary { display: grid; place-items: center; overflow-y: auto; }
.summary-card {
  width: min(420px, 100%);
  text-align: center;
  padding: 24px 8px;
}
.summary-card h2 { margin: 0 0 6px; font-weight: 600; }
.headline { font-size: clamp(3rem, 14vw, 4.5rem); font-weight: 700; margin: 0; line-height: 1; font-variant-numeric: tabular-nums; }
.summary-card > .muted { margin: 4px 0 0; }
.badge {
  display: inline-block;
  margin: 12px 0 0;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--btn-text);
  font-weight: 600;
  font-size: 0.85rem;
}
.squares { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px; margin: 20px auto 0; max-width: 340px; }
.squares span { width: 14px; height: 14px; border-radius: 3px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 22px 0 0; }
.stats div { background: var(--surface); border: 1px solid var(--surface-line); border-radius: 12px; padding: 10px 4px; }
.stats dt { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.stats dd { margin: 4px 0 0; font-size: 1.2rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.drift { margin: 18px 0 0; color: var(--text); min-height: 1.3em; }
.actions { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-top: 24px; }

@media (max-width: 360px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
}

/* ---------- Overlay / toast ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(5, 8, 16, 0.6);
  animation: fadein 200ms ease-out;
}
.overlay[hidden] { display: none; }
.overlay-card {
  width: min(380px, 100%);
  background: var(--bg);
  border: 1px solid var(--surface-line);
  border-radius: 20px;
  padding: 24px;
  text-align: center;
}
.overlay-card h2 { margin: 0 0 12px; }
.overlay-card ol { text-align: left; padding-left: 1.3em; margin: 0 0 20px; line-height: 1.5; }
.overlay-card li + li { margin-top: 6px; }
.help-card { width: min(420px, 100%); max-height: calc(100dvh - 32px); overflow-y: auto; text-align: left; }
.help-card h2, .help-card > button, .help-kicker { display: block; margin-inline: auto; text-align: center; }
.help-kicker { margin: 0 0 2px; color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.12em; }
.help-card h2 { color: var(--accent); }
.help-intro { margin: 0 0 12px; line-height: 1.45; color: var(--muted); }
.help-mode[hidden] { display: none; }
.help-mode ul { margin: 0; padding-left: 1.2em; line-height: 1.5; }
.help-mode li + li { margin-top: 6px; }
#play .topbar #btn-mode-help { margin-right: -8px; }
#laps-desc { text-align: left; line-height: 1.5; }
#laps-desc p { margin: 0 0 10px; }
.lap-dots { display: flex; justify-content: center; gap: 14px; margin: 4px 0 16px; }
.lap-dots span {
  width: 16px; height: 16px;
  border-radius: 50%;
  border: 2px solid var(--muted);
}
.lap-dots span.target { background: var(--accent); border-color: var(--accent); }
.check {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 16px 0 18px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}
.check input { width: 20px; height: 20px; margin: 0; accent-color: var(--accent); cursor: pointer; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

.toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  z-index: 20;
  transform: translate(-50%, 16px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease-out, transform 200ms ease-out;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (prefers-reduced-motion: reduce) {
  .result, .result.show { transform: none; }
  .caption, .hint { animation: fadein 200ms ease-out; }
  .primary:active { transform: none; }
}
@media (max-width: 400px) {
  .topbar { gap: 8px; }
}
.modes-title { margin: 0; color: var(--muted); font-size: 0.85rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.12em; }
/* Home footer: look comes from footer.css; this only places it full width at the bottom of the screen. */
#home > .site-footer {
  align-self: stretch;
  margin: 0 calc(-1 * max(16px, env(safe-area-inset-right))) calc(-1 * max(16px, env(safe-area-inset-bottom)))
    calc(-1 * max(16px, env(safe-area-inset-left)));
}
/* Short windows: let the menu scroll instead of cutting off the last cards and links. */
#home { overflow-y: auto; scrollbar-gutter: stable; } /* same footer width as the content pages */
/* "Dead On!" wordmark (Rubik Dirt, single weight: no faux bold) */
#home-title { font-family: "Rubik Dirt", system-ui, sans-serif; font-weight: 400; letter-spacing: 0.01em; }
