:root {
  /* Light, because the crops are black ink on white paper: any card they sit on has to be
     white too, or the scan's edges show up as rectangles.  --card is that paper; --card-2
     is chrome (buttons, pills, hovers) and must never sit behind a crop. */
  --bg: #eef1f6;
  --card: #ffffff;
  --card-2: #f3f6fa;
  --hover: #e9eef6;
  --line: #dfe4ec;
  --line-2: #c4ccd9;
  --ink: #111827;
  --ink-2: #5b6675;
  --ink-3: #8a94a4;
  --accent: #2563eb;
  --accent-soft: #e8efff;
  --ok: #16a34a;
  --ok-ink: #15803d;
  --ok-soft: #eaf7ef;
  --bad: #dc2626;
  --bad-ink: #b91c1c;
  --bad-soft: #fdecec;
  --warn: #b45309;
  --warn-ink: #92400e;
  --warn-soft: #fdf4e6;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05);
  --r: 12px;
  --pad: 16px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; color: inherit; }

a { color: inherit; text-decoration: none; }

/* ---------- header ---------- */

#bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px var(--pad);
  background: rgba(255, 255, 255, .88);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 9px; font-weight: 600; }
.brand svg { width: 20px; height: 20px; color: var(--accent); }
.brand span { font-size: 14px; }

svg { fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

.avatar {
  margin-left: auto;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid transparent;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.menu {
  position: absolute;
  top: 48px;
  right: var(--pad);
  min-width: 180px;
  padding: 6px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(16, 24, 40, .14);
}

.menu p { margin: 6px 8px 8px; font-size: 12px; color: var(--ink-2); }

.menu button {
  display: block;
  width: 100%;
  padding: 8px;
  text-align: left;
  background: none;
  border: 0;
  border-radius: 7px;
  cursor: pointer;
}

.menu button:hover { background: var(--card-2); }

/* ---------- layout ---------- */

main { max-width: 860px; margin: 0 auto; padding: 20px var(--pad) 64px; }

h1 { margin: 0 0 4px; font-size: 22px; letter-spacing: -.2px; }
h2 { margin: 26px 0 10px; font-size: 15px; }
h3 { margin: 0; font-size: 15px; font-weight: 600; }

.sub { margin: 0 0 18px; color: var(--ink-2); font-size: 14px; }

.crumb {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 14px;
  padding: 5px 10px 5px 6px;
  color: var(--ink-2);
  font-size: 13px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
}

.crumb svg { width: 15px; height: 15px; }
.crumb:hover { color: var(--ink); border-color: var(--line-2); }

/* ---------- stats ---------- */

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 16px 0 4px;
  padding: 14px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.stats.two { grid-template-columns: repeat(2, 1fr); }
.stat span { display: block; color: var(--ink-2); font-size: 12.5px; }
.stat strong { display: block; margin-top: 3px; font-size: 21px; font-weight: 650; letter-spacing: -.3px; }

/* ---------- cards ---------- */

.card {
  padding: var(--pad);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow);
}

.feature { display: block; width: 100%; text-align: left; cursor: pointer; }
.feature:hover { border-color: var(--line-2); background: var(--card-2); }
.feature .ico { display: block; width: 22px; height: 22px; margin-bottom: 10px; color: var(--accent); }
.feature p { margin: 4px 0 14px; color: var(--ink-2); font-size: 13.5px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--card-2);
  border: 1px solid var(--line-2);
  border-radius: 8px;
  font-size: 13.5px;
  cursor: pointer;
}

.btn:hover { background: var(--hover); }
.btn.wide { width: 100%; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: #1d4ed8; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* ---------- subject grid ---------- */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}

.tile {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 13px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  cursor: pointer;
  text-align: left;
}

.tile:hover { border-color: var(--line-2); background: var(--card-2); }
.tile .ico { width: 19px; height: 19px; color: var(--accent); }
.tile b { font-size: 13.5px; font-weight: 600; line-height: 1.3; }
.tile small { color: var(--ink-3); font-size: 11.5px; }
.tile .bar { margin-top: auto; }

.tile.soon { cursor: default; opacity: .62; box-shadow: none; }
.tile.soon:hover { border-color: var(--line); background: var(--card); }
.tile.soon .ico { color: var(--ink-3); }

.pill {
  align-self: flex-start;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .2px;
  text-transform: uppercase;
  color: var(--ink-2);
  background: var(--card-2);
  border: 1px solid var(--line);
}

/* ---------- rows ---------- */

.rows { display: flex; flex-direction: column; gap: 8px; }

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow);
}

