/* Sapere — Part 1 styles
   Serious and calm, never dull. One accent (gold = the light of knowing). */

:root {
  --serif: "Fraunces", "Iowan Old Style", "Palatino Linotype", "Noto Serif", Georgia, serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

  /* light (cool paper, matches the icon) */
  --bg: #f4f6fb;
  --bg-2: #e9edf5;
  --surface: #ffffff;
  --line: rgba(15, 20, 32, .10);
  --line-2: rgba(15, 20, 32, .18);
  --text: #0f1420;
  --muted: #55607a;
  --faint: #8590a8;
  --accent: #1d5fe0;
  --accent-2: #3b7cf5;
  --accent-soft: rgba(59, 124, 245, .14);
  --blue: #2f6fe0;
  --blue-soft: rgba(47, 111, 224, .12);
  --settled: #1f7a4d;
  --debated: #c25a2c;
  --unknown: #6b4fc2;
  --shadow: 0 1px 2px rgba(20, 24, 30, .05), 0 10px 30px -12px rgba(20, 24, 30, .18);
  --glow: 0 0 0 4px rgba(59, 124, 245, .20);
  --radius: 18px;
  --ease: cubic-bezier(.2, .7, .2, 1);
  --spring: cubic-bezier(.34, 1.4, .4, 1);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --dark: 1; }
}
:root[data-theme="dark"] { --dark: 1; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #060a14; --bg-2: #0b1020; --surface: #0f1628;
    --line: rgba(205, 220, 255, .10); --line-2: rgba(205, 220, 255, .18);
    --text: #e8edf8; --muted: #93a0bd; --faint: #66728f;
    --accent: #4ea1ff; --accent-2: #8cc4ff; --accent-soft: rgba(78, 161, 255, .16);
    --blue: #4ea1ff; --blue-soft: rgba(78, 161, 255, .14);
    --settled: #5fd39a; --debated: #ff8f70; --unknown: #b79cff;
    --shadow: 0 1px 2px rgba(0,0,0,.35), 0 14px 40px -14px rgba(0,0,0,.7);
    --glow: 0 0 0 4px rgba(78, 161, 255, .18);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #060a14; --bg-2: #0b1020; --surface: #0f1628;
  --line: rgba(205, 220, 255, .10); --line-2: rgba(205, 220, 255, .18);
  --text: #e8edf8; --muted: #93a0bd; --faint: #66728f;
  --accent: #4ea1ff; --accent-2: #8cc4ff; --accent-soft: rgba(78, 161, 255, .16);
  --blue: #4ea1ff; --blue-soft: rgba(78, 161, 255, .14);
  --settled: #5fd39a; --debated: #ff8f70; --unknown: #b79cff;
  --shadow: 0 1px 2px rgba(0,0,0,.35), 0 14px 40px -14px rgba(0,0,0,.7);
  --glow: 0 0 0 4px rgba(78, 161, 255, .18);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 50% -10%, var(--blue-soft), transparent 60%),
    var(--bg);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  transition: background-color .3s var(--ease), color .3s var(--ease);
}
button { font: inherit; color: inherit; }
a { color: inherit; }
::selection { background: var(--accent-soft); }

/* ---------- top bar ---------- */
.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; padding-top: max(14px, env(safe-area-inset-top));
}
.brand { display: inline-flex; align-items: center; gap: 9px; text-decoration: none; color: var(--text); }
.mark { width: 30px; height: 30px; border-radius: 9px; display: block; box-shadow: 0 0 0 1px var(--line), 0 0 18px -4px var(--blue); }
.wordmark { font-family: var(--serif); font-weight: 600; font-size: 22px; letter-spacing: .005em; font-variation-settings: "opsz" 48; }
.top-actions { display: flex; gap: 6px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid transparent;
  background: transparent; cursor: pointer; display: grid; place-items: center;
  color: var(--muted); transition: background .2s, color .2s, border-color .2s;
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn:hover { background: var(--surface); border-color: var(--line); color: var(--text); }
.icon-btn:active { transform: scale(.96); }
.ic-moon { display: none; }
:root[data-theme="dark"] .ic-sun { display: none; }
:root[data-theme="dark"] .ic-moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .ic-sun { display: none; }
  :root:not([data-theme="light"]) .ic-moon { display: block; }
}

.setup-banner {
  margin: 0 16px 8px; padding: 10px 14px; border-radius: 12px;
  background: var(--accent-soft); border: 1px solid var(--accent); color: var(--text); font-size: 14px;
}
.setup-banner code { font-family: var(--mono); font-size: 13px; background: var(--surface); padding: 1px 6px; border-radius: 6px; }

