/* MAC Attack practice arcade. Approved direction: navy page, teal accents, cream text,
   reading panel in light ink, coral reserved for a wrong pick. */
:root {
  --navy: #0A1830;
  --navy-stage: #08122A;
  --navy-line: #1C3358;
  --navy-raised: #10224A;
  --teal: #1FB6A6;
  --teal-light: #7FE0D3;
  --teal-dark: #0E8C80;
  --cream: #F2F6F5;
  --cream-dim: #B8C4CC;
  --panel: #F7F9FB;
  --panel-line: #D6DEE6;
  --ink: #14213A;
  --ink-soft: #4A5670;
  --coral: #E5735F;
  --coral-dark: #C8452F;
  --focus: #FFD166;
  --display: "Avenir Next Condensed", "Arial Narrow", "Roboto Condensed", "Helvetica Neue", Arial, sans-serif;
  --body: "Avenir Next", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { background: var(--navy); }
body {
  margin: 0;
  font-family: var(--body);
  font-size: 17px;
  line-height: 1.5;
  color: var(--cream);
  background: var(--navy);
  -webkit-font-smoothing: antialiased;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}
.skip {
  position: absolute; left: 8px; top: -60px;
  padding: 10px 14px; background: var(--focus); color: var(--ink);
  font-weight: 600; border-radius: 6px; z-index: 40;
}
.skip:focus { top: 8px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.app { max-width: 1180px; margin: 0 auto; padding: 16px 24px 48px; }

.topbar {
  display: flex; justify-content: space-between; align-items: flex-end;
  gap: 20px; flex-wrap: wrap; margin-bottom: 14px;
}
h1 {
  font-family: var(--display); font-weight: 700;
  font-size: clamp(34px, 5vw, 52px); line-height: 1; letter-spacing: 0.01em;
  margin: 0; text-transform: uppercase;
}
h1 .sub {
  display: block; text-transform: none; font-weight: 500;
  font-size: 0.42em; letter-spacing: 0.04em; color: var(--teal-light); margin-top: 6px;
}
.topic { margin: 8px 0 0; color: var(--cream-dim); max-width: 60ch; }
.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* Study time save status: visible when signed in or when unsaved receipts exist. */
.save-status {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  min-height: 44px; margin: 0 0 14px; padding: 6px 14px;
  border: 1px solid var(--navy-line); border-radius: 10px;
  font-size: 15px; color: var(--cream);
}
.save-status-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--cream-dim); flex: none; }
.save-status.saving .save-status-dot { background: var(--focus); }
.save-status.saved .save-status-dot { background: var(--teal-light); }
.save-status.error { border-color: var(--coral); }
.save-status.error .save-status-dot { background: var(--coral); }
.save-status .btn { margin-left: auto; }

.hud {
  display: flex; gap: 6px; margin: 0 0 18px;
  border: 1px solid var(--navy-line); border-radius: 10px; padding: 8px;
}
.hud div {
  display: flex; flex-direction: column; align-items: flex-start;
  padding: 6px 14px; min-width: 96px; border-right: 1px solid var(--navy-line);
}
.hud div:last-child { border-right: 0; }
.hud dt { font-size: 12px; color: var(--cream-dim); }
.hud dd {
  margin: 0; font-family: var(--display); font-weight: 700;
  font-size: 26px; line-height: 1.1; font-variant-numeric: tabular-nums;
}

