/* ============================================================= tokens */

* { margin: 0; padding: 0; box-sizing: border-box; }

/* Dark is the base look; light overrides below follow the device setting. */
:root {
  --bg: #0d0f1a;
  --panel: #171a2b;
  --panel-2: #232741;
  --text: #f4f5fa;
  --dim: #9aa0b8;
  --accent: #7c5cff;
  --on-accent: #ffffff;
  --good: #22c55e;
  --bad: #f59e0b;
  --urgent: #ef4444;
  --grad-1: #a78bfa;
  --grad-2: #f472b6;
  --grad-3: #fbbf24;
  --ready-glow: #1d2140;
  --timeup: #b91c1c;
  --shadow: rgba(0, 0, 0, 0.45);
  --radius: 22px;
}

@media (prefers-color-scheme: light) {
  :root {
    /* Tinted light — lavender-grey ground, deep ink text, darker accents
       so everything keeps real contrast. */
    --bg: #edeaf6;
    --panel: #ffffff;
    --panel-2: #dfdaee;
    --text: #211c36;
    --dim: #5a546f;
    --accent: #6d28d9;
    --on-accent: #ffffff;
    --good: #15803d;
    --bad: #b45309;
    --urgent: #dc2626;
    --grad-1: #7c3aed;
    --grad-2: #db2777;
    --grad-3: #d97706;
    --ready-glow: #ddd6f0;
    --timeup: #dc2626;
    --shadow: rgba(60, 45, 110, 0.22);
  }
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overscroll-behavior: none;
}

#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
}

#stage.rotated {
  inset: auto;
  top: 50%;
  left: 50%;
  transform-origin: center center;
}

.screen {
  display: none;
  position: absolute;
  inset: 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: calc(env(safe-area-inset-top) + 16px)
           calc(env(safe-area-inset-right) + 20px)
           calc(env(safe-area-inset-bottom) + 16px)
           calc(env(safe-area-inset-left) + 20px);
  text-align: center;
}
.screen.active { display: flex; }

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
}

.hidden { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ============================================================= home */

#screen-home {
  justify-content: flex-start;
  overflow-y: auto;
  gap: 16px;
}

.home-header { position: relative; width: 100%; padding-top: 8px; }

.home-header h1 {
  font-size: clamp(2.2rem, 8vw, 3.2rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(100deg, var(--grad-1), var(--grad-2) 55%, var(--grad-3));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.subtitle {
  color: var(--dim);
  font-size: 0.95rem;
  margin-top: 4px;
  text-wrap: balance;
}

.header-controls {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

#mute-btn { font-size: 1.4rem; padding: 6px; }

/* Language picker: a pill-styled <select>, ready for many languages. */
#lang-picker {
  appearance: none;
  -webkit-appearance: none;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text);
  background: var(--panel);
  border: none;
  border-radius: 999px;
  padding: 6px 26px 6px 14px;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23888da5' stroke-width='1.8' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}
#lang-picker:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* --- mode switcher --- */

#mode-picker {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  width: min(100%, 420px);
  background: var(--panel);
  padding: 6px;
  border-radius: 18px;
  box-shadow: 0 4px 14px var(--shadow);
}
#mode-picker button {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 8px;
  border-radius: 13px;
  color: var(--dim);
}
#mode-picker button.selected {
  background: var(--accent);
  color: var(--on-accent);
}
#mode-picker .mode-name { font-weight: 800; font-size: 1rem; }
#mode-picker .mode-desc { font-size: 0.72rem; opacity: 0.85; }

/* --- "best on a phone" notice (forehead mode on desktop) --- */

#phone-notice {
  display: flex;
  align-items: center;
  gap: 16px;
  text-align: left;
  width: min(100%, 560px);
  background: var(--panel);
  border: 1px solid var(--accent);
  border-radius: 14px;
  padding: 12px 18px;
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--dim);
}
#phone-notice b { color: var(--text); }
#phone-notice img {
  flex: none;
  width: 120px;
  height: 120px;
  border-radius: 10px;
  background: #fff; /* QR needs a light tile in dark mode */
}

/* --- deck grid --- */

#deck-list {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  width: min(100%, 420px);
}

/* Calm cards: neutral panel with one small color accent (the emoji chip). */
.deck-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  padding: 14px 14px 12px;
  border-radius: 18px;
  text-align: left;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--panel-2);
  box-shadow: 0 3px 10px var(--shadow);
  transition: transform 0.12s ease;
  min-height: 116px;
}
.deck-card:active { transform: scale(0.96); }