/* ---------- main ---------- */
main { flex: 1; width: 100%; max-width: 720px; margin: 0 auto; padding: 0 16px 40px; }
main.has-answer { max-width: 760px; }
@media (min-width: 900px) { main.has-answer { max-width: 1040px; } }

/* hero */
.hero { text-align: center; padding: clamp(28px, 10vh, 96px) 0 18px; }
.hero-title {
  font-family: var(--serif); font-weight: 400; font-size: clamp(40px, 9vw, 64px);
  line-height: 1.02; margin: 0 0 12px; letter-spacing: -.015em; font-variation-settings: "opsz" 144;
}
.hero-title em { font-style: italic; color: var(--accent); }
.hero-sub { margin: 0; color: var(--muted); font-size: 16px; }
main.has-answer .hero { display: none; }

/* ask box */
.ask { margin: 10px 0 0; position: sticky; top: 0; z-index: 5; padding: 8px 0 6px; background: linear-gradient(var(--bg) 80%, transparent); }
main:not(.has-answer) .ask { position: static; background: none; }
.ask-box {
  position: relative; display: flex; align-items: flex-end; gap: 8px;
  background: var(--surface); border: 1px solid var(--line-2); border-radius: 26px;
  padding: 8px 8px 8px 18px; box-shadow: var(--shadow);
  transition: box-shadow .25s var(--ease), border-color .25s var(--ease), transform .25s var(--ease);
}
main:not(.has-answer) .ask-box { animation: breathe 4.5s ease-in-out infinite; }
.ask-box:focus-within { border-color: var(--accent); box-shadow: var(--shadow), var(--glow); animation: none; }
.ask-box textarea {
  flex: 1; resize: none; border: 0; outline: 0; background: transparent; color: var(--text);
  font: inherit; font-size: 17px; line-height: 1.45; padding: 8px 0; max-height: 160px;
}
.ask-box textarea::placeholder { color: var(--faint); }
.ask-btn {
  flex: none; width: 42px; height: 42px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--accent); color: #fff; display: grid; place-items: center;
  transition: transform .2s var(--spring), background .2s, opacity .2s;
}
.ask-btn svg { width: 20px; height: 20px; }
.ask-btn:hover { transform: scale(1.06); background: var(--accent-2); }
.ask-btn:active { transform: scale(.94); }
.ask-btn[disabled] { opacity: .5; cursor: default; transform: none; }
.ask-hint { display: flex; justify-content: space-between; color: var(--faint); font-size: 12.5px; padding: 8px 16px 0; }
.ask-hint .count:empty { display: none; }
main.has-answer .ask-hint { display: none; }

/* suggestions */
.suggest { margin-top: 22px; }
main.has-answer .suggest { display: none; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chip {
  border: 1px solid var(--line-2); background: transparent; color: var(--muted);
  border-radius: 999px; padding: 8px 14px; font-size: 14px; cursor: pointer;
  transition: all .2s var(--ease); animation: rise .5s var(--ease) both;
}
.chip:nth-child(2) { animation-delay: .06s } .chip:nth-child(3) { animation-delay: .12s } .chip:nth-child(4) { animation-delay: .18s }
.chip:hover { border-color: var(--accent); color: var(--text); background: var(--accent-soft); transform: translateY(-1px); }
.recent { margin-top: 28px; }
.recent-label { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--faint); margin-bottom: 8px; text-align: center; }
.recent-list { display: flex; flex-direction: column; gap: 4px; }
.recent-item {
  text-align: left; background: transparent; border: 0; border-bottom: 1px solid var(--line); padding: 10px 4px;
  color: var(--muted); cursor: pointer; font-family: var(--serif); font-size: 17px; display: flex; justify-content: space-between; gap: 10px;
}
.recent-item:hover { color: var(--text); }
.recent-item span:last-child { color: var(--faint); font-family: var(--sans); font-size: 13px; flex: none; }

/* ---------- answer ---------- */
.answer { margin-top: 18px; }
.asked {
  font-family: var(--serif); font-weight: 400; font-size: clamp(24px, 5.6vw, 34px); line-height: 1.18;
  margin: 10px 0 18px; letter-spacing: -.01em; animation: rise .5s var(--ease) both; font-variation-settings: "opsz" 72;
}

.thinking { display: flex; flex-direction: column; gap: 10px; padding: 6px 0 16px; }
.thinking[hidden] { display: none; }
.thread { height: 2px; border-radius: 2px; background: var(--line); overflow: hidden; position: relative; }
.thread i {
  position: absolute; inset: 0; width: 40%;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  animation: thread 1.4s var(--ease) infinite;
}
.thinking-text { color: var(--muted); font-size: 14px; }

