/* Doofus. Original code, no third-party assets. Mobile first. Light and dark
   through prefers-color-scheme. No inline styles anywhere - the CSP forbids
   them, which is why this file exists. */

/* Self-hosted variable fonts from npm (@fontsource-variable), latin and
   latin-ext subsets, SIL Open Font Licence text in public/fonts/. Nothing is
   fetched from a third party: font-src is 'self'. Languages outside those
   subsets fall back to the system face; that is documented, not a bug. */

@font-face {
  font-family: 'Figtree';
  font-style: normal;
  font-weight: 300 900;
  font-display: swap;
  src: url('/fonts/figtree-latin-ext-wght-normal.woff2') format('woff2-variations');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Figtree';
  font-style: normal;
  font-weight: 300 900;
  font-display: swap;
  src: url('/fonts/figtree-latin-wght-normal.woff2') format('woff2-variations');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Source Serif 4';
  font-style: normal;
  font-weight: 200 900;
  font-display: swap;
  src: url('/fonts/source-serif-4-latin-ext-wght-normal.woff2') format('woff2-variations');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Source Serif 4';
  font-style: normal;
  font-weight: 200 900;
  font-display: swap;
  src: url('/fonts/source-serif-4-latin-wght-normal.woff2') format('woff2-variations');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --sans: 'Figtree', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --serif: 'Source Serif 4', ui-serif, Georgia, 'Times New Roman', serif;

  /* Coral on cream. Every pair below was checked against WCAG AA: body text
     and small print clear 4.5:1, the focus ring and the send button clear 3:1
     as non-text UI. The accent takes dark ink, not white - white on coral is
     about 2.9:1 and would fail. */
  --bg: #faf9f5;
  --panel: #f0eee6;
  --raised: #ffffff;
  --ink: #1f1e1c;
  --ink-soft: #565449;
  --ink-faint: #6b6859;
  --thought: #706d62;
  --line: #e4e1d7;
  --accent: #d6704f;
  --accent-ink: #241a13;
  --accent-soft: #f4e3d8;
  --focus: #a64f2e;
  --alert-bg: #fbf0e4;
  --alert-line: #b8763c;
  --alert-ink: #4a2f10;

  --radius: 14px;
  --radius-sm: 9px;
  --gutter: 16px;
  --sidebar-w: 260px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #262624;
    --panel: #30302e;
    --raised: #383735;
    --ink: #f5f4ef;
    --ink-soft: #c9c6bb;
    --ink-faint: #a8a59a;
    --thought: #a5a296;
    --line: #46443f;
    --accent: #d6704f;
    --accent-ink: #241a13;
    --accent-soft: #3a2a22;
    --focus: #e9a184;
    --alert-bg: #35291d;
    --alert-line: #c98b4f;
    --alert-ink: #f6dfc6;
  }
}

* { box-sizing: border-box; }

/* The hidden attribute must win over any layout rule below. Without this,
   `display: flex` on a hidden form shows it anyway - which for the email form
   would mean showing the address field before the age screen. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}

button, input, select, textarea { font: inherit; color: inherit; }

a { color: var(--ink-soft); text-underline-offset: 2px; }
a:hover { color: var(--ink); }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- shell ---------- */

.app {
  display: flex;
  height: 100dvh;
  overflow: hidden;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 30;
  width: var(--sidebar-w);
  max-width: 82vw;
  padding: 18px 14px calc(18px + env(safe-area-inset-bottom));
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 18px;
  transform: translateX(-100%);
  transition: transform .22s ease;
}
.sidebar.open { transform: none; }

.scrim {
  position: fixed; inset: 0; z-index: 25;
  background: rgba(0,0,0,.42);
}

.sidebar-head { display: flex; align-items: center; gap: 10px; }
.mark { display: inline-flex; width: 30px; height: 30px; }
.mark svg { width: 100%; height: 100%; }
.wordmark { font-family: var(--serif); font-size: 1.22rem; letter-spacing: .01em; }