.deck-emoji {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  font-size: 1.5rem;
}
.deck-name { font-size: 1.02rem; font-weight: 700; line-height: 1.15; }
.deck-count {
  margin-top: auto;
  font-size: 0.72rem;
  color: var(--dim);
}
.deck-season {
  position: absolute;
  bottom: 10px; right: 10px; /* top-right corner belongs to the checkmark */
  font-size: 0.66rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--on-accent);
}

/* --- multi-deck selection --- */

.deck-check {
  position: absolute;
  top: 10px; right: 10px;
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 2px solid var(--panel-2);
  color: transparent;
  font-size: 0.8rem;
  font-weight: 800;
  transition: background 0.12s, border-color 0.12s;
}
.deck-card.selected { border-color: var(--accent); }
.deck-card.selected .deck-check {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

#start-bar {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 14px);
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: calc(100vw - 24px);
  background: var(--accent);
  padding: 8px 8px 8px 20px;
  border-radius: 999px;
  box-shadow: 0 10px 30px var(--shadow),
              0 4px 26px rgba(124, 92, 255, 0.45);
  z-index: 20;
  animation: bar-rise 0.22s ease;
}
@keyframes bar-rise {
  from { opacity: 0; transform: translate(-50%, 14px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}
#start-count {
  color: var(--on-accent);
  opacity: 0.92;
  font-weight: 700;
  font-size: 0.95rem;
  white-space: nowrap;
}
#btn-start {
  background: var(--on-accent);
  color: var(--accent);
  font-weight: 800;
  font-size: 1.05rem;
  padding: 12px 26px;
  border-radius: 999px;
}
#btn-start:active { transform: scale(0.97); }

/* Keep the last decks reachable above the floating bar. */
#screen-home.selecting { padding-bottom: 96px; }

/* --- footer / settings --- */

.home-footer { margin-top: 4px; width: 100%; }
.time-label {
  display: block;
  font-size: 0.8rem;
  color: var(--dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 8px;
}

#time-picker {
  display: inline-flex;
  gap: 6px;
  background: var(--panel);
  padding: 5px;
  border-radius: 999px;
  box-shadow: 0 4px 14px var(--shadow);
}
#time-picker button {
  padding: 8px 18px;
  border-radius: 999px;
  font-weight: 600;
  color: var(--dim);
}
#time-picker button.selected { background: var(--accent); color: var(--on-accent); }

.how-to {
  margin-top: 14px;
  font-size: 0.85rem;
  color: var(--dim);
  line-height: 1.5;
  text-wrap: balance;
}
.how-to b { color: var(--text); }

/* --- about / SEO copy --- */

.about {
  width: min(100%, 420px);
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--panel-2);
  text-align: left;
  display: grid;
  gap: 8px;
}
.about h2 {
  font-size: 0.95rem;
  font-weight: 700;
}
.about p {
  font-size: 0.83rem;
  color: var(--dim);
  line-height: 1.55;
}
.about h3 {
  font-size: 0.86rem;
  font-weight: 700;
  margin-top: 4px;
}
.about p a { color: var(--accent); }

/* ============================================================ ready */

#screen-ready {
  gap: 14px;
  background: radial-gradient(ellipse at 50% 30%, var(--ready-glow) 0%, var(--bg) 70%);
}

.ready-deck { font-size: 1.1rem; font-weight: 700; color: var(--dim); }

#screen-ready h2 { font-size: clamp(1.8rem, 6vw, 2.6rem); font-weight: 800; }

#screen-ready p { color: var(--dim); max-width: 36ch; line-height: 1.5; }

#ready-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 3.4rem;
  padding: 18px 30px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 3px solid transparent;
  box-shadow: 0 8px 24px var(--shadow);
  transition: border-color 0.2s, box-shadow 0.2s;
}
#ready-indicator .phone-icon { animation: lift 1.6s ease-in-out infinite; }
#ready-indicator.ok {
  border-color: var(--good);
  box-shadow: 0 0 30px rgba(34, 197, 94, 0.35);
}
#ready-indicator.ok .phone-icon { animation: none; }

@keyframes lift {
  0%, 100% { transform: translateY(6px) rotate(-8deg); }
  50%      { transform: translateY(-8px) rotate(0deg); }
}

/* ======================================================== countdown */

#screen-countdown { background: var(--bg); }

#countdown-number {
  font-size: clamp(7rem, 40vh, 14rem);
  font-weight: 800;
  color: var(--accent);
}
#countdown-number.pop { animation: pop 0.85s ease-out; }

@keyframes pop {
  0%   { transform: scale(1.6); opacity: 0.2; }
  35%  { transform: scale(1);   opacity: 1; }
  100% { transform: scale(0.92); opacity: 0.9; }
}

/* ============================================================= play */

#screen-play { padding: 0; }