/* depth toggle */
.depths { animation: rise .5s var(--ease) both; }
.seg {
  position: relative; display: inline-grid; grid-template-columns: 1fr 1fr; gap: 0;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 999px; padding: 3px; margin-bottom: 14px;
}
.seg-btn {
  position: relative; z-index: 1; border: 0; background: transparent; cursor: pointer; padding: 7px 18px;
  border-radius: 999px; color: var(--muted); font-weight: 500; font-size: 14px; transition: color .2s;
}
.seg-btn.is-on { color: var(--text); }
.seg-pill {
  position: absolute; top: 3px; bottom: 3px; left: 3px; width: calc(50% - 3px); border-radius: 999px;
  background: var(--surface); box-shadow: var(--shadow); transition: transform .35s var(--spring);
}
.seg[data-depth="technical"] .seg-pill { transform: translateX(100%); }
@media (min-width: 900px) { .seg { display: none; } }

.depth-grid { display: grid; grid-template-columns: 1fr; gap: 18px; }
.depth { display: none; animation: fade .3s var(--ease) both; }
.depth.is-on { display: block; }
@media (min-width: 900px) {
  .depth-grid { grid-template-columns: 1fr 1fr; gap: 28px; }
  .depth { display: block; }
  .depth::before {
    content: attr(data-label); display: block; font-size: 12px; letter-spacing: .08em; text-transform: uppercase;
    color: var(--faint); margin-bottom: 8px;
  }
  .depth-technical { border-left: 1px solid var(--line); padding-left: 28px; }
}

/* prose */
.prose { font-family: var(--serif); font-size: 19px; line-height: 1.55; font-variation-settings: "opsz" 18; }
.depth-technical .prose { font-family: var(--sans); font-size: 16px; line-height: 1.6; }
.prose p { margin: 0 0 .9em; }
.prose p:last-child { margin-bottom: 0; }
.prose ul, .prose ol { margin: 0 0 .9em; padding-left: 1.3em; }
.prose li { margin: .25em 0; }
.prose h4 { margin: 1em 0 .4em; font-size: 1em; font-weight: 600; }
.prose code { font-family: var(--mono); font-size: .9em; background: var(--bg-2); border: 1px solid var(--line); padding: 1px 6px; border-radius: 6px; }
.prose pre {
  background: #0a1020; color: #e3e9f6; border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px;
  overflow: auto; font-size: 13.5px; line-height: 1.5; margin: .8em 0;
}
.prose pre code { background: none; border: 0; padding: 0; color: inherit; font-size: inherit; }
.prose .cite + .cite { margin-left: 4px; }
.prose .cite { color: var(--accent); font-family: var(--sans); font-size: .72em; vertical-align: super; margin-left: 1px; text-decoration: none; }
.prose .cursor { display: inline-block; width: .55em; height: 1em; background: var(--accent); vertical-align: -0.15em; margin-left: 2px; animation: blink 1s steps(2) infinite; border-radius: 2px; }

/* honesty mark */
.honesty { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin: 22px 0 6px; animation: rise .5s var(--ease) both; }
.honesty-pill {
  display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px 6px 10px; border-radius: 999px;
  border: 1px solid var(--line-2); background: var(--surface); font-size: 13.5px; font-weight: 500; white-space: nowrap;
}
.honesty-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--faint); box-shadow: 0 0 0 3px var(--accent-soft); }
.honesty[data-mark="settled"] .honesty-dot { background: var(--settled); box-shadow: 0 0 0 3px color-mix(in srgb, var(--settled) 22%, transparent); }
.honesty[data-mark="debated"] .honesty-dot { background: var(--debated); box-shadow: 0 0 0 3px color-mix(in srgb, var(--debated) 22%, transparent); }
.honesty[data-mark="unknown"] .honesty-dot { background: var(--unknown); box-shadow: 0 0 0 3px color-mix(in srgb, var(--unknown) 22%, transparent); }
.honesty-why { color: var(--muted); font-size: 14px; }

/* question behind the question */
.next {
  display: grid; gap: 4px; width: 100%; text-align: left; margin: 18px 0 0; padding: 16px 18px 16px 20px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); cursor: pointer;
  position: relative; overflow: hidden; box-shadow: var(--shadow); animation: rise .5s var(--ease) both;
  transition: transform .25s var(--ease), border-color .25s;
}
.next::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: linear-gradient(#dfe7f5, var(--accent)); }
.next:hover { transform: translateY(-2px); border-color: var(--accent); }
.next-label { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--faint); }
.next-q { font-family: var(--serif); font-size: 20px; line-height: 1.3; }
.next-go { color: var(--accent); font-size: 14px; font-weight: 500; margin-top: 2px; }

