/* Studyhall — one stylesheet, light and dark from the same tokens. */

:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #eef1f7;
  --ink: #16202e;
  --ink-2: #52627a;
  --ink-3: #8593a8;
  --line: #dde3ec;
  --accent: #2f6fed;
  --accent-ink: #ffffff;
  --good: #1a8f5f;
  --good-bg: #e6f6ee;
  --bad: #cf3446;
  --bad-bg: #fdecee;
  --warn: #b7791f;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(18, 32, 52, .06), 0 6px 20px rgba(18, 32, 52, .06);
  --maxw: 940px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10151d;
    --surface: #182029;
    --surface-2: #1f2935;
    --ink: #e8eef6;
    --ink-2: #a7b6c9;
    --ink-3: #75879e;
    --line: #2a3542;
    --accent: #5b93ff;
    --accent-ink: #0b1119;
    --good: #43c98b;
    --good-bg: #16332a;
    --bad: #ff6b7d;
    --bad-bg: #3a1f26;
    --warn: #e0a944;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .28);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  padding-bottom: env(safe-area-inset-bottom);
}

h1, h2, h3 { line-height: 1.25; }
h3 { margin: 0 0 .6rem; font-size: 1rem; letter-spacing: .01em; }

/* ------------------------------------------------------------- layout -- */
.wrap { max-width: var(--maxw); margin: 0 auto; padding: 1.1rem 1rem 4rem; }
.wrap.narrow { max-width: 640px; }
.screen[hidden] { display: none; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; margin-top: .8rem; }
.section-title { font-size: .82rem; text-transform: uppercase; letter-spacing: .08em;
  color: var(--ink-3); margin: 1.6rem 0 .7rem; }
.page-title { font-size: 1.5rem; margin: .4rem 0 1rem; }
.muted { color: var(--ink-2); font-size: .9rem; margin: 0 0 .7rem; }
.fineprint { color: var(--ink-3); font-size: .8rem; text-align: center; margin-top: 1rem; }

/* ---------------------------------------------------------------- top -- */
.top {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between;
  gap: .5rem; padding: .55rem .9rem;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: .5rem; background: none;
  border: 0; color: var(--ink); font: inherit; font-weight: 650; cursor: pointer;
  padding: .2rem .3rem; border-radius: 10px; }
.brand-mark { font-size: 1.2rem; }
.top-right { display: flex; gap: .4rem; }
.chip {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: 999px; padding: .32rem .75rem; font: inherit; font-size: .86rem;
  cursor: pointer; white-space: nowrap;
}
.chip.hot { border-color: var(--accent); color: var(--accent); font-weight: 600; }

/* -------------------------------------------------------------- cards -- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 1rem; margin-bottom: .9rem;
}

/* ------------------------------------------------------------- inputs -- */
.field {
  width: 100%; padding: .7rem .85rem; margin-bottom: .6rem;
  border: 1px solid var(--line); border-radius: 11px;
  background: var(--surface-2); color: var(--ink); font: inherit;
}
.field:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea.field { resize: vertical; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  padding: .7rem 1rem; border-radius: 11px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font: inherit; font-weight: 550;
  cursor: pointer; text-align: center;
}
.btn:hover { border-color: var(--ink-3); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.wide { width: 100%; }
.btn.good { background: var(--good-bg); border-color: var(--good); color: var(--good); }
.btn.bad  { background: var(--bad-bg);  border-color: var(--bad);  color: var(--bad); }
.btn[disabled] { opacity: .5; cursor: default; }
.back { background: none; border: 0; color: var(--ink-2); font: inherit;
  cursor: pointer; padding: .2rem 0; margin-bottom: .4rem; }
.err { color: var(--bad); font-size: .88rem; min-height: 1.2em; margin: .4rem 0 0; }

.seg { display: grid; gap: .3rem; background: var(--surface-2);
  border-radius: 11px; padding: .25rem; margin-bottom: .9rem; }
.seg.two { grid-template-columns: 1fr 1fr; }
.seg button { border: 0; background: none; color: var(--ink-2); font: inherit;
  padding: .5rem; border-radius: 9px; cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--ink); font-weight: 600;
  box-shadow: var(--shadow); }

