/* ---------- Reset & base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html {
  font-size: clamp(16px, 0.45vw + 14.5px, 18px);
  text-size-adjust: 100%;
}
body {
  margin: 0;
  font-family: var(--serif, "Crimson Pro", "Iowan Old Style", Palatino, serif);
  line-height: 1.6;
  color: var(--ink, #2a241d);
  background: var(--paper, #f6f1e7);
  font-feature-settings: "kern" 1, "liga" 1, "calt" 1, "onum" 1;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
.container { max-width: var(--container, 1080px); margin: 0 auto; padding: 0 1.25rem; }
.container.narrow { max-width: var(--container-narrow, 760px); }
.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
a { color: var(--ochre); }
a:hover { color: var(--ochre-soft); }
em { font-style: italic; color: var(--ink); }

/* ---------- Typography utility ---------- */
.prose { max-width: var(--measure, 68ch); }
.tabular { font-variant-numeric: tabular-nums; }
.smallcaps {
  font-variant-caps: all-small-caps;
  letter-spacing: 0.04em;
}
h1, h2, h3 { text-wrap: balance; }

/* ---------- Landing hero (index.html) ---------- */
.landing-hero {
  padding: 2.5rem 0 1.5rem;
  border-bottom: 1px solid var(--rule);
}
.brand-row {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 2rem; flex-wrap: wrap;
}
.landing-hero h1.brand-page {
  font-family: var(--serif);
  font-size: clamp(2.4rem, 4vw + 1rem, 3.6rem);
  font-weight: 600;
  margin: 0 0 0.25rem;
  letter-spacing: -0.015em;
  line-height: 1.02;
  color: var(--ochre);
}
.landing-hero .subtitle {
  font-size: 1.1rem;
  color: var(--ink-soft);
  max-width: 42rem;
  margin: 0;
  line-height: 1.55;
  text-wrap: pretty;
}
.hero-stats-row {
  display: flex; gap: 2rem;
  font-family: var(--sans);
  margin-top: 0.5rem;
}
.hero-stats-row .hero-stat-n {
  font-family: var(--serif);
  font-size: 1.6rem;
  color: var(--ochre);
  line-height: 1;
}

/* ---------- Mode toggle ---------- */
.mode-bar { margin: 2rem 0 1rem; }
.mode-toggle {
  display: flex; gap: 0;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--paper-soft);
}
.mode-btn {
  flex: 1;
  background: transparent;
  border: none;
  padding: 0.85rem 1rem;
  text-align: left;
  font: inherit;
  font-family: var(--sans);
  font-size: 0.95rem;
  cursor: pointer;
  color: var(--ink-soft);
  border-right: 1px solid var(--rule);
  transition: background 120ms ease, color 120ms ease;
}
.mode-btn:last-child { border-right: none; }
.mode-btn:hover { background: var(--paper-warm); color: var(--ochre); }
.mode-btn.active { background: var(--ochre); color: var(--paper); }
.mode-btn.active .mode-hint { color: var(--paper-warm); }
.mode-btn .mode-hint {
  display: block;
  font-size: 0.78rem;
  color: var(--ink-mute);
  margin-top: 0.15rem;
}

