:root {
  --bg: #111418;
  --fg: #f5f3ee;
  --muted: #a3acb6;
  --line: #3a4048;
  --green: #007a33;   /* white text: 5.5:1 */
  --red: #c8102e;     /* white text: 5.9:1 */
  --go: #1f9d55;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

button { font: inherit; cursor: pointer; }

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* ---------- Start ---------- */

#start {
  overflow-y: auto;
  justify-content: safe center;
  gap: clamp(14px, 4vh, 32px);
  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));
  text-align: center;
  touch-action: pan-y;
}

h1 {
  font-size: clamp(1.5rem, 6vmin, 2.6rem);
  font-weight: 800;
  letter-spacing: -0.01em;
}

.start-btn {
  font-size: clamp(2.2rem, 11vmin, 4.5rem);
  font-weight: 900;
  padding: 0.3em 1.8em;
  border: 0;
  border-radius: 999px;
  background: var(--go);
  color: #fff;
  box-shadow: 0 6px 0 #146b39;
  transition: transform 0.08s, box-shadow 0.08s;
}
.start-btn:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 2px 0 #146b39; }
.start-btn:disabled { background: var(--line); color: #7d858e; box-shadow: none; cursor: default; }

.chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  max-width: 780px;
}

.chip {
  font-size: clamp(0.95rem, 3.2vmin, 1.15rem);
  font-weight: 700;
  padding: 0.6em 1.1em;
  border-radius: 999px;
  border: 2px solid var(--fg);
  background: var(--fg);
  color: var(--bg);
  transition: background 0.15s, color 0.15s, border-color 0.15s, opacity 0.15s;
}
.chip[aria-pressed="false"] {
  background: transparent;
  color: #6f7883;
  border-color: var(--line);
}

.rule { font-size: clamp(1rem, 3.4vmin, 1.25rem); color: var(--muted); font-weight: 600; }
.status { color: #ff8a80; font-weight: 600; }

.examples { max-width: 34em; color: var(--muted); font-size: clamp(0.95rem, 3.2vmin, 1.1rem); }
.examples summary { cursor: pointer; font-weight: 700; color: var(--fg); padding: 0.4em; }
.examples ul { list-style: none; padding: 0; margin-top: 0.4em; display: grid; gap: 0.35em; }
.status:empty { display: none; }

/* ---------- Countdown ---------- */

#countdown { background: var(--bg); touch-action: none; }

.cd-num {
  font-size: min(62vh, 45vw);
  font-weight: 900;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.cd-num.pop { animation: pop 0.9s ease-out; }
@keyframes pop {
  from { transform: scale(1.4); opacity: 0.15; }
  35%  { transform: scale(1);   opacity: 1; }
}

.cd-hint { font-size: clamp(1rem, 6vh, 2.2rem); font-weight: 800; color: var(--muted); }

.end-btn {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  font-size: 1rem;
  font-weight: 700;
  padding: 0.55em 1.1em;
  border-radius: 999px;
  border: 2px solid #5a626d;
  background: transparent;
  color: var(--fg);
}
.end-btn:active { background: #2a3037; }

/* ---------- Play ---------- */

/* One background per category; white text is at least 5.5:1 on each. */
#play {
  --cat: #1d5fa8;
  background: var(--cat);
  touch-action: none;
  gap: 2.5vh;
  padding: 4vh 5vw 8vh;
  text-align: center;
}

.number {
  font-weight: 900;
  color: #fff;
  white-space: nowrap;
  line-height: 1;
  font-variant-numeric: lining-nums;
  text-shadow: 0 0.03em 0 rgba(0, 0, 0, 0.25);
}

.word {
  max-width: 90vw;
  font-size: clamp(1rem, 11vh, 4rem);
  font-weight: 800;
  line-height: 1.1;
  color: rgba(255, 255, 255, 0.9);
  text-wrap: balance;
}
.word:empty { display: none; }

.play-hint {
  position: absolute;
  bottom: max(1.5vh, env(safe-area-inset-bottom));
  font-size: clamp(0.7rem, 3vh, 0.95rem);
  font-weight: 600;
  color: rgba(255, 255, 255, 0.55);
}

/* ---------- Portrait hint (iOS cannot lock orientation) ---------- */

.rotate {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  background: var(--bg);
  font-size: clamp(1.6rem, 8vw, 2.6rem);
  font-weight: 800;
  text-align: center;
  padding: 16px;
  touch-action: none;
}
.rotate-icon { width: 96px; height: 96px; color: var(--fg); animation: turn 2s ease-in-out infinite; }
@keyframes turn {
  0%, 25%  { transform: rotate(0deg); }
  60%, 100% { transform: rotate(-90deg); }
}

@media (orientation: portrait) {
  body.in-game .rotate { display: flex; }
}

@media (prefers-reduced-motion: reduce) {
  .cd-num.pop, .rotate-icon { animation: none; }
}
