/*
 * Design tokens and page chrome from the RDT Visualizer (~/sr_gbn_visualizer): warm
 * neutral surfaces, one brand red (the KN logo red), slate for structure, and
 * mint/sun/sky as supporting accents. Glossary layout below.
 */
:root {
  --brand: #c2284a;
  --brand-2: #a62c4d;
  --brand-deep: #961d33;
  --accent: #e97991;
  --rose-soft: #f4d9df;
  --mint: #44c7a4;
  --sun: #ffd166;
  --sky: #65c7f7;

  --bg: #f7f3ea;
  --card: #fffdf8;
  --card-2: #f3ece0;
  --line: #eadfce;
  --ink: #161922;
  --ink-2: #2c303a;
  --muted: #6b6f7a;
  --on-brand: #ffffff;
  --focus: #ffd166;
  --mark: rgba(255, 209, 102, 0.55);

  --shadow-soft: 0 18px 45px rgb(15 23 42 / 10%);
  --shadow-card: 0 8px 24px rgb(15 23 42 / 6%);
  --shadow-button: 0 4px 0 rgb(111 20 48 / 18%), 0 8px 18px rgb(111 20 48 / 12%);
  --radius: 2rem;
  --radius-md: 1.4rem;
  --radius-sm: 1rem;
  --font-sans: 'Plus Jakarta Sans', ui-sans-serif, system-ui, sans-serif;
  --font-display: 'Manrope', ui-sans-serif, system-ui, sans-serif;
  --font-mono: ui-monospace, 'SFMono-Regular', 'JetBrains Mono', Menlo, Consolas, monospace;
  --topbar-h: 72px;
  color-scheme: light;
}

/* Dark tokens: defined twice (auto via media query, explicit via data-theme). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --brand: #e97991;
    --brand-2: #e06482;
    --brand-deep: #e97991;
    --rose-soft: #3a1d27;
    --bg: #0d0f16;
    --card: #161922;
    --card-2: #1e222d;
    --line: #2a2f3b;
    --ink: #e9ebf1;
    --ink-2: #c9ccd6;
    --muted: #9aa0ad;
    --on-brand: #161922;
    --mark: rgba(255, 209, 102, 0.28);
    --shadow-soft: 0 18px 45px rgb(0 0 0 / 35%);
    --shadow-card: 0 8px 24px rgb(0 0 0 / 25%);
    --shadow-button: 0 4px 0 rgb(0 0 0 / 30%);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --brand: #e97991;
  --brand-2: #e06482;
  --brand-deep: #e97991;
  --rose-soft: #3a1d27;
  --bg: #0d0f16;
  --card: #161922;
  --card-2: #1e222d;
  --line: #2a2f3b;
  --ink: #e9ebf1;
  --ink-2: #c9ccd6;
  --muted: #9aa0ad;
  --on-brand: #161922;
  --mark: rgba(255, 209, 102, 0.28);
  --shadow-soft: 0 18px 45px rgb(0 0 0 / 35%);
  --shadow-card: 0 8px 24px rgb(0 0 0 / 25%);
  --shadow-button: 0 4px 0 rgb(0 0 0 / 30%);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.45;
}
html { scroll-padding-top: calc(var(--topbar-h) + 16px); }

button, select, input { font: inherit; color: inherit; }

button:focus-visible, select:focus-visible, input:focus-visible, a:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

::selection { color: #fff; background: #c2284a; }

[hidden] { display: none !important; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* ---------- top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  gap: 12px 20px;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; gap: 12px; align-items: center; min-width: 0; }
.logo { height: 45px; width: auto; flex: none; }
:root[data-theme="dark"] .logo { filter: brightness(1.75) saturate(0.85); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .logo { filter: brightness(1.75) saturate(0.85); } }

h1 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.3rem;
  letter-spacing: -0.01em;
  color: var(--brand-deep);
}
.subtitle { margin: 0; color: var(--muted); font-size: 0.82rem; }
.kicker { margin: 0 0 1px; font-size: 0.66rem; font-weight: 800; letter-spacing: 0.1em; text-transform: uppercase; color: var(--brand-deep); opacity: 0.85; }

.top-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.pill {
  min-height: 38px;
  padding: 0 14px;
  border: 0;
  border-radius: 999px;
  background: var(--card);
  box-shadow: var(--shadow-soft);
  font-weight: 800;
  font-size: 0.85rem;
  color: var(--ink-2);
  cursor: pointer;
}
.pill:hover { color: var(--brand); }
.pill.on { background: var(--brand); color: var(--on-brand); }
.pill.icon { width: 38px; padding: 0; }

.card {
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 42px;
  justify-content: center;
  padding: 0 16px;
  border-radius: 16px;
  border: 2px solid transparent;
  background: var(--card-2);
  font-weight: 800;
  cursor: pointer;
  text-decoration: none;
  color: var(--ink-2);
  transition: transform 0.08s ease, background 0.15s ease;
}
.btn:active { transform: translateY(2px); }
.btn.primary { background: var(--brand); color: var(--on-brand); box-shadow: var(--shadow-button); }
.btn.ghost:hover { border-color: color-mix(in srgb, var(--brand) 30%, transparent); color: var(--brand); }

.segmented { display: inline-flex; padding: 3px; border-radius: 999px; background: var(--card-2); }
.segmented button {
  border: 0; background: transparent; padding: 6px 14px; border-radius: 999px;
  font-weight: 800; font-size: 0.82rem; color: var(--muted); cursor: pointer;
}
.segmented button.on { background: var(--card); color: var(--brand); box-shadow: 0 2px 8px rgb(0 0 0 / 8%); }
.segmented button:disabled { opacity: 0.45; cursor: default; }

.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; font-weight: 700; font-size: 0.88rem; color: var(--ink-2); }
.check input { accent-color: var(--brand); width: 16px; height: 16px; }
.check.disabled { opacity: 0.45; cursor: default; }

.field { display: inline-flex; align-items: center; gap: 8px; font-size: 0.72rem; font-weight: 800;
  text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); min-width: 0; }
.field select {
  min-height: 38px;
  padding: 0 10px;
  border: 2px solid color-mix(in srgb, var(--brand) 14%, var(--line));
  border-radius: 14px;
  background: var(--card);
  font-weight: 700;
  font-size: 0.88rem;
  text-transform: none;
  letter-spacing: 0;
  color: var(--ink);
  max-width: 100%;
}
.field select:focus { border-color: var(--brand); }

/* ---------- controls ---------- */

