/* =============================================================================
   quotes.teahubery.com — quotes.css
   A Tufte-grounded reading surface. Palette + type ported from the Toan Ngo PhD
   Thesis Design System (ET Book serif, maroon accent, warm parchment ground),
   the same object as the /thesis reader and modumatics.com. Self-contained:
   no external fonts, CSS, JS, analytics, or cookies beyond one theme preference.
   ========================================================================== */

/* ---- 1. TOKENS: light (parchment) is the default ------------------------- */
:root {
  --serif: 'ET Book', 'TeX Gyre Pagella', 'Palatino Linotype', 'Book Antiqua', Palatino, Georgia, serif;
  --sans:  'Lato', 'Helvetica Neue', Arial, sans-serif;
  --mono:  'JetBrains Mono', 'SFMono-Regular', Menlo, Consolas, monospace;
  --brand: 'Quicksand', 'Futura', 'Century Gothic', 'Avenir Next', sans-serif;

  --bg:        #fbf6ec;   /* parchment ground (tufte) */
  --bg-raised: #f4efe6;   /* raised warm panel */
  --bg-sunk:   #f6f1e6;
  --ink:       #322d27;   /* primary text — warm, soft */
  --ink-2:     #574f45;   /* secondary */
  --ink-3:     #8a8073;   /* muted / captions */
  --rule:      #e2dcd2;   /* hairlines */
  --rule-soft: #efeae1;
  --accent:    #800000;   /* darkred — the one brand accent */
  --accent-ink:#5e0000;
  --accent-tint:#f3e3e3;
  --shadow-sm: 0 1px 2px rgba(40,20,10,.06);
  --shadow-md: 0 2px 10px rgba(40,20,10,.08);
  --shadow-lg: 0 10px 34px rgba(40,20,10,.13);
  --sel:       rgba(128,0,0,.14);

  /* 14-hue categorical topic set, harmonised with the jewel-earth palette */
  --t-cosmos:#3f5d7e; --t-science:#2f7268; --t-skepticism:#a07a20; --t-wonder:#a85a32;
  --t-religion:#6b4e7a; --t-mortality:#6f655a; --t-earth:#6e7539; --t-politics:#800000;
  --t-knowledge:#4a6ea0; --t-humanity:#b3704c; --t-evolution:#3f8a7c; --t-exploration:#4a5a94;
  --t-mind:#8a5a6a; --t-pseudoscience:#7a7488;
}

/* ---- dark theme (shared block; applied by toggle OR by system pref) ------ */
:root[data-theme="dark"] {
  --bg:        #1b1916;
  --bg-raised: #24211d;
  --bg-sunk:   #17150f;
  --ink:       #ece5d8;
  --ink-2:     #c3baa9;
  --ink-3:     #8f8778;
  --rule:      #35312a;
  --rule-soft: #2a2721;
  --accent:    #e0897a;   /* lightened maroon for contrast on dark */
  --accent-ink:#e6a494;
  --accent-tint:#38231f;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.3);
  --shadow-md: 0 2px 12px rgba(0,0,0,.4);
  --shadow-lg: 0 12px 40px rgba(0,0,0,.5);
  --sel:       rgba(224,137,122,.22);

  --t-cosmos:#7fa0c6; --t-science:#5fb3a5; --t-skepticism:#d3ac54; --t-wonder:#d9906a;
  --t-religion:#b090c4; --t-mortality:#b3a996; --t-earth:#adb46f; --t-politics:#e0897a;
  --t-knowledge:#87a9de; --t-humanity:#d69a76; --t-evolution:#6fc3b2; --t-exploration:#8a9adc;
  --t-mind:#c98fa5; --t-pseudoscience:#b0aac6;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="dark"]) {
    --bg:#1b1916; --bg-raised:#24211d; --bg-sunk:#17150f;
    --ink:#ece5d8; --ink-2:#c3baa9; --ink-3:#8f8778;
    --rule:#35312a; --rule-soft:#2a2721;
    --accent:#e0897a; --accent-ink:#e6a494; --accent-tint:#38231f;
    --shadow-sm:0 1px 2px rgba(0,0,0,.3); --shadow-md:0 2px 12px rgba(0,0,0,.4); --shadow-lg:0 12px 40px rgba(0,0,0,.5);
    --sel:rgba(224,137,122,.22);
    --t-cosmos:#7fa0c6; --t-science:#5fb3a5; --t-skepticism:#d3ac54; --t-wonder:#d9906a;
    --t-religion:#b090c4; --t-mortality:#b3a996; --t-earth:#adb46f; --t-politics:#e0897a;
    --t-knowledge:#87a9de; --t-humanity:#d69a76; --t-evolution:#6fc3b2; --t-exploration:#8a9adc;
    --t-mind:#c98fa5; --t-pseudoscience:#b0aac6;
  }
}

