:root {
  --bg: #eef6ff;
  --surface: #ffffff;
  --text: #1a2744;
  --muted: #5a6b8a;
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --success: #16a34a;
  --success-bg: #dcfce7;
  --error: #dc2626;
  --error-bg: #fee2e2;
  --border: #d0dceb;
  --shadow: 0 10px 30px rgba(26, 39, 68, 0.12);
  --radius: 16px;
}

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

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background:
    radial-gradient(circle at top left, #dbeafe, transparent 40%),
    radial-gradient(circle at bottom right, #fce7f3, transparent 35%),
    var(--bg);
  color: var(--text);
  line-height: 1.4;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app {
  max-width: 960px;
  margin: 0 auto;
  min-height: 100vh;
  padding: 1rem 1.25rem 2rem;
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr);
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "nav topbar"
    "nav main";
  column-gap: 1.25rem;
}

.tabs {
  grid-area: nav;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  align-self: start;
  position: sticky;
  top: 1rem;
}

.tab {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0.4rem 1.1rem;
  border-radius: 12px;
  font-size: 1.05rem;
  font-weight: 700;
  text-decoration: none;
  color: var(--muted);
  border: 2px solid transparent;
}

.tab:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.6);
}

.tab.active {
  color: var(--primary-dark);
  background: var(--surface);
  border-color: var(--border);
}

.top-bar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.nav-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  font-size: 1.3rem;
  color: var(--text);
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(26, 39, 68, 0.06);
}

.nav-toggle:focus-visible {
  outline: 3px solid #93c5fd;
  outline-offset: 2px;
}

.nav-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 150;
}

.nav-backdrop[hidden] {
  display: none;
}

.top-bar-spacer {
  flex: 1;
}

.timer-wrap,
.score-wrap {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.45rem 0.9rem;
  box-shadow: 0 2px 8px rgba(26, 39, 68, 0.06);
}

/* display:flex above otherwise overrides the native [hidden] rule */
.timer-wrap[hidden],
.wrong-wrap[hidden],
.typed-answer[hidden],
.choices[hidden],
.word-display[hidden] {
  display: none;
}

.score.wrong {
  color: var(--error);
}

.timer-label,
.score-label {
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 600;
}

.timer,
.score {
  font-size: 1.25rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.settings-btn {
  width: 48px;
  height: 48px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  font-size: 1.4rem;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(26, 39, 68, 0.06);
  transition: transform 0.15s ease, background 0.15s ease;
}

.settings-btn:hover {
  transform: scale(1.05);
  background: #f8fafc;
}

.settings-btn:focus-visible {
  outline: 3px solid #93c5fd;
  outline-offset: 2px;
}

.main {
  grid-area: main;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px);
  box-shadow: var(--shadow);
  padding: 2rem 1.25rem;
  text-align: center;
}

.equation {
  margin: 0;
  font-size: clamp(2rem, 8vw, 3.25rem);
  font-weight: 800;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
}

.clock-prompt {
  margin: 0;
  font-size: clamp(1.25rem, 4vw, 1.75rem);
  font-weight: 700;
  color: var(--text);
}

.clock-display {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 220px;
  width: 100%;
}

.clock-face {
  width: min(280px, 80vw);
  height: auto;
  display: block;
}

.clock-face-ring {
  fill: #fff;
  stroke: #1e293b;
  stroke-width: 4;
}

.clock-tick {
  stroke: #1e293b;
  stroke-width: 3;
  stroke-linecap: round;
}

.clock-number {
  fill: #1e293b;
  font-size: 14px;
  font-weight: 700;
  font-family: system-ui, sans-serif;
}

.clock-hand {
  stroke-linecap: round;
}

.clock-hand-hour {
  stroke: #1e293b;
  stroke-width: 5;
}

.clock-hand-minute {
  stroke: #2563eb;
  stroke-width: 3.5;
}

.clock-center {
  fill: #1e293b;
}