/* Buttons */
.btn {
  min-height: 46px; padding: 10px 20px; border-radius: 10px;
  border: 1.5px solid transparent; font: inherit; font-weight: 600; cursor: pointer;
}
.btn.primary { background: var(--teal-dark); color: #fff; }
.btn.primary:hover { background: #0B766C; }
.btn.quiet { background: transparent; color: var(--cream); border-color: var(--navy-line); }
.btn.quiet:hover { border-color: var(--cream-dim); }
.question-panel .btn.quiet { color: var(--ink); border-color: var(--panel-line); }
.question-panel .btn.quiet:hover { border-color: var(--ink-soft); }
.btn.small { min-height: 44px; padding: 8px 14px; font-size: 14px; }
.btn.danger { background: var(--coral-dark); color: #fff; }
.btn:disabled { opacity: 0.55; cursor: default; }

/* Menu */
#menu { max-width: 780px; }
#menu h2 { margin: 0 0 12px; font-family: var(--display); font-size: 28px; font-weight: 700; }
#menu .menu-note { margin: 0 0 14px; color: var(--cream-dim); font-size: 15px; }
.topics-container { display: grid; gap: 10px; margin: 0 0 18px; padding: 0; list-style: none; }
.topic-item {
  display: grid; grid-template-columns: 52px 1fr auto; align-items: center; gap: 12px;
  width: 100%; min-height: 56px; padding: 8px 16px 8px 8px;
  border: 1.5px solid var(--navy-line); border-radius: 10px;
  background: var(--navy-raised); color: var(--cream);
  font: inherit; font-size: 18px; text-align: left; cursor: pointer;
}
.topic-item:hover, .topic-item.selected { border-color: var(--teal); }
.topic-item .topic-number {
  display: grid; place-items: center; width: 44px; height: 44px; border-radius: 8px;
  font-family: var(--display); font-weight: 700; font-size: 20px;
  background: var(--navy); color: var(--teal-light);
}
.topic-item .topic-count { font-size: 13px; color: var(--cream-dim); white-space: nowrap; }
.topic-item.back { border-style: dashed; }
.menu-hint { margin: 0; font-size: 14px; color: var(--cream-dim); }

/* Board */
.board {
  display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(300px, 0.9fr);
  gap: 22px; align-items: start;
}
.board.stage-hidden { grid-template-columns: minmax(0, 1fr); max-width: 780px; }

.question-panel { background: var(--panel); color: var(--ink); border-radius: 14px; padding: 24px 26px 26px; }
.phase-line { margin: 0 0 10px; font-size: 14px; color: var(--ink-soft); min-height: 21px; }
.prompt { font-size: 21px; line-height: 1.45; font-weight: 500; margin: 0 0 20px; max-width: 62ch; }

.options { display: grid; gap: 10px; margin-bottom: 18px; }
.opt {
  display: grid; grid-template-columns: 44px 1fr; align-items: center; gap: 12px;
  width: 100%; min-height: 52px; padding: 8px 14px 8px 8px;
  border: 1.5px solid var(--panel-line); border-radius: 10px;
  background: #fff; color: var(--ink);
  font: inherit; text-align: left; line-height: 1.35; cursor: pointer;
  transition: border-color 120ms, background-color 120ms;
}
.opt .letter {
  display: grid; place-items: center; width: 40px; height: 40px; border-radius: 8px;
  font-family: var(--display); font-weight: 700; font-size: 22px;
  background: var(--navy); color: var(--cream);
}
.opt:hover:not(:disabled) { border-color: var(--teal-dark); }
.opt:disabled { cursor: default; }
.options.reading .opt:disabled { background: #F1F4F7; }
.opt.chosen { border-color: var(--ink); }
.opt.correct { border-color: var(--teal-dark); background: #E6F7F4; }
.opt.correct .letter { background: var(--teal-dark); }
.opt.wrong { border-color: var(--coral-dark); background: #FCEDE9; }
.opt.wrong .letter { background: var(--coral-dark); }

.controls { display: flex; gap: 10px; flex-wrap: wrap; }

.feedback { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--panel-line); }
.fb-heading { margin: 0 0 6px; font-family: var(--display); font-weight: 700; font-size: 24px; line-height: 1.1; }
.fb-heading.ok { color: var(--teal-dark); }
.fb-heading.miss { color: var(--coral-dark); }
.fb-answer { margin: 0 0 14px; color: var(--ink-soft); }
.rationale-label { margin: 0 0 6px; font-size: 14px; font-weight: 600; color: var(--ink-soft); }
.rationale { margin: 0; max-width: 66ch; line-height: 1.55; }
.source { margin: 12px 0 0; font-size: 13px; color: var(--ink-soft); font-style: italic; }

/* Stage */
.stage { background: var(--navy-stage); border: 1px solid var(--navy-line); border-radius: 14px; padding: 14px 16px 16px; }
.stage-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; }
.stage-head h2 { margin: 0; font-family: var(--display); font-weight: 700; font-size: 22px; letter-spacing: 0.02em; }
canvas {
  display: block; width: 100%; height: auto; aspect-ratio: 900 / 700;
  border-radius: 10px; background: var(--navy-stage); touch-action: manipulation;
}
.pad { display: grid; grid-template-columns: 1fr 1.6fr 1fr; gap: 10px; margin-top: 12px; }
.pad-btn {
  min-height: 52px; border-radius: 10px; border: 1.5px solid var(--navy-line);
  background: var(--navy-raised); color: var(--cream);
  font: inherit; font-weight: 600; font-size: 18px; cursor: pointer;
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
}
.pad-btn.fire { background: var(--teal-dark); border-color: var(--teal-dark); color: #fff; }
.pad-btn:active { filter: brightness(1.15); }
.stage-hint { margin: 12px 0 0; font-size: 13px; color: var(--cream-dim); }

/* Summary */
.summary { margin-top: 24px; border: 1px solid var(--navy-line); border-radius: 14px; padding: 24px 26px; }
.summary h2 { margin: 0 0 14px; font-family: var(--display); font-weight: 700; font-size: 34px; line-height: 1; text-transform: uppercase; }
.summary h3 { margin: 22px 0 10px; font-size: 18px; }
.counters { display: flex; gap: 6px; flex-wrap: wrap; margin: 0; border: 1px solid var(--navy-line); border-radius: 10px; padding: 8px; }
.counters div { padding: 6px 16px; min-width: 110px; border-right: 1px solid var(--navy-line); }
.counters div:last-child { border-right: 0; }
.counters dt { font-size: 12px; color: var(--cream-dim); }
.counters dd { margin: 0; font-family: var(--display); font-weight: 700; font-size: 30px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.missed { margin: 0; padding-left: 20px; display: grid; gap: 14px; }
.missed li { max-width: 72ch; }
.missed .q { font-weight: 600; margin: 0 0 4px; }
.missed .a { margin: 0 0 4px; color: var(--cream-dim); }
.missed .a b { color: var(--cream); font-weight: 600; }
.missed .r { margin: 0; color: var(--cream-dim); }
.note { font-size: 14px; color: var(--cream-dim); max-width: 72ch; }
.summary .controls { margin-top: 18px; }

/* Dialogs (session timer, sign in, profile) */
.dialog-backdrop {
  position: fixed; inset: 0; background: rgba(4, 10, 24, 0.8);
  display: flex; justify-content: center; align-items: center; z-index: 30; padding: 16px;
}
.dialog {
  background: var(--panel); color: var(--ink); border-radius: 14px;
  padding: 24px; width: min(520px, 100%); max-height: 92vh; overflow-y: auto;
}
.dialog h2 { margin: 0 0 12px; font-family: var(--display); font-size: 28px; }
.dialog h3 { margin: 16px 0 8px; font-size: 15px; color: var(--ink-soft); }
.dialog input {
  width: 100%; min-height: 46px; padding: 10px 12px; margin: 6px 0;
  border: 1.5px solid var(--panel-line); border-radius: 8px; font: inherit; color: var(--ink); background: #fff;
}
.dialog .btn.quiet { color: var(--ink); border-color: var(--panel-line); }
.dialog .controls { margin-top: 14px; }
.dialog .toggle-link { margin-top: 12px; }
.dialog .toggle-link button { background: none; border: 0; padding: 0; color: var(--teal-dark); font: inherit; text-decoration: underline; cursor: pointer; min-height: 44px; }
.error-message { color: var(--coral-dark); min-height: 1.2em; margin: 6px 0; font-size: 14px; }
.session-display { font-family: var(--display); font-size: 48px; font-weight: 700; margin: 12px 0; font-variant-numeric: tabular-nums; }
.user-email { font-weight: 600; word-break: break-all; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.stat-card { background: #fff; border: 1.5px solid var(--panel-line); border-radius: 10px; padding: 10px 12px; }
.stat-label { font-size: 12px; color: var(--ink-soft); }
.stat-value { font-family: var(--display); font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.daily-log { max-height: 200px; overflow-y: auto; display: grid; gap: 4px; }
.daily-entry { display: flex; justify-content: space-between; gap: 12px; padding: 6px 10px; background: #fff; border: 1px solid var(--panel-line); border-radius: 6px; font-size: 14px; }

@media (max-width: 860px) {
  .board { grid-template-columns: minmax(0, 1fr); }
  .topbar { align-items: flex-start; }
  .hud { width: 100%; overflow-x: auto; }
  .hud div { min-width: 0; flex: 1; padding: 6px 10px; }
}
@media (max-width: 480px) {
  .app { padding: 12px 14px 40px; }
  .question-panel { padding: 18px 16px 20px; }
  .prompt { font-size: 19px; }
  .hud dd { font-size: 22px; }
  .topic-item { font-size: 16px; grid-template-columns: 44px 1fr; }
  .topic-item .topic-count { grid-column: 2; }
}
@media (prefers-reduced-motion: reduce) {
  .opt, .btn { transition: none; }
}
@media (forced-colors: active) {
  .opt, .btn, .pad-btn, .topic-item { border: 2px solid ButtonText; }
  .opt.correct, .opt.wrong, .topic-item.selected { outline: 3px solid Highlight; }
}
