:root {
  --bg0: #0a0e14;
  --ink: #e8eef7;
  --muted: #8a9bb0;
  --accent: #6ec6a8;
  --accent2: #7aa2ff;
  --warm: #e8b86d;
  --card: rgba(16, 22, 34, 0.72);
  --stroke: rgba(180, 210, 255, 0.14);
  --radius: 18px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg0);
}
body { overflow-x: hidden; }

#ambient {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
}

#app {
  position: relative;
  z-index: 1;
  max-width: 920px;
  margin: 0 auto;
  padding: 1.25rem 1.25rem 3rem;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 0.85rem; }
.brand-mark {
  width: 2.4rem; height: 2.4rem;
  display: grid; place-items: center;
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(110,198,168,.35), rgba(122,162,255,.35));
  border: 1px solid var(--stroke);
  font-size: 1.2rem;
  color: var(--accent);
}
.brand h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 650;
  letter-spacing: 0.02em;
}
.tagline {
  margin: 0.1rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}
.top-controls { display: flex; gap: 0.5rem; }

.card {
  background: var(--card);
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  padding: 1.35rem 1.4rem;
  backdrop-filter: blur(14px);
  box-shadow: 0 18px 50px rgba(0,0,0,.28);
}
.hero h2, .summary h2, #view-progress h2 {
  margin: 0 0 0.6rem;
  font-weight: 650;
}
.hero p { margin: 0 0 1.1rem; line-height: 1.55; color: #c5d0e0; }
.hero-actions, .play-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  margin-bottom: 0.75rem;
}
.muted { color: var(--muted); font-size: 0.9rem; }
.kind { font-size: 1.05rem; line-height: 1.55; color: #d7e4f5; }

button {
  font: inherit;
  cursor: pointer;
  border-radius: 999px;
  border: 1px solid var(--stroke);
  padding: 0.65rem 1.15rem;
  background: rgba(255,255,255,0.04);
  color: var(--ink);
  transition: background .2s, border-color .2s, transform .15s;
}
button:hover { background: rgba(255,255,255,0.09); }
button:active { transform: scale(0.98); }
button:focus-visible { outline: 2px solid var(--accent2); outline-offset: 2px; }
button.primary {
  background: linear-gradient(135deg, #3d8f78, #4a6fbf);
  border-color: transparent;
  font-weight: 600;
}
button.primary:hover { filter: brightness(1.08); }
button.ghost { background: transparent; }
button:disabled { opacity: 0.45; cursor: not-allowed; }

.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 0.85rem;
  margin-top: 0.5rem;
}
.game-card {
  text-align: left;
  border-radius: var(--radius);
  padding: 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  background: var(--card);
  border: 1px solid var(--stroke);
}
.game-card .g-ico {
  color: var(--accent);
  font-size: 1.35rem;
  margin-bottom: 0.2rem;
}
.game-card strong { font-size: 1rem; }
.game-card span:last-child {
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.35;
}

.view[hidden], [hidden] { display: none !important; }
.view.active { display: block; }

.session-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.85rem 1.15rem;
  margin-bottom: 0.85rem;
}
.phase {
  font-weight: 650;
  color: var(--warm);
  margin-right: 0.6rem;
}
.score-chip {
  background: rgba(110,198,168,0.12);
  border: 1px solid rgba(110,198,168,0.28);
  border-radius: 999px;
  padding: 0.35rem 0.85rem;
  font-size: 0.9rem;
}

.stage { min-height: 280px; }
.stage h3 {
  margin: 0 0 0.35rem;
  font-size: 1.15rem;
}
.prompt {
  margin: 0.4rem 0 1rem;
  color: #c5d0e0;
  line-height: 1.45;
}
.feedback {
  margin-top: 0.9rem;
  min-height: 1.4rem;
  font-weight: 560;
}
.feedback.ok { color: var(--accent); }
.feedback.bad { color: #f0a0a0; }

/* Memory grid */
.mem-grid {
  display: grid;
  gap: 8px;
  margin: 1rem auto;
  width: min(100%, 320px);
}
.mem-cell {
  aspect-ratio: 1;
  border-radius: 10px;
  border: 1px solid var(--stroke);
  background: rgba(255,255,255,0.04);
  padding: 0;
  cursor: pointer;
}
.mem-cell.lit {
  background: linear-gradient(145deg, #6ec6a8, #7aa2ff);
  box-shadow: 0 0 18px rgba(110,198,168,0.45);
  border-color: transparent;
}
.mem-cell.pick {
  background: rgba(232,184,109,0.55);
  border-color: var(--warm);
}
.mem-cell.correct {
  background: rgba(110,198,168,0.7);
}
.mem-cell.wrong {
  background: rgba(220,90,90,0.55);
}

/* Choices */
.choices {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  margin-top: 0.5rem;
}
.choices button {
  min-width: 3.2rem;
  border-radius: 12px;
  font-size: 1.05rem;
}

/* Word / math */
.scramble {
  font-size: 1.85rem;
  letter-spacing: 0.22em;
  font-weight: 650;
  color: var(--accent2);
  margin: 0.6rem 0 1rem;
  text-align: center;
}
.input-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  align-items: center;
}
.input-row input {
  flex: 1;
  min-width: 140px;
  font: inherit;
  font-size: 1.1rem;
  padding: 0.7rem 0.9rem;
  border-radius: 12px;
  border: 1px solid var(--stroke);
  background: rgba(0,0,0,0.28);
  color: var(--ink);
}
.input-row input:focus {
  outline: 2px solid var(--accent2);
  outline-offset: 1px;
}
.timer {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
}
.math-q {
  font-size: 2rem;
  font-weight: 650;
  text-align: center;
  margin: 1rem 0;
  letter-spacing: 0.04em;
}

.stat-list {
  list-style: none;
  padding: 0;
  margin: 0 0 1.1rem;
}
.stat-list li {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--stroke);
  font-size: 0.95rem;
}
.stat-list li span:last-child { color: var(--accent); font-weight: 600; }

.foot {
  margin-top: auto;
  text-align: center;
  font-size: 0.8rem;
  padding-top: 0.5rem;
}

@media (max-width: 520px) {
  .brand h1 { font-size: 1.05rem; }
  .scramble { font-size: 1.45rem; }
  .math-q { font-size: 1.55rem; }
}