.clock-digital {
  font-size: clamp(2.5rem, 10vw, 4rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.06em;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  color: #1e293b;
  background: #f1f5f9;
  border: 3px solid #1e293b;
  border-radius: 12px;
  padding: 0.75rem 1.25rem;
}

.money-question {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  width: 100%;
}

.money-prompt {
  margin: 0;
  font-size: clamp(1.25rem, 4vw, 1.75rem);
  font-weight: 700;
  color: var(--text);
}

.money-equation-text {
  margin: 0;
  font-size: clamp(1.5rem, 5vw, 2.25rem);
  font-weight: 800;
  letter-spacing: 0.02em;
}

.money-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  max-width: 100%;
}

.coin-img {
  object-fit: contain;
  filter: drop-shadow(0 2px 3px rgba(15, 23, 42, 0.25));
  user-select: none;
}

.money-compare {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: center;
  gap: 1.25rem;
  width: 100%;
}

.money-compare-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.65rem;
  flex: 1 1 140px;
  max-width: 280px;
  padding: 0.75rem;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: #f8fafc;
}

.money-group-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2rem;
  height: 2rem;
  padding: 0 0.5rem;
  border-radius: 999px;
  background: #1e293b;
  color: #fff;
  font-weight: 800;
  font-size: 1rem;
}

.equation-side {
  min-height: 1.4em;
}

.equation-column {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  justify-items: end;
  width: min(320px, 100%);
  line-height: 1.05;
}

.column-answer-slot {
  justify-self: stretch;
  width: 100%;
  min-width: 0;
  padding-top: 0.75rem;
}

.column-answer-slot .answer-area {
  max-width: none;
}

.column-number {
  padding: 0 0.2em;
}

.column-row {
  display: grid;
  grid-template-columns: 0.8em 1fr;
  width: 100%;
  align-items: baseline;
}

.column-operator {
  justify-self: start;
}

.column-row .column-number {
  justify-self: end;
}

.column-line {
  width: 100%;
  border-top: 0.1em solid currentColor;
  margin-top: 0.08em;
}

.answer-area {
  width: 100%;
  max-width: 420px;
}

.typed-answer {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  align-items: stretch;
}

.answer-input {
  width: 100%;
  min-height: 64px;
  font-size: 2rem;
  text-align: center;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 0.75rem;
  font-weight: 700;
  color: var(--text);
  background: #f8fafc;
}

.answer-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.2);
}

.choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.choice-btn {
  min-height: 64px;
  font-size: 1.5rem;
  font-weight: 700;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: #f8fafc;
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.1s ease;
}

.choice-btn:hover:not(:disabled) {
  border-color: var(--primary);
  transform: translateY(-1px);
}

.choice-btn.selected {
  border-color: var(--primary);
  background: #dbeafe;
}

.choice-btn:disabled {
  cursor: default;
  opacity: 0.85;
}

.btn {
  min-height: 52px;
  border: none;
  border-radius: 12px;
  font-size: 1.1rem;
  font-weight: 700;
  padding: 0.7rem 1.25rem;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}

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

.btn:focus-visible {
  outline: 3px solid #93c5fd;
  outline-offset: 2px;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-secondary {
  background: #e2e8f0;
  color: var(--text);
}

.btn-secondary:hover {
  background: #cbd5e1;
}

.feedback {
  min-height: 1.75rem;
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
}

.feedback.correct {
  color: var(--success);
}

.feedback.incorrect {
  color: var(--error);
}

.word-display {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-start;
  gap: 0.75rem 1rem;
  width: 100%;
}

.word-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  min-width: 3rem;
}

.word-letter,
.word-blank {
  min-height: 1.2em;
  font-size: clamp(2rem, 8vw, 3.25rem);
  font-weight: 800;
  line-height: 1.2;
  text-transform: lowercase;
}

.word-blank {
  color: var(--muted);
  min-width: 1.1em;
  text-align: center;
  border-bottom: 3px solid var(--border);
}

.letter-input {
  width: 3rem;
  min-height: 52px;
  font-size: 1.5rem;
  text-align: center;
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 0.25rem;
  font-weight: 700;
  color: var(--text);
  background: #f8fafc;
  text-transform: lowercase;
}

.letter-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.2);
}

.letter-choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem;
  width: min(100%, 7.5rem);
}

