:root {
  color-scheme: dark;
  --bg: #080b0f;
  --surface: #111821;
  --surface-strong: #17212c;
  --border: #263241;
  --text: #edf2f7;
  --muted: #93a4b5;
  --accent: #f2b84b;
  --accent-strong: #ffd27a;
  --blue: #61a5ff;
  --blue-strong: #9bc7ff;
  --success: #58d68d;
  --error: #ff6b6b;
  --warning: #f6c85f;
  --radius: 8px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.24);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100%;
  margin: 0;
  background-color: var(--bg);
  background-image: radial-gradient(circle, rgba(147, 164, 181, 0.12) 1px, transparent 1px);
  background-size: 28px 28px;
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
  letter-spacing: 0;
}

button,
textarea,
input {
  font: inherit;
}

a {
  color: inherit;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 64px;
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: rgba(8, 11, 15, 0.94);
  backdrop-filter: blur(12px);
}

.brand {
  color: var(--accent);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 1.05rem;
  font-weight: 800;
  text-decoration: none;
}

.brand span {
  color: var(--text);
}

.topbar-note,
.menu-link {
  color: var(--muted);
  font-size: 0.92rem;
  text-decoration: none;
}

.menu-link {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}

.menu-link:hover,
.menu-link:focus-visible {
  color: var(--text);
}

.page,
.game-page {
  width: min(100%, 980px);
  margin: 0 auto;
  padding: 2rem 1rem;
}

.home-page {
  padding-bottom: 3rem;
}

.hero {
  padding: 2rem 0 1.5rem;
}

.eyebrow {
  margin: 0 0 0.55rem;
  color: var(--accent);
  font-size: 0.9rem;
  font-weight: 700;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0.7rem;
  font-size: 3rem;
  line-height: 1.05;
}

h2 {
  font-size: 1.35rem;
  line-height: 1.15;
}

.lead {
  max-width: 42rem;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 1.08rem;
}

.menu-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  margin-top: 1.25rem;
}

.game-card {
  display: flex;
  min-height: 240px;
  flex-direction: column;
  justify-content: space-between;
  gap: 1.25rem;
  padding: 1.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  text-decoration: none;
}

.game-card:hover,
.game-card:focus-visible {
  border-color: var(--accent);
  outline: none;
}

.game-card.accent-two:hover,
.game-card.accent-two:focus-visible {
  border-color: var(--blue);
}

.card-index {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
}

.game-card h2 {
  margin: 0.45rem 0 0.5rem;
}

.game-card p {
  margin: 0;
  color: var(--muted);
}

.card-action {
  align-self: flex-start;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.7rem 1rem;
  border-radius: var(--radius);
  background: var(--accent);
  color: #1c1400;
  font-weight: 800;
}

.accent-two .card-action {
  background: var(--blue);
  color: #04111f;
}

.privacy-note {
  margin: 1.25rem 0 0;
  color: var(--muted);
  text-align: center;
}

.screen {
  min-height: calc(100vh - 104px);
  min-height: calc(100svh - 104px);
}

.intro-screen {
  display: grid;
  place-items: center;
}

.intro-copy {
  width: min(100%, 620px);
}