.wrap { max-width: 1180px; margin: 0 auto; padding: 18px 20px 8px; }

.controls {
  position: sticky;
  top: calc(var(--topbar-h) + 8px);
  z-index: 10;
  padding: 14px 16px;
  display: grid;
  gap: 12px;
  border-radius: var(--radius-md);
}

.searchbox { position: relative; display: flex; align-items: center; }
.searchbox svg {
  position: absolute; left: 16px; width: 20px; height: 20px;
  fill: none; stroke: var(--muted); stroke-width: 2.4; stroke-linecap: round; pointer-events: none;
}
.searchbox input {
  width: 100%;
  min-height: 52px;
  padding: 0 84px 0 48px;
  border: 2px solid color-mix(in srgb, var(--brand) 14%, var(--line));
  border-radius: 18px;
  background: var(--bg);
  font-size: 1.08rem;
  font-weight: 700;
  color: var(--ink);
  -webkit-appearance: none;
  appearance: none;
}
.searchbox input::placeholder { color: var(--muted); font-weight: 600; }
.searchbox input:focus { outline: none; border-color: var(--brand); background: var(--card); }
.searchbox input::-webkit-search-cancel-button { display: none; }
.kbd-hint, .searchbox .clear { position: absolute; right: 12px; }
.kbd-hint {
  padding: 2px 9px; border-radius: 8px; border: 2px solid var(--line);
  font-family: var(--font-mono); font-size: 0.8rem; font-weight: 700; color: var(--muted); background: var(--card);
}
.searchbox input:focus ~ .kbd-hint { display: none; }
.searchbox .clear {
  width: 34px; height: 34px; border: 0; border-radius: 999px; background: var(--card-2);
  font-size: 1.2rem; line-height: 1; font-weight: 800; color: var(--ink-2); cursor: pointer;
}
.searchbox .clear:hover { color: var(--brand); }

.chapters {
  display: flex; gap: 6px; padding: 3px; border-radius: 999px; background: var(--card-2);
  overflow-x: auto; scrollbar-width: none;
}
.chapters::-webkit-scrollbar { display: none; }
.chapters button {
  flex: 1 0 auto;
  display: inline-flex; align-items: baseline; justify-content: center; gap: 6px;
  border: 0; background: transparent; padding: 7px 14px; border-radius: 999px;
  font-weight: 800; font-size: 0.85rem; color: var(--muted); cursor: pointer; white-space: nowrap;
}
.chapters button small { font-weight: 700; font-size: 0.72rem; opacity: 0.75; }
.chapters button:hover { color: var(--brand); }
.chapters button.on { background: var(--brand); color: var(--on-brand); box-shadow: var(--shadow-button); }

