/* Design notes (2026-07 redesign):
   - Warm paper palette, serif (Newsreader) for headings and the wordmark,
     system stack for everything else. One webfont, non-italic subset only.
   - Single column, max 680px. Cards on a soft background.
   - Plain language on the surface; scoring machinery behind disclosures.
   - Theme: follows system preference until the user toggles; the choice
     persists in localStorage. body[data-th] carries the active theme.
   - Every wait state is designed: cold start (~60s after idle) gets staged
     messages; first guide generation (~10-20s) narrates what's happening.
   - No layout shift: the status line has fixed height, skeletons match
     final card geometry. prefers-reduced-motion disables all animation. */

:root { color-scheme: light dark; }
body {
  --bg:#FAF7F1; --card:#FFFFFF; --ink:#211C15; --ink2:#5D5446; --ink3:#766B59;
  --line:#E3DACB; --line2:#EFE8DB; --accent:#4A4238; --accent-strong:#211C15;
  --chip:#F3EDE2; --guide-bg:#FBF7EE; --code-bg:#26201A; --code-ink:#EDE5D6;
  --seg1:#6B5F4F; --seg2:#C99A3A; --seg3:#7B8B5E; --err:#A3422E; --cta-ink:#FFF7EE;
  --shadow:rgba(80,60,30,.07);
}
body[data-th="dark"] {
  --bg:#171310; --card:#211B15; --ink:#EDE5D6; --ink2:#C2B6A4; --ink3:#9A8E7D;
  --line:#372F26; --line2:#2A241D; --accent:#C9BFB0; --accent-strong:#EDE5D6;
  --chip:#2B241C; --guide-bg:#251F18; --code-bg:#100D0A; --code-ink:#E5DCCB;
  --seg1:#A89C8A; --seg2:#CBA24A; --seg3:#8FA075; --err:#E07A5F; --cta-ink:#211C15;
  --shadow:rgba(0,0,0,.25);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0; min-height: 100vh; display: flex; flex-direction: column;
  background: var(--bg); color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  transition: background .25s, color .25s;
}
.serif { font-family: "Newsreader", Georgia, serif; }
a { color: var(--accent); }
a:hover { color: var(--accent-strong); }
input, button, select { font-family: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

@keyframes gsPulse { 0%,100% { opacity:.45 } 50% { opacity:1 } }
@keyframes gsDot { 0%,100% { transform:scale(1); opacity:.6 } 50% { transform:scale(1.3); opacity:1 } }
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* Header */
.topbar {
  width: 100%; max-width: 720px; margin: 0 auto; padding: 20px 20px 0;
  display: flex; justify-content: space-between; align-items: center;
}
.wordmark {
  font-family: "Newsreader", Georgia, serif; font-weight: 600; font-size: 21px;
  letter-spacing: -0.01em; color: var(--ink); background: none; border: none; padding: 4px 0;
}
.wordmark span { color: var(--accent-strong); }
.theme-toggle {
  width: 36px; height: 36px; border: 1px solid var(--line); border-radius: 999px;
  display: flex; align-items: center; justify-content: center;
  color: var(--ink3); background: none; font-size: 15px;
}

.main {
  width: 100%; max-width: 680px; margin: 0 auto; padding: 0 20px 40px;
  flex: 1; display: flex; flex-direction: column;
}

/* Hero */
.hero { text-align: center; padding-top: clamp(36px, 11vh, 110px); }
.hero h1 {
  font-family: "Newsreader", Georgia, serif; font-weight: 500;
  font-size: clamp(31px, 6vw, 46px); line-height: 1.12; letter-spacing: -0.015em;
  margin: 0 0 14px;
}
.hero p {
  margin: 0 auto 30px; font-size: 16px; line-height: 1.55; color: var(--ink2);
  max-width: 540px; text-wrap: pretty;
}
.searched-gap { height: 18px; }

/* Search bar */
.search-card {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 2px 10px var(--shadow), 0 12px 32px var(--shadow);
  padding: 0 16px; min-height: 58px;
}
.search-card input {
  flex: 1; border: none; outline: none; background: none;
  font-size: 16.5px; color: var(--ink); min-width: 0; height: 44px;
}
.kbd-hint {
  font: 500 12px ui-monospace, Menlo, monospace; color: var(--ink3);
  border: 1px solid var(--line); border-radius: 6px; padding: 3px 7px; background: var(--bg);
}
@media (hover: none) { .kbd-hint { display: none; } }
.search-go {
  background: var(--accent-strong); color: var(--cta-ink); border: none; border-radius: 9px;
  font-size: 14px; font-weight: 600; padding: 0 16px; height: 40px;
}

/* Example chips */
.examples {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 12px 26px;
  margin: 24px auto 0; max-width: 600px;
}
.chip {
  background: none; border: none; padding: 6px 0; font-size: 14.5px; color: var(--accent);
  text-decoration: underline; text-decoration-style: dotted;
  text-underline-offset: 4px; text-decoration-color: var(--line);
}

/* Filters row */
.filters {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center;
  gap: 6px 18px; margin: 26px 0 0; font-size: 13px; color: var(--ink3);
}
.filters select {
  border: none; background: none; color: var(--ink3); font-size: 13px; padding: 8px 0;
  cursor: pointer;
}
.quiet-btn {
  display: flex; align-items: center; gap: 7px; background: none; border: none;
  color: var(--ink3); font-size: 13px; padding: 8px 0;
}
.switch {
  width: 26px; height: 15px; border-radius: 99px; background: var(--line);
  position: relative; transition: background .15s; flex: none;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 11px; height: 11px;
  border-radius: 99px; background: #fff; transition: left .15s;
}
.quiet-btn[aria-pressed="true"] .switch { background: var(--accent); }
.quiet-btn[aria-pressed="true"] .switch::after { left: 13px; }

/* Tune ranking panel */
.tune {
  margin: 14px auto 0; width: 100%; max-width: 440px;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 16px 18px;
}
.tune > p { margin: 0 0 12px; font-size: 12.5px; color: var(--ink3); }
.tune label {
  display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--ink2);
  margin-top: 10px;
}
.tune label:first-of-type { margin-top: 0; }
.tune label > span:first-child { width: 86px; flex: none; }
.tune input[type="range"] { flex: 1; min-width: 0; }
.tune output {
  width: 34px; text-align: right; flex: none;
  font: 500 12px ui-monospace, Menlo, monospace; color: var(--ink3);
}

