/* Хутугт: monochrome, light and dark. What the books and the AI say is set in a serif (Source Serif 4), everything
   around it in the system's sans. The chat comes first, then the admin dashboard. */
:root {
  color-scheme: light;
  --bg: #ffffff;
  --raised: #ffffff;
  --fg: #141414;
  --muted: #5f5f5f;
  --faint: #8c8c8c;
  --line: #ebebeb;
  --line-strong: #dcdcdc;
  --ring: #c4c4c4;
  --tint: #f4f4f4;
  --tint-strong: #e8e8e8;
  --scrim: rgba(0, 0, 0, .3);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .05);
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 12px 32px rgba(0, 0, 0, .08);
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --serif: "Source Serif 4", Georgia, Cambria, "Times New Roman", serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --read: 400;  /* the serif's weight for reading text */
  --col: 46rem;
  --ease: cubic-bezier(.2, .8, .2, 1);
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #181818;
    --raised: #202020;
    --fg: #e8e8e8;
    --muted: #a6a6a6;
    --faint: #7a7a7a;
    --line: #262626;
    --line-strong: #363636;
    --ring: #4a4a4a;
    --read: 360;
    --tint: #232323;
    --tint-strong: #303030;
    --scrim: rgba(0, 0, 0, .55);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 12px 32px rgba(0, 0, 0, .5);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { height: 100%; }