/* ---- 2. RESET + BASE ----------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh;
  background: var(--bg); color: var(--ink);
  font-family: var(--serif); font-size: 18px; line-height: 1.6;
  font-feature-settings: "onum" 1, "liga" 1, "kern" 1;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
  transition: background 240ms ease, color 240ms ease;
}
::selection { background: var(--sel); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
h1,h2,h3 { font-weight: 700; line-height: 1.2; margin: 0; }
button { font-family: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }

.mono { font-family: var(--mono); }
.sc { font-variant: small-caps; letter-spacing: .04em; }
.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; }

/* ---- 3. TOP BAR ---------------------------------------------------------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 1rem;
  padding: .7rem clamp(1rem, 4vw, 2.2rem);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(1.4) blur(9px);
  border-bottom: 1px solid var(--rule);
}
.brand { display: flex; align-items: center; gap: .6rem; flex: none; color: var(--ink); }
.brand:hover { text-decoration: none; }
.brand .mark {
  width: 34px; height: 34px; border-radius: 8px; flex: none;
  background: var(--accent); color: #fff; box-shadow: var(--shadow-sm);
  display: grid; place-items: center; font-family: var(--serif);
  font-size: 1.5rem; line-height: 1; font-weight: 700; padding-bottom: 6px;
}
.brand .word { display: flex; flex-direction: column; line-height: 1.05; }
.brand .word b { font-family: var(--brand); font-weight: 700; font-size: 1.02rem; letter-spacing: .01em; }
.brand .word span { font-family: var(--sans); font-size: .6rem; letter-spacing: .16em; text-transform: uppercase; color: var(--ink-3); }

.nav { display: flex; gap: .1rem; margin-left: .5rem; flex-wrap: wrap; }
.nav a {
  font-family: var(--sans); font-size: .82rem; font-weight: 600; color: var(--ink-2);
  padding: .4rem .62rem; border-radius: 6px; letter-spacing: .01em;
}
.nav a:hover { background: var(--rule-soft); color: var(--ink); text-decoration: none; }
.nav a.on { color: var(--accent); background: color-mix(in srgb, var(--accent) 9%, transparent); }

.bar-spacer { flex: 1; }
.iconbtn {
  display: grid; place-items: center; width: 34px; height: 34px; flex: none;
  background: transparent; border: 1px solid var(--rule); border-radius: 7px;
  color: var(--ink-2); font-size: .95rem; transition: background 120ms, border-color 120ms;
}
.iconbtn:hover { background: var(--rule-soft); border-color: var(--ink-3); color: var(--ink); }

/* ---- 4. LAYOUT ----------------------------------------------------------- */
main { display: block; }
.wrap { max-width: 74rem; margin: 0 auto; padding: 0 clamp(1rem, 4vw, 2.2rem); }
.section-head { display: flex; align-items: baseline; gap: 1rem; flex-wrap: wrap; margin: 2.4rem 0 1.2rem; }
.section-head h2 { font-family: var(--serif); font-size: 1.5rem; font-variant: small-caps; letter-spacing: .02em; }
.section-head .count { font-family: var(--mono); font-size: .75rem; color: var(--ink-3); }
.kicker { font-family: var(--sans); font-size: .68rem; font-weight: 700; letter-spacing: .16em; text-transform: uppercase; color: var(--accent); }

