:root {
  --bg: #0c0d12;
  --bg-soft: #14161d;
  --bg-card: #191c25;
  --text: #f2f4f9;
  --muted: #949cb0;
  --line: #262a36;
  --glow: #15181f;
  --accent: #fb7185;
  --good: #4ecdc4;
  --warn: #ffd93d;
  --bad: #ff6b6b;
  --radius: 18px;
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
}

:root[data-theme="classic"] {
  --bg: #12141c;
  --bg-soft: #1b1e2b;
  --bg-card: #21273a;
  --text: #eef1f7;
  --muted: #9aa3b8;
  --line: #2e3550;
  --glow: #1d2233;
  --accent: #ff6b6b;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

/* Per-game accents (refined default) */
.card[data-game="hue-hunt"]   { --accent: #fb7185; }
.card[data-game="echo"]       { --accent: #2dd4bf; }
.card[data-game="chromatic"]  { --accent: #fbbf24; }
.card[data-game="flash"]      { --accent: #a78bfa; }
.card[data-game="flashmath"]  { --accent: #fb923c; }
.card[data-game="sprint"]     { --accent: #38bdf8; }
.card[data-game="digit-span"] { --accent: #34d399; }
.card[data-game="interval"]   { --accent: #c084fc; }
.card[data-game="where"]      { --accent: #60a5fa; }

:root[data-theme="classic"] .card[data-game="hue-hunt"]   { --accent: #ff6b6b; }
:root[data-theme="classic"] .card[data-game="echo"]       { --accent: #4ecdc4; }
:root[data-theme="classic"] .card[data-game="chromatic"]  { --accent: #ffd93d; }
:root[data-theme="classic"] .card[data-game="flash"]      { --accent: #9b8cff; }
:root[data-theme="classic"] .card[data-game="flashmath"]  { --accent: #ff9f43; }
:root[data-theme="classic"] .card[data-game="sprint"]     { --accent: #5fd1f9; }
:root[data-theme="classic"] .card[data-game="digit-span"] { --accent: #26de81; }
:root[data-theme="classic"] .card[data-game="interval"]   { --accent: #c56cf0; }
:root[data-theme="classic"] .card[data-game="where"]      { --accent: #54a0ff; }

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

html, body {
  margin: 0;
  padding: 0;
  background: radial-gradient(1100px 700px at 50% -20%, var(--glow), var(--bg));
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  min-height: 100%;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

a, button {
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

a { color: inherit; text-decoration: none; }

/* ---------- HUB ---------- */
.hub-head {
  text-align: center;
  padding: max(64px, calc(48px + env(safe-area-inset-top))) 20px 24px;
}
.logo {
  font-size: clamp(2.4rem, 7vw, 4.2rem);
  font-weight: 900;
  letter-spacing: 6px;
  margin: 0;
  background: linear-gradient(90deg, #fb7185, #fbbf24, #2dd4bf);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
:root[data-theme="classic"] .logo {
  background: linear-gradient(90deg, #ff6b6b, #ffd93d, #4ecdc4);
  -webkit-background-clip: text;
  background-clip: text;
}
.tagline { color: var(--muted); font-size: 1.05rem; margin-top: 10px; }

.theme-switch { margin-top: 16px; }
.theme-btn {
  font-family: inherit;
  font-size: .82rem;
  font-weight: 600;
  color: var(--muted);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  padding: 7px 15px;
  border-radius: 999px;
  cursor: pointer;
  transition: color .15s, border-color .15s, background .15s;
}
.theme-btn:active { transform: scale(.97); }
@media (hover: hover) {
  .theme-btn:hover { color: var(--text); border-color: var(--accent); }
}

.grid {
  max-width: 1000px;
  margin: 0 auto;
  padding: 20px;
  padding-left: max(20px, env(safe-area-inset-left));
  padding-right: max(20px, env(safe-area-inset-right));
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 22px;
}
.card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 26px;
  transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease;
  position: relative;
  overflow: hidden;
}
.card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 5px;
  background: var(--accent);
}
@media (hover: hover) {
  .card:hover {
    transform: translateY(-6px);
    border-color: var(--accent);
    box-shadow: var(--shadow);
  }
}
.card:active {
  transform: translateY(-2px) scale(.99);
  border-color: var(--accent);
  box-shadow: var(--shadow);
}
.card-emoji { font-size: 2.6rem; }
.card h2 { margin: 12px 0 8px; font-size: 1.5rem; }
.card p { color: var(--muted); line-height: 1.5; margin: 0 0 16px; }
.tag {
  display: inline-block;
  font-size: .78rem;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--accent);
  border: 1px solid currentColor;
  padding: 4px 10px;
  border-radius: 999px;
  opacity: .9;
}
.hub-foot { text-align: center; color: var(--muted); padding: 30px; font-size: .9rem; }

/* ---------- GAME SHELL ---------- */
.game {
  max-width: 640px;
  margin: 0 auto;
  padding: 20px 18px 60px;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0 18px;
}
.back {
  color: var(--muted);
  font-size: .95rem;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  transition: background .15s;
}
.back:hover { background: var(--bg-soft); }
.game h1 { font-size: 1.5rem; margin: 0; }

.stats {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.stat {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 16px;
  min-width: 84px;
  text-align: center;
}
.stat .label { display: block; font-size: .72rem; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }
.stat .value { font-size: 1.5rem; font-weight: 800; }

.btn {
  appearance: none;
  border: none;
  background: var(--accent);
  color: #10131c;
  font-weight: 800;
  font-size: 1rem;
  padding: 12px 22px;
  border-radius: 12px;
  cursor: pointer;
  transition: transform .12s, filter .12s;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: scale(.97); }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }

.center { text-align: center; }
.hint { color: var(--muted); font-size: .95rem; }
.hidden { display: none !important; }

/* ---------- HUE HUNT ---------- */
#board {
  display: grid;
  gap: 8px;
  margin: 0 auto 18px;
  aspect-ratio: 1;
  max-width: 460px;
  width: 100%;
}
.tile {
  border-radius: 10px;
  cursor: pointer;
  transition: transform .08s;
  border: none;
}
.tile:active { transform: scale(.94); }
.timerbar {
  height: 10px;
  border-radius: 999px;
  background: var(--bg-soft);
  overflow: hidden;
  margin: 0 auto 20px;
  max-width: 460px;
}
.timerbar > span {
  display: block;
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--good), var(--warn), var(--bad));
  transform-origin: left;
}
.flash-good { animation: pop .3s ease; }
@keyframes pop { 0%{transform:scale(1)} 50%{transform:scale(1.03)} 100%{transform:scale(1)} }

/* ---------- ECHO ---------- */
.pads {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  max-width: 420px;
  margin: 0 auto 22px;
}
.pad {
  aspect-ratio: 1;
  border-radius: 20px;
  border: none;
  cursor: pointer;
  opacity: .55;
  transition: opacity .12s, transform .08s;
}
.pad.lit { opacity: 1; transform: scale(1.03); box-shadow: 0 0 40px currentColor; }
.pad:active { transform: scale(.97); }
.pad.p0 { background: #ff6b6b; color: #ff6b6b; }
.pad.p1 { background: #4ecdc4; color: #4ecdc4; }
.pad.p2 { background: #ffd93d; color: #ffd93d; }
.pad.p3 { background: #9b8cff; color: #9b8cff; }

/* ---------- CHROMATIC ---------- */
.target-wrap { text-align: center; margin-bottom: 16px; }
.picker { display: grid; gap: 14px; margin: 0 auto 18px; max-width: 460px; }
.slider-row { display: grid; grid-template-columns: 24px 1fr 46px; align-items: center; gap: 12px; }
.slider-row label { font-weight: 800; }
.slider-row input[type=range] { width: 100%; accent-color: var(--accent); }
.swatch-preview {
  height: 70px; border-radius: 12px; border: 1px solid var(--line); margin: 0 auto 16px; max-width: 460px;
}
.guess-list { display: grid; gap: 10px; max-width: 460px; margin: 0 auto 18px; }
.guess-row {
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 12px;
  align-items: center;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 12px;
}
.guess-swatch { width: 44px; height: 44px; border-radius: 8px; }
.feedback { display: flex; gap: 14px; font-size: .9rem; flex-wrap: wrap; }
.feedback .fb { display: flex; align-items: center; gap: 4px; }
.fb .ch { font-weight: 800; }
.fb .arrow { font-size: 1.05rem; }
.close { color: var(--good); font-weight: 800; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 30px;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-card);
  border: 1px solid var(--line);
  padding: 12px 20px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: opacity .2s, transform .2s;
  pointer-events: none;
  z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 18, .78);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 60;
}
.modal {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 30px;
  text-align: center;
  max-width: 380px;
  width: 100%;
  box-shadow: var(--shadow);
}
.modal h2 { margin-top: 0; font-size: 1.8rem; }
.modal .big { font-size: 3rem; font-weight: 900; margin: 6px 0; }
.modal .btn { margin-top: 16px; }