/* ---------- Ask form ---------- */
.ask form { display: flex; flex-direction: column; gap: 0.75rem; }
textarea {
  font: inherit;
  font-size: 1.1rem;
  padding: 0.9rem 1rem;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  resize: vertical;
  background: var(--paper-soft);
  color: var(--ink);
  font-family: var(--serif);
  line-height: 1.5;
}
textarea:focus { outline: 2px solid var(--accent); outline-offset: -2px; }
button[type="submit"], .route-continuation {
  align-self: flex-start;
  background: var(--ochre);
  color: var(--paper);
  border: none;
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius);
  font-family: var(--sans);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  letter-spacing: 0.01em;
  transition: background 120ms ease;
}
button[type="submit"]:hover, .route-continuation:hover { background: var(--ochre-soft); }
button[type="submit"]:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Answer ---------- */
.answer-section { margin-top: 2.5rem; max-width: var(--measure); }
.answer-banner {
  background: #fff4d6;
  border-left: 4px solid var(--accent);
  padding: 0.8rem 1rem;
  font-family: var(--sans);
  font-size: 0.92rem;
  color: var(--ink-soft);
  margin-bottom: 1.25rem;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.answer-banner.creative {
  background: var(--paper-warm);
  border-left-color: var(--ochre-soft);
  color: var(--ochre);
}
.answer-body {
  font-size: 1.15rem;
  line-height: 1.7;
  color: var(--ink);
  white-space: pre-wrap;
  max-width: var(--measure);
}
.answer-body p { margin: 0 0 1em; }
/* Drop cap only on Q&A page, desktop */
@media (min-width: 561px) {
  body[data-page="ask"] .answer-body > p:first-child::first-letter,
  body[data-page="ask"] .answer-body:not(:has(p))::first-letter {
    float: left;
    font-family: var(--serif);
    font-size: 3.6em;
    font-weight: 600;
    line-height: 0.85;
    padding: 0.1em 0.12em 0 0;
    color: var(--ochre);
  }
}
.answer-body sup.cite {
  font-size: 0.7em;
  padding: 0 0.2em;
  color: var(--ochre);
  font-family: var(--sans);
}

/* ---------- Citation list ---------- */
.citations-list {
  margin-top: 2rem;
  max-width: var(--measure);
}
.citation {
  border-top: 1px solid var(--rule);
  padding: 1rem 0;
  cursor: pointer;
  transition: background 120ms ease;
}
.citation:hover {
  background: var(--paper-soft);
  margin: 0 -1.25rem;
  padding-left: 1.25rem;
  padding-right: 1.25rem;
}
.citation-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: baseline;
}
.citation-title {
  font-family: var(--serif);
  font-weight: 500;
  color: var(--ochre);
  font-size: 1.05rem;
}
.citation-meta {
  font-family: var(--sans);
  font-size: 0.78rem;
  color: var(--ink-mute);
  white-space: nowrap;
  font-variant-caps: all-small-caps;
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
}
.citation-snippet {
  margin-top: 0.5rem;
  color: var(--ink-soft);
  font-size: 1rem;
  line-height: 1.55;
}

/* ---------- Out-of-scope action ---------- */
.oos-actions { margin-top: 1.5rem; }
.oos-prompt { color: var(--ink-soft); font-size: 1.02rem; margin-bottom: 0.75rem; }

/* ---------- Loading ---------- */
.loading {
  display: flex; align-items: center; gap: 0.75rem;
  margin: 2.5rem 0;
  color: var(--ink-soft);
  font-family: var(--sans);
}
/* [hidden] should hide regardless of display: flex above. Without this,
   `display: flex` wins and the spinner shows on initial page load even
   when no question has been asked yet. */
.loading[hidden] { display: none; }
.answer-section[hidden] { display: none; }
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--rule);
  border-top-color: var(--ochre);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Daily reading widget (landing) ---------- */
.daily-reading {
  margin-top: 4rem;
  padding-top: 2rem;
  border-top: 1px solid var(--rule);
}
.daily-reading-title {
  font-family: var(--serif);
  font-size: 1.5rem;
  color: var(--ochre);
  margin: 0 0 0.5rem;
}
.daily-reading-blurb {
  font-family: var(--sans);
  font-size: 0.95rem;
  color: var(--ink-soft);
  max-width: 60ch;
  margin: 0 0 1.25rem;
}
.daily-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 0.85rem;
}
.daily-card {
  background: var(--paper-soft);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 0.9rem 1.05rem;
  cursor: pointer;
  transition: border-color 120ms ease, transform 100ms ease, box-shadow 120ms ease;
  display: flex; flex-direction: column;
  gap: 0.2rem;
}
.daily-card:hover {
  transform: translateY(-1px);
  border-color: var(--accent);
  box-shadow: var(--shadow-1);
}
.daily-card-year {
  font-family: var(--serif);
  font-size: 1.4rem;
  color: var(--ochre);
  line-height: 1;
  margin: 0;
}
.daily-card-work {
  font-family: var(--sans);
  font-size: 0.88rem;
  color: var(--ink);
  margin: 0;
  line-height: 1.4;
}
.daily-card-to {
  font-family: var(--sans);
  font-size: 0.78rem;
  color: var(--ink-soft);
  margin: 0;
}