/* sources */
.sources { margin-top: 22px; animation: rise .5s var(--ease) both; }
.sources-label { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--faint); margin-bottom: 8px; }
.sources-list { display: grid; gap: 6px; }
@media (min-width: 640px) { .sources-list { grid-template-columns: 1fr 1fr; } }
.src {
  display: grid; grid-template-columns: 22px 1fr auto; align-items: center; gap: 10px;
  padding: 9px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
  text-decoration: none; color: var(--text); min-width: 0; transition: border-color .2s, transform .2s var(--ease);
}
.src:hover { border-color: var(--accent); transform: translateY(-1px); }
.src.is-used { border-color: color-mix(in srgb, var(--accent) 55%, var(--line)); }
.src-ico { width: 22px; height: 22px; border-radius: 6px; background: var(--bg-2); display: grid; place-items: center; font-size: 11px; font-weight: 600; color: var(--muted); overflow: hidden; }
.src-ico img { width: 16px; height: 16px; }
.src-main { min-width: 0; display: grid; gap: 1px; }
.src-host { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.src-title { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.src-n { font-size: 12px; color: var(--accent); font-weight: 600; }
.src-age { font-size: 11.5px; color: var(--faint); }
.sources-none { color: var(--muted); font-size: 14px; }

/* actions */
.actions { display: flex; gap: 10px; align-items: center; margin-top: 22px; animation: rise .5s var(--ease) both; }
.keep {
  display: inline-flex; align-items: center; gap: 8px; padding: 11px 18px; border-radius: 999px; cursor: pointer;
  border: 1.5px solid var(--accent); background: transparent; color: var(--accent); font-weight: 600;
  transition: background .2s, color .2s, transform .2s var(--spring);
}
.keep svg { width: 18px; height: 18px; }
.keep:hover { background: var(--accent); color: #fff; }
.keep:active { transform: scale(.96); }
.ghost { background: transparent; border: 1px solid var(--line-2); color: var(--muted); padding: 10px 16px; border-radius: 999px; cursor: pointer; transition: all .2s; }
.ghost:hover { color: var(--text); border-color: var(--text); }

.err { margin-top: 16px; padding: 14px 16px; border-radius: 12px; border: 1px solid var(--debated); color: var(--text); background: color-mix(in srgb, var(--debated) 10%, var(--surface)); font-size: 15px; }

/* footer */
.foot { display: flex; justify-content: center; gap: 8px; align-items: center; color: var(--faint); font-size: 12.5px; padding: 18px 16px; padding-bottom: max(18px, env(safe-area-inset-bottom)); }
.link { background: none; border: 0; padding: 0; color: var(--faint); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.link:hover { color: var(--text); }

/* sheet */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 20; animation: fade .25s both; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; max-width: 560px; margin: 0 auto;
  background: var(--surface); color: var(--text); border-radius: 22px 22px 0 0; padding: 10px 22px 22px;
  padding-bottom: max(22px, env(safe-area-inset-bottom)); box-shadow: 0 -10px 40px rgba(0,0,0,.25);
  animation: up .35s var(--ease) both; max-height: 86dvh; overflow: auto;
}
.sheet-art { width: 100%; max-width: 300px; display: block; margin: 0 auto 12px; border-radius: 18px; box-shadow: 0 10px 40px -10px rgba(0,0,0,.6); }
.sheet-tag { text-align: center; color: var(--muted); font-size: 14px; margin: 0 0 14px; font-style: italic; }
.sheet-handle { width: 38px; height: 4px; border-radius: 4px; background: var(--line-2); margin: 4px auto 14px; }
.sheet-title { font-family: var(--serif); font-weight: 400; font-size: 26px; margin: 0 0 6px; }
.sheet-intro { color: var(--muted); margin: 0 0 14px; font-size: 15px; }
.promises { margin: 0 0 14px; padding-left: 1.2em; display: grid; gap: 10px; font-size: 15px; }
.promises b { font-weight: 600; }
.sheet-foot { color: var(--muted); font-size: 14px; margin: 0 0 14px; }
.sheet-close { width: 100%; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); z-index: 30;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 14px;
  box-shadow: var(--shadow); animation: up .3s var(--ease) both; max-width: calc(100% - 32px); text-align: center;
}

/* animations */
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes up { from { opacity: 0; transform: translate(-50%, 12px); } to { opacity: 1; transform: translate(-50%, 0); } }
.sheet { animation-name: sheetup; }
@keyframes sheetup { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes thread { 0% { transform: translateX(-100%); } 100% { transform: translateX(260%); } }
@keyframes breathe { 0%, 100% { box-shadow: var(--shadow); } 50% { box-shadow: var(--shadow), 0 0 0 6px var(--accent-soft); } }
@keyframes blink { to { opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001s !important; animation-iteration-count: 1 !important; transition-duration: .001s !important; }
}
[hidden] { display: none !important; }
