:root {
  --bg: #f7f5f2;
  --panel: #ffffff;
  --ink: #1c1c1e;
  --muted: #6f6a63;
  --line: #e4dfd8;
  --gold: #c9a87c;
  --ok: #4c8a53;
  --warn: #b4453c;
  --radius: 10px;
}

* { box-sizing: border-box; }

/* The `hidden` attribute hides things only through the browser's own
   `[hidden] { display: none }`, which ANY author display rule outranks —
   `.gate { display: grid }` kept the login card on screen after a successful
   login, so the base rendered below the fold and looked like a dead button.
   This rule makes `hidden` mean hidden. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.6 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

h1, h2, h3 { font-family: 'Cormorant Garamond', Georgia, serif; font-weight: 600; line-height: 1.2; }

/* ── Login gate ─────────────────────────────────────────────── */
.gate { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.gate-card {
  width: min(360px, 100%); background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 32px 28px; text-align: center;
}
.gate-brand { letter-spacing: .28em; font-size: 12px; color: var(--gold); margin: 0 0 6px; }
.gate-title { margin: 0 0 24px; font-size: 30px; }
.gate-label { display: block; text-align: left; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.gate-input {
  width: 100%; padding: 12px 14px; font-size: 18px; letter-spacing: .3em; text-align: center;
  border: 1px solid var(--line); border-radius: var(--radius); background: #fff; color: var(--ink);
}
.gate-input:focus { outline: 2px solid var(--gold); outline-offset: 1px; }
.gate-btn {
  width: 100%; margin-top: 16px; padding: 12px; font-size: 15px; font-weight: 600;
  border: 0; border-radius: var(--radius); background: var(--ink); color: #fff; cursor: pointer;
}
.gate-error { margin: 14px 0 0; color: var(--warn); font-size: 14px; }

/* ── Frame ──────────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.topbar-brand { font-weight: 600; letter-spacing: .04em; }
.whoami { margin-left: auto; color: var(--muted); font-size: 14px; }
.icon-btn { border: 0; background: none; font-size: 18px; cursor: pointer; padding: 4px 6px; }
.link-btn { border: 0; background: none; color: var(--muted); font-size: 14px; cursor: pointer; text-decoration: underline; }

.body { display: grid; grid-template-columns: 280px 1fr; align-items: start; }
.sidebar {
  position: sticky; top: 53px; max-height: calc(100dvh - 53px); overflow: auto;
  padding: 20px 12px 40px; border-right: 1px solid var(--line);
}
/* min-width:0 is load-bearing: a grid item defaults to min-width:auto and
   refuses to shrink below its content, so one wide table pushes the whole
   page sideways on a phone. */
.reader { padding: 28px clamp(16px, 5vw, 56px) 96px; max-width: 820px; min-width: 0; }

.sec-title { font-size: 12px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); margin: 18px 8px 8px; }
.toc-item {
  display: flex; gap: 8px; align-items: baseline; width: 100%; text-align: left;
  padding: 9px 10px; border: 0; border-radius: var(--radius); background: none;
  font: inherit; font-size: 14px; color: var(--ink); cursor: pointer;
}
.toc-item:hover { background: #efeae3; }
.toc-item[aria-current="true"] { background: #efeae3; font-weight: 600; }
.toc-tick { width: 14px; color: var(--ok); }
.toc-min { margin-left: auto; color: var(--muted); font-size: 12px; }
.toc-progress { margin: 4px 8px 12px; height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; }
.toc-progress > i { display: block; height: 100%; background: var(--gold); }

.art-title { font-size: clamp(26px, 4vw, 36px); margin: 0 0 4px; }
.art-meta { color: var(--muted); font-size: 13px; margin: 0 0 28px; }
.kb-lead { font-size: 18px; color: #3a3630; }

@media (max-width: 860px) {
  /* The bar has to survive 360px without wrapping to a second line. */
  .topbar { gap: 8px; padding: 10px 12px; }
  .topbar-brand { font-size: 15px; white-space: nowrap; }
  .brand-prefix { display: none; }
  .whoami { font-size: 13px; }

  .body { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 53px auto 0 0; width: 84vw; max-width: 320px; z-index: 15;
    background: var(--panel); border-right: 1px solid var(--line); transform: translateX(-100%);
    transition: transform .18s ease;
  }
  .sidebar.open { transform: none; }
}
@media (min-width: 861px) { #menu-toggle { display: none; } }

/* ── Comments ───────────────────────────────────────────────── */
.art-body .has-anchor { position: relative; }
.cm-badge-btn {
  position: absolute; top: -2px; right: -34px; border: 0; background: none;
  font-size: 13px; color: var(--muted); cursor: pointer; opacity: .35; transition: opacity .15s;
}
.art-body .has-anchor:hover .cm-badge-btn, .cm-badge-btn.has-open { opacity: 1; }
.cm-badge-btn.has-open { color: var(--gold); }

.cm-panel {
  margin: 12px 0 24px; padding: 16px; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius);
}
.cm-title { margin: 0 0 12px; font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.cm-empty { color: var(--muted); font-size: 14px; margin: 0 0 12px; }
.cm { border-top: 1px solid var(--line); padding: 12px 0; font-size: 14px; }
.cm:first-of-type { border-top: 0; padding-top: 0; }
.cm.is-resolved { opacity: .55; }
.cm header i { color: var(--muted); font-style: normal; font-size: 12px; margin-left: 6px; }
.cm p { margin: 6px 0; white-space: pre-wrap; }
.cm-badge { margin-left: 8px; font-size: 11px; color: var(--ok); border: 1px solid var(--ok); border-radius: 999px; padding: 1px 7px; }
.cm-reply { margin: 8px 0 0 16px; padding-left: 12px; border-left: 2px solid var(--gold); }
.cm-acts { display: flex; gap: 12px; margin-top: 6px; }
.cm-act { border: 0; background: none; padding: 0; color: var(--muted); font-size: 13px; cursor: pointer; text-decoration: underline; }
.cm-panel textarea {
  width: 100%; padding: 10px; font: inherit; font-size: 14px;
  border: 1px solid var(--line); border-radius: var(--radius); resize: vertical;
}
.cm-panel button[type="submit"] {
  margin-top: 8px; padding: 8px 16px; font-size: 14px; border: 0;
  border-radius: var(--radius); background: var(--ink); color: #fff; cursor: pointer;
}
.cm-replyform { margin: 8px 0 0 16px; }

@media (max-width: 860px) {
  .cm-badge-btn { position: static; display: block; margin-top: 4px; opacity: 1; }
}

/* ── Studied flag and quiz ──────────────────────────────────── */
.art-footer { margin-top: 48px; padding-top: 24px; border-top: 1px solid var(--line); }
.qz { margin-bottom: 28px; }
.qz-title { font-size: 22px; margin: 0 0 14px; }
.qz-list { padding-left: 20px; margin: 0; }
.qz-item { margin-bottom: 18px; }
.qz-q { margin: 0 0 8px; font-weight: 500; }
.qz-opts { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.qz-opt {
  padding: 8px 14px; font: inherit; font-size: 14px; text-align: left; cursor: pointer;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
}
.qz-opt:disabled { cursor: default; }
.qz-opt.is-right { border-color: var(--ok); background: #eef6ef; }
.qz-opt.is-wrong { border-color: var(--warn); background: #fbeeed; }
.qz-why { margin: 8px 0 0; font-size: 14px; color: var(--muted); }
.qz-score { margin-top: 10px; font-weight: 600; }

.done-btn {
  padding: 12px 22px; font: inherit; font-size: 15px; font-weight: 600; cursor: pointer;
  border: 1px solid var(--ink); border-radius: var(--radius); background: none; color: var(--ink);
}
.done-btn.is-done { background: var(--ok); border-color: var(--ok); color: #fff; }

/* ── Search ─────────────────────────────────────────────────── */
.search-dlg { width: min(620px, 92vw); border: 1px solid var(--line); border-radius: var(--radius); padding: 0; }
.search-dlg::backdrop { background: rgba(28, 28, 30, .35); }
.search-input { width: 100%; padding: 16px 18px; font: inherit; font-size: 17px; border: 0; border-bottom: 1px solid var(--line); }
.search-input:focus { outline: none; }
.search-results { list-style: none; margin: 0; padding: 6px; max-height: 60vh; overflow: auto; }
.search-hit {
  display: block; width: 100%; text-align: left; padding: 10px 12px; font: inherit;
  border: 0; border-radius: var(--radius); background: none; cursor: pointer;
}
.search-hit:hover { background: #efeae3; }
.search-hit span { display: block; color: var(--muted); font-size: 13px; margin-top: 2px; }
.search-none { padding: 14px; color: var(--muted); font-size: 14px; }

/* ── Journey diagram ────────────────────────────────────────── */
.kb-journey { margin: 28px 0; }
.kb-switch { display: inline-flex; padding: 3px; margin-bottom: 16px; background: #ece7e0; border-radius: 999px; }
.kb-switch button {
  padding: 7px 20px; font: inherit; font-size: 14px; border: 0; border-radius: 999px;
  background: none; color: var(--muted); cursor: pointer;
}
.kb-switch button[aria-pressed="true"] { background: var(--panel); color: var(--ink); font-weight: 600; }

.kb-step { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); margin-bottom: 8px; }
.kb-step.is-only { border-left: 3px solid var(--gold); }
.kb-step-head {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 14px;
  font: inherit; text-align: left; background: none; border: 0; cursor: pointer;
}
.kb-step-n {
  flex: none; width: 24px; height: 24px; display: grid; place-items: center;
  border-radius: 50%; background: var(--ink); color: #fff; font-size: 12px;
}
.kb-step.is-only .kb-step-n { background: var(--gold); }
.kb-step-title { font-weight: 500; }
.kb-step-chev { margin-left: auto; color: var(--muted); }
.kb-step-head[aria-expanded="true"] .kb-step-chev { transform: rotate(180deg); }
.kb-step-body { padding: 0 14px 14px 50px; }
.kb-row { display: grid; grid-template-columns: 170px 1fr; gap: 12px; padding: 8px 0; border-top: 1px dashed var(--line); }
.kb-row-t { font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.kb-row-b p { margin: 0 0 6px; }
.kb-row-staff .kb-row-t { color: var(--gold); }
.kb-row-trap .kb-row-t { color: var(--warn); }

@media (max-width: 620px) {
  .kb-row { grid-template-columns: 1fr; gap: 2px; }
  .kb-step-body { padding-left: 14px; }
}

/* ── Article content ────────────────────────────────────────── */
.art-body h2 { font-size: 24px; margin: 34px 0 12px; }
.art-body p { margin: 0 0 14px; }
.art-body ul, .art-body ol { margin: 0 0 14px; padding-left: 22px; }
.art-body li { margin-bottom: 6px; }
.art-body strong { font-weight: 600; }

.kb-compare { width: 100%; border-collapse: collapse; margin: 18px 0 24px; font-size: 14px; }
.kb-compare th, .kb-compare td { border: 1px solid var(--line); padding: 10px 12px; text-align: left; vertical-align: top; }
.kb-compare th { background: #efeae3; font-weight: 600; }
.kb-compare tbody th { background: var(--panel); font-weight: 500; width: 30%; }
.kb-table-wrap { overflow-x: auto; max-width: 100%; -webkit-overflow-scrolling: touch; }
/* Wide enough that cells read as sentences rather than one word per line; on a
   phone the wrapper scrolls sideways instead of squeezing the columns. */
.kb-compare { min-width: 620px; }

.kb-note {
  margin: 20px 0; padding: 14px 16px; background: #fdf8ef;
  border: 1px solid var(--gold); border-radius: var(--radius);
}
.kb-note > summary { cursor: pointer; font-weight: 600; }
.kb-note > summary::marker { color: var(--gold); }
.kb-note p:last-child, .kb-note ul:last-child { margin-bottom: 0; }

.kb-key {
  margin: 20px 0; padding: 14px 16px; border-left: 3px solid var(--ink);
  background: var(--panel); font-size: 15px;
}
.kb-key p:last-child { margin-bottom: 0; }

.kb-shot { margin: 20px 0; }
.kb-shot img { display: block; max-width: 100%; border: 1px solid var(--line); border-radius: var(--radius); }
.kb-shot figcaption { margin-top: 6px; font-size: 13px; color: var(--muted); }
