/* app.css — layout and components. Reads values from tokens.css.
   Change look-and-feel in tokens.css first; only edit here for STRUCTURE. */

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--fs-base);
  line-height: var(--lh-base);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

code, kbd, pre { font-family: var(--mono); font-size: 0.92em; }
pre {
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--s3);
  overflow-x: auto;
  line-height: 1.45;
}

/* ---------- layout ---------- */
.wrap {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 var(--gutter);
}

.site-header {
  border-bottom: 1px solid var(--border);
  background: var(--bg-raised);
  position: sticky;
  top: 0;
  z-index: 20;
}
.site-header .wrap {
  display: flex;
  align-items: center;
  gap: var(--s4);
  min-height: 56px;
  flex-wrap: wrap;
}
.brand {
  font-weight: var(--fw-bold);
  color: var(--text);
  letter-spacing: -0.01em;
}
.brand:hover { text-decoration: none; }
.nav { display: flex; gap: var(--s4); margin-left: auto; flex-wrap: wrap; }
.nav a { color: var(--text-muted); font-size: var(--fs-sm); }
.nav a.active, .nav a:hover { color: var(--text); text-decoration: none; }

main { padding: var(--s6) 0 var(--s7); }

.page-title {
  font-size: var(--fs-2xl);
  line-height: var(--lh-tight);
  margin: 0 0 var(--s2);
  letter-spacing: -0.02em;
}
.page-sub { color: var(--text-muted); margin: 0 0 var(--s6); }

section { margin-bottom: var(--s6); }
h2 { font-size: var(--fs-xl); margin: 0 0 var(--s3); letter-spacing: -0.01em; }
h3 { font-size: var(--fs-lg); margin: 0 0 var(--s2); }

/* ---------- cards ---------- */
.card {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--s4);
}
.grid {
  display: grid;
  gap: var(--s4);
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
}
.card-link { display: block; color: inherit; }
.card-link:hover {
  text-decoration: none;
  border-color: var(--border-strong);
  background: var(--bg-sunken);
}
.card-link h3 { color: var(--text); }
.card-link p { color: var(--text-muted); font-size: var(--fs-sm); margin: 0; }

/* ---------- stats ---------- */
.stats {
  display: grid;
  gap: var(--s3);
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  margin-bottom: var(--s5);
}
.stat {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--s4);
}
.stat .num {
  font-size: var(--fs-2xl);
  font-weight: var(--fw-bold);
  line-height: 1;
  letter-spacing: -0.02em;
  display: block;
}
.stat .lbl {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: var(--s2);
  display: block;
}
.stat.ok    .num { color: var(--ok); }
.stat.warn  .num { color: var(--warn); }
.stat.danger .num { color: var(--danger); }

/* ---------- progress ---------- */
.bar {
  height: 8px;
  background: var(--bg-sunken);
  border-radius: 99px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.bar > span {
  display: block;
  height: 100%;
  background: var(--ok);
  transition: width .25s ease;
}

/* ---------- topic list ---------- */
.topic {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: var(--s3);
  overflow: hidden;
}
.topic[data-state="done"]    { border-left: 3px solid var(--ok); }
.topic[data-state="partial"] { border-left: 3px solid var(--warn); }
.topic[data-state="none"]    { border-left: 3px solid var(--border-strong); }
.topic[data-state="overdue"] { border-left: 3px solid var(--danger); }

.topic-head {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s3) var(--s4);
  cursor: pointer;
  user-select: none;
  flex-wrap: wrap;
}
.topic-head:hover { background: var(--bg-sunken); }
.topic-head .tw { flex: 1; min-width: 200px; }
.topic-head .tt { font-weight: var(--fw-med); }
.topic-head .tm {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  margin-top: 2px;
}
.topic-head .tc {
  font-variant-numeric: tabular-nums;
  font-size: var(--fs-sm);
  color: var(--text-muted);
  white-space: nowrap;
}
.topic-body {
  display: none;
  padding: var(--s3) var(--s4) var(--s4);
  border-top: 1px solid var(--border);
  background: var(--bg-sunken);
}
.topic.open .topic-body { display: block; }