/* Wait area: skeleton or cold-start panel */
.wait-slot { margin-top: 22px; }
.status-spacer { height: 20px; margin-bottom: 14px; }
.skeleton-list { display: flex; flex-direction: column; gap: 14px; }
.skeleton {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 18px; animation: gsPulse 1.4s ease-in-out infinite;
  display: flex; gap: 12px; align-items: flex-start;
}
.skeleton .sk-av { width: 40px; height: 40px; border-radius: 99px; background: var(--chip); flex: none; }
.skeleton .sk-lines { flex: 1; display: flex; flex-direction: column; gap: 9px; padding-top: 3px; }
.skeleton .sk-lines span { display: block; border-radius: 5px; }
.skeleton .sk-a { height: 14px; width: 38%; background: var(--chip); }
.skeleton .sk-b { height: 12px; width: 82%; background: var(--line2); }
.skeleton .sk-c { height: 11px; width: 55%; background: var(--line2); }

.centered-panel { text-align: center; padding: 64px 24px; max-width: 460px; margin: 0 auto; }
.centered-panel h2 {
  font-family: "Newsreader", Georgia, serif; font-weight: 500; font-size: 23px; margin: 0 0 10px;
}
.centered-panel p { margin: 0; font-size: 14px; line-height: 1.6; color: var(--ink2); text-wrap: pretty; }
.pulse-dot {
  display: inline-block; width: 10px; height: 10px; border-radius: 99px;
  background: var(--accent-strong); animation: gsDot 1.6s ease-in-out infinite; margin-bottom: 18px;
}

