:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #1a1d21;
  --ink-soft: #5b6470;
  --line: #e2e5ea;
  --line-strong: #cdd3db;
  --accent: #2f5d8c;
  --accent-soft: #eaf1f8;
  --good: #1f7a55;
  --good-soft: #e7f4ee;
  --bad: #a63a30;
  --bad-soft: #fbecea;
  --warn: #8a6a12;
  --warn-soft: #fbf3de;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 25, 35, .06), 0 6px 18px rgba(20, 25, 35, .05);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; font-weight: 650; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: .95rem; }
p { margin: 0 0 .75rem; }
a { color: var(--accent); }

.hidden { display: none !important; }
.muted { color: var(--ink-soft); }
.small { font-size: .85rem; }
.mono { font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------- app frame */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  background: var(--panel); border-bottom: 1px solid var(--line);
  padding: .7rem 1.25rem; position: sticky; top: 0; z-index: 10;
}
.topbar .context { font-size: .9rem; color: var(--ink-soft); }
.topbar .context strong { color: var(--ink); font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: .75rem; }

.timer {
  font-variant-numeric: tabular-nums; font-size: 1.05rem; font-weight: 600;
  background: var(--accent-soft); color: var(--accent);
  padding: .25rem .6rem; border-radius: 6px;
}
.timer.hidden-value { color: transparent; text-shadow: 0 0 9px rgba(47,93,140,.55); }

.wrap { max-width: 1180px; margin: 0 auto; padding: 1.5rem 1.25rem 4rem; }
.wrap.narrow { max-width: 720px; }

.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.5rem;
}
.panel + .panel { margin-top: 1.25rem; }