/* ---- 5. THE STAGE (single big quote — home / daily / shuffle) ------------ */
.stage {
  min-height: calc(100vh - 3.4rem);
  display: grid; grid-template-rows: auto 1fr auto;
  padding: 1rem clamp(1rem, 5vw, 3rem) 1.6rem;
}
.stage-top { display: flex; align-items: center; justify-content: center; gap: .6rem; padding-top: .6rem; }
.stage-mode {
  font-family: var(--sans); font-size: .68rem; font-weight: 700; letter-spacing: .18em;
  text-transform: uppercase; color: var(--ink-3);
  display: inline-flex; align-items: center; gap: .5rem;
}
.stage-mode .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.stage-mode .dot.live { animation: pulse 2s ease-in-out infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.35} }

.stage-body {
  display: grid; align-content: center; justify-items: center;
  text-align: center; gap: 1.6rem; max-width: 54rem; margin: 0 auto; width: 100%;
}
.stage-figure { position: relative; display: flex; justify-content: center; }
.stage-mark {
  font-family: var(--serif); color: var(--accent); opacity: .26;
  font-size: clamp(4rem, 11vw, 8rem); line-height: .6; height: .5em;
  display: block; margin-bottom: .1em; user-select: none;
}
/* author portrait replaces the quote mark on the stage */
.stage-portrait {
  width: clamp(88px, 12vw, 132px); height: clamp(88px, 12vw, 132px);
  border-radius: 50%; object-fit: cover; object-position: center 22%;
  display: block; margin-bottom: .35rem; user-select: none;
  border: 3px solid var(--bg);
  box-shadow: 0 0 0 1px var(--rule), var(--shadow-md);
  filter: saturate(.92) contrast(1.02);
}
:root[data-theme="dark"] .stage-portrait { filter: saturate(.9) contrast(1.03) brightness(.94); }
.stage-quote {
  font-family: var(--serif); color: var(--ink);
  font-size: clamp(1.5rem, 3.6vw, 2.7rem); line-height: 1.32; letter-spacing: .003em;
  text-wrap: pretty; margin: 0;
}
.stage-quote.long { font-size: clamp(1.25rem, 2.7vw, 1.95rem); line-height: 1.4; }
.stage-quote.xlong { font-size: clamp(1.08rem, 2.1vw, 1.5rem); line-height: 1.5; }
.stage-attr {
  font-family: var(--serif); font-style: italic; color: var(--ink-2);
  font-size: clamp(1rem, 1.6vw, 1.15rem); display: flex; gap: .5rem; flex-wrap: wrap;
  align-items: baseline; justify-content: center;
}
.stage-attr .who { font-style: normal; font-variant: small-caps; letter-spacing: .05em; color: var(--ink); }
.stage-attr .work { color: var(--ink-2); }
.stage-attr .yr { font-family: var(--mono); font-size: .82em; color: var(--ink-3); font-style: normal; }
.stage-topics { display: flex; gap: .4rem; flex-wrap: wrap; justify-content: center; }