.filters { display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: center; }
.filters .segmented { margin-left: auto; }

.chapter-info {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px;
  margin-top: 14px; padding: 12px 18px;
  border-radius: var(--radius-sm);
  background: var(--rose-soft);
}
.chapter-info h2 { margin: 0; font-family: var(--font-display); font-size: 1.05rem; color: var(--brand-deep); }
.chapter-info p { margin: 0; color: var(--ink-2); font-size: 0.88rem; font-weight: 600; }
.chapter-info .open { margin-left: auto; }

.status { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 16px; align-items: baseline; margin: 16px 4px 6px; }
.count { margin: 0; font-weight: 800; color: var(--ink-2); }
.count small { font-weight: 600; color: var(--muted); }
.legend { margin: 0; font-size: 0.8rem; color: var(--muted); }

.jump { display: flex; flex-wrap: wrap; gap: 2px; margin: 0 0 8px; }
.jump a {
  min-width: 28px; padding: 3px 6px; border-radius: 8px; text-align: center;
  font-family: var(--font-display); font-weight: 800; font-size: 0.85rem;
  color: var(--ink-2); text-decoration: none;
}
.jump a:hover { background: var(--card-2); color: var(--brand); }

/* ---------- results ---------- */

.results {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr));
  gap: 12px;
  align-items: start;
}
.group {
  grid-column: 1 / -1;
  margin: 14px 4px 0;
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--brand-deep);
  border-bottom: 2px solid var(--line);
  line-height: 1.6;
}
.group:first-child { margin-top: 0; }
.group small { font-family: var(--font-sans); font-size: 0.8rem; font-weight: 700; color: var(--muted); margin-left: 8px; }

.entry {
  position: relative;
  min-width: 0;
  padding: 14px 16px 12px;
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
}
.entry.target { border-color: var(--brand); animation: flash 1.6s ease; }
@keyframes flash { 0%, 40% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--brand) 25%, transparent); } 100% { box-shadow: var(--shadow-card); } }