body {
  margin: 0;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.6 var(--sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
::placeholder { color: var(--faint); opacity: 1; }
::selection { background: rgba(128, 128, 128, .3); }
:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; }
.ico { flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* Shared: top bar, buttons */
.bar { flex: none; display: flex; align-items: center; gap: 10px; height: 56px; padding: 0 12px 0 20px; }
.brand {
  border: 0; background: none; padding: 0; color: var(--fg); text-decoration: none;
  font: 600 20px/1 var(--serif); letter-spacing: -.015em;
}
.spacer { flex: 1; }
.icon {
  flex: none; width: 36px; height: 36px; display: inline-grid; place-items: center;
  border: 0; border-radius: 10px; background: transparent; color: var(--muted);
  transition: background .15s, color .15s;
}
.icon svg { width: 18px; height: 18px; }
.primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 38px; padding: 0 18px;
  border: 0; border-radius: 999px; background: var(--fg); color: var(--bg);
  font-size: 14.5px; font-weight: 500; text-decoration: none; white-space: nowrap;
  transition: opacity .15s, transform .1s;
}
.primary svg { width: 16px; height: 16px; }
.primary:active:not(:disabled) { transform: scale(.97); }
.primary:disabled { opacity: .35; cursor: default; }
.ghost {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px;
  border: 1px solid var(--line-strong); border-radius: 999px; background: transparent; color: var(--muted);
  font-size: 14px; text-decoration: none; white-space: nowrap;
  transition: color .15s, border-color .15s, background .15s;
}
.ghost svg { width: 15px; height: 15px; }
@media (hover: hover) {
  .icon:hover { background: var(--tint); color: var(--fg); }
  .ghost:hover { color: var(--fg); border-color: var(--faint); }
  .primary:hover:not(:disabled) { opacity: .86; }
}
/* A delete or restore button asks once more before it acts; the question wins over any size or hover color. */
.icon[data-armed], .ghost[data-armed] {
  width: auto !important; padding: 0 12px !important; font-size: 13px; white-space: nowrap;
  border-color: var(--fg) !important; background: var(--fg) !important; color: var(--bg) !important;
}

/* ---------------------------------------------------------------- Chat */

body:not(.admin) .bar > * { transition: opacity .2s; }
body.is-empty:not(.admin) .bar > * { opacity: 0; pointer-events: none; }

.scroller { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-gutter: stable both-edges; }
.thread { max-width: var(--col); margin: 0 auto; padding: 8px 24px 48px; display: flex; flex-direction: column; gap: 30px; }
.thread:empty { display: none; }

.msg-user, .msg-bot { animation: enter .3s var(--ease) both; }
@keyframes enter { from { opacity: 0; transform: translateY(6px); } }
.msg-user {
  align-self: flex-end; max-width: min(85%, 34rem);
  background: var(--tint); border-radius: 20px; padding: 10px 18px;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg-bot { font: var(--read) 17px/1.75 var(--serif); overflow-wrap: anywhere; }
.msg-bot p { margin: 0 0 14px; }
.msg-bot h3 { margin: 26px 0 8px; font: 600 18px/1.4 var(--serif); letter-spacing: -.005em; }
.msg-bot ul, .msg-bot ol { margin: 0 0 14px; padding-left: 24px; }
.msg-bot li { margin: 0 0 6px; padding-left: 4px; }
.msg-bot li::marker { color: var(--faint); }
.msg-bot strong { font-weight: 600; }
.msg-bot .note { font: 13px/1.5 var(--sans); color: var(--faint); }

/* Citation chips: a passage is filled, an admin's fact is outlined. */
.cite {
  position: relative; display: inline-flex; align-items: center; height: 19px; margin-left: 4px; padding: 0 6px;
  border: 0; border-radius: 6px; background: var(--tint); color: var(--muted);
  font: 500 11.5px/1 var(--sans); font-variant-numeric: tabular-nums; letter-spacing: .01em;
  white-space: nowrap; vertical-align: 2px;
  transition: background .15s, color .15s, box-shadow .15s;
}
.cite + .cite { margin-left: 3px; }
.cite::after { content: ""; position: absolute; inset: -9px -2px; }  /* a finger-sized target around a small chip */
.cite.fact { background: transparent; box-shadow: inset 0 0 0 1px var(--line-strong); }
@media (hover: hover) { .cite:hover { background: var(--tint-strong); color: var(--fg); } }
.cite[aria-expanded="true"] { background: var(--fg); color: var(--bg); box-shadow: none; }

/* While the AI works: a twinkling spark and a verb, Claude Code style */
.thinking { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 10px; min-height: 30px; font: 15px/1.4 var(--sans); }
.thinking .verb {
  background: linear-gradient(90deg, var(--faint) 0%, var(--faint) 30%, var(--fg) 50%, var(--faint) 70%, var(--faint) 100%);
  background-size: 300% 100%;
  -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: shimmer 2.4s linear infinite;
}
.thinking .meta { color: var(--faint); font-size: 13px; font-variant-numeric: tabular-nums; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }
.spark { width: 17px; height: 17px; color: var(--fg); overflow: visible; }
.spark path { fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; transform-origin: 12px 12px; }
.thinking .spark, .caret .spark { animation: turn 4s linear infinite; animation-delay: var(--r, 0s); }
.thinking .spark path, .caret .spark path { animation: twinkle 1.2s ease-in-out infinite; animation-delay: var(--t, 0s); }
.spark path:nth-child(2) { animation-delay: calc(var(--t, 0s) - .3s); }
.spark path:nth-child(3) { animation-delay: calc(var(--t, 0s) - .6s); }
.spark path:nth-child(4) { animation-delay: calc(var(--t, 0s) - .9s); }
@keyframes turn { to { transform: rotate(1turn); } }
@keyframes twinkle { 0%, 100% { transform: scale(.4); } 50% { transform: scale(1); } }
.caret { display: inline-block; margin-left: 6px; vertical-align: -1px; }
.caret .spark { width: 13px; height: 13px; }

/* Under each answer */
.actions { display: flex; align-items: center; flex-wrap: wrap; gap: 2px; margin: 4px 0 0 -7px; font: 13px/1.4 var(--sans); color: var(--faint); }
.actions .icon { width: 32px; height: 32px; border-radius: 8px; color: var(--faint); }
.actions .icon svg { width: 16px; height: 16px; }
.actions .icon[aria-pressed="true"] { color: var(--fg); }
.actions .icon[aria-pressed="true"] svg { fill: currentColor; }
.actions .done { display: inline-flex; align-items: center; gap: 7px; margin-left: 10px; font-variant-numeric: tabular-nums; }
.actions .done .spark { width: 12px; height: 12px; color: var(--faint); }
@media (hover: hover) { .actions .icon:hover { color: var(--fg); } }
.why { display: flex; gap: 8px; max-width: 30rem; margin: 10px 0 0; font-family: var(--sans); }
.why input {
  flex: 1; min-width: 0; height: 38px; padding: 0 16px; font-size: 15px; color: var(--fg);
  background: var(--bg); border: 1px solid var(--line-strong); border-radius: 999px; outline: 0;
}
.why input:focus { border-color: var(--faint); }
.why .primary { height: 38px; font-size: 14px; }
.error {
  border: 1px solid var(--line-strong); border-radius: 14px; padding: 12px 16px;
  font: 14px/1.55 var(--sans); color: var(--muted);
}
.error code { font: 13px var(--mono); color: var(--fg); }

/* Composer */
.dock { flex: none; padding: 0 16px max(14px, env(safe-area-inset-bottom)); }
.composer {
  max-width: var(--col); margin: 0 auto;
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--raised); border: 1px solid var(--line-strong); border-radius: 26px;
  padding: 7px 7px 7px 20px; box-shadow: var(--shadow);
  transition: border-color .15s;
}
.composer:focus-within { border-color: var(--ring); }
.composer textarea {
  flex: 1; min-height: 40px; max-height: 200px; padding: 8px 0;
  border: 0; outline: 0; resize: none; background: transparent; font-size: 16px; line-height: 1.5;
}
.send {
  flex: none; width: 38px; height: 38px; border-radius: 50%; border: 0;
  display: grid; place-items: center; background: var(--fg); color: var(--bg);
  transition: background .15s, color .15s, transform .1s;
}
.send:active:not(:disabled) { transform: scale(.92); }
.send:disabled { background: var(--tint-strong); color: var(--faint); cursor: default; }
.send svg { width: 18px; height: 18px; }
.send .i-stop, .send.stop .i-send { display: none; }
.send.stop .i-stop { display: block; }
.chars { flex: none; align-self: flex-end; height: 38px; display: grid; place-items: center; font-size: 12px; color: var(--faint); font-variant-numeric: tabular-nums; }
.fineprint { max-width: var(--col); margin: 10px auto 0; text-align: center; font-size: 12px; line-height: 1.4; color: var(--faint); }

/* The daily limit: a word while questions are left, then a note where the question box was */
.remaining { max-width: var(--col); margin: 0 auto 8px; text-align: center; font-size: 12.5px; line-height: 1.4; color: var(--faint); }
.limit {
  max-width: var(--col); margin: 0 auto; padding: 16px 22px 18px;
  background: var(--raised); border: 1px solid var(--line-strong); border-radius: 22px; box-shadow: var(--shadow);
  animation: enter .3s var(--ease) both;
}
.limit strong { display: block; font: 600 17px/1.4 var(--serif); letter-spacing: -.005em; }
.limit p { margin: 4px 0 0; font-size: 14.5px; line-height: 1.55; color: var(--muted); }

/* Empty state: greeting and composer meet in the middle of the screen */
.hero { display: none; padding: 0 24px 32px; text-align: center; animation: enter .5s var(--ease) both; }
.hero h1 { margin: 0; font: 500 clamp(44px, 7vw, 58px)/1.05 var(--serif); letter-spacing: -.025em; }
.hero p { margin: 12px 0 0; color: var(--muted); font-size: 17px; }
.hero .books { margin-top: 10px; font-size: 13px; color: var(--faint); }
.suggestions { display: none; max-width: var(--col); margin: 14px auto 0; gap: 10px; grid-template-columns: 1fr 1fr; }
.suggestions button {
  text-align: left; border: 1px solid var(--line); background: transparent; border-radius: 16px;
  padding: 13px 16px; font-size: 14px; line-height: 1.45; color: var(--muted);
  transition: background .15s, color .15s, border-color .15s;
}
@media (hover: hover) { .suggestions button:hover { background: var(--tint); border-color: var(--tint); color: var(--fg); } }
body.is-empty .scroller { display: flex; flex-direction: column; justify-content: flex-end; }
body.is-empty .hero { display: block; }
body.is-empty .dock { flex: 1; }
body.is-empty .suggestions { display: grid; }
body.is-empty .fineprint { display: none; }

.notice {
  max-width: var(--col); margin: 4px auto 16px; padding: 12px 16px;
  border: 1px solid var(--line-strong); border-radius: 14px; font-size: 14px; color: var(--muted);
}
body.is-empty .notice { margin: 0 auto 28px; }
.notice code { font: 13px var(--mono); color: var(--fg); }
.notice a { color: var(--fg); text-underline-offset: 3px; }

/* When the AI can't answer anyone (no credit left …) */
.alert {
  width: min(26rem, calc(100vw - 32px)); padding: 24px 24px 20px;
  background: var(--raised); color: var(--fg); border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow);
}
.alert::backdrop { background: var(--scrim); }
.alert h2 { margin: 0 0 8px; font: 600 20px/1.3 var(--serif); letter-spacing: -.01em; }
.alert p { margin: 0 0 20px; font-size: 15px; color: var(--muted); }
.alert form { display: flex; justify-content: flex-end; }