.stage-fade > * { animation: fade 420ms ease both; }
@keyframes fade { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.stage-controls {
  display: flex; align-items: center; justify-content: center; gap: .5rem; flex-wrap: wrap;
  padding-top: .4rem;
}
.ctl {
  font-family: var(--sans); font-size: .8rem; font-weight: 600; color: var(--ink-2);
  background: var(--bg-raised); border: 1px solid var(--rule); border-radius: 8px;
  padding: .5rem .8rem; display: inline-flex; align-items: center; gap: .45rem;
  transition: background 120ms, border-color 120ms, color 120ms;
}
.ctl:hover { border-color: var(--ink-3); color: var(--ink); }
.ctl.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.ctl.primary:hover { background: var(--accent-ink); }
.ctl .k { font-family: var(--mono); font-size: .64rem; color: var(--ink-3); border: 1px solid var(--rule); border-radius: 4px; padding: 0 .3rem; }
.ctl.primary .k { color: #fff; border-color: rgba(255,255,255,.4); }
.stage-counter { font-family: var(--mono); font-size: .72rem; color: var(--ink-3); min-width: 5.5rem; text-align: center; }

/* ---- 6. TOPIC CHIPS ------------------------------------------------------ */
.chip {
  --c: var(--ink-3);
  font-family: var(--sans); font-size: .72rem; font-weight: 700; letter-spacing: .02em;
  color: var(--c); background: color-mix(in srgb, var(--c) 13%, transparent);
  border: 1px solid color-mix(in srgb, var(--c) 30%, transparent);
  border-radius: 100px; padding: .2rem .62rem; display: inline-flex; align-items: center; gap: .35rem;
  transition: background 120ms, transform 120ms;
}
a.chip:hover { text-decoration: none; background: color-mix(in srgb, var(--c) 22%, transparent); transform: translateY(-1px); }
.chip .n { font-family: var(--mono); font-weight: 400; font-size: .82em; opacity: .8; }
[data-topic="cosmos"]{--c:var(--t-cosmos)} [data-topic="science"]{--c:var(--t-science)}
[data-topic="skepticism"]{--c:var(--t-skepticism)} [data-topic="wonder"]{--c:var(--t-wonder)}
[data-topic="religion"]{--c:var(--t-religion)} [data-topic="mortality"]{--c:var(--t-mortality)}
[data-topic="earth"]{--c:var(--t-earth)} [data-topic="politics"]{--c:var(--t-politics)}
[data-topic="knowledge"]{--c:var(--t-knowledge)} [data-topic="humanity"]{--c:var(--t-humanity)}
[data-topic="evolution"]{--c:var(--t-evolution)} [data-topic="exploration"]{--c:var(--t-exploration)}
[data-topic="mind"]{--c:var(--t-mind)} [data-topic="pseudoscience"]{--c:var(--t-pseudoscience)}

.tier-badge { font-family: var(--mono); font-size: .6rem; letter-spacing: .1em; text-transform: uppercase;
  color: var(--accent); border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
  border-radius: 4px; padding: .05rem .32rem; }

/* ---- 7. BROWSE / GRID ---------------------------------------------------- */
.toolbar {
  display: flex; gap: .7rem; align-items: center; flex-wrap: wrap;
  padding: 1rem 0 1.2rem; position: sticky; top: 3.4rem; z-index: 20;
  background: color-mix(in srgb, var(--bg) 90%, transparent); backdrop-filter: blur(6px);
}
.search {
  display: flex; align-items: center; gap: .5rem; flex: 1; min-width: 12rem;
  background: var(--bg-raised); border: 1px solid var(--rule); border-radius: 9px; padding: .5rem .75rem;
}
.search input { flex: 1; border: 0; background: transparent; color: var(--ink); font-family: var(--serif); font-size: 1rem; }
.search input:focus { outline: none; }
.search .ico { color: var(--ink-3); }
.select {
  font-family: var(--sans); font-size: .82rem; font-weight: 600; color: var(--ink-2);
  background: var(--bg-raised); border: 1px solid var(--rule); border-radius: 8px; padding: .5rem .7rem;
}
.filterbar { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: 1.4rem; }
.filterbar .chip { cursor: pointer; }
.filterbar .chip[aria-pressed="true"] { background: color-mix(in srgb, var(--c) 30%, transparent); box-shadow: inset 0 0 0 1px var(--c); }

.grid { columns: 3 20rem; column-gap: 1.5rem; }
.qcard {
  break-inside: avoid; margin: 0 0 1.5rem; padding: 1.3rem 1.4rem 1.15rem;
  background: var(--bg-raised); border: 1px solid var(--rule); border-radius: 10px;
  box-shadow: var(--shadow-sm); transition: box-shadow 160ms, border-color 160ms, transform 160ms;
}
.qcard:hover { box-shadow: var(--shadow-md); border-color: color-mix(in srgb, var(--accent) 22%, var(--rule)); }
.qcard .q { font-family: var(--serif); font-size: 1.06rem; line-height: 1.5; color: var(--ink); text-wrap: pretty; margin: 0 0 .8rem; }
.qcard .q::before { content: "\201C"; color: var(--accent); font-size: 1.3em; line-height: 0; margin-right: .05em; opacity: .5; }
.qcard .meta { display: flex; align-items: baseline; justify-content: space-between; gap: .6rem; flex-wrap: wrap; }
.qcard .attr { font-family: var(--serif); font-style: italic; font-size: .86rem; color: var(--ink-3); }
.qcard .attr .yr { font-family: var(--mono); font-style: normal; font-size: .78rem; }
.qcard .chips { display: flex; gap: .3rem; flex-wrap: wrap; margin-top: .7rem; }
.qcard .card-actions { display: flex; gap: .3rem; margin-top: .55rem; opacity: 0; transition: opacity 140ms; }
.qcard:hover .card-actions, .qcard:focus-within .card-actions { opacity: 1; }
.qcard .card-actions button { font-family: var(--sans); font-size: .68rem; color: var(--ink-3); background: transparent; border: 1px solid var(--rule); border-radius: 5px; padding: .2rem .45rem; }
.qcard .card-actions button:hover { color: var(--ink); border-color: var(--ink-3); }

/* index (by person / by work / by topic landing) */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); gap: 1rem; }
.tile {
  display: block; padding: 1.2rem 1.3rem; border: 1px solid var(--rule); border-radius: 10px;
  background: var(--bg-raised); color: var(--ink); box-shadow: var(--shadow-sm);
  transition: box-shadow 160ms, transform 160ms, border-color 160ms;
}
.tile:hover { text-decoration: none; box-shadow: var(--shadow-md); transform: translateY(-2px); border-color: color-mix(in srgb, var(--accent) 22%, var(--rule)); }
.tile .t-title { font-family: var(--serif); font-size: 1.2rem; font-weight: 700; }
.tile .t-sub { font-family: var(--sans); font-size: .76rem; color: var(--ink-3); margin-top: .2rem; }
.tile .t-count { font-family: var(--mono); font-size: .74rem; color: var(--accent); margin-top: .7rem; }
.tile[data-topic] { border-left: 3px solid var(--c); }