.hero { font-size: 2rem; margin: 1.6rem 0 .2rem; text-align: center; }
.hero-sub { text-align: center; color: var(--ink-2); margin: 0 0 1.4rem; }
.emoji-row { display: flex; flex-wrap: wrap; gap: .35rem; margin: .2rem 0 .8rem; }
.emoji-row button { font-size: 1.25rem; background: var(--surface-2); cursor: pointer;
  border: 2px solid transparent; border-radius: 10px; padding: .3rem .45rem; }
.emoji-row button.on { border-color: var(--accent); }

/* --------------------------------------------------------------- menu -- */
.greet { font-size: 1.35rem; font-weight: 650; margin: .3rem 0 1rem; }
.track { margin-bottom: 1.1rem; }
.track-head { display: flex; align-items: center; gap: .5rem;
  font-size: .82rem; text-transform: uppercase; letter-spacing: .08em;
  color: var(--ink-3); margin-bottom: .4rem; }

/* Dense subject list. The 1px grid gap over a line-coloured background draws
   the row separators, so no row needs a border of its own and none doubles up
   at the ends. */
.subj-list { display: grid; gap: 1px; background: var(--line);
  border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow); }
.subj-row {
  display: grid; align-items: center; gap: .7rem;
  grid-template-columns: 1.5rem minmax(0, 1fr) minmax(0, auto) 3.5rem 5.6rem;
  width: 100%; padding: .5rem .8rem; border: 0; cursor: pointer;
  background: var(--surface); color: var(--ink); font: inherit; text-align: left;
}
.subj-row:hover { background: var(--surface-2); }
.subj-row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.sr-emoji { font-size: 1.15rem; line-height: 1.2; }
.sr-name { display: flex; align-items: center; gap: .4rem; min-width: 0; }
.sr-name b { font-weight: 620; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.sr-auth, .sr-count { color: var(--ink-3); font-size: .76rem; text-align: right;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr-count { font-variant-numeric: tabular-nums; }
.sr-prog { display: flex; align-items: center; gap: .45rem; }
.sr-prog .minibar { flex: 1; margin: 0; }
.sr-pct { font-size: .74rem; color: var(--ink-2); width: 2.3rem;
  text-align: right; font-variant-numeric: tabular-nums; }
.sr-none { flex: 1; text-align: right; color: var(--ink-3); }

/* The authority is the first thing to go, then the pool size: on a phone the
   name and the progress are what a subject is picked by. */
@media (max-width: 700px) {
  .subj-row { grid-template-columns: 1.4rem minmax(0, 1fr) 3.4rem 4.6rem; }
  .sr-auth { display: none; }
}
@media (max-width: 430px) {
  .subj-row { grid-template-columns: 1.4rem minmax(0, 1fr) 4.4rem; gap: .5rem; }
  .sr-count { display: none; }
}

.subject-card {
  display: block; width: 100%; text-align: left; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: .9rem 1rem; font: inherit; color: var(--ink);
}
.subject-card:hover { border-color: var(--accent); }
.sc-top { display: flex; align-items: center; gap: .55rem; }
.sc-emoji { font-size: 1.5rem; }
.sc-name { font-weight: 650; }
.sc-auth { color: var(--ink-3); font-size: .78rem; }
.sc-blurb { color: var(--ink-2); font-size: .88rem; margin: .5rem 0 .6rem; }
.sc-foot { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.pill { font-size: .74rem; padding: .18rem .5rem; border-radius: 999px;
  background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.pill.due { background: color-mix(in srgb, var(--accent) 16%, transparent);
  color: var(--accent); font-weight: 600; }
.pill.sm { font-size: .68rem; padding: .1rem .4rem; }
.pill.good { background: var(--good-bg); color: var(--good); }

.minibar { height: 5px; border-radius: 3px; background: var(--surface-2);
  overflow: hidden; margin-top: .55rem; }
.minibar i { display: block; height: 100%; background: var(--accent); }

/* ------------------------------------------------------------ subject -- */
.subject-head { display: flex; gap: .8rem; align-items: flex-start; margin-bottom: 1rem; }
.subject-head .sc-emoji { font-size: 2.2rem; }
.subject-head .sc-blurb { margin: .35rem 0 0; max-width: 56ch; }
.subject-head h1 { font-size: 1.4rem; margin: 0 0 .15rem; }
.readiness { margin-bottom: 1rem; }
.modes { display: grid; gap: .6rem;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
.mode {
  display: flex; gap: .7rem; align-items: flex-start; text-align: left;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: .85rem .9rem; font: inherit; color: var(--ink); cursor: pointer;
}
.mode:hover { border-color: var(--accent); }
.mode .em { font-size: 1.35rem; }
.mode b { display: block; }
.mode span { color: var(--ink-2); font-size: .84rem; }
.cats { display: grid; gap: .5rem;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.cat {
  display: flex; align-items: center; gap: .55rem; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 11px; padding: .6rem .7rem; font: inherit; color: var(--ink);
  text-align: left;
}
.cat:hover { border-color: var(--accent); }
.cat .em { font-size: 1.15rem; }
.cat b { font-size: .9rem; font-weight: 600; display: block; }
.cat small { color: var(--ink-3); font-size: .76rem; }
.subject-foot { margin-top: 1.6rem; color: var(--ink-3); font-size: .82rem; }
.subject-foot code { font-size: .8rem; }

/* --------------------------------------------------------------- quiz -- */
.quiz-bar { position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: .7rem; padding: .6rem .9rem;
  background: var(--bg); border-bottom: 1px solid var(--line); }
.quit { background: none; border: 0; color: var(--ink-2); font-size: 1.1rem;
  cursor: pointer; padding: .1rem .3rem; }
.bar { flex: 1; height: 7px; border-radius: 4px; background: var(--surface-2);
  overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent);
  transition: width .25s ease; }
.counter { color: var(--ink-2); font-size: .85rem; font-variant-numeric: tabular-nums; }
.timer { font-variant-numeric: tabular-nums; font-weight: 600; font-size: .9rem;
  padding: .15rem .5rem; border-radius: 999px; background: var(--surface-2); }
.timer.low { background: var(--bad-bg); color: var(--bad); }

.q-cat { color: var(--ink-3); font-size: .8rem; text-transform: uppercase;
  letter-spacing: .07em; margin: 1rem 0 .5rem; }
.q-text { font-size: 1.12rem; font-weight: 550; margin-bottom: 1rem; }
.q-fig { max-width: 100%; border-radius: 11px; border: 1px solid var(--line);
  background: #fff; margin-bottom: 1rem; }
.choices { display: grid; gap: .55rem; }
.choice {
  display: flex; gap: .7rem; align-items: flex-start; text-align: left;
  padding: .8rem .9rem; border-radius: 12px; cursor: pointer; font: inherit;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
}
.choice:hover:not([disabled]) { border-color: var(--accent); }
.choice .key { flex: 0 0 1.5rem; height: 1.5rem; border-radius: 50%;
  background: var(--surface-2); color: var(--ink-2); font-size: .82rem;
  display: grid; place-items: center; font-weight: 600; }
.choice.right { border-color: var(--good); background: var(--good-bg); }
.choice.right .key { background: var(--good); color: #fff; }
.choice.wrong { border-color: var(--bad); background: var(--bad-bg); }
.choice.wrong .key { background: var(--bad); color: #fff; }
.choice[disabled] { cursor: default; }

.feedback { margin-top: 1rem; padding: .9rem 1rem; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--line); }
.verdict { font-weight: 650; margin-bottom: .35rem; }
.verdict.ok { color: var(--good); }
.verdict.no { color: var(--bad); }
.expl { color: var(--ink-2); font-size: .93rem; }
.ref { color: var(--ink-3); font-size: .8rem; margin-top: .5rem; }
.flagbtn { background: none; border: 0; color: var(--ink-3); font: inherit;
  font-size: .8rem; cursor: pointer; padding: .4rem 0 0; }
.flagbtn:hover { color: var(--bad); }
.flagbtn.done { color: var(--good); }
.exam-note { color: var(--ink-3); font-size: .85rem; margin-top: 1rem;
  text-align: center; }
#next-btn { margin-top: 1rem; }

/* ------------------------------------------------------------ results -- */
.score-card { text-align: center; }
.ring { position: relative; width: 150px; height: 150px; margin: .3rem auto .6rem; }
.ring svg { transform: rotate(-90deg); width: 150px; height: 150px; }
.ring .track { stroke: var(--surface-2); }
.ring .fill { stroke: var(--accent); transition: stroke-dasharray .7s ease; }
.ring-mid { position: absolute; inset: 0; display: grid; place-content: center; }
.pct { font-size: 2.1rem; font-weight: 700; line-height: 1; }
.frac { color: var(--ink-3); font-size: .85rem; }
.verdict-line { font-size: 1.15rem; font-weight: 650; }
.sub { color: var(--ink-2); font-size: .92rem; margin: .3rem 0 0; }

.catrow { display: flex; align-items: center; gap: .6rem; padding: .38rem 0; }
.catrow .nm { flex: 1; font-size: .9rem; }
.catrow .sc { color: var(--ink-2); font-size: .85rem;
  font-variant-numeric: tabular-nums; }
.catrow .bar { max-width: 110px; }
.missed .m { border-top: 1px solid var(--line); padding: .8rem 0; }
.missed .m:first-child { border-top: 0; }
.missed .mq { font-weight: 550; margin-bottom: .45rem; }
.missed .ml { font-size: .88rem; padding: .18rem 0; color: var(--ink-2); }
.missed .ml.right { color: var(--good); font-weight: 600; }
.missed .ml.wrong { color: var(--bad); text-decoration: line-through; }

/* --------------------------------------------------------- flashcards -- */
.flashcard { min-height: 150px; display: grid; align-content: center; gap: .8rem; }
.card-answer { border-top: 1px dashed var(--line); padding-top: .8rem; }
.card-answer .a { font-size: 1.05rem; font-weight: 600; color: var(--good);
  padding: .15rem 0; }
.card-answer .note { color: var(--ink-2); font-size: .9rem; margin-top: .5rem; }
.card-answer .warn { color: var(--warn); font-size: .86rem; margin-top: .5rem; }

/* -------------------------------------------------------------- stats -- */
.tiles { display: grid; gap: .6rem; margin-bottom: .9rem;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
.tile { background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: .8rem .9rem; }
.tile .v { font-size: 1.5rem; font-weight: 700; line-height: 1.1; }
.tile .l { color: var(--ink-3); font-size: .78rem; text-transform: uppercase;
  letter-spacing: .06em; }
.gauge { height: 12px; border-radius: 7px; background: var(--surface-2);
  position: relative; overflow: hidden; margin: .5rem 0 .3rem; }
.gauge i { display: block; height: 100%; background: var(--accent); }
.gauge i.ready { background: var(--good); }
.gauge .mark { position: absolute; top: -3px; bottom: -3px; width: 2px;
  background: var(--ink); opacity: .55; }
.daybars { display: flex; align-items: flex-end; gap: 3px; height: 60px; }
.daybars i { flex: 1; background: var(--accent); border-radius: 2px 2px 0 0;
  min-height: 2px; opacity: .8; }

/* -------------------------------------------------------------- modal -- */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  background: rgba(8, 14, 22, .55); padding: 1rem; }
.modal[hidden] { display: none; }
.modal-box { background: var(--surface); border-radius: var(--radius);
  padding: 1.1rem; width: 100%; max-width: 440px; box-shadow: var(--shadow); }

.toast { position: fixed; left: 50%; bottom: 1.4rem; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: .6rem 1rem; border-radius: 999px;
  font-size: .9rem; z-index: 60; box-shadow: var(--shadow); }
.toast[hidden] { display: none; }

@media (max-width: 480px) {
  .row2 { grid-template-columns: 1fr; }
  .hero { font-size: 1.7rem; }
}