.new-chat {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 12px;
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: left;
}
.new-chat:hover { border-color: var(--ink-faint); }

.recents { flex: 1; min-height: 0; overflow-y: auto; }
.recents-title {
  margin: 0 0 6px 4px; font-size: .72rem; font-weight: 600;
  letter-spacing: .07em; text-transform: uppercase; color: var(--ink-faint);
}
.recents ul { list-style: none; margin: 0; padding: 0; }
.recent {
  display: block; width: 100%; text-align: left;
  padding: 7px 10px; border: 0; background: none;
  border-radius: var(--radius-sm); cursor: pointer;
  color: var(--ink-soft);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.recent:hover { background: var(--raised); color: var(--ink); }

.sidebar-foot { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
.linkish {
  border: 0; background: none; padding: 6px 4px;
  color: var(--ink-soft); cursor: pointer; text-decoration: underline;
}
.linkish:hover { color: var(--ink); }

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: grid; grid-template-columns: 38px 1fr 38px; align-items: center; gap: 8px;
  min-height: 52px;
  padding: 6px var(--gutter);
  border-bottom: 1px solid var(--line);
  padding-top: calc(6px + env(safe-area-inset-top));
}
.topbar-centre { display: flex; align-items: center; justify-content: center; gap: 8px; min-width: 0; }
.topbar-mark { display: inline-flex; width: 24px; height: 24px; flex: none; }
.topbar .menu-button { font-weight: 600; font-size: .95rem; color: var(--ink); }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; min-width: 38px;
  border: 0; background: none; border-radius: var(--radius-sm);
  cursor: pointer; font-size: 1.15rem; color: var(--ink-soft);
}
.icon-btn:hover { background: var(--panel); color: var(--ink); }

/* ---------- the mark ---------- */

.mark { display: block; width: 100%; height: 100%; overflow: visible; }
.mark-pupil { transition: transform .4s ease-out; transform-box: fill-box; transform-origin: center; }
/* While a reply is pending both pupils roll slowly to one side. */
.mark[data-thinking] .mark-pupil { transform: translate(1.3px, .5px) !important; transition: transform 1.4s ease-in-out; }
.sidebar-head .mark { width: 30px; height: 30px; }

/* ---------- menus (replace the native selects) ---------- */

.menu { position: relative; display: inline-block; min-width: 0; }
.menu-button {
  display: inline-flex; align-items: center; gap: 5px; max-width: 100%;
  border: 1px solid var(--line); background: none;
  border-radius: 999px; padding: 4px 10px;
  color: var(--ink-faint); font-size: .8rem; cursor: pointer;
  white-space: nowrap;
}
.menu-button:hover { color: var(--ink); border-color: var(--ink-faint); }
.menu-button:disabled { opacity: .55; cursor: default; }
.menu-button[aria-expanded="true"] { color: var(--ink); border-color: var(--ink-faint); }
.topbar .menu-button { border-color: transparent; padding: 6px 8px; }
.topbar .menu-button:hover, .topbar .menu-button[aria-expanded="true"] { border-color: var(--line); }
.menu-caret { font-size: .8em; opacity: .7; }
.menu-list {
  position: absolute; z-index: 40; width: 288px; max-width: calc(100vw - 32px);
  padding: 4px; margin: 6px 0;
  background: var(--raised); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: 0 10px 30px rgba(0,0,0,.14);
}
.menu-down { top: 100%; left: 50%; transform: translateX(-50%); }
.menu-up { bottom: 100%; left: 0; }
.menu-item {
  display: flex; align-items: flex-start; gap: 8px; width: 100%;
  padding: 8px 10px; border: 0; background: none; border-radius: var(--radius-sm);
  text-align: left; cursor: pointer; color: var(--ink);
}
.menu-item:hover, .menu-item:focus-visible { background: var(--accent-soft); outline: none; }
.menu-item:disabled { opacity: .55; cursor: not-allowed; }
.menu-item:disabled:hover { background: none; }
.menu-tick { width: 14px; flex: none; padding-top: 2px; color: var(--accent); font-weight: 600; }
.menu-body { display: flex; flex-direction: column; min-width: 0; }
.menu-label { font-weight: 600; font-size: .92rem; }
.menu-desc { font-size: .8rem; color: var(--ink-faint); }