.empty { text-align: center; color: var(--ink-3); font-style: italic; padding: 4rem 1rem; }

/* person tiles carry a portrait */
.tile-person { display: flex; align-items: center; gap: 1rem; }
.tile-portrait { width: 56px; height: 56px; border-radius: 50%; object-fit: cover; object-position: center 22%;
  flex: none; box-shadow: 0 0 0 1px var(--rule); }

/* ---- capability gate (no/invalid key) ---- */
.gate {
  min-height: calc(100vh - 3.4rem); display: grid; align-content: center; justify-items: center;
  text-align: center; gap: .9rem; padding: 2rem clamp(1rem, 6vw, 3rem); max-width: 34rem; margin: 0 auto;
}
.gate-mark { font-size: 2.6rem; opacity: .9; }
.gate h1 { font-family: var(--serif); font-size: clamp(1.6rem, 4vw, 2.2rem); font-variant: small-caps; letter-spacing: .02em; }
.gate p { font-family: var(--serif); font-size: 1.08rem; line-height: 1.6; color: var(--ink-2); max-width: 30rem; }

/* ---- 8. FOOTER ----------------------------------------------------------- */
footer {
  margin-top: 4rem; border-top: 1px solid var(--rule);
  padding: 1.8rem clamp(1rem,4vw,2.2rem); color: var(--ink-3);
  font-family: var(--sans); font-size: .78rem; line-height: 1.6;
  display: flex; gap: 1rem 2rem; flex-wrap: wrap; align-items: baseline; justify-content: space-between;
}
footer a { color: var(--ink-2); font-weight: 600; }
footer .prov { max-width: 40rem; }
.stage + footer { margin-top: 0; }

/* ---- 9. TOASTS ----------------------------------------------------------- */
.toast {
  position: fixed; left: 50%; bottom: 1.4rem; transform: translateX(-50%) translateY(1.5rem);
  background: var(--ink); color: var(--bg); font-family: var(--sans); font-size: .8rem; font-weight: 600;
  padding: .55rem .9rem; border-radius: 8px; box-shadow: var(--shadow-lg);
  opacity: 0; pointer-events: none; transition: opacity 180ms, transform 180ms; z-index: 100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---- 10. RESPONSIVE + MOTION -------------------------------------------- */
@media (max-width: 640px) {
  body { font-size: 17px; }
  .nav { display: none; }
  .grid { columns: 1; }
  .toolbar { top: 3.2rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