/* Maintenance: while the site is being improved, no one may ask. An empty chat gives way to a little robot mending
   the gears (shown by chat.js, which takes its `hidden` away); a chat with answers stays readable, with a note
   (#paused) where the question box was. */
.maintenance {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px 24px max(56px, env(safe-area-inset-bottom)); text-align: center; animation: enter .5s var(--ease) both;
}
body.is-maintenance.is-empty .bar, body.is-maintenance.is-empty .scroller, body.is-maintenance.is-empty .dock,
body.is-maintenance .composer, body.is-maintenance .suggestions, body.is-maintenance .remaining,
body.is-maintenance #limit { display: none; }
.maintenance h1 { margin: 0; max-width: 24ch; font: 500 clamp(27px, 5vw, 36px)/1.2 var(--serif); letter-spacing: -.02em; text-wrap: balance; }
.maintenance h1:focus, #paused:focus { outline: none; }  /* focused for screen readers, not for a click */
.maintenance p { margin: 12px 0 0; max-width: 32rem; color: var(--muted); font-size: 16.5px; text-wrap: balance; }
.fixer { width: min(320px, 82vw); height: auto; margin-bottom: 24px; overflow: visible; color: var(--fg); }
.fixer .line, .fixer .paper, .fixer .tint, .fixer .shade { stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.fixer .line { fill: none; }
.fixer .paper, .fixer .dot { fill: var(--bg); }
.fixer .tint, .fixer .soft { fill: var(--tint); }
.fixer .shade, .fixer .blush { fill: var(--tint-strong); }
.fixer .ink { fill: currentColor; }
.fixer .tube, .fixer .tube-in { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.fixer .tube { stroke: currentColor; stroke-width: 9; }
.fixer .tube-in { stroke: var(--bg); stroke-width: 4.2; }
.fixer .glint { overflow: visible; }
.fixer .glint path { fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; transform-origin: 12px 12px; animation: twinkle 1.6s ease-in-out infinite; }
.fixer .glint:nth-of-type(2) path { animation-delay: -.5s; }
.fixer .glint:nth-of-type(3) path { animation-delay: -1s; }
.fixer .glint:nth-of-type(4) path { animation-delay: -.25s; }
/* The gears turn as meshed gears do, the small one twice as fast the other way; the arm works the wrench. */
.fixer .gear-big { transform-origin: 92px 100px; animation: turn 12s linear infinite; }
.fixer .gear-small { transform-origin: 53.8px 61.8px; animation: turn 6s linear infinite reverse; }
.fixer .arm { transform-origin: 175px 119px; animation: work 1.1s ease-in-out infinite alternate; }
.fixer .eye { transform-box: fill-box; transform-origin: center; animation: blink 4.5s infinite; }
@keyframes work { from { transform: rotate(-7deg); } to { transform: rotate(5deg); } }
@keyframes blink { 0%, 94%, 100% { transform: scaleY(1); } 97% { transform: scaleY(.1); } }

/* Citation popover: the passage or fact a chip points to. On a phone it is a sheet from the bottom. */
.pop {
  position: fixed; z-index: 20; width: min(400px, calc(100vw - 32px)); max-height: min(440px, 70vh);
  display: flex; flex-direction: column;
  background: var(--raised); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow);
  font: 14px/1.5 var(--sans); animation: pop-in .16s var(--ease);
}
.pop-head { flex: none; display: flex; align-items: center; gap: 10px; padding: 14px 16px 10px; }
.pop-mark { flex: none; width: 30px; height: 30px; display: grid; place-items: center; border-radius: 9px; background: var(--tint); color: var(--muted); }
.pop-mark svg { width: 16px; height: 16px; }
.pop-title { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.35; }
.pop-title strong { font-weight: 600; }
.pop-title span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 13px; }
.pop-close { display: none; }
.pop-about { flex: none; padding: 0 16px 6px 56px; font-size: 12.5px; color: var(--faint); }
.pop-text { padding: 2px 16px 16px; overflow-y: auto; overscroll-behavior: contain; white-space: pre-wrap; font: var(--read) 15.5px/1.7 var(--serif); }
.scrim { display: none; }
@keyframes pop-in { from { opacity: 0; transform: translateY(4px) scale(.98); } }
@keyframes sheet-in { from { transform: translateY(100%); } }
@keyframes fade-in { from { opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  .thinking .verb { background: none; color: var(--muted); }
}

/* ---------------------------------------------------------------- Admin: tabs over one column */

body.admin { display: block; height: auto; min-height: 100dvh; }
.admin .bar, .tabs-inner, .page { max-width: calc(var(--col) + 48px); margin: 0 auto; }
.admin .bar { height: 60px; padding: 0 24px; }
.crumb { color: var(--faint); }
.tabs {
  position: sticky; top: 0; z-index: 5; border-bottom: 1px solid var(--line);
  background: var(--bg); background: color-mix(in srgb, var(--bg) 86%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(14px); backdrop-filter: saturate(1.4) blur(14px);
}
.tabs-inner { display: flex; gap: 4px; padding: 0 14px; overflow-x: auto; scrollbar-width: none; }
.tabs-inner::-webkit-scrollbar { display: none; }
.tab {
  position: relative; flex: none; padding: 13px 10px; color: var(--muted); text-decoration: none;
  font-size: 15px; white-space: nowrap; transition: color .15s;
}
.tab[aria-selected="true"] { color: var(--fg); font-weight: 500; }
.tab[aria-selected="true"]::after { content: ""; position: absolute; left: 10px; right: 10px; bottom: -1px; height: 2px; border-radius: 2px; background: var(--fg); }
.tab .count { margin-left: 5px; color: var(--faint); font-size: 13px; font-weight: 400; font-variant-numeric: tabular-nums; }
.count:empty { display: none; }
@media (hover: hover) { .tab:hover { color: var(--fg); } }

.page { padding: 36px 24px 120px; }
.panel { animation: enter .3s var(--ease) both; }
.panel-head { margin-bottom: 24px; }
.panel-head h1 { margin: 0 0 6px; font: 500 32px/1.15 var(--serif); letter-spacing: -.02em; }
.panel-head p { margin: 0; max-width: 36rem; color: var(--muted); }
.page h2 { margin: 44px 0 4px; font-size: 17px; font-weight: 600; letter-spacing: -.005em; }
.page h2 .count { margin-left: 6px; color: var(--faint); font-weight: 400; }
.hint { margin: 0; font-size: 14px; color: var(--muted); }
.hint a { color: var(--fg); text-underline-offset: 3px; }
.hint strong { color: var(--fg); font-weight: 600; }
.page > .notice { margin: 0 0 28px; border-color: var(--fg); color: var(--fg); }
.empty { padding: 20px 0; font-size: 14px; color: var(--faint); list-style: none; }
.clamp { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden; cursor: pointer; }
.clamp.open { display: block; }

/* Overview: the maintenance switch, what the AI cost, and what readers thought */
.switch-row { margin-bottom: 20px; transition: border-color .2s; }
.switch-row:has([aria-checked="true"]) { border-color: var(--fg); }
.switch {
  flex: none; position: relative; width: 46px; height: 28px; padding: 0; border: 0; border-radius: 999px;
  background: var(--ring); transition: background .2s;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: #fff; box-shadow: var(--shadow-sm); transition: transform .2s var(--ease), background .2s;
}
.switch[aria-checked="true"] { background: var(--fg); }
.switch[aria-checked="true"]::after { background: var(--bg); transform: translateX(18px); }
.switch:disabled { opacity: .5; cursor: default; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 14px; }
.stat { padding: 16px 18px; border: 1px solid var(--line); border-radius: 16px; }
.stat-label { font-size: 13px; color: var(--muted); }
.stat-value { margin: 6px 0 4px; font: 500 28px/1.1 var(--serif); letter-spacing: -.01em; font-variant-numeric: lining-nums tabular-nums; }
.stat-sub { font-size: 12.5px; color: var(--faint); }
.stat-sub span, .item-meta span { white-space: nowrap; }
.fb { display: grid; gap: 6px; padding: 18px 0; border-bottom: 1px solid var(--line); }
.fb-head { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--faint); }
.rate { width: 24px; height: 24px; display: grid; place-items: center; border-radius: 7px; background: var(--tint); color: var(--fg); }
.rate svg { width: 13px; height: 13px; fill: currentColor; }
.fb-q { font-weight: 600; }
.fb-a { font: var(--read) 15.5px/1.65 var(--serif); color: var(--muted); }
.fb-c { padding-left: 12px; border-left: 2px solid var(--line-strong); font-size: 14px; }
.fb-go { margin-top: 6px; }

/* Visitors: the address and when it came last, its browser and visits below, and under a click on the address the
   questions asked from it */
.visitor { display: grid; grid-template-columns: 1fr auto; align-items: baseline; gap: 2px 12px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.ip {
  min-width: 0; font: 14.5px/1.5 var(--mono); color: var(--fg); overflow-wrap: anywhere;
  text-decoration: underline; text-decoration-color: var(--line-strong); text-underline-offset: 4px;
}
span.ip { text-decoration: none; }
button.ip {
  justify-self: start; display: inline-flex; align-items: center; gap: 4px;
  margin: -6px 0; padding: 6px 0; border: 0; background: none; text-align: left;  /* a taller target, same place */
}
.ip svg { width: 14px; height: 14px; color: var(--faint); transition: transform .2s; }
.ip[aria-expanded="true"] svg { transform: rotate(180deg); }
@media (hover: hover) { button.ip:hover { text-decoration-color: currentColor; } }
.visitor-when { font-size: 13px; color: var(--faint); font-variant-numeric: tabular-nums; white-space: nowrap; }
.visitor-meta { grid-column: 1 / -1; font-size: 13px; color: var(--faint); }
.visitor-meta span { white-space: nowrap; }
.visitor-meta a { color: var(--muted); text-underline-offset: 3px; }
.asked { grid-column: 1 / -1; }
.asked-list { margin: 8px 0 0; padding-left: 20px; list-style: disc; font-size: 15px; line-height: 1.5; color: var(--fg); }
.asked-list li { margin: 4px 0; padding-left: 2px; overflow-wrap: anywhere; }
.asked-list li::marker { color: var(--faint); }
.asked p { margin: 6px 0 0; font-size: 13px; color: var(--faint); }
details.more .asked { margin: 0 0 0 20px; }

/* A fact is written like a chat message: text on top, its source and author below, one button. */
.compose {
  border: 1px solid var(--line-strong); border-radius: 18px; background: var(--raised); box-shadow: var(--shadow-sm);
  transition: border-color .15s, box-shadow .2s;
}
.compose:focus-within { border-color: var(--ring); box-shadow: var(--shadow); }
.compose textarea {
  display: block; width: 100%; min-height: 104px; max-height: 50vh; padding: 16px 18px 8px;
  border: 0; outline: 0; resize: none; background: transparent; font: var(--read) 17px/1.65 var(--serif);
}
.compose .fields { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }
.field {
  flex: 1 1 11rem; min-width: 0; height: 40px; display: flex; align-items: center; gap: 9px; padding: 0 12px;
  border-radius: 11px; background: var(--tint); color: var(--faint); cursor: text; transition: box-shadow .15s;
}
.field svg { width: 15px; height: 15px; }
.field input { flex: 1; min-width: 0; height: 100%; border: 0; outline: 0; background: transparent; font-size: 15px; color: var(--fg); }
.field:focus-within { box-shadow: inset 0 0 0 1px var(--faint); }
.compose .buttons { display: flex; gap: 8px; margin-left: auto; }
.compose .keys { align-self: center; margin-right: 4px; font-size: 12px; color: var(--faint); }
.below { margin: 12px 4px 0; }

.list-head { display: flex; align-items: center; gap: 12px; margin: 36px 0 4px; }
.list-head h2 { margin: 0; flex: 1; }
.search {
  width: min(15rem, 50%); height: 36px; display: flex; align-items: center; gap: 8px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 999px; color: var(--faint); transition: border-color .15s;
}
.search:focus-within { border-color: var(--faint); }
.search svg { width: 15px; height: 15px; }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; font-size: 14.5px; color: var(--fg); }
.search input::-webkit-search-cancel-button { display: none; }

.items { margin: 0; padding: 0; list-style: none; }
.item { padding: 16px 0; border-bottom: 1px solid var(--line); }
.item-text { font: var(--read) 16.5px/1.65 var(--serif); white-space: pre-wrap; overflow-wrap: anywhere; }
.item-foot { display: flex; align-items: center; gap: 8px; margin-top: 4px; min-height: 32px; }
.item-meta { flex: 1; min-width: 0; font-size: 13px; color: var(--faint); overflow-wrap: anywhere; }
.item-actions { display: flex; gap: 2px; margin-right: -8px; transition: opacity .15s; }
.item-actions .icon { width: 32px; height: 32px; color: var(--faint); }
.item-actions .icon svg { width: 16px; height: 16px; }
@media (hover: hover) {
  .item-actions { opacity: 0; }
  .item:hover .item-actions, .item:focus-within .item-actions { opacity: 1; }
  .item-actions .icon:hover { color: var(--fg); }
}
.item.editing { padding: 14px 0; }
.fresh { animation: fresh 2.4s ease-out; border-radius: 4px; }
@keyframes fresh { from { background: var(--tint-strong); box-shadow: 0 0 0 10px var(--tint-strong); } to { background: transparent; box-shadow: 0 0 0 10px transparent; } }

/* Books: drop a file, then name it */
.drop {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 32px 20px;
  border: 1.5px dashed var(--line-strong); border-radius: 18px; text-align: center; color: var(--muted); cursor: pointer;
  transition: border-color .15s, background .15s;
}
.drop input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.drop .badge { width: 44px; height: 44px; display: grid; place-items: center; margin-bottom: 8px; border-radius: 13px; background: var(--tint); color: var(--fg); }
.drop .badge svg { width: 22px; height: 22px; }
.drop strong { color: var(--fg); font-size: 16px; font-weight: 600; }
.drop span { font-size: 14px; }
.drop u { color: var(--fg); text-underline-offset: 3px; }
.drop.over { border-color: var(--fg); background: var(--tint); }
.drop:focus-within { outline: 2px solid var(--fg); outline-offset: 2px; }
.hint + .drop, .drop + .card { margin-top: 14px; }
.drop.small { flex-direction: row; justify-content: center; gap: 12px; padding: 18px 20px; text-align: left; }
.drop.small .badge { width: 36px; height: 36px; margin: 0; border-radius: 11px; }
.drop.small .badge svg { width: 18px; height: 18px; }
@media (hover: hover) { .drop:hover { border-color: var(--faint); background: var(--tint); } }

.card {
  display: grid; gap: 16px; padding: 18px;
  border: 1px solid var(--line-strong); border-radius: 18px; background: var(--raised); box-shadow: var(--shadow);
  animation: enter .25s var(--ease) both;
}
.file { display: flex; align-items: center; gap: 12px; min-width: 0; }
.file .badge { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 12px; background: var(--tint); }
.file .badge svg { width: 20px; height: 20px; }
.file-about { flex: 1; min-width: 0; }
.file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.file-size { font-size: 13px; color: var(--faint); }
.lbl { display: grid; gap: 6px; min-width: 0; font-size: 13px; font-weight: 500; color: var(--muted); }
.lbl .optional { font-weight: 400; color: var(--faint); }
.input {
  width: 100%; min-width: 0; height: 44px; padding: 0 14px; border: 1px solid var(--line-strong); border-radius: 12px;
  background: var(--bg); font-size: 16px; font-weight: 400; color: var(--fg); outline: 0; transition: border-color .15s;
}
.input:focus { border-color: var(--faint); }
.input.code { font-family: var(--mono); font-size: 15px; letter-spacing: .04em; text-transform: uppercase; }
.two { display: grid; grid-template-columns: 9rem 1fr; gap: 14px; }
.row { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px; }
.progress { position: relative; height: 3px; overflow: hidden; border-radius: 3px; background: var(--tint); }
.progress::after { content: ""; position: absolute; inset: 0; width: 40%; border-radius: 3px; background: var(--fg); animation: slide 1.1s ease-in-out infinite; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(250%); } }
details.more { margin: 14px 4px 0; font-size: 14px; color: var(--muted); }
details.more summary { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; list-style: none; }
details.more summary::-webkit-details-marker { display: none; }
details.more summary svg { width: 14px; height: 14px; transition: transform .2s; }
details.more[open] summary svg { transform: rotate(90deg); }
details.more p { margin: 8px 0 0 20px; }