/* ---------- conversation ---------- */

.conversation {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0 var(--gutter);
  scroll-behavior: smooth;
}

.empty {
  display: flex; flex-direction: column; justify-content: center;
  min-height: 100%; max-width: 720px; margin: 0 auto;
  padding-bottom: 8vh;
}
.empty[hidden] { display: none; }

.empty-mark { display: block; width: 64px; height: 64px; margin: 0 0 16px; }

.greeting {
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(1.6rem, 6vw, 2.3rem);
  line-height: 1.22;
  margin: 0 0 22px;
}

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 9px 14px;
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  color: var(--ink-soft);
}
.chip:hover { border-color: var(--ink-faint); color: var(--ink); }

.turns { max-width: 720px; margin: 0 auto; padding: 8px 0 24px; }

.turn { margin-bottom: 26px; }

.turn-user .bubble {
  margin-left: auto;
  max-width: 85%;
  width: fit-content;
  padding: 10px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius) var(--radius) 4px var(--radius);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* The thought. Smaller and muted - the two-voice joke depends on the two
   halves of a reply looking different. */
.thought { margin-bottom: 10px; }
.thought-head {
  display: flex; align-items: center; gap: 6px;
  width: 100%; padding: 2px 0;
  border: 0; background: none; cursor: pointer;
  color: var(--ink-faint); font-size: .83rem; text-align: left;
}
.thought-head .caret { transition: transform .15s ease; }
.thought-head[aria-expanded="false"] .caret { transform: rotate(-90deg); }
.thought-body {
  margin-top: 6px; padding-left: 12px;
  border-left: 2px solid var(--line);
  color: var(--thought);
  font-size: .9rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.thought-body[hidden] { display: none; }

.answer { white-space: pre-wrap; overflow-wrap: anywhere; }

/* Out of character. Deliberately nothing like a reply - v4 parodies
   disclaimers in character, so the real ones must not look like a bit. */
.turn-real .answer {
  padding: 13px 15px;
  background: var(--alert-bg);
  border: 1px solid var(--alert-line);
  border-left-width: 4px;
  border-radius: var(--radius-sm);
  color: var(--alert-ink);
  font-size: .95rem;
}
.real-label {
  display: block; margin-bottom: 2px;
  font-size: .7rem; font-weight: 600;
  letter-spacing: .08em; text-transform: uppercase;
  color: var(--alert-ink); opacity: .85;
}
.real-sub {
  display: block; margin-bottom: 8px;
  font-size: .78rem; color: var(--alert-ink); opacity: .75;
}

.turn-actions { margin-top: 8px; }
.share-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px;
  background: none; border: 1px solid var(--line);
  border-radius: 999px; cursor: pointer;
  color: var(--ink-faint); font-size: .82rem;
}
.share-btn:hover { border-color: var(--ink-faint); color: var(--ink); }

.shimmer {
  display: inline-block;
  width: 110px; height: .78rem; border-radius: 4px;
  background: linear-gradient(90deg, var(--line) 25%, var(--panel) 50%, var(--line) 75%);
  background-size: 260% 100%;
  animation: slide 1.25s linear infinite;
}
@keyframes slide { to { background-position: -160% 0; } }

/* ---------- composer ---------- */

.composer-wrap {
  padding: 8px var(--gutter) calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--bg);
}

/* A notice is part of the fiction ("we've run out of money"), so it must NOT
   look like an out-of-character reply. Muted and quiet; the amber alert style
   belongs to .turn-real alone. */
.notice {
  max-width: 720px; margin: 0 auto 8px;
  padding: 9px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--ink-soft);
  font-size: .88rem;
}
.notice[hidden] { display: none; }

