/* Second Hippocampus — mobile first, no framework, no build step.
 *
 * The picture this borrows from is a histology slide: cresyl violet taking to
 * nerve tissue on a pale mount, with Golgi silver sepia reserved for anything
 * to do with time. Everything here is one of three voices --
 *
 *   Fraunces        what the memory says. Warm, and the only serif on screen.
 *   IBM Plex Sans   what you say, and every control.
 *   IBM Plex Mono   what the machine knows: stamps, ranges, provenance.
 *
 * -- and the app is legible mostly because those three never trade places.
 *
 * The shell is fixed, not scrolled: one viewport, a stream in the middle that
 * scrolls, and a dock the thumb can always reach. Nothing here scrolls the
 * page itself, which is what keeps the composer from wandering off when the
 * keyboard opens.
 */

:root {
  --ground: #F2EEF5;
  --ground-2: #E9E2EE;
  --surface: #FFFFFF;
  --surface-2: #EFE9F3;
  --ink: #17111D;
  --ink-2: #453C50;
  --muted: #786C82;
  --faint: #A99FB2;
  --border: #DFD6E5;
  --hair: #E8E1EC;

  --accent: #7C2461;          /* cresyl violet */
  --accent-2: #A63A83;
  --accent-ink: #FFFFFF;
  --accent-soft: #F7E9F3;
  --accent-line: #E3C6DA;

  --sepia: #8A5A22;           /* Golgi silver, for time */
  --sepia-soft: #F6EDDF;
  --good: #1F5C43;
  --stop: #8C2F40;
  --stop-soft: #FBEAED;

  --r-lg: 20px;
  --r-md: 14px;
  --r-sm: 9px;
  --tap: 44px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);

  --shadow-1: 0 1px 2px rgba(23,17,29,.05);
  --shadow-2: 0 2px 6px -2px rgba(23,17,29,.10), 0 12px 30px -22px rgba(23,17,29,.5);
  --shadow-3: 0 -8px 34px -20px rgba(23,17,29,.45);

  --display: Fraunces, Georgia, "Times New Roman", serif;
  --sans: "IBM Plex Sans", ui-sans-serif, system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    /* Dark field rather than bright field: the specimen glows, the mount goes
       black, and the violet is the only thing with any heat in it. */
    --ground: #0E0B12;
    --ground-2: #15111B;
    --surface: #191320;
    --surface-2: #221A2B;
    --ink: #F0E9F4;
    --ink-2: #C7BCD0;
    --muted: #948899;
    --faint: #6D6277;
    --border: #2C2436;
    --hair: #241D2D;

    --accent: #E58CC6;
    --accent-2: #F0A9D6;
    --accent-ink: #17111D;
    --accent-soft: #2A1A26;
    --accent-line: #40283A;

    --sepia: #D8AC72;
    --sepia-soft: #251D13;
    --good: #7FC9A2;
    --stop: #E8919F;
    --stop-soft: #2A171C;

    --shadow-1: 0 1px 2px rgba(0,0,0,.6);
    --shadow-2: 0 2px 8px -2px rgba(0,0,0,.6), 0 14px 34px -24px #000;
    --shadow-3: 0 -10px 36px -22px #000;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

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

body {
  height: 100dvh;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  /* The shell never scrolls. Only .stream does. */
  overflow: hidden;
  overscroll-behavior: none;
}

/* A faint tissue grain, so the ground reads as a mounted slide rather than a
   flat fill. Cheap: two hairline gradients, no image, no request. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: .5;
  background:
    radial-gradient(1100px 620px at 78% -12%, var(--accent-soft), transparent 66%),
    repeating-linear-gradient(0deg, transparent 0 3px, rgba(124,36,97,.014) 3px 4px);
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

/* ================================ shell ================================ */

#main { position: relative; flex: 1; min-height: 0; z-index: 1; }