.flags { display: grid; gap: var(--s2); grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.flag {
  display: flex;
  align-items: center;
  gap: var(--s2);
  padding: var(--s2) var(--s3);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: var(--fs-sm);
}
.flag:hover { border-color: var(--border-strong); }
.flag input { accent-color: var(--ok); width: 16px; height: 16px; flex: none; }
.flag.got { background: var(--ok-soft); border-color: var(--ok); }
.flag .fn { font-family: var(--mono); font-size: var(--fs-xs); flex: 1; }
.flag .fb {
  font-size: var(--fs-xs);
  color: var(--text-faint);
  white-space: nowrap;
}

/* ---------- badges ---------- */
.badge {
  display: inline-block;
  font-size: var(--fs-xs);
  padding: 2px var(--s2);
  border-radius: 99px;
  border: 1px solid var(--border-strong);
  color: var(--text-muted);
  white-space: nowrap;
}
.badge.ok     { color: var(--ok);     border-color: var(--ok);     background: var(--ok-soft); }
.badge.warn   { color: var(--warn);   border-color: var(--warn);   background: var(--warn-soft); }
.badge.danger { color: var(--danger); border-color: var(--danger); background: var(--danger-soft); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  padding: var(--s2) var(--s4);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-raised);
  color: var(--text);
  font: inherit;
  font-size: var(--fs-sm);
  cursor: pointer;
}
.btn:hover { background: var(--bg-sunken); text-decoration: none; }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}
.btn.primary:hover { filter: brightness(1.1); background: var(--accent); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-row { display: flex; gap: var(--s2); flex-wrap: wrap; }

/* ---------- notices ---------- */
.notice {
  border-left: 3px solid var(--warn);
  background: var(--warn-soft);
  padding: var(--s3) var(--s4);
  border-radius: var(--radius-sm);
  font-size: var(--fs-sm);
  margin-bottom: var(--s4);
}
.notice.danger { border-color: var(--danger); background: var(--danger-soft); }
.notice.ok     { border-color: var(--ok);     background: var(--ok-soft); }
.notice strong { color: var(--text); }

/* ---------- drill ---------- */
.drill-stem {
  font-size: var(--fs-lg);
  line-height: 1.45;
  white-space: pre-wrap;
  margin-bottom: var(--s5);
}
.drill-opts { display: grid; gap: var(--s2); margin-bottom: var(--s5); }
.opt {
  display: flex;
  gap: var(--s3);
  padding: var(--s3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-sunken);
  white-space: pre-wrap;
}
.opt .mark { font-family: var(--mono); color: var(--text-faint); flex: none; }
.opt .why {
  display: block;
  margin-top: var(--s2);
  font-size: var(--fs-sm);
  color: var(--text-muted);
}
.revealed .opt[data-correct="true"]  { border-color: var(--ok);     background: var(--ok-soft); }
.revealed .opt[data-correct="false"] { border-color: var(--border); opacity: .75; }
.hidden { display: none !important; }

.transcript {
  background: var(--bg-sunken);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  padding: var(--s3);
  min-height: 3.5em;
  font-size: var(--fs-sm);
  color: var(--text-muted);
  margin-bottom: var(--s4);
  white-space: pre-wrap;
}
.transcript.live { border-color: var(--accent); color: var(--text); }

/* ---------- vault ---------- */
.file-list { display: grid; gap: var(--s1); }
.file-list a {
  display: flex;
  justify-content: space-between;
  gap: var(--s3);
  padding: var(--s2) var(--s3);
  border-radius: var(--radius-sm);
  color: var(--text);
  border: 1px solid transparent;
}
.file-list a:hover {
  background: var(--bg-sunken);
  border-color: var(--border);
  text-decoration: none;
}
.file-list .meta { color: var(--text-faint); font-size: var(--fs-xs); white-space: nowrap; }

/* ---------- gate 2 ---------- */
.gate {
  margin-top: var(--s7);
  padding-top: var(--s5);
  border-top: 1px dashed var(--border-strong);
  text-align: center;
}
.gate p { color: var(--text-faint); font-size: var(--fs-sm); margin: var(--s2) 0 0; }

.footer {
  border-top: 1px solid var(--border);
  padding: var(--s5) 0;
  color: var(--text-faint);
  font-size: var(--fs-xs);
}

@media (max-width: 560px) {
  :root { --fs-2xl: 1.6rem; --fs-3xl: 2rem; }
  .topic-head .tc { width: 100%; }
}

/* ============================================================
   FORCED COLORS / Windows High Contrast

   In this mode Windows replaces every author color with system
   colors, so anything that conveys meaning through color alone
   disappears. Rules below restore meaning using borders, system
   color keywords, and text markers.
   ============================================================ */
@media (forced-colors: active) {

  /* Keep every surface boundary visible — transparent borders
     are painted in forced-colors mode. */
  .card, .stat, .topic, .flag, .opt, .btn, .bar, .transcript,
  .notice, .badge, pre {
    border: 1px solid;
  }

  /* Status is carried by a left rule + a text marker, not hue. */
  .topic[data-state]          { border-left-width: 4px; }
  .topic[data-state="done"]    .tt::before { content: "[done] "; }
  .topic[data-state="partial"] .tt::before { content: "[part] "; }
  .topic[data-state="overdue"] .tt::before { content: "[LATE] "; }

  .flag.got { background: Highlight; color: HighlightText; }
  .flag.got .fn { color: HighlightText; }

  .badge.danger::before { content: "! "; }
  .badge.warn::before   { content: "* "; }

  .notice          { border-left-width: 4px; }
  .notice.danger::before { content: "! "; font-weight: bold; }

  /* Progress bar: the fill must stay distinct from the track. */
  .bar { background: Canvas; }
  .bar > span { background: Highlight; forced-color-adjust: none; }

  /* Revealed drill options: correct one is marked with text, since
     the green background will not survive. */
  .revealed .opt[data-correct="true"]  { border-width: 3px; }
  .revealed .opt[data-correct="false"] { opacity: 1; border-style: dashed; }
  .opt .mark { forced-color-adjust: none; }

  .btn.primary { border-width: 2px; }

  /* Muted text becomes GrayText so hierarchy survives. */
  .page-sub, .tm, .lbl, .meta, .fb, .why, .footer { color: GrayText; }

  .transcript.live { border-width: 2px; }
}