/* ---------- Discover panel (landing) ---------- */
.discover-panel {
  margin-top: 4rem;
  padding-top: 2rem;
  border-top: 1px solid var(--rule);
}
.discover-title {
  font-family: var(--serif);
  font-size: 1.5rem;
  color: var(--ochre);
  margin: 0 0 1rem;
}
.discover-grid {
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
}
.discover-card {
  text-decoration: none;
  color: var(--ink);
  display: flex; flex-direction: column;
  gap: 0.25rem;
}
.discover-card-kicker {
  font-family: var(--sans); font-size: 0.7rem;
  text-transform: uppercase; letter-spacing: 0.14em;
  color: var(--ink-mute); margin: 0;
}
.discover-card-title {
  font-family: var(--serif); font-size: 1.2rem;
  color: var(--ochre); margin: 0;
}
.discover-card-desc {
  font-family: var(--sans); font-size: 0.88rem;
  color: var(--ink-soft); line-height: 1.5;
  margin: 0;
}

/* ---------- Footer ---------- */
.site-footer {
  margin-top: 5rem;
  padding: 2rem 0;
  border-top: 1px solid var(--rule);
  background: var(--paper-warm);
  font-family: var(--sans);
  font-size: 0.88rem;
  color: var(--ink-soft);
}
.site-footer p { margin: 0 0 0.5rem; }
.site-footer p:last-child { margin-bottom: 0; }
.site-footer a { color: var(--ochre); }

/* ---------- Modal ---------- */
/* z-index sits above the sticky site-header (z-index: 20). The modal
   panel is centred on the viewport with translate so it doesn't collide
   with a tall wrapping nav at intermediate widths. */
.citation-modal[hidden] { display: none; }
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(30, 22, 16, 0.55);
  z-index: 100;
  animation: fadeIn 160ms ease;
}
.modal-panel {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: min(760px, calc(100vw - 2rem));
  max-height: calc(100vh - 3rem);
  background: var(--paper-soft);
  border-radius: var(--radius-lg);
  padding: 2rem 2.25rem;
  overflow-y: auto;
  box-shadow: var(--shadow-2);
  z-index: 101;
  animation: slideUp 200ms ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp {
  from { opacity: 0; transform: translate(-50%, -50%) translateY(12px); }
  to { opacity: 1; transform: translate(-50%, -50%); }
}
.modal-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 1rem; margin-bottom: 1rem;
}
.modal-title-stack { flex: 1; min-width: 0; }
.modal-panel h2 {
  font-family: var(--serif);
  margin: 0 0 0.2rem;
  font-size: 1.5rem;
  color: var(--ochre);
  text-wrap: balance;
}
.modal-panel .modal-subtitle {
  font-family: var(--sans);
  font-size: 0.82rem;
  color: var(--ink-mute);
  font-variant-caps: all-small-caps;
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
  margin: 0;
}
.modal-actions {
  display: flex; gap: 0.35rem;
  flex-shrink: 0;
}
.modal-actions button {
  background: var(--paper-warm);
  border: 1px solid var(--rule);
  color: var(--ink-soft);
  width: 32px; height: 32px;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  cursor: pointer;
  font-family: var(--sans);
  display: inline-flex; align-items: center; justify-content: center;
  transition: background 120ms ease, color 120ms ease;
}
.modal-actions button:hover { background: var(--accent); color: var(--paper); }
.modal-actions button:disabled { opacity: 0.35; cursor: not-allowed; background: var(--paper-warm); color: var(--ink-soft); }
.modal-actions button.copied { background: var(--ok); color: var(--paper); border-color: var(--ok); }
/* Buttons rely on the native `title` attribute for on-hover tooltips — no
   visible label inside the button. A previous version of this rule used
   `content: attr(title)` in an ::after pseudo, which rendered the tooltip
   text on top of the icon and made the toolbar unreadable. */