.view {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
/* display:flex above beats the hidden attribute's UA display:none, so hidden
   views have to be told again -- and a view that is merely transparent still
   swallows every tap meant for the one on top of it. */
.view[hidden] { display: none; }

/* ---------------------------------- head ---------------------------------- */
.head {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(10px + var(--safe-t)) 16px 10px;
  border-bottom: 1px solid var(--hair);
  background: color-mix(in srgb, var(--ground) 86%, transparent);
  backdrop-filter: blur(12px);
}
.brand {
  margin: 0;
  font-family: var(--display);
  font-weight: 600;
  font-size: 1.32rem;
  letter-spacing: -.015em;
  font-variation-settings: "SOFT" 12, "WONK" 1;
}

.ghost {
  background: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  min-height: var(--tap);
  padding: 4px 15px;
  font-size: 14px;
}
.ghost:active { background: var(--surface-2); }
.ghost.icon {
  min-width: var(--tap);
  display: grid;
  place-items: center;
  padding: 0;
}
.ghost.danger { color: var(--stop); border-color: color-mix(in srgb, var(--stop) 45%, transparent); }
.ghost.danger:active { background: var(--stop-soft); }

/* --------------------------------- banner --------------------------------- */
.banner {
  flex: none;
  z-index: 30;
  padding: calc(7px + var(--safe-t)) 16px 7px;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: .01em;
  text-align: center;
  background: var(--sepia-soft);
  color: var(--sepia);
  border-bottom: 1px solid var(--border);
}
.banner.bad { background: var(--stop-soft); color: var(--stop); }

/* --------------------------------- stream --------------------------------- */
.stream {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 14px 14px 18px;
  scrollbar-width: none;
}
.stream::-webkit-scrollbar { display: none; }

/* Chat order, for free: the renderers emit newest-first, and column-reverse
   puts newest at the bottom *and* pins the scroller there as things arrive.
   No scrollIntoView, no scrollTop arithmetic, no jump when an answer lands. */
.chat {
  display: flex;
  flex-direction: column-reverse;
  justify-content: flex-start;
  gap: 16px;
}

.stream > .empty {
  margin: auto;
  padding: 36px 26px;
  text-align: center;
  color: var(--muted);
  font-size: 15px;
  max-width: 30ch;
  line-height: 1.6;
}
.chat > .empty { transform: scaleY(-1) scaleX(-1); }   /* un-flip inside column-reverse */

/* ================================ a turn ================================
   One capture: what you said, and what the memory made of it. */
.turn { display: flex; flex-direction: column; gap: 7px; }

/* ---- your side: right, violet, the only filled bubble on screen ---- */
.said {
  align-self: flex-end;
  max-width: 86%;
  background: var(--accent);
  color: var(--accent-ink);
  padding: 10px 14px 8px;
  border-radius: var(--r-lg) var(--r-lg) 5px var(--r-lg);
  box-shadow: var(--shadow-2);
  overflow-wrap: anywhere;
}
.said p { margin: 0; font-size: 15.5px; line-height: 1.45; }
.said .meta {
  display: block;
  margin-top: 5px;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: .05em;
  text-align: right;
  color: color-mix(in srgb, var(--accent-ink) 72%, transparent);
}

/* Queued: still yours, not yet anyone else's. Hollow instead of filled -- the
   difference has to survive a glance, because it is the difference between a
   thought that is safe and one that is only safe *here*. */
.turn[data-status="pending"] .said {
  background: transparent;
  color: var(--ink);
  border: 1px dashed var(--accent-line);
  box-shadow: none;
}
.turn[data-status="pending"] .said .meta { color: var(--sepia); }

.turn[data-status="stuck"] .said {
  background: var(--stop-soft);
  color: var(--stop);
  border: 1px solid color-mix(in srgb, var(--stop) 35%, transparent);
  box-shadow: none;
}
.turn[data-status="stuck"] .said .meta { color: var(--stop); }

/* ---- the memory's side: left, unfilled, quieter ---- */
.echo {
  align-self: flex-start;
  max-width: 90%;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.echo .lede {
  margin: 0;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--faint);
  padding-left: 2px;
}

.facts { margin: 0; padding: 0; list-style: none; display: flex; flex-wrap: wrap; gap: 6px; }
.facts li {
  font-size: 13.5px;
  line-height: 1.35;
  color: var(--ink-2);
  background: var(--surface);
  border: 1px solid var(--accent-line);
  border-left: 3px solid var(--accent);
  border-radius: var(--r-sm);
  padding: 6px 10px;
  box-shadow: var(--shadow-1);
  overflow-wrap: anywhere;
}
/* A fact this one replaced, or a sentence that carried none. Struck, dimmed,
   and still present: knowing nothing was learned is itself worth showing. */
.facts li.dead {
  background: transparent;
  border-color: var(--border);
  border-left-color: var(--faint);
  color: var(--muted);
  text-decoration: line-through;
  text-decoration-thickness: 1px;
  text-decoration-color: var(--faint);
  box-shadow: none;
}

.retry {
  align-self: flex-start;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  min-height: 36px;
  padding: 4px 16px;
  font-size: 13.5px;
  color: var(--ink-2);
}
.why {
  margin: 0;
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.5;
  color: var(--stop);
  padding-left: 2px;
}

/* ================================ answers ================================ */
.asked {
  align-self: flex-end;
  max-width: 86%;
  background: var(--surface-2);
  color: var(--ink);
  border: 1px solid var(--border);
  padding: 9px 14px;
  border-radius: var(--r-lg) var(--r-lg) 5px var(--r-lg);
  font-size: 15px;
  overflow-wrap: anywhere;
}
.asked p { margin: 0; }

.answered {
  align-self: flex-start;
  max-width: 94%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 5px var(--r-lg) var(--r-lg) var(--r-lg);
  padding: 13px 15px;
  box-shadow: var(--shadow-2);
}
/* This is the longest thing the app ever says and the one you read most
   carefully, so it is set in the body face at a comfortable size. The serif was
   the wrong instinct here: characterful at a glance, tiring at a paragraph. */
.answered .a {
  margin: 0;
  font-size: 16.5px;
  line-height: 1.52;
  overflow-wrap: anywhere;
}
.answered .a.thinking { color: var(--faint); }
.answered.unknown { border-left-color: var(--faint); }
.answered.unknown .a { color: var(--ink-2); }

/* An answer the composer produced because the reasoner was unreachable. Loud
   on purpose: a downgraded answer that looks like a normal one is the failure
   mode this whole codebase is arranged against. */
.degraded {
  margin: 8px 0 0;
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--stop);
}