.book { display: flex; align-items: flex-start; gap: 14px; padding: 18px 0; border-bottom: 1px solid var(--line); }
.code-badge {
  flex: none; min-width: 44px; height: 44px; padding: 0 8px; display: grid; place-items: center;
  border-radius: 12px; background: var(--tint); font: 600 13px/1 var(--mono); letter-spacing: .03em;
}
.book-body { flex: 1; min-width: 0; }
.book-title { font: 500 18px/1.35 var(--serif); letter-spacing: -.005em; }
.book-meta { margin-top: 2px; font-size: 13px; color: var(--faint); }
.book-warn { margin-top: 6px; font-size: 13px; color: var(--muted); }
.book-actions { display: flex; align-items: center; gap: 4px; }
.book-actions .ghost { height: 32px; padding: 0 12px; font-size: 13px; }
.book-actions .icon { width: 32px; height: 32px; color: var(--faint); }
.book-actions .icon svg { width: 16px; height: 16px; }

/* Search preview */
.ask { display: flex; gap: 8px; }
.ask .search { flex: 1; width: auto; height: 44px; padding: 0 16px; }
.ask .search input { font-size: 16px; }
.ask .primary { height: 44px; }
.src-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; font-size: 13px; color: var(--faint); }
.src-head .cite { margin: 0; vertical-align: 0; cursor: default; }

