/* =========================================================================
   RDI Hub — styles
   Design: warm archival paper + Stanford cardinal as the single bold anchor.
   Type: Fraunces (display serif = inspiration/craft) × IBM Plex Mono (labels =
   research rigor) × Hanken Grotesk (body). The pairing encodes RDI's dual
   nature. Applied via the frontend-design skill.
   ========================================================================= */
:root {
  /* Palette */
  --paper:   #f1ebdd;
  --paper-2: #e9e1ce;
  --surface: #fbf8f0;
  --ink:     #211b16;
  --ink-2:   #4a4136;
  --muted:   #7d6e59;
  --line:    #dccfba;
  --cardinal: #8c1515;
  --cardinal-deep: #6a1012;
  --accent-soft: #ecdfd4;

  /* Type roles */
  --display: "Newsreader", Georgia, "Times New Roman", serif;
  --body: "Hanken Grotesk", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  --radius: 12px;
  --shadow: 0 1px 2px rgba(33,27,22,.05), 0 12px 32px rgba(33,27,22,.09);
  --maxw: 900px;

  font-family: var(--body);
  color: var(--ink);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }

/* Access gate (sub-pages): hide content until guard.js confirms a session.
   guard.js removes .auth-pending on success, or redirects to the access page. */
html.auth-pending body { visibility: hidden; }
html.auth-pending::after {
  content: "Checking access\2026";
  position: fixed; inset: 0; z-index: 9999;
  display: grid; place-items: center;
  background: #f1ebdd; color: #7d6e59;
  font-family: "IBM Plex Mono", monospace; font-size: 12px;
  letter-spacing: .14em; text-transform: uppercase;
}
@media (prefers-color-scheme: dark) {
  html.auth-pending::after { background: #17130f; color: #94856f; }
}
body {
  background: var(--paper);
  color: var(--ink);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ---------- Brand mark ---------- */
.brand-mark {
  display: inline-grid; place-items: center;
  width: 60px; height: 60px; border-radius: 15px;
  background: linear-gradient(158deg, var(--cardinal), var(--cardinal-deep));
  color: #f6efe4;
  font-family: var(--display); font-weight: 600; font-size: 21px; letter-spacing: .01em;
  box-shadow: 0 8px 20px rgba(108,16,18,.28), inset 0 1px 0 rgba(255,255,255,.14);
}
.brand-mark.sm { width: 34px; height: 34px; font-size: 14px; border-radius: 9px; box-shadow: 0 3px 10px rgba(108,16,18,.24); }

/* ---------- Gate ---------- */
.gate {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  padding: 32px 24px;
  background: radial-gradient(125% 85% at 50% -18%, var(--surface) 0%, var(--paper) 52%, var(--paper-2) 100%);
}
.gate-inner {
  position: relative; z-index: 1;
  width: 100%; max-width: 470px; text-align: center;
  animation: rise .7s cubic-bezier(.2,.7,.2,1) both;
}
.eyebrow {
  font-family: var(--mono); font-size: 11.5px; font-weight: 500;
  letter-spacing: .2em; text-transform: uppercase; color: var(--muted);
  margin: 22px 0 0;
}
.gate-name {
  font-family: var(--display); font-weight: 600;
  font-size: clamp(31px, 6.4vw, 42px); line-height: 1.06;
  letter-spacing: -.014em; color: var(--ink); margin: 12px 0 0;
}
.gate-tagline {
  font-family: var(--display); font-style: italic; font-weight: 500;
  font-size: clamp(18px, 3.4vw, 21px); line-height: 1.4;
  color: var(--ink-2); margin: 18px 0 0;
}
.gate-tagline em { font-style: italic; color: var(--cardinal); }
.gate-sub {
  color: var(--ink-2); font-size: 15.5px; line-height: 1.62;
  max-width: 40ch; margin: 20px auto 0;
}
.btn-google {
  display: inline-flex; align-items: center; gap: 11px;
  margin-top: 30px; padding: 13px 22px;
  border-radius: 11px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink);
  font-family: var(--body); font-size: 15px; font-weight: 600; cursor: pointer;
  box-shadow: 0 1px 2px rgba(33,27,22,.05);
  transition: box-shadow .18s ease, transform .06s ease, border-color .18s ease;
}
.btn-google:hover { box-shadow: var(--shadow); border-color: #c9ba9f; transform: translateY(-1px); }
.btn-google:active { transform: translateY(0); }
.btn-google:focus-visible { outline: 2px solid var(--cardinal); outline-offset: 3px; }
.g-icon { width: 18px; height: 18px; flex: 0 0 auto; }
.gate-fine {
  font-family: var(--mono); font-size: 11px; letter-spacing: .03em;
  color: var(--muted); margin: 26px 0 0;
}
.auth-msg { font-size: 13.5px; margin: 16px 0 0; color: var(--ink-2); }
.auth-msg.ok { color: var(--cardinal); }
.auth-msg.err { color: #b3261e; }

@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

/* ---------- App (hub) — inherits the same type + color system ---------- */
.topbar { position: sticky; top: 0; z-index: 5; background: rgba(251,248,240,.82); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.topbar-inner { max-width: var(--maxw); margin: 0 auto; padding: 13px 22px; display: flex; align-items: center; justify-content: space-between; }
.logo { display: flex; align-items: center; gap: 11px; font-family: var(--display); font-weight: 600; font-size: 18px; }
.user { display: flex; align-items: center; gap: 12px; }
.user-email { font-family: var(--mono); color: var(--muted); font-size: 12.5px; }
.btn-ghost { font-family: var(--body); background: none; border: 1px solid var(--line); color: var(--ink-2); padding: 7px 13px; border-radius: 9px; font-size: 13px; cursor: pointer; transition: border-color .15s, color .15s; }
.btn-ghost:hover { border-color: var(--cardinal); color: var(--cardinal); }

.wrap { max-width: var(--maxw); margin: 0 auto; padding: 44px 22px 90px; }
.intro h2 { font-family: var(--display); font-weight: 600; font-size: 28px; letter-spacing: -.01em; margin: 0 0 8px; }
.intro p { color: var(--ink-2); margin: 0; max-width: 62ch; }

.section { margin-top: 44px; }
.section-head { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
.section-head h3 { font-family: var(--mono); font-size: 12px; font-weight: 500; text-transform: uppercase; letter-spacing: .16em; color: var(--cardinal); margin: 0; white-space: nowrap; }
.section-head .rule { flex: 1; height: 1px; background: var(--line); }

.cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 15px; }
@media (max-width: 620px) { .cards { grid-template-columns: 1fr; } }

.card { display: block; text-decoration: none; color: inherit; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 19px 19px 17px; transition: border-color .16s, box-shadow .16s, transform .06s; }
.card:hover { border-color: #c9ba9f; box-shadow: var(--shadow); transform: translateY(-2px); }
.card:active { transform: translateY(0); }
.card-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.card h4 { font-family: var(--display); font-weight: 600; margin: 0; font-size: 17px; letter-spacing: -.005em; }
.pill { font-family: var(--mono); font-size: 10px; font-weight: 500; letter-spacing: .07em; text-transform: uppercase; color: var(--cardinal); background: var(--accent-soft); padding: 4px 9px; border-radius: 999px; white-space: nowrap; }
.card p { margin: 9px 0 0; color: var(--ink-2); font-size: 14px; line-height: 1.55; }

.foot { margin-top: 60px; padding-top: 22px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; font-family: var(--mono); letter-spacing: .02em; }

/* ---------- Dark ---------- */
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #17130f; --paper-2: #221b15; --surface: #211a14;
    --ink: #f0e8da; --ink-2: #c3b6a2; --muted: #94856f; --line: #362b21;
    --cardinal: #e0605f; --cardinal-deep: #b23a3a; --accent-soft: #2a1a17;
  }
  .gate { background: radial-gradient(125% 85% at 50% -18%, #241b14 0%, var(--paper) 58%); }
  .brand-mark { color: #1c1310; }
  .topbar { background: rgba(33,26,20,.82); }
}

/* =========================================================================
   Hosted Guide reader (guide.html) — the RDI Guide rendered natively.
   Two-column: sticky TOC rail + reading column. Editorial "research journal"
   feel. Plus the floating navigation assistant. Generated by build_guide.py.
   ========================================================================= */
.logo { text-decoration: none; color: inherit; }
.anchor { display: block; height: 0; scroll-margin-top: 120px; }

/* Guide layout is left-locked to one column (not centered) with a max width. */
/* Logo locks to the content's left edge; Hub button right-justifies to the viewport. */
.guide-body .topbar-inner { max-width: none; margin: 0; padding-left: 26px; padding-right: 26px; }

/* ---------- Pinned location header (breadcrumb) ---------- */
.guide-subbar {
  position: sticky; top: 63px; z-index: 4;
  height: 46px; overflow: hidden;
  background: rgba(251,248,240,.9); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.subbar-inner {
  max-width: 748px; margin: 0 auto; height: 100%;
  display: flex; align-items: center; gap: 14px; padding: 0 24px;
}
.subbar-btn {
  display: inline-flex; align-items: center; gap: 8px;
  font-family: var(--body); font-size: 13px; font-weight: 600; color: var(--ink-2);
  background: none; border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 11px; cursor: pointer; white-space: nowrap;
  transition: border-color .15s, color .15s;
}
.subbar-btn:hover { border-color: var(--cardinal); color: var(--cardinal); }
.subbar-ico { font-size: 14px; line-height: 1; }
.crumbs { display: flex; align-items: center; gap: 9px; min-width: 0; font-size: 13px; }
.crumb-part { font-family: var(--mono); font-size: 11px; text-transform: uppercase; letter-spacing: .12em; color: var(--cardinal); white-space: nowrap; }
.crumb-sep { color: var(--muted); }
.crumb-sec { font-family: var(--display); font-weight: 600; color: var(--ink); font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Layout: the guide-text column is centered on the whole viewport; the TOC is a
   capped-width bar floating in the left margin (wide screens) or a drawer (narrow). */
.guide-shell { display: block; }

/* ---------- TOC rail ---------- */
/* Base = off-canvas drawer (narrow screens); toggled by the Contents button. */
.toc-rail {
  position: fixed; top: 109px; left: 0; z-index: 30;
  width: min(300px, 86vw); height: calc(100vh - 109px); overflow-y: auto;
  background: var(--surface); border-right: 1px solid var(--line);
  padding: 24px 18px; transform: translateX(-102%);
  transition: transform .24s ease, opacity .2s ease;
  scrollbar-width: thin;
}
body.toc-open .toc-rail { transform: none; box-shadow: var(--shadow); }

/* Wide screens: persistent capped TOC floating in the left margin (no overlap
   with the centered content column). Content stays viewport-centered regardless. */
@media (min-width: 1260px) {
  .toc-rail {
    left: 28px; width: 230px; max-width: 230px;
    background: none; border-right: 0; box-shadow: none;
    padding: 26px 12px 40px 0; transform: none;
  }
  body.toc-collapsed .toc-rail { opacity: 0; pointer-events: none; transform: translateX(-12px); }
}
.toc-eyebrow {
  font-family: var(--mono); font-size: 10.5px; font-weight: 500;
  letter-spacing: .18em; text-transform: uppercase; color: var(--muted);
  margin: 0 0 14px;
}
.toc-group { margin-bottom: 14px; }
.toc-part {
  display: block; text-decoration: none;
  font-family: var(--display); font-weight: 600; font-size: 15px;
  color: var(--ink); padding: 4px 0; letter-spacing: -.005em;
}
.toc-part:hover { color: var(--cardinal); }
.toc-group ul { list-style: none; margin: 4px 0 0; padding: 0 0 0 2px; }
.toc-link {
  display: block; text-decoration: none;
  font-size: 13px; line-height: 1.35; color: var(--muted);
  padding: 5px 0 5px 12px; border-left: 2px solid var(--line);
  transition: color .14s, border-color .14s;
}
.toc-link:hover { color: var(--ink-2); border-color: #c9ba9f; }
.toc-part.active { color: var(--cardinal); }
.toc-link.active { color: var(--cardinal); border-color: var(--cardinal); font-weight: 600; }

/* ---------- Reading column (centered on the viewport) ---------- */
.guide-main { padding: 46px 24px 96px; }
.guide { max-width: 700px; margin: 0 auto; }
.guide-eyebrow {
  font-family: var(--mono); font-size: 11.5px; font-weight: 500;
  letter-spacing: .18em; text-transform: uppercase; color: var(--cardinal); margin: 0;
}
.guide-masthead {
  font-family: var(--display); font-weight: 600;
  font-size: clamp(32px, 5vw, 46px); line-height: 1.05;
  letter-spacing: -.016em; color: var(--ink); margin: 14px 0 0;
}
.guide-lede { color: var(--ink-2); font-size: 17px; line-height: 1.6; margin: 16px 0 0; max-width: 56ch; }
.guide-rule { height: 1px; background: var(--line); margin: 30px 0 4px; }

.guide { color: var(--ink-2); }
.guide p { font-size: 17px; line-height: 1.72; margin: 0 0 20px; color: var(--ink-2); }
.guide p.runin { font-weight: 700; color: var(--ink); font-size: 16px; margin: 26px 0 6px; }
.guide p.note { font-size: 14px; color: var(--muted); font-style: italic; margin: 0 0 18px; }

/* headings within content */
.part-title, .phase-title {
  font-family: var(--display); font-weight: 700; color: var(--ink);
  font-size: 30px; letter-spacing: -.015em; line-height: 1.12; margin: 56px 0 18px;
  scroll-margin-top: 120px;
}
.sec-title {
  font-family: var(--display); font-weight: 600; color: var(--ink);
  font-size: 23px; letter-spacing: -.01em; line-height: 1.2; margin: 46px 0 14px;
  scroll-margin-top: 120px;
}
.phase-open { scroll-margin-top: 112px; }
.subsec {
  font-family: var(--body); font-weight: 700; color: var(--ink);
  font-size: 17px; margin: 30px 0 10px;
}

/* lists */
.guide ul, .guide ol { margin: 0 0 22px; padding-left: 0; }
.guide ul { list-style: none; }
.guide ul li { position: relative; padding-left: 26px; }
.guide ul li::before {
  content: ""; position: absolute; left: 6px; top: .72em;
  width: 6px; height: 6px; border-radius: 999px; background: var(--cardinal);
}
.guide ol { padding-left: 22px; }
.guide li { font-size: 17px; line-height: 1.6; color: var(--ink-2); margin: 0 0 10px; }
.guide li strong { color: var(--ink); }
.guide a { color: var(--cardinal); text-decoration: underline; text-underline-offset: 2px; text-decoration-thickness: 1px; }
.guide a:hover { color: var(--cardinal-deep); }
.guide strong { color: var(--ink); font-weight: 700; }
.guide code { font-family: var(--mono); font-size: .88em; background: var(--accent-soft); padding: 1px 5px; border-radius: 5px; }

/* callout (from Markdown blockquotes) */
.callout {
  margin: 0 0 24px; padding: 16px 20px;
  background: var(--surface); border: 1px solid var(--line);
  border-left: 3px solid var(--cardinal); border-radius: 10px;
  font-size: 15.5px; line-height: 1.6; color: var(--ink-2);
}
.callout strong { color: var(--ink); }

/* tables */
.tbl-wrap { overflow-x: auto; margin: 0 0 26px; border: 1px solid var(--line); border-radius: 10px; }
.guide table { border-collapse: collapse; width: 100%; font-size: 14px; }
.guide th, .guide td { text-align: left; padding: 10px 13px; border-bottom: 1px solid var(--line); vertical-align: top; }
.guide th { font-family: var(--mono); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--cardinal); background: var(--accent-soft); }
.guide tbody tr:last-child td { border-bottom: 0; }

/* phase opener */
.phase-open { margin: 64px 0 8px; }
.phase-kicker {
  font-family: var(--mono); font-size: 12px; font-weight: 500;
  letter-spacing: .16em; text-transform: uppercase; color: var(--cardinal); margin: 0;
}
.phase-title { margin: 8px 0 22px; font-size: clamp(28px, 4vw, 38px); }
.phase-map { margin: 0 0 8px; }
.phase-map img { width: 100%; height: auto; display: block; border: 1px solid var(--line); border-radius: 12px; background: #fff; padding: 14px; }
.phase-map figcaption { font-family: var(--mono); font-size: 11px; color: var(--muted); letter-spacing: .02em; margin-top: 10px; }

.guide-foot { max-width: 700px; margin: 0 auto; }

/* ---------- Navigation assistant ---------- */
.chat-launcher {
  position: fixed; right: 22px; bottom: 22px; z-index: 40;
  display: inline-flex; align-items: center; gap: 9px;
  padding: 12px 18px; border-radius: 999px; border: 1px solid var(--cardinal);
  background: linear-gradient(158deg, var(--cardinal), var(--cardinal-deep));
  color: #f6efe4; font-family: var(--body); font-size: 14px; font-weight: 600;
  cursor: pointer; box-shadow: 0 8px 24px rgba(108,16,18,.30);
  transition: transform .08s ease, box-shadow .18s ease;
}
.chat-launcher:hover { transform: translateY(-2px); box-shadow: 0 12px 30px rgba(108,16,18,.36); }
.chat-launcher-dot { width: 8px; height: 8px; border-radius: 999px; background: #7ee2a8; box-shadow: 0 0 0 3px rgba(126,226,168,.28); }

.chat-panel {
  position: fixed; right: 22px; bottom: 22px; z-index: 41;
  width: min(380px, calc(100vw - 32px)); height: min(560px, calc(100vh - 44px));
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: var(--shadow); overflow: hidden;
  animation: rise .28s cubic-bezier(.2,.7,.2,1) both;
}
.chat-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.chat-head strong { font-family: var(--display); font-size: 16px; }
.chat-badge { font-family: var(--mono); font-size: 9.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--cardinal); background: var(--accent-soft); padding: 3px 7px; border-radius: 999px; margin-left: 9px; }
.chat-close { background: none; border: 0; font-size: 22px; line-height: 1; color: var(--muted); cursor: pointer; padding: 0 4px; }
.chat-close:hover { color: var(--ink); }
.chat-log { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 11px; }
.msg { font-size: 14px; line-height: 1.5; padding: 10px 13px; border-radius: 12px; max-width: 88%; }
.msg-bot { background: var(--paper-2); color: var(--ink-2); border-bottom-left-radius: 4px; align-self: flex-start; }
.msg-user { background: linear-gradient(158deg, var(--cardinal), var(--cardinal-deep)); color: #f6efe4; border-bottom-right-radius: 4px; align-self: flex-end; }
.chat-jumps { display: flex; flex-direction: column; gap: 6px; margin-top: 9px; }
.chat-jumps a { font-size: 13px; color: var(--cardinal); text-decoration: none; padding: 7px 11px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.chat-jumps a:hover { border-color: var(--cardinal); }
.chat-form { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); }
.chat-form input { flex: 1; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-family: var(--body); font-size: 14px; background: var(--paper); color: var(--ink); }
.chat-form input:focus { outline: 2px solid var(--cardinal); outline-offset: 1px; }
.chat-form button { border: 0; background: linear-gradient(158deg, var(--cardinal), var(--cardinal-deep)); color: #f6efe4; width: 42px; border-radius: 10px; font-size: 18px; cursor: pointer; }

/* ---------- Example galleries (rubrics, emails) -> popups ---------- */
.ex-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 13px; margin: 8px 0 28px; }
.ex-card {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  text-align: left; background: var(--surface); border: 1px solid var(--line);
  border-radius: 11px; padding: 15px 16px; cursor: pointer; font-family: var(--body);
  color: var(--ink); transition: border-color .15s, box-shadow .15s, transform .06s;
}
.ex-card:hover { border-color: var(--cardinal); box-shadow: var(--shadow); transform: translateY(-1px); }
.ex-card-t { font-family: var(--display); font-weight: 600; font-size: 15.5px; line-height: 1.25; }
.ex-card-cta { font-family: var(--mono); font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--cardinal); white-space: nowrap; }
@media (max-width: 620px) { .ex-grid { grid-template-columns: 1fr; } }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 24px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(20,15,11,.5); backdrop-filter: blur(2px); }
.modal-card {
  position: relative; z-index: 1; width: min(760px, 100%); max-height: 86vh;
  display: flex; flex-direction: column; background: var(--surface);
  border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow);
  animation: rise .24s cubic-bezier(.2,.7,.2,1) both; overflow: hidden;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-head h3 { font-family: var(--display); font-weight: 600; font-size: 18px; margin: 0; }
.modal-close { background: none; border: 0; font-size: 24px; line-height: 1; color: var(--muted); cursor: pointer; }
.modal-close:hover { color: var(--ink); }
.modal-body { padding: 20px 22px 26px; overflow-y: auto; }
.modal-body > *:first-child { margin-top: 0; }
.modal-src { display: none; }
body.modal-open { overflow: hidden; }

/* ---------- Responsive ---------- */
/* Drawer is the base layout (< 1260px). Keep the breadcrumb compact on small screens. */
@media (max-width: 620px) {
  .crumb-part { display: none; }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .gate-inner { animation: none; }
  * { transition-duration: .01ms !important; }
}