.prov { margin: 12px 0 0; display: grid; gap: 6px; border-top: 1px solid var(--hair); padding-top: 10px; }
.prov details {
  font-size: 13.5px;
  color: var(--ink-2);
  background: var(--ground-2);
  border-radius: var(--r-sm);
  padding: 7px 10px;
}
.prov summary {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--muted);
  list-style: none;
  display: flex;
  gap: 7px;
  align-items: baseline;
  overflow-wrap: anywhere;
}
.prov summary::-webkit-details-marker { display: none; }
.prov summary::before {
  content: "▸";
  color: var(--accent);
  font-size: 9px;
  transition: transform .16s ease;
  display: inline-block;
}
.prov details[open] summary::before { transform: rotate(90deg); }
.prov .dead summary { color: var(--faint); }
.prov .dead summary::before { color: var(--faint); }
.prov .win {
  margin: 7px 0 0;
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--sepia);
  letter-spacing: .04em;
}
.prov blockquote {
  margin: 6px 0 0;
  padding-left: 10px;
  border-left: 2px solid var(--accent-line);
  color: var(--ink-2);
  font-style: italic;
  overflow-wrap: anywhere;
}
audio { width: 100%; margin-top: 8px; height: 34px; }

.rate { display: flex; gap: 8px; margin-top: 12px; }
.rate button {
  border: 1px solid var(--border);
  background: none;
  border-radius: 999px;
  min-height: 38px;
  padding: 2px 16px;
  font-size: 13.5px;
  color: var(--muted);
}
.rate button.on { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

/* ================================== dock ==================================
   The one thing that never moves. Everything reachable without shifting grip. */
.dock {
  flex: none;
  display: flex;
  gap: 9px;
  align-items: flex-end;
  /* No safe-area padding here: the tab bar sits *below* this and already pays
     for the inset. Adding it twice left a dead band of dock-coloured nothing
     between the composer and the tabs, tall as the navigation bar. */
  padding: 9px 12px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  box-shadow: var(--shadow-3);
}
.dock input {
  flex: 1;
  min-width: 0;
  min-height: var(--tap);
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: var(--ground);
  color: var(--ink);
  outline: none;
}
.dock input::placeholder { color: var(--faint); }
.dock input:focus { border-color: var(--accent); background: var(--surface); }
.dock input[type="search"]::-webkit-search-cancel-button { -webkit-appearance: none; }

/* POC: the one-tap dictation button. Quieter than send -- it fills the field,
   it does not commit anything, and the difference should be visible before the
   thumb lands. Delete this rule with the buttons. */
.dictate {
  flex: none;
  width: var(--tap);
  height: var(--tap);
  border: 1px solid var(--accent-line);
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  display: grid;
  place-items: center;
  transition: transform .12s ease;
}
.dictate[hidden] { display: none; }
.dictate:active { transform: scale(.93); }

.send {
  flex: none;
  width: var(--tap);
  height: var(--tap);
  border: none;
  border-radius: 50%;
  background: linear-gradient(150deg, var(--accent-2), var(--accent));
  color: var(--accent-ink);
  display: grid;
  place-items: center;
  box-shadow: 0 6px 18px -8px var(--accent);
  transition: transform .12s ease;
}
.send:active { transform: scale(.93); }

/* ================================ timeline ================================ */
.spine { position: relative; padding-left: 22px; }
/* The thread the whole record hangs from. Sepia, because this column is time. */
.spine::before {
  content: "";
  position: absolute;
  left: 5px;
  top: 6px;
  bottom: 6px;
  width: 1px;
  background: linear-gradient(var(--sepia-soft), var(--border) 12%, var(--border) 88%, transparent);
}

.day {
  position: sticky;
  top: -14px;
  z-index: 2;
  margin: 20px 0 12px -22px;
  padding: 5px 11px;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--sepia);
  background: var(--sepia-soft);
  border: 1px solid color-mix(in srgb, var(--sepia) 20%, transparent);
  border-radius: 999px;
  width: fit-content;
}
.day:first-child { margin-top: 2px; }