.composer {
  max-width: 720px; margin: 0 auto;
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 10px;
}
.composer:focus-within { border-color: var(--ink-faint); }

.composer textarea {
  display: block; width: 100%;
  border: 0; background: none; resize: none;
  padding: 5px 2px; max-height: 160px;
  outline: none;
}
.composer textarea::placeholder { color: var(--ink-faint); }

.composer-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin-top: 4px;
}
.composer-controls { display: flex; gap: 6px; min-width: 0; }
.composer-right { display: flex; align-items: center; gap: 8px; }

/* The native selects stay in the DOM as state holders (see menu.js). */
.pill { max-width: 46vw; }

.counter { font-size: .76rem; color: var(--ink-faint); }
.counter[hidden] { display: none; }

.send {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; min-width: 34px;
  border: 0; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink);
  cursor: pointer; font-size: 1rem;
}
.send:disabled { opacity: .38; cursor: default; }

.disclaimer, .footnote {
  max-width: 720px; margin: 8px auto 0;
  text-align: center; color: var(--ink-faint);
}
.disclaimer { font-size: .8rem; }
.footnote { font-size: .74rem; margin-top: 4px; }

/* ---------- dialogs ---------- */

.sheet {
  width: min(460px, calc(100vw - 32px));
  margin: auto;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--raised);
  color: var(--ink);
}
.sheet::backdrop { background: rgba(0,0,0,.48); }
.sheet-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.sheet h2 { margin: 0 0 4px; font-family: var(--serif); font-weight: 400; font-size: 1.28rem; }
.sheet p { color: var(--ink-soft); font-size: .92rem; }
.tagline { font-family: var(--serif); color: var(--ink) !important; }
.tagline:empty { display: none; }
.sheet-links, .fineprint { font-size: .8rem; }
.fineprint { color: var(--ink-faint); }

.stack { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.stack label { font-size: .88rem; color: var(--ink-soft); }
.stack select, .stack input {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg);
}
.consent { font-size: .76rem; margin: 0; }
.primary {
  padding: 10px 14px; border: 0; border-radius: var(--radius-sm);
  background: var(--accent); color: var(--accent-ink);
  cursor: pointer; font-weight: 600;
}
.primary:disabled { opacity: .5; cursor: default; }
.result { margin-top: 12px; }
.result[hidden] { display: none; }

/* ---------- 404 ---------- */

.lost { text-align: center; padding-top: 22vh; }
.lost-mark { width: 64px; height: 64px; margin: 0 auto 18px; display: block; }
.lost h1 { margin-bottom: 4px; }
.primary-link {
  display: inline-block; margin-top: 10px; padding: 10px 18px;
  background: var(--accent); color: var(--accent-ink); border-radius: var(--radius-sm);
  text-decoration: none; font-weight: 600;
}

/* ---------- wide screens ---------- */

@media (min-width: 880px) {
  .sidebar { position: static; transform: none; max-width: none; }
  .scrim, #menu { display: none !important; }
  .conversation, .composer-wrap { padding-left: 28px; padding-right: 28px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; animation-iteration-count: 1 !important;
      transition-duration: .001ms !important; scroll-behavior: auto !important; }
  .mark-pupil, .mark[data-thinking] .mark-pupil { transform: none !important; }
}

/* ---------- privacy and terms ---------- */

.doc { max-width: 680px; margin: 0 auto; padding: 32px 16px 64px; }
.doc h1 { font-family: var(--serif); font-weight: 400; font-size: clamp(1.5rem, 5vw, 2rem); margin: 0 0 6px; }
.doc h2 { font-family: var(--serif); font-weight: 400; font-size: 1.15rem; margin: 30px 0 8px; }
.doc p, .doc li { color: var(--ink-soft); }
.doc ul { padding-left: 20px; }
.doc .updated { font-size: .82rem; color: var(--ink-faint); margin-top: 0; }
.doc .back { display: inline-block; margin-bottom: 20px; }
.draft {
  padding: 12px 14px; margin: 18px 0 26px;
  background: var(--alert-bg); border: 1px solid var(--alert-line);
  border-left-width: 4px; border-radius: var(--radius-sm);
  color: var(--alert-ink); font-size: .88rem;
}
.draft strong { color: var(--alert-ink); }