.entry-head { display: flex; align-items: flex-start; gap: 10px; }
.abbr {
  margin: 0; font-family: var(--font-display); font-weight: 800; font-size: 1.45rem; line-height: 1.15;
  color: var(--brand-deep); overflow-wrap: anywhere;
}
.permalink {
  margin-left: auto; flex: none; width: 30px; height: 30px; border: 0; border-radius: 999px;
  background: transparent; color: var(--muted); cursor: pointer; display: grid; place-items: center;
}
.icon { fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.permalink .icon { width: 16px; height: 16px; stroke-width: 2.2; }
.icon.filled { fill: currentColor; stroke: none; }
.watch { color: var(--brand); font-weight: 800; text-decoration: none; white-space: nowrap; }
.watch:hover { text-decoration: underline; }
.watch .icon { width: 12px; height: 12px; margin-right: 3px; vertical-align: -1px; }
.pop {
  position: absolute; z-index: 40; width: max-content; max-width: min(340px, calc(100vw - 16px));
  padding: 10px; display: grid; gap: 4px;
  background: var(--card); border: 2px solid var(--line); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-soft); font-size: 0.85rem;
}
.pop-title { margin: 0 4px 4px; display: grid; color: var(--ink-2); }
.pop-title b { font-family: var(--font-display); color: var(--brand-deep); }
.pop-note { margin: 2px 4px 0; font-size: 0.74rem; color: var(--muted); }
.pop-link {
  display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-radius: 10px;
  background: var(--card-2); color: var(--ink); font-weight: 800; text-decoration: none;
}
.pop-link:hover, .pop-link:focus-visible { background: var(--brand); color: var(--on-brand); }
.pop-link .icon { width: 16px; height: 16px; flex: none; }
.chip .icon, .open .icon { width: 12px; height: 12px; margin-left: 2px; vertical-align: -1px; stroke-width: 3; }
.permalink:hover { background: var(--card-2); color: var(--brand); }
.long { margin: 2px 0 0; font-weight: 800; color: var(--ink); overflow-wrap: anywhere; }
.expl { margin: 6px 0 0; color: var(--ink-2); font-size: 0.92rem; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tag {
  padding: 2px 10px; border-radius: 999px; background: var(--card-2);
  font-size: 0.72rem; font-weight: 800; letter-spacing: 0.02em; color: var(--muted);
}
.tag.new { background: color-mix(in srgb, var(--mint) 22%, var(--card)); color: color-mix(in srgb, var(--mint) 45%, var(--ink)); }
.intro { margin: 8px 0 0; font-size: 0.8rem; color: var(--muted); font-weight: 600; }

.refs { margin: 10px 0 0; padding: 8px 0 0; border-top: 1px dashed var(--line); display: grid; gap: 6px; }
.ref { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; font-size: 0.82rem; }
.ref.current .chip { background: var(--brand); color: var(--on-brand); }
a.chip { text-decoration: none; border: 2px solid color-mix(in srgb, var(--brand) 24%, var(--line)); padding: 0 8px; }
a.chip:hover { background: var(--brand); color: var(--on-brand); border-color: var(--brand); }
.ref.current a.chip { border-color: var(--brand); }
.chip {
  flex: none; padding: 1px 9px; border-radius: 999px; background: var(--card-2);
  font-weight: 800; font-size: 0.75rem; color: var(--ink-2); white-space: nowrap;
}
.sl {
  display: inline-block; min-width: 24px; padding: 0 4px; text-align: center;
  font-family: var(--font-mono); font-size: 0.8rem; font-weight: 600; color: var(--ink-2);
  border-radius: 6px; text-decoration: none;
}
a.sl:hover { background: var(--card-2); color: var(--brand); }
button.sl { border: 0; background: transparent; cursor: pointer; line-height: inherit; }
button.sl:hover, button.sl[aria-expanded="true"] { background: var(--card-2); color: var(--brand); }
.sl.def { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 3px; text-decoration-color: var(--brand); font-weight: 800; }
.more { color: var(--muted); font-size: 0.78rem; font-weight: 700; }
.open {
  margin-left: auto; padding: 1px 10px; border-radius: 999px;
  border: 2px solid color-mix(in srgb, var(--brand) 24%, var(--line));
  font-size: 0.74rem; font-weight: 800; color: var(--brand); text-decoration: none; white-space: nowrap;
}
.open:hover { background: var(--brand); color: var(--on-brand); border-color: var(--brand); }
.questions { margin: 2px 0 0; padding-left: 18px; font-size: 0.8rem; color: var(--ink-2); }
.qlang { color: var(--muted); font-size: 0.72rem; font-weight: 700; }
.questions-title { margin: 6px 0 0; font-size: 0.72rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.toggle {
  margin-top: 8px; padding: 0; border: 0; background: none; cursor: pointer;
  font-size: 0.8rem; font-weight: 800; color: var(--brand);
}
.toggle:hover { text-decoration: underline; }
mark { background: var(--mark); color: inherit; border-radius: 3px; padding: 0 1px; }

.empty { padding: 28px 24px; text-align: center; }
.empty h2 { margin: 0 0 6px; font-family: var(--font-display); color: var(--brand-deep); }
.empty p { margin: 0 0 10px; color: var(--ink-2); }
.empty-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* ---------- footer, toast ---------- */

.pagefoot { max-width: 920px; margin: 0 auto; padding: 28px 20px 26px; color: var(--muted); font-size: 0.78rem; text-align: center; }
.pagefoot p { margin: 4px 0; }
.pagefoot .disclaimer {
  margin-bottom: 12px; padding: 12px 16px; border-radius: var(--radius-sm);
  background: var(--card-2); color: var(--ink-2); font-size: 0.84rem; text-align: left;
}
.pagefoot .legal { font-weight: 700; color: var(--ink-2); }
.pagefoot a { color: inherit; text-decoration: underline; text-decoration-color: color-mix(in srgb, currentColor 40%, transparent); text-underline-offset: 2px; }
.pagefoot a:hover { color: var(--brand); }
.pagefoot .disclaimer a { color: var(--brand); font-weight: 800; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--ink); color: var(--card); padding: 10px 18px; border-radius: 999px; font-weight: 800;
  box-shadow: var(--shadow-soft); z-index: 50;
}

@media (max-width: 760px) {
  .filters .segmented { margin-left: 0; }
  .controls { position: static; }
}

@media (max-width: 640px) {
  .topbar { padding: 8px 16px; }
  .subtitle { display: none; }
  .kicker { font-size: 0.6rem; }
  h1 { font-size: 1.15rem; }
  .logo { height: 38px; }
  .wrap { padding: 12px 16px 8px; }
  .controls { padding: 12px; }
  .searchbox input { font-size: 1rem; min-height: 48px; }
  .kbd-hint { display: none; }
  .chapters button { flex: 0 0 auto; }
  .field { width: 100%; }
  .field select { flex: 1; }
  .legend { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