.row .mark { flex: none; width: 18px; height: 18px; color: var(--ink-3); }
.row .mark.done { color: var(--ok); }
.row .grow { min-width: 0; flex: 1; }
.row .grow small { display: block; margin-top: 2px; color: var(--ink-3); font-size: 12px; }
.row .acts { display: flex; flex: none; gap: 7px; }
.row.mixed { border-style: dashed; box-shadow: none; }

.bar { height: 4px; border-radius: 999px; background: var(--line); overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 999px; background: var(--ink-3); }
.bar i.good { background: var(--ok); }
.bar i.poor { background: var(--bad); }

.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: 8px;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  vertical-align: 2px;
}

.tag.strong { color: var(--ok-ink); background: var(--ok-soft); }
.tag.weak { color: var(--bad-ink); background: var(--bad-soft); }
.tag.flag { color: var(--warn-ink); background: var(--warn-soft); }
.tag svg { width: 12px; height: 12px; }

.wrong { flex: none; color: var(--ink-2); font-size: 12.5px; }

/* ---------- practice ---------- */

.q {
  --k: 1;
  margin-bottom: 12px;
  padding: 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow);
}

.q header { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.q header b { color: var(--ink-2); font-size: 12px; font-weight: 600; letter-spacing: .3px; }

/* One page of the book is one WebP atlas; every crop is a window onto it, scaled by --k
   so a stem fills the card at any viewport.

   multiply is what hides the seams: the scans are black ink on white paper, and under
   multiply white leaves the backdrop untouched while the ink stays ink.  So a crop shows
   no rectangle -- not on the white card, not on a hover, not on the green or red of an
   answered row.  Without it every crop advertises its own boundary. */
.crop {
  width: calc(var(--w) * var(--k) * 1px);
  height: calc(var(--h) * var(--k) * 1px);
  max-width: 100%;
  background-repeat: no-repeat;
  background-size: calc(var(--aw) * var(--k) * 1px) calc(var(--ah) * var(--k) * 1px);
  background-position: calc(var(--x) * var(--k) * -1px) calc(var(--y) * var(--k) * -1px);
  mix-blend-mode: multiply;
}

.opts { display: flex; flex-direction: column; gap: 7px; margin-top: 12px; }

.opt {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  position: relative;              /* so the hidden key cannot escape and cause overflow */
  width: 100%;
  padding: 9px 11px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 9px;
  cursor: pointer;
  text-align: left;
}

.opt:hover:not(:disabled) { border-color: var(--line-2); background: var(--card-2); }
.opt:disabled { cursor: default; }

/* The crop already reads "(a)", "(b)" ... in the book's own type, so a second letter beside
   it is just noise.  It stays in the markup because it is the button's accessible name --
   the crop is a background image with no text of its own -- so this hides it from sight
   only.  Not `display: none`, which would take it from screen readers too. */
.opt .key {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.opt.picked { border-color: var(--line-2); }
.opt.right { border-color: var(--ok); background: var(--ok-soft); }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }

.note {
  margin: 10px 0 0;
  padding: 9px 11px;
  color: var(--warn-ink);
  font-size: 12.5px;
  background: var(--warn-soft);
  border: 1px solid #f0dcb6;
  border-radius: 9px;
}

.sticky {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px calc(var(--pad) * -1) 0;
  padding: 12px var(--pad);
  background: rgba(255, 255, 255, .94);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
}

.sticky .grow { flex: 1; }
.sticky small { color: var(--ink-2); font-size: 12.5px; }

.sets { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 14px; }

.set {
  padding: 6px 11px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12.5px;
  cursor: pointer;
}

.set.on { border-color: var(--accent); color: #1d4ed8; background: var(--accent-soft); }
.set.done { color: var(--ok-ink); }

/* ---------- login ---------- */

.login { max-width: 380px; margin: 8vh auto 0; text-align: center; }
.login .mark { width: 42px; height: 42px; margin: 0 auto 18px; color: var(--accent); }
.login h1 { font-size: 25px; }
.login .card { margin-top: 22px; text-align: left; }
.login .or { margin: 14px 0 12px; color: var(--ink-3); font-size: 12px; text-align: center; }
.login .fine { margin: 14px 0 0; color: var(--ink-3); font-size: 12px; line-height: 1.5; }

#gbtn { display: flex; justify-content: center; min-height: 40px; }

.empty { padding: 28px 16px; color: var(--ink-2); font-size: 14px; text-align: center; }

@media (max-width: 560px) {
  .stats { grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .stat strong { font-size: 18px; }
  .grid { grid-template-columns: repeat(2, 1fr); }
  .row { padding: 11px 12px; }
  .row .acts { flex-direction: column; }
}