#play-stage {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  transition: background 0.12s;
}
#play-stage.flash-correct { background: var(--good); }
#play-stage.flash-pass    { background: var(--bad); }

.play-topbar {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 10px);
  left: calc(env(safe-area-inset-left) + 16px);
  right: calc(env(safe-area-inset-right) + 16px);
  display: flex;
  align-items: center;
  gap: 14px;
}

#timer {
  font-size: 1.6rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
#timer.urgent { color: var(--urgent); animation: pulse 1s infinite; }

@keyframes pulse {
  50% { opacity: 0.35; }
}

#score-pill {
  font-weight: 700;
  background: var(--panel);
  padding: 4px 14px;
  border-radius: 999px;
}

#btn-quit {
  margin-left: auto;
  font-size: 1.3rem;
  color: var(--dim);
  padding: 6px 10px;
}

#word {
  font-size: clamp(2.2rem, 11vw, 5.5rem);
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.01em;
  padding: 0 6vw;
  text-wrap: balance;
}

#word { transition: filter 0.35s ease, opacity 0.35s ease; }
#word.blurred {
  filter: blur(18px);
  opacity: 0.55;
}

#peek-hint {
  position: absolute;
  bottom: 28%;
  left: 0; right: 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--dim);
  pointer-events: none;
}

#verdict {
  position: absolute;
  font-size: clamp(3rem, 14vw, 7rem);
  font-weight: 900;
  color: #fff;
  text-shadow: 0 6px 24px rgba(0, 0, 0, 0.3);
}

#play-stage.flash-correct #word,
#play-stage.flash-pass #word { color: #fff; }

#fallback-controls {
  position: absolute;
  bottom: calc(env(safe-area-inset-bottom) + 14px);
  left: 0; right: 0;
  display: flex;
  justify-content: center;
  gap: 14px;
}
#fallback-controls button {
  font-size: 1.05rem;
  font-weight: 700;
  padding: 12px 22px;
  border-radius: 14px;
  color: #fff;
}
#btn-pass    { background: rgba(217, 119, 6, 0.9); }
#btn-correct { background: rgba(21, 128, 61, 0.9); }

/* ========================================================== time up */

#screen-timeup { background: var(--timeup); }
.timeup-text {
  font-size: clamp(3rem, 16vw, 8rem);
  font-weight: 900;
  color: #fff;
  animation: pop 0.85s ease-out;
}

/* ========================================================== results */

#screen-results { justify-content: flex-start; gap: 10px; overflow-y: auto; }

#screen-results h2 { margin-top: 8px; color: var(--dim); font-weight: 600; }

.score-big span {
  font-size: clamp(4rem, 20vw, 7rem);
  font-weight: 800;
  color: var(--good);
}
#result-total { color: var(--dim); }

#result-list {
  list-style: none;
  width: min(100%, 420px);
  margin: 10px 0;
  display: grid;
  gap: 6px;
}
#result-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  background: var(--panel);
  border-radius: 12px;
  padding: 10px 14px;
  font-weight: 600;
  box-shadow: 0 2px 8px var(--shadow);
}
#result-list li .mark { font-weight: 800; width: 1.2em; }
#result-list li.good .mark { color: var(--good); }
#result-list li.bad .mark { color: var(--bad); }
#result-list li.bad .w { text-decoration: line-through; opacity: 0.65; }

.result-actions {
  margin-top: auto;
  padding-top: 10px;
  display: grid;
  gap: 10px;
  width: min(100%, 420px);
}

/* ========================================================== buttons */

.big-btn {
  background: var(--accent);
  color: var(--on-accent);
  font-size: 1.15rem;
  font-weight: 700;
  padding: 16px 20px;
  border-radius: 16px;
  box-shadow: 0 8px 22px var(--shadow);
}
.big-btn:active { transform: scale(0.97); }

.ghost-btn {
  color: var(--dim);
  font-weight: 600;
  padding: 12px;
}

button:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* ------------------------------------------- static pages & site links */

body.static-page { overflow: auto; height: auto; min-height: 100%; }

.static-content {
  max-width: 620px;
  margin: 0 auto;
  padding: 48px 24px calc(env(safe-area-inset-bottom) + 48px);
  display: grid;
  gap: 18px;
}
.static-content h1 { font-size: 1.9rem; font-weight: 800; text-wrap: balance; }
.static-content p { color: var(--dim); line-height: 1.6; }

/* Printable-cards download list. */
.pdf-all {
  display: block;
  text-align: center;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 700;
  padding: 14px 20px;
  border-radius: 14px;
  text-decoration: none;
  box-shadow: 0 6px 18px var(--shadow);
}
.pdf-all:active { transform: scale(0.98); }