.letter-choice-btn {
  min-height: 44px;
  min-width: 44px;
  font-size: 1.15rem;
  padding: 0.25rem;
}

.unscramble-answer {
  margin-bottom: 0.5rem;
}

.unscramble-pool {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  margin: 0.75rem 0 0.25rem;
}

.unscramble-tile {
  min-width: 3.25rem;
  min-height: 3.25rem;
  font-size: clamp(1.35rem, 5vw, 1.75rem);
  text-transform: lowercase;
}

.unscramble-pool .choice-btn.used {
  opacity: 0.35;
  visibility: hidden;
  pointer-events: none;
}

.unscramble-slot-filled {
  cursor: pointer;
}

.unscramble-undo {
  margin-top: 0.25rem;
}

.sentence-display {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: baseline;
  gap: 0.15rem 0.35rem;
  width: 100%;
  max-width: 36rem;
  font-size: clamp(1.5rem, 5vw, 2rem);
  font-weight: 700;
  line-height: 1.45;
  text-align: center;
}

.sentence-text {
  color: var(--text);
}

.sentence-blank {
  display: inline-block;
  min-width: 3.5rem;
  padding: 0 0.15rem;
  color: var(--muted);
  border-bottom: 3px solid var(--border);
  letter-spacing: 0.08em;
  font-weight: 800;
}

.sentence-choices {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.75rem;
  width: 100%;
  max-width: 420px;
  margin: 0 auto 0.5rem;
}

.sentence-choice-btn {
  min-width: 5.5rem;
  padding: 0.5rem 1rem;
  text-transform: lowercase;
}

.sentence-input {
  width: 100%;
  min-height: 64px;
  font-size: 1.75rem;
  text-align: center;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 0.75rem;
  font-weight: 700;
  color: var(--text);
  background: #f8fafc;
  text-transform: lowercase;
}

.sentence-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.2);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 100;
}

.modal-overlay[hidden] {
  display: none;
}

.modal {
  width: min(100%, 440px);
  max-height: min(92vh, 720px);
  overflow: auto;
  background: var(--surface);
  border-radius: calc(var(--radius) + 4px);
  box-shadow: var(--shadow);
  padding: 1.5rem;
}

.modal h2 {
  margin: 0 0 1.25rem;
  font-size: 1.5rem;
}

.settings-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  margin: 0;
  border: none;
  padding: 0;
  text-align: left;
}

.field > span,
.field > legend {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text);
  padding: 0;
}

.field select {
  min-height: 48px;
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 0.5rem 0.75rem;
  font-size: 1rem;
  background: #f8fafc;
  color: var(--text);
}

.checkbox-row,
.radio-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem 1rem;
}

.field-hint {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
}

.checkbox-row label,
.radio-row label {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 44px;
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
}

.form-error {
  margin: 0;
  color: var(--error);
  background: var(--error-bg);
  border-radius: 10px;
  padding: 0.65rem 0.8rem;
  font-weight: 600;
}

.form-error[hidden] {
  display: none;
}

.modal-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  margin-top: 0.5rem;
}

.modal-actions .btn {
  min-width: 100px;
}

body.modal-open {
  overflow: hidden;
}

@media (max-width: 720px) {
  .app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "topbar"
      "main";
  }

  .nav-toggle {
    display: inline-flex;
  }

  .tabs {
    position: fixed;
    inset: 0 auto 0 0;
    align-self: stretch;
    width: min(260px, 80vw);
    padding: 1.25rem 1rem;
    background: var(--surface);
    box-shadow: var(--shadow);
    border-right: 1px solid var(--border);
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    z-index: 200;
    overflow-y: auto;
  }

  .tabs.open {
    transform: translateX(0);
  }

  body.nav-open {
    overflow: hidden;
  }
}

@media (max-width: 480px) {
  .top-bar {
    flex-wrap: wrap;
  }

  .choices {
    grid-template-columns: 1fr;
  }

  .letter-choices {
    grid-template-columns: 1fr 1fr;
  }

  .modal-actions {
    flex-direction: column-reverse;
  }

  .modal-actions .btn {
    width: 100%;
  }
}