/* ------------------------------------------------------------- controls */
button, .btn {
  font: inherit; font-weight: 550; cursor: pointer;
  border: 1px solid var(--line-strong); background: var(--panel); color: var(--ink);
  border-radius: 8px; padding: .55rem 1.1rem; transition: background .12s, border-color .12s;
}
button:hover:not(:disabled), .btn:hover { background: #f0f3f7; }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover:not(:disabled) { background: #26496e; }
button.ghost { border-color: transparent; background: transparent; color: var(--ink-soft); }
button.ghost:hover { background: #eef1f5; }

label.field { display: block; margin-bottom: 1rem; font-size: .9rem; font-weight: 550; }
label.field span { display: block; margin-bottom: .3rem; }
input[type=text], input[type=email], input[type=password], select {
  font: inherit; width: 100%; padding: .55rem .7rem;
  border: 1px solid var(--line-strong); border-radius: 8px; background: #fff; color: var(--ink);
}
/* Hide the native reveal-password icon some browsers (Edge, older Chrome)
   draw inside the field — it otherwise makes the password box look like a
   different control from the text/email boxes next to it. */
input[type=password]::-ms-reveal, input[type=password]::-ms-clear { display: none; }
input:focus, select:focus, button:focus-visible, .choice:focus-visible, .conf-btn:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
input[type=number] { font: inherit; width: 100%; padding: .55rem .7rem; border: 1px solid var(--line-strong); border-radius: 8px; background: #fff; color: var(--ink); }
input[type=checkbox] { width: 16px; height: 16px; }

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 560px) { .field-row { grid-template-columns: 1fr; } }

.check-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: .35rem .8rem;
  max-height: 220px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px;
  padding: .7rem .8rem; background: #fbfcfd; font-size: .85rem;
}
.check-grid label { display: flex; align-items: flex-start; gap: .4rem; cursor: pointer; font-weight: 400; }
.check-grid input { width: auto; margin-top: .15rem; }
.check-grid .empty { color: var(--ink-soft); grid-column: 1 / -1; }

/* --------------------------------------------------------------- player */
.player { display: grid; grid-template-columns: 210px 1fr; gap: 1.5rem; align-items: start; }
@media (max-width: 860px) { .player { grid-template-columns: 1fr; } }

/* The active question panel (practice/diagnostic/fulltest all share this
   #playerScreen id): NOT height-capped — capping it clipped answer choices
   on shorter viewports instead of just avoiding scroll (a real bug from an
   earlier pass at this). Instead: tighter vertical spacing so a normal
   question's stem + choices fit a typical viewport without any scrolling,
   and the footer (Back/Next/Submit) is sticky to the *page* bottom, so on
   genuinely long content (a full reading passage) that does need to
   scroll, the footer stays reachable without hunting for it, and nothing
   is ever cut off. */
#playerScreen { padding-bottom: 1.25rem; }
#playerScreen .question-meta { margin-bottom: .6rem; }
#playerScreen .stimulus { padding: .75rem .9rem; margin-bottom: .85rem; }
#playerScreen .stem { margin-bottom: .7rem; }
#playerScreen .choices { gap: .4rem; margin-bottom: 1rem; }
#playerScreen .choice { padding: .6rem .85rem; }
#playerScreen .confidence { padding-top: .8rem; margin-bottom: .9rem; }
#playerScreen .panel { padding: 1.1rem 1.25rem; }

.navigator { position: sticky; top: 74px; }
.navigator h3 { font-size: .75rem; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-soft); }
.nav-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: .4rem; }
.nav-btn {
  aspect-ratio: 1; padding: 0; font-size: .85rem; border-radius: 6px;
  border: 1px solid var(--line-strong); background: #fff; color: var(--ink-soft); position: relative;
}
.nav-btn.answered { background: var(--accent-soft); border-color: #b9cee2; color: var(--accent); font-weight: 650; }
.nav-btn.current { outline: 2px solid var(--accent); outline-offset: 1px; }
.nav-btn.marked::after {
  content: "★"; position: absolute; top: -6px; right: -3px; font-size: .7rem; color: var(--warn);
}
.nav-legend { margin-top: .8rem; font-size: .78rem; color: var(--ink-soft); line-height: 1.7; }
.nav-legend i { font-style: normal; display: inline-block; width: 11px; height: 11px; border-radius: 3px; margin-right: .4rem; vertical-align: -1px; border: 1px solid var(--line-strong); }
.nav-legend i.a { background: var(--accent-soft); border-color: #b9cee2; }

.question-meta {
  display: flex; flex-wrap: wrap; gap: .4rem; align-items: center;
  margin-bottom: 1rem; font-size: .78rem;
}
.tag {
  background: #eef1f5; color: var(--ink-soft); border-radius: 999px; padding: .15rem .6rem;
  border: 1px solid var(--line);
}
.tag.difficulty-easy { background: var(--good-soft); color: var(--good); border-color: #c9e5d8; }
.tag.difficulty-medium { background: var(--warn-soft); color: var(--warn); border-color: #ecdfb8; }
.tag.difficulty-hard { background: var(--bad-soft); color: var(--bad); border-color: #f0cdc8; }

.stimulus {
  background: #fbfcfd; border: 1px solid var(--line); border-left: 3px solid var(--line-strong);
  border-radius: 8px; padding: 1rem 1.15rem; margin-bottom: 1.25rem;
  white-space: pre-wrap; line-height: 1.7;
}
.stimulus.table-like { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .88rem; }
.stem { font-weight: 550; margin-bottom: 1rem; }

.choices { display: grid; gap: .55rem; margin-bottom: 1.5rem; }
.choice {
  display: flex; gap: .8rem; align-items: flex-start; text-align: left; width: 100%;
  padding: .8rem 1rem; border: 1px solid var(--line-strong); border-radius: 8px;
  background: #fff; cursor: pointer;
}
.choice:hover { background: #f7f9fb; }
.choice .label {
  flex: 0 0 26px; height: 26px; border-radius: 50%; border: 1px solid var(--line-strong);
  display: grid; place-items: center; font-size: .82rem; font-weight: 650; color: var(--ink-soft);
}
.choice.selected { border-color: var(--accent); background: var(--accent-soft); }
.choice.selected .label { background: var(--accent); border-color: var(--accent); color: #fff; }
.choice.correct { border-color: var(--good); background: var(--good-soft); }
.choice.correct .label { background: var(--good); border-color: var(--good); color: #fff; }
.choice.incorrect { border-color: var(--bad); background: var(--bad-soft); }
.choice.incorrect .label { background: var(--bad); border-color: var(--bad); color: #fff; }

.spr { margin-bottom: 1.5rem; }
.spr input { max-width: 260px; font-size: 1.1rem; font-variant-numeric: tabular-nums; }

.confidence { border-top: 1px solid var(--line); padding-top: 1.1rem; margin-bottom: 1.25rem; }
.confidence .prompt { font-weight: 550; font-size: .92rem; margin-bottom: .55rem; }
.conf-row { display: flex; gap: .5rem; flex-wrap: wrap; }
.conf-btn { flex: 1 1 150px; text-align: left; padding: .6rem .85rem; line-height: 1.3; }
.conf-btn b { display: block; font-size: .92rem; }
.conf-btn small { color: var(--ink-soft); }
.conf-btn.selected { border-color: var(--accent); background: var(--accent-soft); }
.conf-btn.selected small { color: var(--accent); }
.conf-warn { color: var(--warn); font-size: .85rem; margin-top: .5rem; }

.player-footer {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  border-top: 1px solid var(--line); padding-top: 1rem; padding-bottom: 1rem; flex-wrap: wrap;
  /* Sticks to the bottom of the viewport once the question content is tall
     enough to push it below the fold, so "Next"/"Submit" is always
     reachable without scrolling. */
  position: sticky; bottom: 0; background: var(--panel);
  box-shadow: 0 -6px 12px -8px rgba(20, 25, 35, .12);
  z-index: 5;
}
.footer-actions { display: flex; gap: .5rem; }

/* -------------------------------------------------------------- results */
.score-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; }
.stat .value { font-size: 1.7rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat .label { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-soft); }

table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: .55rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .74rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-soft); font-weight: 600; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: #fafbfc; }

.bar { height: 7px; border-radius: 4px; background: #eceff3; overflow: hidden; min-width: 70px; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.bar.good > span { background: var(--good); }
.bar.bad > span { background: var(--bad); }

.pill { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 600; }
.pill.ok { background: var(--good-soft); color: var(--good); }
.pill.no { background: var(--bad-soft); color: var(--bad); }
.pill.flag { background: var(--warn-soft); color: var(--warn); }

.review-item { border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.25rem; margin-bottom: .9rem; background: var(--panel); }
.review-item .head { display: flex; justify-content: space-between; gap: 1rem; align-items: center; margin-bottom: .6rem; }
.explanation { background: #fbfcfd; border-left: 3px solid var(--accent); padding: .7rem .9rem; border-radius: 6px; margin-top: .8rem; font-size: .92rem; }

.tabs { display: flex; gap: .3rem; margin-bottom: 1.25rem; border-bottom: 1px solid var(--line); }
.tab { border: none; background: none; padding: .6rem .9rem; border-bottom: 2px solid transparent; border-radius: 0; color: var(--ink-soft); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 650; }

.toast {
  position: fixed; bottom: 1.25rem; left: 50%; transform: translateX(-50%);
  background: #1a1d21; color: #fff; padding: .6rem 1.1rem; border-radius: 8px;
  font-size: .88rem; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: opacity .2s;
}
.toast.show { opacity: 1; }

/* ---------------------------------------------------------- home dashboard */
.hero { text-align: center; padding: 2.5rem 1rem 1.5rem; }
.hero h1 { font-size: 1.9rem; margin-bottom: .4rem; }
.hero p { color: var(--ink-soft); font-size: 1.02rem; max-width: 560px; margin: 0 auto; }

.mode-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.25rem; margin: 2rem 0; }
@media (max-width: 860px) { .mode-grid { grid-template-columns: 1fr; } }

.mode-card {
  display: flex; flex-direction: column; gap: .6rem; text-align: left;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1.6rem 1.5rem; text-decoration: none; color: var(--ink);
  transition: transform .12s, border-color .12s;
}
.mode-card:hover { transform: translateY(-2px); border-color: var(--accent); }
.mode-card.disabled { opacity: .55; pointer-events: none; }
.mode-card .icon { font-size: 1.6rem; }
.mode-card h2 { font-size: 1.15rem; margin: 0; }
.mode-card .tagline { color: var(--accent); font-weight: 600; font-size: .92rem; }
.mode-card p.desc { color: var(--ink-soft); font-size: .9rem; margin: 0; flex-grow: 1; }
.mode-card .meta { font-size: .78rem; color: var(--ink-soft); border-top: 1px solid var(--line); padding-top: .6rem; margin-top: .2rem; }
.mode-card .soon { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--warn); font-weight: 700; }

.home-footer { text-align: center; color: var(--ink-soft); font-size: .85rem; margin-top: 1rem; }

/* --------------------------------------------------------------- figures */
.figure { background: #fbfcfd; border: 1px solid var(--line); border-radius: 8px; padding: .75rem; }

/* ---------------------------------------------------------- math tool panels */
.tool-panel {
  position: fixed; top: 64px; right: 1rem; z-index: 20; width: 260px;
  background: var(--panel); border: 1px solid var(--line-strong); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: .9rem;
}
.tool-panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .6rem; }
.calc-display {
  background: #1a1d21; color: #fff; font-size: 1.5rem; font-variant-numeric: tabular-nums;
  text-align: right; padding: .6rem .7rem; border-radius: 6px; margin-bottom: .6rem; overflow-x: auto;
}
.calc-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: .4rem; }
.calc-grid button { padding: .6rem 0; font-size: 1rem; }
.ref-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; font-size: .78rem; text-align: center; }
.ref-grid > div { display: flex; flex-direction: column; align-items: center; gap: .3rem; }
.ref-fact { font-size: .78rem; line-height: 1.4; padding: .4rem 0; }
@media (max-width: 700px) { .tool-panel { right: .5rem; left: .5rem; width: auto; } }