.pdf-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 10px;
}
.pdf-list a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--panel-2);
  border-radius: 12px;
  padding: 12px 14px;
  color: var(--text);
  font-weight: 600;
  text-decoration: none;
  box-shadow: 0 2px 8px var(--shadow);
}
.pdf-list a:hover { border-color: var(--accent); }
.pdf-list a span {
  color: var(--dim);
  font-weight: 500;
  font-size: 0.8rem;
  white-space: nowrap;
}

.site-links {
  display: grid;
  gap: 8px;
  padding-top: 8px;
}
.site-links a {
  color: var(--accent);
  font-weight: 600;
  font-size: 0.88rem;
  text-decoration: none;
}
.site-links a:hover { text-decoration: underline; }

/* Exit button available on every pre-game screen. */
.screen-close {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 10px);
  right: calc(env(safe-area-inset-right) + 14px);
  font-size: 1.35rem;
  color: var(--dim);
  padding: 8px 12px;
  z-index: 5;
}

/* ==================================================== big screens */

/* Laptops, desktops and large tablets: the game is watched from across
   the room, so scale the play surface up and let the home screen breathe
   instead of staying phone-column narrow. */
@media (min-width: 760px) {
  #screen-home { gap: 20px; }

  /* The floating bottom bar gets lost on a large screen — dock the start
     bar in the flow, right above the deck grid, via flex order. */
  .home-header { order: 1; }
  #mode-picker { order: 2; }
  #phone-notice { order: 2; font-size: 1.05rem; }

  .header-controls { gap: 14px; }
  #lang-picker {
    font-size: 1.05rem;
    padding: 10px 36px 10px 18px;
    background-position: right 14px center;
    background-size: 12px 8px;
  }
  #mute-btn { font-size: 2rem; padding: 8px 10px; }
  #start-bar {
    order: 3;
    position: static;
    transform: none;
    animation: bar-drop 0.22s ease;
    padding: 10px 10px 10px 24px;
  }
  @keyframes bar-drop {
    from { opacity: 0; transform: translateY(-10px); }
    to   { opacity: 1; transform: none; }
  }
  #start-count { font-size: 1.05rem; }
  #btn-start { font-size: 1.15rem; padding: 14px 32px; }
  #deck-list { order: 4; }
  .home-footer { order: 5; }
  .about { order: 6; }
  /* The bar no longer floats, so no extra room needed at the bottom. */
  #screen-home.selecting {
    padding-bottom: calc(env(safe-area-inset-bottom) + 16px);
  }

  #mode-picker { width: min(100%, 560px); }
  #mode-picker button { padding: 14px 10px; }
  #mode-picker .mode-name { font-size: 1.15rem; }
  #mode-picker .mode-desc { font-size: 0.8rem; }

  #deck-list {
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
    width: min(100%, 780px);
  }
  .deck-card { min-height: 136px; padding: 16px 16px 14px; }
  .deck-emoji { width: 52px; height: 52px; font-size: 1.8rem; }
  .deck-name { font-size: 1.12rem; }
  .deck-count { font-size: 0.8rem; }

  .about { width: min(100%, 640px); }
  .about h2 { font-size: 1.05rem; }
  .about p { font-size: 0.92rem; }
  .how-to { font-size: 0.95rem; }

  #screen-ready h2 { font-size: clamp(2.2rem, 5vw, 3.4rem); }
  #screen-ready p { max-width: 52ch; font-size: 1.1rem; }
  #ready-indicator { font-size: 4.2rem; }

  #timer { font-size: 2.4rem; }
  #score-pill { font-size: 1.2rem; padding: 6px 20px; }
  #btn-quit { font-size: 1.7rem; }
  #word { font-size: clamp(4rem, 11vw, 11rem); padding: 0 8vw; }
  #verdict { font-size: clamp(4rem, 13vw, 10rem); }
  #peek-hint { font-size: 1.3rem; }

  #fallback-controls {
    gap: 22px;
    bottom: calc(env(safe-area-inset-bottom) + 28px);
  }
  #fallback-controls button {
    font-size: 1.4rem;
    padding: 18px 36px;
    border-radius: 18px;
  }

  .timeup-text { font-size: clamp(4rem, 14vw, 11rem); }

  .score-big span { font-size: clamp(5rem, 16vw, 9rem); }
  #result-list { width: min(100%, 640px); }
  #result-list li { font-size: 1.1rem; padding: 12px 18px; }
  .result-actions { width: min(100%, 640px); }
  .big-btn { font-size: 1.3rem; }
}

@media (min-width: 1200px) {
  #deck-list { grid-template-columns: repeat(4, 1fr); width: min(100%, 1020px); }
}