.ep { position: relative; margin: 0 0 14px; }
/* The node on the thread. Filled when the sentence left a fact behind, hollow
   when it did not -- so scrolling the spine shows where the memory thickened. */
.ep::before {
  content: "";
  position: absolute;
  left: -21px;
  top: 7px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--ground);
  border: 2px solid var(--faint);
}
.ep.rich::before { background: var(--accent); border-color: var(--accent); }

.ep .when {
  margin: 0 0 4px;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--muted);
}
.ep .said-plain {
  margin: 0;
  font-size: 15.5px;
  line-height: 1.45;
  color: var(--ink);
  overflow-wrap: anywhere;
}
.ep .facts { margin-top: 8px; }

/* display:block beats the hidden attribute's UA display:none, exactly as it
   does on .view -- which is how "carregar mais" stayed on screen under four
   entries, offering a page that does not exist. */
.more[hidden] { display: none; }
.more {
  margin: 18px auto 10px;
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  min-height: var(--tap);
  padding: 6px 24px;
  font-size: 14px;
}

/* ================================== map ==================================
   Canvas first: it gets the entire view, and everything else floats over it. */
.canvas-wrap { position: relative; flex: 1; min-height: 0; }
#graph {
  position: absolute;
  inset: 0;
  /* Full bleed on purpose -- it is the one screen here that is a view rather
     than a form, so it gets the glass. */
  width: 100%;
  height: 100%;
  display: block;
  background:
    radial-gradient(120% 90% at 50% 0%, var(--ground-2), var(--ground) 70%);
  touch-action: none;            /* the canvas handles its own drags */
  overscroll-behavior: contain;
}

/* ================================== tabs ================================== */
.tabs {
  flex: none;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 5px 4px calc(5px + var(--safe-b));
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
}
.tabs button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  border: none;
  background: none;
  color: var(--faint);
  font-size: 10.5px;
  letter-spacing: .01em;
  min-height: var(--tap);
  padding: 5px 0 3px;
  border-radius: 12px;
  transition: color .15s ease;
}
.tabs button.on { color: var(--accent); }
.tabs button.on svg { transform: translateY(-1px); }
.tabs button svg { transition: transform .18s cubic-bezier(.34,1.56,.64,1); }

/* ================================ settings ================================ */
dialog {
  border: none;
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  padding: 0;
  width: 100%;
  max-width: 560px;
  margin: auto auto 0;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-3);
}
dialog::backdrop { background: rgba(10,6,14,.55); backdrop-filter: blur(2px); }
.sheet-handle {
  width: 42px; height: 4px;
  border-radius: 999px;
  background: var(--border);
  margin: 0 auto 4px;
}
.settings { padding: 12px 18px calc(20px + var(--safe-b)); display: grid; gap: 14px; }
.settings h2 {
  margin: 0;
  font-family: var(--display);
  font-weight: 600;
  font-size: 1.15rem;
}
.settings label { display: grid; gap: 6px; font-size: 12.5px; color: var(--muted); }
.settings label.row { display: flex; align-items: center; gap: 10px; font-size: 13.5px; color: var(--ink-2); }
.settings input[type=url], .settings input[type=password] {
  min-height: var(--tap);
  padding: 8px 13px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 13px;
}
.settings input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--accent); }
.settings-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.settings-actions button { min-height: var(--tap); }
.settings-actions .primary {
  border: none;
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 999px;
  padding: 6px 24px;
}
.stats {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--muted);
  background: var(--ground);
  border: 1px solid var(--hair);
  border-radius: 11px;
  padding: 10px 12px;
  white-space: pre-wrap;
  line-height: 1.65;
  max-height: 34vh;
  overflow-y: auto;
}

/* ================================= motion ================================= */
.turn, .ep { animation: rise .22s cubic-bezier(.22,.8,.3,1) both; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    transition-duration: .001ms !important;
  }
}