.modal-actions .modal-close { font-size: 1.4rem; }
.modal-body { font-size: 1.05rem; line-height: 1.65; max-width: var(--measure); }
.modal-body .meta {
  font-family: var(--sans);
  font-size: 0.85rem;
  color: var(--ink-mute);
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.25rem 0.85rem;
  margin-bottom: 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--rule-soft);
}
.modal-body .meta > strong {
  font-variant-caps: all-small-caps;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
}
.modal-body .neighbor {
  margin-top: 1.5rem;
  padding: 0.75rem 1rem;
  background: var(--paper-warm);
  border-left: 3px solid var(--rule);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 0.95rem;
  color: var(--ink-soft);
  font-style: italic;
}
.modal-body .neighbor em {
  font-style: normal;
  font-family: var(--sans);
  font-size: 0.78rem;
  font-variant-caps: all-small-caps;
  letter-spacing: 0.04em;
  color: var(--ink-mute);
}
.modal-body .chunk-text {
  white-space: pre-wrap;
  margin-top: 1.25rem;
  font-family: var(--serif);
  font-size: 1.08rem;
  line-height: 1.7;
}
.modal-body .neighbor + .chunk-text { margin-top: 1.5rem; }

/* ---------- Eval scores in footer (legacy id) ---------- */
.eval-scores { color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.eval-scores .ok { color: var(--ok); }
.eval-scores .warn { color: var(--warn); }

/* ---------- Mobile ---------- */
@media (max-width: 720px) {
  .modal-panel { padding: 1.5rem; max-height: calc(100vh - 2rem); }
}
@media (max-width: 560px) {
  .mode-toggle { flex-direction: column; }
  .mode-btn { border-right: none; border-bottom: 1px solid var(--rule); }
  .mode-btn:last-child { border-bottom: none; }
  .citation-head { flex-direction: column; gap: 0.25rem; }
  .citation-meta { white-space: normal; }
}
@media (max-width: 380px) {
  .mode-btn .mode-hint { display: none; }
}

/* ---------- In-browser AI: settings gear + tier cards + loader (localmind) ----------
   Ported from gandhi/site/styles.css with nehru's design tokens.
   Token substitutions: --saffron -> --ochre, saffron-hover #9a5417 -> --ochre-soft,
   --card -> --paper-soft, --line -> --rule, --parchment-2 -> --paper-warm,
   saffron tint rgba(193,103,33,.06) -> ochre tint rgba(90,36,24,.06).
   Reuses nehru's existing .loading/.spinner/@keyframes spin/.citation* and
   .answer-banner/.answer-banner.creative — only .decline/.fallback are added here. */

/* gear button: right-aligned above/below the Ask box */
.ask-tools { position: relative; display: flex; justify-content: flex-end; margin: .5rem 0 0; }
.ai-gear { display: inline-flex; align-items: center; gap: .4rem; font: inherit; font-size: .8rem;
  color: var(--ink-soft); background: none; border: none; cursor: pointer; padding: .25rem .35rem; border-radius: var(--radius); }
.ai-gear:hover { color: var(--ochre); }
.ai-gear svg { width: 15px; height: 15px; }
.ai-gear-state { font-weight: 500; }
.ai-gear.is-on { color: var(--ochre); }
.ai-gear.is-on svg { transform: rotate(30deg); transition: transform .2s; }

/* settings popover */
.ai-settings { position: absolute; right: 0; top: calc(100% + .4rem); z-index: 40; width: min(370px, 92vw);
  background: var(--paper-soft); border: 1px solid var(--rule); border-radius: 12px;
  box-shadow: var(--shadow-2); padding: 1.1rem 1.15rem 1rem; text-align: left; }
.ai-settings h3 { font-family: var(--serif); font-size: 1.18rem; margin: 0 0 .5rem; }
.ai-settings p { font-size: .85rem; color: var(--ink-soft); margin: 0 0 .7rem; line-height: 1.5; }

/* two opt-in tiers: Standard (~1 GB) and Best (~2 GB, WebGPU) */
.ai-tiers { display: flex; flex-direction: column; gap: .6rem; margin: 0 0 .9rem; }
.ai-tier { border: 1px solid var(--rule); border-radius: var(--radius-lg); padding: .7rem .8rem; background: transparent;
  transition: border-color .15s, background .15s; }
.ai-tier.is-active { border-color: var(--ochre); background: rgba(90,36,24,.06); }
.ai-tier-head { display: flex; align-items: baseline; justify-content: space-between; gap: .5rem; margin: 0 0 .25rem; }
.ai-tier-head strong { font-size: .95rem; color: var(--ink); }
.ai-tier-head span { font-size: .72rem; color: var(--ink-soft); white-space: nowrap; }
.ai-tier-desc { font-size: .78rem; color: var(--ink-soft); margin: 0 0 .6rem; line-height: 1.45; }
.ai-tier-cap { font-size: .74rem; color: var(--ochre-soft); margin: .5rem 0 0; line-height: 1.4; }
.ai-enable { font: inherit; font-weight: 600; font-size: .82rem; color: var(--paper); background: var(--ochre);
  border: none; border-radius: 8px; padding: .45rem .9rem; cursor: pointer; width: 100%; }
.ai-enable:hover { background: var(--ochre-soft); }
.ai-enable:disabled { background: var(--rule); color: var(--ink-soft); cursor: not-allowed; }
.ai-tier.is-active .ai-enable { background: none; color: var(--ochre); border: 1px solid var(--ochre); }
.ai-tier.is-active .ai-enable:hover { background: rgba(90,36,24,.1); }
.ai-cancel { font: inherit; font-size: .82rem; color: var(--ink-soft); background: none; border: none; cursor: pointer; }
.ai-cancel:hover { color: var(--ink); }

/* inline "turn on AI" link inside the fallback banner */
.link-btn { font: inherit; color: var(--ochre); background: none; border: none; padding: 0;
  cursor: pointer; text-decoration: underline; }
.link-btn:hover { color: var(--ochre-soft); }

/* answer-banner variants — nehru's banner uses a left-border accent (see .answer-banner above) */
.answer-banner.fallback { background: var(--paper-warm); border-left-color: var(--rule); color: var(--ink-soft); }
.answer-banner.decline { background: #f5ece0; border-left-color: var(--ochre-soft); color: var(--ink-soft); }

/* ---- discreet download loader: inline below the Ask box, or viewport-bottom ---- */
.site-loader { position: fixed; left: 0; right: 0; bottom: 0; z-index: 60; pointer-events: none; }
.site-loader-track { height: 3px; width: 100%; background: var(--paper-warm); overflow: hidden; border-radius: 999px; }
.site-loader-fill { height: 100%; width: 0; background: var(--ochre); transition: width .25s ease; }
.site-loader-fill.indeterminate { width: 32%; animation: loader-slide 1.15s ease-in-out infinite; }
@keyframes loader-slide { 0% { transform: translateX(-110%); } 100% { transform: translateX(360%); } }
.site-loader-label { position: absolute; right: .7rem; bottom: .55rem; font-family: var(--sans);
  font-size: .72rem; color: var(--ink-soft); background: var(--paper-soft); border: 1px solid var(--rule);
  border-radius: 999px; padding: .18rem .65rem; box-shadow: var(--shadow-1); }

/* Inline variant — in normal flow, directly under the chatbox, label below the track. */
.site-loader-anchor:empty { display: none; }
.site-loader--inline { position: static; margin: .55rem 0 0; pointer-events: auto; }
.site-loader--inline .site-loader-label { position: static; display: block; text-align: right; margin-top: .35rem;
  background: none; border: none; box-shadow: none; padding: 0; color: var(--ochre); }

/* inline [N] citation markers (in-browser AI answers) */
.cite-ref {
  font-family: var(--sans); font-size: .72em; font-weight: 600; vertical-align: super;
  color: var(--ochre); cursor: pointer; text-decoration: none; padding: 0 1px;
}
.cite-ref:hover, .cite-ref:focus { text-decoration: underline; outline: none; }