.drawer-note { margin: 2px 0 6px 4px; font-size: .74rem; color: var(--ink-faint); line-height: 1.4; }
.mark-slot { display: inline-flex; width: 30px; height: 30px; }

/* ---------- Phase 2: the chrome ---------- */

/* Waiting: three pulsing dots and the status verb, in --ink-faint. */
.pending { display: inline-flex; align-items: center; gap: 10px; min-height: 24px; color: var(--ink-faint); font-size: .85rem; }
.dots { display: inline-flex; gap: 4px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--ink-faint); animation: pulse 1.2s ease-in-out infinite; }
.dots i:nth-child(2) { animation-delay: .2s; }
.dots i:nth-child(3) { animation-delay: .4s; }
@keyframes pulse { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-2px); } }
.answer.fading { opacity: .35; transition: opacity .3s ease; }

/* The retry caption sits above D's answer in D's own voice. */
.caption { margin: 0 0 6px; color: var(--ink-faint); font-size: .85rem; }

/* Action row: Share first as a text pill, then 16px line icons in 32px targets. */
.turn-actions { display: flex; align-items: center; gap: 2px; margin-top: 8px; }
.turn-actions .share-btn { margin-right: 6px; }
.icon-action {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; padding: 0;
  border: 0; background: none; border-radius: var(--radius-sm);
  color: var(--ink-faint); cursor: pointer;
}
.icon-action:hover { background: var(--panel); color: var(--ink); }
.icon-action:disabled { opacity: .45; cursor: default; }
.icon-action:disabled:hover { background: none; color: var(--ink-faint); }
.feedback-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip-small { padding: 6px 11px; font-size: .84rem; }

/* Budget and cap: a centred system row with hairline rules, like a date divider.
   The operator's voice inside the transcript, where screenshots happen. */
.system-row {
  display: flex; align-items: center; gap: 12px;
  margin: 4px 0 26px; color: var(--ink-faint); font-size: .84rem; text-align: center;
}
.system-row::before, .system-row::after { content: ''; flex: 1; border-top: 1px solid var(--line); }
.system-row span { max-width: 32ch; }

/* The counter above the composer, at three or fewer. */
.remaining { max-width: 720px; margin: 0 auto 6px; padding: 0 4px; color: var(--ink-faint); font-size: .8rem; }
.remaining[hidden] { display: none; }

/* Toasts: the operator's voice, inverted, above the composer. */
/* Anchored to the top edge of the composer block, whatever its height. */
.composer-wrap { position: relative; }
.toasts {
  position: absolute; left: 0; right: 0; bottom: 100%; margin-bottom: 12px;
  display: flex; justify-content: center; padding: 0 var(--gutter);
  pointer-events: none; z-index: 40;
}
.toast {
  display: inline-flex; align-items: center; gap: 14px;
  max-width: 440px; padding: 10px 14px;
  background: var(--ink); color: var(--bg);
  border-radius: var(--radius-sm); box-shadow: 0 8px 24px rgba(0,0,0,.18);
  font-size: .88rem; line-height: 1.35;
  opacity: 0; transform: translateY(8px);
  transition: opacity .15s ease, transform .15s ease;
  pointer-events: auto;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-action {
  padding: 4px 8px; margin: -4px -6px -4px 0;
  border: 0; border-radius: 6px; background: none;
  color: var(--bg); font-weight: 600; font-size: .88rem; cursor: pointer;
  text-decoration: underline; text-underline-offset: 3px;
}
@media (prefers-reduced-motion: reduce) {
  .dots i { animation: none; opacity: .7; }
  .toast { transition: none; }
}