/* Backup, and the maintenance switch above */
.save, .switch-row { display: flex; align-items: center; gap: 16px; padding: 18px; border: 1px solid var(--line); border-radius: 18px; }
.save > div, .switch-row > div { flex: 1; min-width: 0; }
.save strong, .switch-row strong { display: block; font-weight: 600; }

.toast {
  position: fixed; left: 50%; bottom: max(24px, calc(env(safe-area-inset-bottom) + 12px)); z-index: 50;
  display: flex; align-items: center; gap: 16px; width: max-content; max-width: calc(100vw - 32px);
  padding: 12px 18px; border-radius: 14px; background: var(--fg); color: var(--bg); box-shadow: var(--shadow);
  font-size: 14.5px; transform: translateX(-50%); animation: toast-in .3s var(--ease);
}
.toast a { flex: none; color: inherit; font-weight: 600; text-underline-offset: 3px; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 10px); } }

/* ---------------------------------------------------------------- Phones */

@media (max-width: 640px) {
  .bar { height: 52px; padding: 0 8px 0 16px; }
  .thread { padding: 4px 16px 32px; gap: 26px; }
  .msg-user { max-width: 88%; }
  .msg-bot { font-size: 16.5px; line-height: 1.72; }
  .dock { padding: 0 12px max(10px, env(safe-area-inset-bottom)); }
  .hero { padding-bottom: 28px; }
  .suggestions { grid-template-columns: 1fr; gap: 8px; }
  .suggestions button:nth-child(n + 3) { display: none; }
  .why input { font-size: 16px; }

  .pop {
    left: 0; right: 0; top: auto; bottom: 0; width: auto; max-height: 78dvh;
    border-width: 1px 0 0; border-radius: 20px 20px 0 0;
    padding-bottom: env(safe-area-inset-bottom); animation: sheet-in .3s var(--ease);
  }
  .pop::before { content: ""; flex: none; width: 36px; height: 4px; margin: 8px auto 0; border-radius: 4px; background: var(--line-strong); }
  .pop-close { display: grid; margin-right: -6px; }
  .pop-text { padding-bottom: 24px; font-size: 16.5px; }
  .scrim:not([hidden]) { display: block; position: fixed; inset: 0; z-index: 19; background: var(--scrim); animation: fade-in .2s; }

  .admin .bar { height: 54px; padding: 0 16px; }
  .tabs-inner { padding: 0 6px; gap: 0; }
  .page { padding: 26px 16px 100px; }
  .panel-head h1 { font-size: 27px; }
  .stats { gap: 8px; }
  .stat { padding: 12px; border-radius: 14px; }
  .stat-value { font-size: 20px; }
  .compose textarea { min-height: 120px; padding: 14px 16px 6px; }
  .compose .buttons { flex: 1 1 100%; }
  .compose .buttons > * { flex: 1; height: 42px; }
  .compose .keys { display: none; }
  .field input, .input.code { font-size: 16px; }  /* below 16px, iPhones zoom in on the field */
  .list-head { flex-wrap: wrap; }
  .search { width: 100%; height: 42px; }
  .search input { font-size: 16px; }
  .two { grid-template-columns: 1fr; }
  .row > * { flex: 1; height: 42px; }
  .book { flex-wrap: wrap; }
  .book-actions { flex-basis: 100%; margin: -6px 0 0 58px; }
  .save { flex-direction: column; align-items: stretch; }
  .save .primary { height: 42px; }
}