.instructions {
  margin: 1.5rem 0;
  padding: 1.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.instructions h2 {
  margin-bottom: 0.75rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.instructions ol {
  display: grid;
  gap: 0.55rem;
  margin: 0;
  padding-left: 1.25rem;
  color: var(--muted);
}

.instructions li::marker {
  color: var(--accent);
  font-weight: 800;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.actions.centered {
  justify-content: center;
  margin-top: 1rem;
}

.btn {
  min-height: 46px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  cursor: pointer;
  font-weight: 800;
  line-height: 1;
  text-decoration: none;
  transition: transform 120ms ease, opacity 120ms ease, border-color 120ms ease;
  touch-action: manipulation;
}

.btn:hover,
.btn:focus-visible {
  opacity: 0.88;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--accent);
  color: #1c1400;
}

.btn-blue {
  background: var(--blue);
  color: #04111f;
}

.btn-secondary {
  border-color: var(--border);
  background: var(--surface);
  color: var(--text);
}

.btn-small {
  min-height: 42px;
  padding: 0.6rem 0.8rem;
  font-size: 0.92rem;
}

.play-screen {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.game-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.75rem;
  align-items: center;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.6rem;
}

.stat {
  min-height: 68px;
  display: grid;
  place-items: center;
  padding: 0.55rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.stat-value {
  color: var(--accent);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 1.35rem;
  font-weight: 800;
  line-height: 1;
}

.blue-stat .stat-value {
  color: var(--blue);
}

.stat-label {
  color: var(--muted);
  font-size: 0.78rem;
}

.phase-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  color: var(--muted);
}

.phase-pill {
  display: inline-flex;
  min-height: 36px;
  align-items: center;
  padding: 0.45rem 0.7rem;
  border: 1px solid rgba(242, 184, 75, 0.45);
  border-radius: 999px;
  color: var(--accent-strong);
  background: rgba(242, 184, 75, 0.08);
  font-weight: 800;
}

.blue-pill {
  border-color: rgba(97, 165, 255, 0.45);
  color: var(--blue-strong);
  background: rgba(97, 165, 255, 0.08);
}

.phase-detail {
  text-align: right;
}

.timer {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-strong);
}

.timer-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.blue-fill {
  background: var(--blue);
}

.memory-arena {
  position: relative;
  flex: 1;
  min-height: 430px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(17, 24, 33, 0.78);
  box-shadow: var(--shadow);
}

.circle,
.target {
  position: absolute;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
}

.circle {
  display: grid;
  place-items: center;
  border: 2px solid var(--accent);
  background: #161f29;
  color: var(--accent-strong);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 1.2rem;
  font-weight: 900;
  pointer-events: none;
}

.circle.reveal {
  border-color: var(--error);
  color: var(--error);
  opacity: 0.88;
}

.target {
  border: 2px dashed rgba(242, 184, 75, 0.55);
  background: rgba(242, 184, 75, 0.06);
  cursor: pointer;
  touch-action: manipulation;
}

.target:hover,
.target:focus-visible {
  background: rgba(242, 184, 75, 0.14);
  outline: none;
}

.target.hit {
  border-color: var(--success);
  background: rgba(88, 214, 141, 0.18);
  pointer-events: none;
}

.target.miss {
  border-color: var(--error);
  background: rgba(255, 107, 107, 0.18);
  pointer-events: none;
}

.count-panel,
.answer-panel {
  width: min(100%, 620px);
  margin: 0 auto;
  padding: 1.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.count-panel {
  min-height: 300px;
  display: grid;
  place-items: center;
  text-align: center;
}

.challenge-meta {
  margin-bottom: 0.7rem;
  color: var(--blue-strong);
  font-weight: 800;
}

.number-flash {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 5rem;
  font-weight: 900;
  line-height: 1;
}

.answer-panel {
  display: grid;
  gap: 0.8rem;
}

.answer-prompt {
  margin-bottom: 0;
  color: var(--text);
  font-weight: 800;
}

.feedback {
  width: min(100%, 620px);
  margin: 0 auto;
  padding: 0.9rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}

.feedback.good {
  border-color: rgba(88, 214, 141, 0.55);
  background: rgba(88, 214, 141, 0.1);
}

.feedback.bad {
  border-color: rgba(255, 107, 107, 0.55);
  background: rgba(255, 107, 107, 0.1);
}

.feedback.warn {
  border-color: rgba(246, 200, 95, 0.55);
  background: rgba(246, 200, 95, 0.1);
}

.expected-sequence {
  display: block;
  margin-top: 0.45rem;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.equation-display {
  font-size: 3.5rem;
  letter-spacing: 0.03em;
}

.how-to-example {
  margin-top: 1.1rem;
}

.example-label {
  margin-bottom: 0.4rem;
  color: var(--blue-strong);
  font-size: 0.9rem;
  font-weight: 700;
}

.example-table {
  width: 100%;
  border-collapse: collapse;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.9rem;
}

.example-table th,
.example-table td {
  padding: 0.35rem 0.6rem;
  border: 1px solid var(--border);
  text-align: left;
}

.example-table th {
  color: var(--muted);
  font-weight: 700;
  background: var(--surface-strong);
}

.example-table td:first-child {
  color: var(--blue-strong);
}

.example-table td:last-child {
  color: var(--text);
}

.calc-input-row {
  display: flex;
  gap: 0.6rem;
  align-items: stretch;
}

.calc-input {
  flex: 1;
  min-height: 48px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  background: #091018;
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 1.4rem;
  text-align: center;
  appearance: textfield;
}

.calc-input::-webkit-outer-spin-button,
.calc-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
}

.calc-input:focus {
  border-color: var(--blue);
  outline: none;
}

.calc-input:disabled {
  opacity: 0.4;
}

.game-over-panel {
  width: min(100%, 620px);
  margin: 0 auto;
  padding: 1.75rem 1.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: center;
}

.game-over-panel h2 {
  margin-bottom: 0.5rem;
  color: var(--blue-strong);
  font-size: 1.75rem;
}

.final-score {
  margin-bottom: 1.25rem;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.hidden {
  display: none !important;
}

@media (max-width: 720px) {
  .menu-grid {
    grid-template-columns: 1fr;
  }

  .game-toolbar {
    grid-template-columns: 1fr;
  }

  .status-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .memory-arena {
    min-height: 390px;
  }
}

@media (max-width: 480px) {
  .topbar {
    padding: 0.75rem 1rem;
  }

  .topbar-note {
    display: none;
  }

  .page,
  .game-page {
    padding: 1rem;
  }

  h1 {
    font-size: 2.25rem;
  }

  .lead {
    font-size: 1rem;
  }

  .game-card {
    min-height: 220px;
  }

  .status-grid {
    gap: 0.5rem;
  }

  .stat {
    min-height: 62px;
  }

  .stat-value {
    font-size: 1.15rem;
  }

  .phase-row {
    align-items: flex-start;
    flex-direction: column;
    gap: 0.5rem;
  }

  .phase-detail {
    text-align: left;
  }

  .memory-arena {
    min-height: 360px;
  }

  .circle,
  .target {
    width: 52px;
    height: 52px;
  }

  .number-flash {
    font-size: 4rem;
  }

  .actions .btn {
    flex: 1 1 160px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