/* Results */
.results-wrap { margin-top: 22px; }
.status-line { height: 20px; margin: 0 0 14px; font-size: 13px; color: var(--ink3); }
.results { display: flex; flex-direction: column; gap: 14px; list-style: none; margin: 0; padding: 0; }
.result {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 18px; box-shadow: 0 1px 4px var(--shadow);
  display: flex; gap: 12px; align-items: flex-start;
}
.avatar { width: 40px; height: 40px; border-radius: 99px; flex: none; background: var(--chip); }
.avatar-fallback {
  width: 40px; height: 40px; border-radius: 99px; flex: none; background: var(--chip);
  color: var(--accent); display: flex; align-items: center; justify-content: center;
  font: 600 17px "Newsreader", Georgia, serif;
}
.result-body { flex: 1; min-width: 0; }
.result-name {
  font-size: 16px; font-weight: 600; color: var(--ink); text-decoration: none;
  word-break: break-word;
}
.result-name:hover {
  color: var(--accent-strong); text-decoration: underline; text-underline-offset: 3px;
}
.result-desc { margin: 5px 0 0; font-size: 14.5px; line-height: 1.5; color: var(--ink2); text-wrap: pretty; }
.result-meta {
  display: flex; flex-wrap: wrap; gap: 5px 16px; margin-top: 9px;
  font-size: 13px; color: var(--ink3);
}
.result-meta .lang { display: flex; align-items: center; gap: 6px; }
.lang-dot { width: 9px; height: 9px; border-radius: 99px; display: inline-block; }
.topics { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.topic { font-size: 12px; color: var(--ink2); background: var(--chip); border-radius: 999px; padding: 3px 10px; }

.result-actions {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin-top: 13px;
}
.guide-btn {
  display: flex; align-items: center; gap: 8px;
  border: 1.5px solid var(--accent); color: var(--accent); background: none;
  border-radius: 999px; padding: 0 17px; height: 40px; font-size: 13.5px; font-weight: 600;
}
.guide-btn:hover { background: var(--chip); }
.guide-btn svg { flex: none; }
.why-btn {
  background: none; border: none; color: var(--ink3); font-size: 13px; padding: 10px 2px;
  text-decoration: underline; text-decoration-style: dotted;
  text-underline-offset: 4px; text-decoration-color: var(--line);
}

/* Score breakdown */
.score-panel {
  margin-top: 14px; background: var(--guide-bg); border: 1px solid var(--line2);
  border-radius: 12px; padding: 14px 16px;
}
.score-bar {
  display: flex; height: 10px; border-radius: 99px; overflow: hidden; background: var(--line2);
}
.score-legend {
  display: flex; flex-wrap: wrap; gap: 6px 20px; margin-top: 11px;
  font-size: 12.5px; color: var(--ink2);
}
.score-legend > span { display: flex; align-items: center; gap: 6px; }
.score-legend .total { margin-left: auto; font-weight: 600; }
.swatch { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }
.score-panel .hint { margin: 9px 0 0; font-size: 12px; color: var(--ink3); }

/* Guide panels */
.guide-panel {
  margin-top: 14px; background: var(--guide-bg); border: 1px solid var(--line2);
  border-radius: 12px;
}
.guide-waiting { padding: 26px 20px; text-align: center; }
.guide-waiting .pulse-dot { width: 8px; height: 8px; margin-bottom: 10px; }
.guide-waiting .headline { margin: 0 0 6px; font-size: 14px; font-weight: 600; color: var(--ink); }
.guide-waiting .sub {
  margin: 0 auto; font-size: 12.5px; line-height: 1.55; color: var(--ink3); max-width: 380px;
}
.guide-failed { padding: 24px 20px; text-align: center; }
.guide-failed .headline { margin: 0 0 6px; font-size: 14px; font-weight: 600; color: var(--err); }
.guide-failed .sub { margin: 0 0 14px; font-size: 12.5px; color: var(--ink3); }
.retry-btn {
  border: 1.5px solid var(--accent); color: var(--accent); background: none;
  border-radius: 999px; padding: 0 18px; height: 38px; font-size: 13px; font-weight: 600;
}
.guide-open { padding: 18px 20px; }
.guide-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.guide-eyebrow {
  font-size: 12px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase;
  color: var(--accent);
}
.guide-badge { font-size: 11.5px; color: var(--ink3); }
.guide-section { margin-bottom: 18px; }
.guide-section:last-of-type { margin-bottom: 0; }
.guide-section-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 2px; }
.guide-section-num { font: 600 11px ui-monospace, Menlo, monospace; color: var(--accent); }
.guide-section-title {
  font-size: 12.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
  color: var(--ink2);
}
.guide-open p { margin: 8px 0; font-size: 14px; line-height: 1.65; color: var(--ink); }
.guide-open ul { margin: 8px 0; padding-left: 20px; }
.guide-open li { margin: 4px 0; font-size: 14px; line-height: 1.6; color: var(--ink); }
.guide-open code {
  background: var(--chip); padding: 1px 5px; border-radius: 4px; font-size: 12.5px;
  font-family: ui-monospace, Menlo, monospace;
}
.codeblock { position: relative; margin: 10px 0; }
.codeblock pre {
  background: var(--code-bg); color: var(--code-ink); border-radius: 10px;
  padding: 14px 72px 14px 16px; font-size: 13px; line-height: 1.6;
  font-family: ui-monospace, Menlo, monospace; overflow-x: auto; margin: 0;
}
.codeblock pre code { background: none; padding: 0; border-radius: 0; font-size: 13px; color: inherit; }
.copy-btn {
  position: absolute; top: 8px; right: 8px;
  font: 500 11.5px system-ui, sans-serif; background: rgba(250,247,241,.1);
  color: var(--code-ink); border: 1px solid rgba(250,247,241,.22);
  border-radius: 6px; padding: 4px 10px;
}
.guide-footnote {
  margin: 16px 0 0; padding-top: 12px; border-top: 1px dashed var(--line);
  font-size: 12px; font-style: italic; color: var(--ink3);
}

/* Zero / error panels reuse .centered-panel */
.centered-panel .chips-inline {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 10px 24px; margin-top: 20px;
}
.centered-panel h2.error { color: var(--err); }
.retry-search {
  margin-top: 18px; border: 1.5px solid var(--accent); color: var(--accent); background: none;
  border-radius: 999px; padding: 0 20px; height: 42px; font-size: 13.5px; font-weight: 600;
}

footer { padding: 26px 20px; text-align: center; font-size: 12.5px; color: var(--ink3); }
footer a {
  color: var(--ink3); text-decoration: underline; text-underline-offset: 3px;
  text-decoration-color: var(--line);
}
.about-search {
  text-decoration: underline; text-decoration-style: dotted; text-underline-offset: 3px;
  text-decoration-color: var(--line); cursor: help;
}
