:root {
  /* The document is light by default. The dark block below flips this so form
     controls, scrollbars and the caret follow the same choice as the paint. */
  color-scheme: light;
  --ink: #1c1917;
  --ink-soft: #57534e;
  --cream: #f7f1e6;
  --cream-2: #f1e8d7;
  --paper: #fffcf6;
  --paper-2: #fffefb;
  --line: #e2d3ba;
  --line-soft: #efe3cf;
  --danger: #e58a79;

  /* Surfaces and effects that used to be literal colours. Naming them is what
     lets the dark scheme swap the whole product's paint in one place, without
     a second set of component rules. */
  --main-bg: #ffffff;
  --surface: #ffffff;
  --bubble: #ffffff;
  --composer-wrap: #ffffff;
  --quote-bg: rgba(243, 234, 216, 0.5);
  --veil: rgba(255, 252, 246, 0.86);
  --modal-veil: rgba(42, 33, 24, 0.42);
  --drawer-veil: rgba(42, 33, 24, 0.45);
  --thumb-close: rgba(255, 255, 255, 0.92);
  --shadow-pop: 0 10px 30px rgba(60, 46, 30, 0.16);
  --shadow-pop-soft: 0 10px 30px rgba(60, 46, 30, 0.14);
  --glow: 255, 255, 255;
  --sheen: 226, 211, 186;
  --pulse: 138, 111, 122;

  --danger-ink: #b4503c;
  --danger-ink-strong: #a8412f;
  --danger-bg: #fff3f0;
  --danger-bg-strong: #ffe9e4;
  --danger-surface: #fff7f5;
  --danger-line: #d8b0b0;
  --warn-ink: #8a4a12;
  --warn-ink-soft: #8a6a1f;
  --warn-bg: #fbe6cd;
  --warn-line: #e0a86a;
  --good: #1f6b3a;
  --good-ink: #f3ead8;
  --good-surface: #eef7f1;
  --good-line: #cfe6d6;

  /* One family for the whole product — headings, body, prompts, replies and the
     legal pages. Hierarchy comes from weight and size, not a second face. Kept
     as two variables so the display face can be split off again later. */
  --font-sans: "Bricolage Grotesque", "Space Grotesk", system-ui, -apple-system, sans-serif;
  --font-display: "Bricolage Grotesque", "Space Grotesk", system-ui, sans-serif;
  /* Numeric readouts: counts, meters and the character readout. Tabular by
     nature, so digits do not shuffle sideways as they tick. */
  --font-mono: "DM Mono", "SFMono-Regular", Consolas, monospace;
  --season: #f6c6d6;
  --season-2: #b7d8a8;
  --season-ink: #8a6f7a;
  /* Focus rings and the blockquote rule need a colour that stays visible on the
     page; in light mode it is the season, in dark it is the season's ink. */
  --focus: #f6c6d6;
  /* The header scene's sky lives here rather than in app.js so the dark scheme
     can swap it without rebuilding the header. */
  --sky: linear-gradient(180deg, #fde4ee 0%, #fdf1f6 52%, #eef7ea 100%);
}

body[data-season="spring"] {
  --season: #f6c6d6;
  --season-2: #b7d8a8;
  --season-ink: #8a6f7a;
  --focus: #f6c6d6;
  --pulse: 138, 111, 122;
  --sky: linear-gradient(180deg, #fde4ee 0%, #fdf1f6 52%, #eef7ea 100%);
}
body[data-season="summer"] {
  --season: #f9d98a;
  --season-2: #b9dcf0;
  --season-ink: #9a8755;
  --focus: #f9d98a;
  --pulse: 154, 135, 85;
  --sky: linear-gradient(180deg, #86c6f0 0%, #c6e7fc 58%, #eaf7ff 100%);
}
body[data-season="autumn"] {
  --season: #e5533d;
  --season-2: #c73a28;
  --season-ink: #8a2c1f;
  --focus: #e5533d;
  --pulse: 138, 44, 31;
  --sky: linear-gradient(180deg, #f8d8ad 0%, #fbe7d4 42%, #fff6ee 100%);
}
body[data-season="winter"] {
  --season: #cfe2f0;
  --season-2: #a9c9e0;
  --season-ink: #7a95a8;
  --focus: #cfe2f0;
  --pulse: 122, 149, 168;
  --sky: linear-gradient(180deg, #c4dcf2 0%, #e2f0fb 55%, #f8fcff 100%);
}

/* ---------- Dark scheme ----------
   Chosen from Settings (System / Light / Dark). theme.js resolves System to
   `light` or `dark` on <html>, so this block is the only place the paint is
   swapped; light mode is every value above and stays the fallback. The palette
   is warm-dark rather than blue-black so it still reads as the same cream
   paper product at night. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --ink: #ece5d8;
  --ink-soft: #b3aa9c;
  --cream: #14171b;
  --cream-2: #1b1f24;
  --paper: #20252b;
  --paper-2: #272d34;
  --line: #3a424c;
  --line-soft: #2f363f;
  --danger: #f08b78;

  --main-bg: #181c21;
  --surface: #232830;
  --bubble: #272d34;
  --composer-wrap: #181c21;
  --quote-bg: rgba(255, 255, 255, 0.045);
  --veil: rgba(20, 23, 27, 0.86);
  --modal-veil: rgba(0, 0, 0, 0.62);
  --drawer-veil: rgba(0, 0, 0, 0.68);
  --thumb-close: rgba(32, 37, 43, 0.92);
  --shadow-pop: 0 10px 30px rgba(0, 0, 0, 0.55);
  --shadow-pop-soft: 0 10px 30px rgba(0, 0, 0, 0.45);
  --glow: 0, 0, 0;
  --sheen: 120, 132, 148;

  --danger-ink: #f09a86;
  --danger-ink-strong: #ff9b84;
  --danger-bg: #3a2522;
  --danger-bg-strong: #4a2a26;
  --danger-surface: #2e1f1d;
  --danger-line: #6b3a36;
  --warn-ink: #f0b46a;
  --warn-ink-soft: #e8c07a;
  --warn-bg: #3a2d1c;
  --warn-line: #6b4f2b;
  --good: #3f8f66;
  --good-ink: #eaf7ef;
  --good-surface: #1d2b23;
  --good-line: #2f4a3a;
}

/* Each dark sky is lifted a step off the old near-black so the seasonal sprites
   keep their silhouettes: the snowman's black top hat is the extreme case and
   needs roughly 2:1 against the sky behind it, while the header still reads as
   night against the darker page below. Winter therefore gets the biggest lift,
   because that is the scene whose art is dark-on-dark. */
:root[data-theme="dark"] body[data-season="spring"] {
  --season: #6d4a58;
  --season-2: #4f6b47;
  --season-ink: #e6b7c8;
  --focus: #e6b7c8;
  --pulse: 230, 183, 200;
  --sky: linear-gradient(180deg, #3a2d3f 0%, #2a2e36 52%, #25322c 100%);
}
:root[data-theme="dark"] body[data-season="summer"] {
  --season: #6b5a2a;
  --season-2: #3f6b88;
  --season-ink: #edc97e;
  --focus: #edc97e;
  --pulse: 237, 201, 126;
  --sky: linear-gradient(180deg, #24415c 0%, #1e2f3f 58%, #1a2028 100%);
}
:root[data-theme="dark"] body[data-season="autumn"] {
  --season: #7a3527;
  --season-2: #8a3a2a;
  --season-ink: #f0907a;
  --focus: #f0907a;
  --pulse: 240, 144, 122;
  --sky: linear-gradient(180deg, #463427 0%, #322821 42%, #221e1a 100%);
}
:root[data-theme="dark"] body[data-season="winter"] {
  --season: #33495e;
  --season-2: #3f5f78;
  --season-ink: #a9c9e0;
  --focus: #a9c9e0;
  --pulse: 169, 201, 224;
  --sky: linear-gradient(180deg, #4b6884 0%, #384d62 55%, #27333f 100%);
}

* { box-sizing: border-box; }

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

body {
  background: var(--cream);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 15px;
  /* Both elements, not just body. With only body hidden, the root element can
     still scroll on mobile, which shows up as a phantom scrollbar on a page
     that visually fits. */
  overflow: hidden;
  image-rendering: pixelated;
}

button, textarea { font-family: inherit; }

.app {
  display: grid;
  grid-template-columns: clamp(260px, 22vw, 380px) 1fr;
  height: 100vh;
  width: 100%;
}

/* ---------- Pixel icons ---------- */
.pix-ico {
  width: 12px;
  height: 12px;
  flex: 0 0 auto;
  display: block;
}

/* ---------- Sidebar ---------- */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px 14px 14px;
  background: var(--cream-2);
  border-right: 1px solid var(--line);
  overflow-y: auto;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 18px;
  line-height: 1.2;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.pixel-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  text-align: left;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}
.pixel-btn:hover { background: var(--paper-2); }
.pixel-btn:active { transform: translate(1px, 1px); }

.new-chat-btn { background: var(--season); }

.side-section { min-width: 0; }
.side-title {
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 8px;
}

/* Chat list: scrolls on its own and fades out at the bottom edge so it reads
   as "more below" instead of a hard cut-off. */
.chat-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
  max-height: 220px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 4px;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}
.chat-list.is-scrollable:not(.at-end) {
  -webkit-mask-image: linear-gradient(to bottom, #000 0, #000 calc(100% - 26px), transparent 100%);
  mask-image: linear-gradient(to bottom, #000 0, #000 calc(100% - 26px), transparent 100%);
}
.chat-list::-webkit-scrollbar { width: 8px; }
.chat-list::-webkit-scrollbar-track { background: transparent; }
.chat-list::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 999px;
  border: 1px solid transparent;
  background-clip: content-box;
}
.chat-list::-webkit-scrollbar-thumb:hover { background-color: var(--ink-soft); background-clip: content-box; }

.chat-item {
  /* Without this the items shrink inside the fixed-height column and overlap. */
  flex: 0 0 auto;
  width: 100%;
  min-height: 34px;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.35;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}
.chat-item:hover { background: var(--paper); border-color: var(--line-soft); }
.chat-item.active { background: var(--paper); border-color: var(--line); }

/* Each row is the chat button plus a three-dot trigger. */
.chat-row {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 0 0 auto;
  min-width: 0;
}
.chat-row .chat-item { flex: 1 1 auto; min-width: 0; }
.chat-more {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  opacity: 0.55;
  transition: opacity 0.15s ease, background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.chat-more:hover, .chat-more.open, .chat-more:focus-visible, .chat-item.active + .chat-more { opacity: 1; }
.chat-more:hover, .chat-more.open { background: var(--paper); border-color: var(--line); color: var(--ink); }
.chat-more:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.chat-more svg { width: 14px; height: 14px; display: block; }
/* In dark mode the row dots are white rather than muted ink, and the resting
   opacity is lifted so "quiet" still reads against the dark sidebar. `:where()`
   keeps the rule at the base specificity, so the hover/open rules below can
   still take it to full white. */
:where(:root[data-theme="dark"]) .chat-more { color: #ffffff; opacity: 0.8; }
:where(:root[data-theme="dark"]) .chat-more:hover,
:where(:root[data-theme="dark"]) .chat-more.open,
:where(:root[data-theme="dark"]) .chat-more:focus-visible { color: #ffffff; }

/* Anchored to the dot, but appended to <body> so the scrolling chat list's
   overflow and fade mask can't clip it. */
.chat-menu {
  position: fixed;
  z-index: 90;
  min-width: 168px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 6px;
  box-shadow: var(--shadow-pop);
}
.chat-menu-item {
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  padding: 8px 10px;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.chat-menu-item:hover { background: var(--paper-2); }
.chat-menu-item:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.chat-menu-item.danger { color: var(--danger-ink); }
.chat-menu-item.danger:hover { background: var(--danger-bg); border-color: var(--line-soft); }
/* Armed = the second click that actually deletes. */
.chat-menu-item.armed { background: var(--danger-bg-strong); border-color: var(--danger); color: var(--danger-ink); }

.pool-card {
  position: relative;
  margin-top: auto;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
}
/* A plain heading: the card has nothing to expand, so it is not a control. */
.pool-title {
  color: var(--ink);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.02em;
  line-height: 1.2;
}
.pool-total { color: var(--ink-soft); font-size: 13px; margin: 7px 0 2px; }
/* The headline is a count of prompts, so it can be the loudest thing in the
   card — it is the number a person actually acts on. */
.pool-number {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 30px;
  line-height: 1.1;
  letter-spacing: 0;
  margin-top: 4px;
}
.pool-sub {
  color: var(--ink-soft);
  font-size: 12px;
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 6px;
}
/* A sentence explaining what the number means and why it moves, rather than
   leaving the reader to infer it from a meter. */
.pool-note {
  margin: 9px 0 0;
  font-size: 11px;
  line-height: 1.5;
  color: var(--ink-soft);
}
.pool-badge {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 1px 6px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--ink-soft);
  background: transparent;
}
.pool-badge.live {
  color: var(--ink);
  background: var(--season);
  border-color: var(--season-ink);
}
/* Low and exhausted read as caution, so they are warm rather than seasonal. */
.pool-badge.warn {
  color: var(--warn-ink);
  background: var(--warn-bg);
  border-color: var(--warn-line);
}
.pool-card.exhausted { border-color: var(--danger); }
.pool-card.exhausted .pool-number { color: var(--danger); }

/* The pool card before its first snapshot. The placeholders and the "checking"
   badge say what is happening; this sweep is what makes it read as loading
   rather than as a card that has failed to load. The band is a translucent
   --sheen, so it shows against the --paper card in either colour scheme
   without turning it into a coloured block. */
.pool-card.is-loading::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background-image: linear-gradient(
    100deg,
    rgba(var(--sheen), 0) 30%,
    rgba(var(--sheen), 0.55) 50%,
    rgba(var(--sheen), 0) 70%
  );
  background-size: 220% 100%;
  background-position: 120% 0;
  animation: pool-shimmer 1.8s linear infinite;
}
@keyframes pool-shimmer {
  from { background-position: 120% 0; }
  to { background-position: -120% 0; }
}

.meter {
  height: 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  overflow: hidden;
  margin: 10px 0 7px;
}
.meter-fill {
  height: 100%;
  background: var(--good);
  transition: width 0.45s cubic-bezier(0.22, 1, 0.36, 1), background-color 0.3s ease;
}
.meter-fill.is-mid { background: #d9a13a; }
.meter-fill.is-low { background: var(--danger); }
.meter-fill.is-off { background: var(--line-soft); }
.pool-caption {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  color: var(--ink-soft);
}

/* ---------- Main ---------- */
.main {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  background: var(--main-bg);
}

.header-art { position: absolute; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }
.topbar-content {
  position: relative;
  z-index: 1;
  height: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
}
.pixel-sprite { position: absolute; }
.pixel-group { position: absolute; left: 0; top: 0; }
.fall-item {
  animation-name: fall-sway;
  animation-timing-function: linear;
  animation-iteration-count: infinite;
  will-change: transform, opacity;
}
/* Tumbling fall: the sprite drifts sideways by --sway and rotates by --spin as
   it crosses the bar, fading in near the top and out before the bottom edge so
   the loop neither pops in nor is cut off mid-sprite (the bar clips overflow).
   --fall is set from the header's real height in JS. */
@keyframes fall-sway {
  0%   { transform: translate(0, 0) rotate(0deg); opacity: 0; }
  10%  { opacity: 1; }
  62%  { opacity: 1; }
  100% { transform: translate(var(--sway, 42px), var(--fall, 86px)) rotate(var(--spin, 220deg)); opacity: 0; }
}

/* Cloud drift: a slow sideways slide, eased and mirrored so no cloud ever
   snaps back to its start. */
.scene-sprite.drift {
  animation: cloud-drift 40s ease-in-out infinite alternate;
  will-change: transform;
}
@keyframes cloud-drift {
  from { transform: translateX(-14px); }
  to   { transform: translateX(22px); }
}

@media (prefers-reduced-motion: reduce) {
  .fall-item { display: none; }
  .scene-sprite.drift { animation: none; transform: translateX(-6px); }
}

.topbar {
  position: relative;
  z-index: 2;
  height: 72px;
  border-bottom: 1px solid var(--line);
  background: var(--sky);
  overflow: visible;
}
.topbar h1 { margin: 0; font-family: var(--font-display); font-weight: 600; font-size: 17px; letter-spacing: 0.01em; color: var(--ink); }
/* The title block must be allowed to shrink below its text width, otherwise it
   refuses to truncate and shoves the actions off the header. */
.topbar-copy { min-width: 0; }
.topbar h1, .topbar p { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar p { margin: 2px 0 0; font-size: 12px; color: var(--ink-soft); }
/* The header sits over the seasonal scene, and a petal or leaf can pass behind
   the title. A soft halo in the scheme's own direction keeps both lines legible
   without hiding the art. */
.topbar h1, .topbar p { text-shadow: 0 1px 0 rgba(var(--glow), 0.75), 0 0 6px rgba(var(--glow), 0.55); }

.topbar-lead { display: flex; align-items: center; gap: 10px; min-width: 0; }

/* ---------- Sidebar toggle ---------- */
.menu-btn {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink-soft);
  cursor: pointer;
  transition: color 0.12s ease, background 0.12s ease, transform 0.12s ease;
}
.menu-btn:hover { background: var(--paper-2); color: var(--ink); }
.menu-btn:active { transform: translate(1px, 1px); }
.menu-btn:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.menu-btn.on { background: var(--season); border-color: var(--season-ink); color: var(--ink); }
/* In dark mode the sidebar toggle keeps a transparent chip and turns its three
   lines white, so the control reads against the seasonal sky without a black
   square around it. */
:root[data-theme="dark"] .menu-btn,
:root[data-theme="dark"] .menu-btn:hover,
:root[data-theme="dark"] .menu-btn.on {
  background: transparent;
  border-color: transparent;
  color: #ffffff;
}
.menu-ico { width: 12px; height: 12px; display: block; }

/* Collapsed on desktop: the sidebar is display:none, so it is no longer a grid
   item and .main would auto-place into the FIRST column. That column must
   therefore be the single 1fr, not "0 1fr" — with a zero-width first column the
   whole app renders at zero width and the page goes blank. */
body.sidebar-collapsed .app { grid-template-columns: 1fr; }
body.sidebar-collapsed .sidebar { display: none; }

/* ---------- Skills ---------- */
/* The catalogue is opened by the AI in chat now (the topbar and sidebar
   buttons are gone), but the modal's own layout is unchanged. */
.skills-body { margin-top: 10px; }
.skills-sub {
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1.5;
  margin: 0 0 12px;
}
.skills-list { display: flex; flex-direction: column; gap: 8px; }
.skills-empty {
  color: var(--ink-soft);
  font-size: 13px;
  text-align: center;
  padding: 12px 0;
}
.skills-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}
.skills-count {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
  flex: 0 0 auto;
}
.skills-hint { font-size: 11.5px; color: var(--ink-soft); text-align: right; }

.skill-card {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 9px 10px;
}
.skill-card.is-on { border-color: var(--season-ink); background: var(--season); }
.skill-card.kind-creator {
  background: var(--good-surface);
  border-color: var(--good-line);
}
.skill-head { display: flex; align-items: center; gap: 8px; padding-right: 30px; }
.skill-name { font-weight: 700; font-size: 13px; }
.skill-tag {
  flex: 0 0 auto;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 999px;
  color: var(--ink-soft);
  border: 1px solid var(--line);
}
.skill-desc {
  margin-top: 3px;
  font-size: 11.5px;
  line-height: 1.45;
  color: var(--ink-soft);
}
.skill-toggle {
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 4px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink-soft);
  cursor: pointer;
}
.skill-card.is-on .skill-toggle {
  background: var(--good);
  border-color: var(--good);
  color: var(--good-ink);
}
.skill-del {
  position: absolute;
  bottom: 8px;
  right: 8px;
  font-size: 11px;
  line-height: 1;
  padding: 4px 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
  color: var(--ink-soft);
  cursor: pointer;
}
.skill-del:hover { color: var(--danger-ink); border-color: var(--danger-line); }
.skill-ask {
  margin-top: 8px;
  width: 100%;
  font-size: 12px;
}

.chat {
  position: relative;
  z-index: 1;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  overflow-y: auto;
  scroll-behavior: smooth;
}
body.empty-chat .chat { justify-content: center; }

.chat-hero {
  display: none;
  flex: 0 0 auto;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 22px;
  /* Lifted clear of the vertical centre so the catchphrase sits above the
     composer instead of straddling it. Once the template grid joins it the
     hero is taller, so the trailing lift shrinks (see .has-templates below). */
  padding: 20px 24px 104px;
  pointer-events: none;
  z-index: 0;
}
body.empty-chat .chat-hero { display: flex; }
body.empty-chat.has-templates .chat-hero { padding-bottom: 22px; }
.hero-line {
  max-width: 620px;
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: 500;
  color: var(--ink);
  line-height: 1.3;
  letter-spacing: 0;
}

/* ---------- Starting templates (clean-chat hero) ---------- */
/* The hero is pointer-events:none so the catchphrase cannot swallow clicks;
   the tiles opt back in, because they are the one interactive thing here. */
.hero-templates {
  pointer-events: auto;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.hero-templates[hidden] { display: none; }
.tpl-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.tpl-tile {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-height: 88px;
  padding: 12px 13px;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper-2);
  color: var(--ink);
  font-family: var(--font-sans);
  cursor: pointer;
  transition: transform 0.08s ease, border-color 0.12s ease, background 0.12s ease;
}
.tpl-tile:hover { border-color: var(--season-ink); background: var(--paper); }
.tpl-tile:active { transform: translate(1px, 1px); }
/* The featured tile is the one bit of colour on the clean chat. */
.tpl-tile.is-theme { background: var(--season); border-color: var(--season-ink); }
.tpl-tile.is-theme:hover { background: var(--season); filter: brightness(1.03); }
.tpl-kicker {
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.tpl-tile.is-theme .tpl-kicker { color: var(--season-ink); font-weight: 500; }
.tpl-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15px;
  line-height: 1.2;
}
.tpl-desc {
  font-size: 11.5px;
  line-height: 1.4;
  color: var(--ink-soft);
}
.tpl-browse {
  align-self: center;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}
.tpl-browse:hover { border-color: var(--season-ink); }
.tpl-browse:active { transform: translate(1px, 1px); }
.tpl-browse .pix-ico { color: var(--ink-soft); }
.tpl-browse-count {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 500;
  color: var(--ink-soft);
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--cream-2);
}
.tpl-browse-count:empty { display: none; }
.messages {
  width: 100%;
  max-width: 860px;
  margin: 0 auto;
  padding: 18px 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex: 1 0 auto;
}
body.empty-chat .messages { display: none; }

.msg { display: flex; gap: 10px; align-items: flex-start; justify-content: flex-start; animation: rise-text 0.2s ease both; }
.msg.user { justify-content: flex-end; }
@keyframes rise-text { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.msg-body {
  position: relative;
  max-width: min(720px, 90%);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 13px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}
.msg.user .msg-body { background: var(--bubble); }
/* The reply is prose on the page, not a card. The generated prompt keeps its
   own box below (that is the object being copied into Nanogram); everything
   around it — the tag, the advice, the assumptions — sits unboxed. Player turns
   and error notices keep their boxes: they are messages, not replies. */
.msg.assistant:not(.is-error) .msg-body {
  background: transparent;
  border: 0;
  border-radius: 0;
  padding: 0;
}
.msg.user .msg-tag { text-align: right; }
/* A failed request stays in the transcript, so mark it as not-a-reply. */
.msg.is-error .msg-body {
  background: var(--danger-surface);
  border-color: var(--danger);
}
.msg.is-error .msg-content strong { color: var(--danger-ink); }
/* A dropped connection is not the player's mistake, so it is amber rather
   than the red used for rejected or failed requests. */
.msg.is-error.is-network .msg-body {
  background: var(--warn-bg);
  border-color: var(--warn-line);
}
.msg.is-error.is-network .msg-content strong { color: var(--warn-ink); }

.msg-images { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.msg-images img {
  width: 140px;
  max-height: 140px;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: block;
}

/* A video reference is one chip in the transcript — first frame plus a stat
   line — not a gallery of its frames. */
.msg-videos { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.msg-video {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 340px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}
.msg-video img { width: 64px; height: 48px; object-fit: cover; border-radius: 5px; display: block; }
.msg-video-meta { font-size: 11px; color: var(--ink-soft); line-height: 1.35; }

.msg-tag {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin: 0 0 5px;
}

.msg-body p { margin: 0 0 8px; }
.msg-body p:last-child { margin-bottom: 0; }
.msg-body h1, .msg-body h2, .msg-body h3, .msg-body h4 { margin: 12px 0 5px; line-height: 1.25; font-weight: 700; }
.msg-body h1 { font-size: 17px; } .msg-body h2 { font-size: 16px; } .msg-body h3 { font-size: 15px; }
.msg-body ul, .msg-body ol { margin: 7px 0; padding-left: 22px; }
.msg-body li { margin: 3px 0; }
.msg-body strong { color: var(--season-ink); }
.msg-body blockquote {
  border-left: 3px solid var(--focus);
  margin: 8px 0;
  padding: 3px 10px;
  color: var(--ink-soft);
  background: var(--quote-bg);
}
.msg-body code {
  font-family: var(--font-mono);
  font-size: 12.5px;
  background: var(--paper-2);
  border: 1.5px solid var(--line-soft);
  padding: 1px 5px;
  border-radius: 5px;
}
.msg-body pre {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 13px;
  overflow-x: auto;
  margin: 10px 0;
  /* The block the generator receives is prose, not code — let it wrap like
     prose instead of forcing a horizontal scrollbar. */
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg-body pre code {
  background: none;
  border: none;
  padding: 0;
  /* The prompt itself reads in the product's body face: it is the deliverable,
     not a listing. Monospace stays for short inline code only. */
  font-family: var(--font-sans);
  font-size: 13.5px;
  line-height: 1.65;
}

/* The generated prompt is the deliverable, so it keeps a framed block even
   though the reply around it is unboxed. Its header bar is part of the block:
   the label on the left, the copy control on the right. */
.prompt-block {
  margin: 10px 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  overflow: hidden;
}
.prompt-block-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 5px 7px 5px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}
.prompt-block-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.prompt-block pre {
  margin: 0;
  border: 0;
  border-radius: 0;
  background: var(--surface);
}

/* One icon, one action: copy the prompt it sits beside. Inside a block it is
   part of the header; a reply with no block falls back to a small control under
   the prose (see the direct-child rule below). */
.msg-copy,
.msg-retry {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
  color: var(--ink-soft);
  cursor: pointer;
  transition: color 0.12s ease, background 0.12s ease, transform 0.12s ease;
}
.msg-copy:hover,
.msg-retry:hover { background: var(--paper-2); color: var(--ink); }
.msg-copy:active,
.msg-retry:active { transform: translate(1px, 1px); }
.msg-copy:focus-visible,
.msg-retry:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.msg-copy.copied { color: var(--ink); background: var(--season); border-color: var(--season-ink); }
.msg-copy svg,
.msg-retry svg { width: 13px; height: 13px; display: block; }

/* The reply's footer. Retry is on every reply; the fallback copy control joins
   it when a fence could not be decorated. Right-aligned under the text in a
   single row, so two controls never stack into two lonely rows. */
.msg-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin: 8px 0 0 auto;
}

/* Edit mirrors the copy control's placement but sits top-LEFT: user bubbles
   flow right, so the right corner is where their text runs out. */
.msg-edit {
  position: absolute;
  top: -12px;
  left: -12px;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink-soft);
  cursor: pointer;
  transition: color 0.12s ease, background 0.12s ease, transform 0.12s ease;
}
.msg-edit:hover { background: var(--paper-2); color: var(--ink); }
.msg-edit:active { transform: translate(1px, 1px); }
.msg-edit:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.msg-edit svg { width: 13px; height: 13px; display: block; }

/* The draft replaces the bubble's text in place, so it inherits the bubble's
   width rather than being a separate card floating below it. */
.msg-edit-panel { display: flex; flex-direction: column; gap: 8px; }
.msg-edit-input {
  width: 100%;
  min-height: 62px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  line-height: 1.5;
  resize: vertical;
}
.msg-edit-input:focus { outline: 3px solid var(--focus); outline-offset: 2px; }
.msg-edit-row { display: flex; justify-content: flex-end; gap: 8px; }
/* .pixel-btn is full-width by default, which would stretch both actions across
   the bubble; these are inline buttons sized to their labels. */
.msg-edit-save, .msg-edit-cancel { width: auto; padding: 6px 12px; font-size: 12px; }
.msg-edit-save { background: var(--season); }

/* A reply the player stopped: kept for the record, but visibly incomplete. */
.msg-stopped {
  margin-top: 7px;
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

/* streaming */

/* A highlight sweeps across the line while the AI is thinking. The text is
   transparent with the gradient clipped to it, which is what makes the sheen
   travel across the glyphs rather than across a box. */
.loading-line {
  font-size: 14px;
  font-weight: 500;
  color: var(--ink-soft);
  min-height: 1.5em;
}
.shimmer {
  background-image: linear-gradient(
    100deg,
    var(--ink-soft) 0%,
    var(--ink-soft) 35%,
    var(--season-ink) 50%,
    var(--ink-soft) 65%,
    var(--ink-soft) 100%
  );
  background-size: 220% 100%;
  background-position: 120% 0;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
  animation: shimmer-sweep 2.2s linear infinite;
}

@keyframes shimmer-sweep {
  from { background-position: 120% 0; }
  to { background-position: -120% 0; }
}

/* The bubble being written to right now. Dimmed slightly so it reads as
   provisional next to settled replies, with a blinking caret on the last
   line. The caret only exists during streaming, so it disappears the moment
   generation stops. */
.msg.streaming .msg-body { opacity: 0.92; }
.streaming-text::after {
  content: "";
  display: inline-block;
  width: 7px;
  height: 14px;
  margin-left: 3px;
  vertical-align: -2px;
  background: var(--season-ink);
  animation: caret-blink 1s steps(2, start) infinite;
}
@keyframes caret-blink { 0%, 100% { opacity: 0; } 50% { opacity: 1; } }

/* When the stream ends the bubble settles: the caret is gone and the text
   fades up into its final styling instead of snapping. */
.msg.settled .msg-body {
  animation: settle-in 420ms cubic-bezier(0.22, 1, 0.36, 1) both;
}
@keyframes settle-in {
  from { opacity: 0.55; transform: translateY(2px); }
  to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .streaming-text::after { animation: none; opacity: 1; }
  .msg.settled .msg-body { animation: none; }
  /* No sweep: fall back to plain dimmed text, still legible. */
  .shimmer {
    animation: none;
    background: none;
    color: var(--ink-soft);
    -webkit-text-fill-color: currentColor;
  }
  /* The pool card keeps its placeholders and "checking" badge; the sweep is
     the only thing motion would add, so it is dropped. */
  .pool-card.is-loading::after { animation: none; opacity: 0; }
  .drop-card { animation: none; }
}

/* clickable planning choices */
.choices-panel {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-top: 1px dashed var(--line-soft);
  padding-top: 10px;
}
.choices-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.choices-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}
.choices-progress {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
  background: var(--paper-2);
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  padding: 1px 8px;
}
.choices-progress.complete {
  color: var(--ink);
  background: var(--season);
  border-color: var(--season-ink);
}
.choices-group { display: flex; flex-direction: column; gap: 6px; }
.choices-group.is-answered .choices-label { color: var(--ink); }
.choices-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
}

/* native select, styled to match the pixel chips */
.choice-select-wrap { position: relative; display: block; }
.choice-select {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 8px;
  padding: 8px 34px 8px 11px;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.12s ease, background 0.12s ease;
}
.choice-select:hover { background: var(--paper-2); }
.choice-select:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}
.choices-group.is-answered .choice-select {
  border-color: var(--season-ink);
  background: var(--season);
}
.choice-caret {
  position: absolute;
  right: 12px;
  top: 50%;
  width: 9px;
  height: 9px;
  margin-top: -6px;
  border-right: 1px solid var(--ink-soft);
  border-bottom: 1px solid var(--ink-soft);
  transform: rotate(45deg);
  pointer-events: none;
}

.choice-hint {
  font-size: 12px;
  line-height: 1.35;
  color: var(--ink-soft);
  padding: 0 2px;
}
.choice-hint[hidden] { display: none; }

.choices-options { display: flex; flex-wrap: wrap; gap: 7px; }
.choice-btn {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 999px;
  padding: 6px 12px;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, transform 0.12s ease;
}
.choice-btn:hover { background: var(--paper-2); }
.choice-btn:active { transform: translate(1px, 1px); }
.choice-btn:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}
.choice-btn.selected { background: var(--season); border-color: var(--season-ink); }

/* The per-question free-text escape hatch. Styled as a chip so it reads as one
   more option, but dashed to mark it as the player's own rather than yours. */
.choice-btn-custom {
  border-style: dashed;
  color: var(--ink-soft);
}
.choice-btn-custom:hover { color: var(--ink); }
.choice-btn-custom.selected {
  background: var(--paper-2);
  border-color: var(--season-ink);
  border-style: solid;
  color: var(--ink);
}
.choice-custom { margin-top: 2px; }
.choice-custom[hidden] { display: none; }
.choice-custom-input {
  width: 100%;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 8px 11px;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
}
.choice-custom-input::placeholder { color: var(--ink-soft); font-weight: 400; }
.choice-custom-input:focus {
  outline: none;
  border-style: solid;
  border-color: var(--season-ink);
  background: var(--paper);
}
.choice-custom-input:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.choices-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.choices-clear {
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink-soft);
  border-radius: 8px;
  padding: 7px 10px;
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.choices-clear:hover { background: var(--paper-2); border-color: var(--line-soft); }
.choices-clear:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.choices-send {
  border: 1px solid var(--line);
  background: var(--season);
  color: var(--ink);
  border-radius: 8px;
  padding: 7px 12px;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.choices-send:focus-visible { outline: 3px solid var(--ink-soft); outline-offset: 2px; }
.choices-send:active { transform: translate(1px, 1px); }
.choices-send:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Reference image picker ---------- */
/* The strip the AI's [refs] lookup fills. Same family as the choices panel:
   dashed top rule, small-caps title, chips that answer. */
.refs-panel {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-top: 1px dashed var(--line-soft);
  padding-top: 10px;
}
.refs-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}
.refs-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.refs-note {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
}
.refs-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.refs-item {
  position: relative;
  width: 96px;
  height: 96px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.12s ease, transform 0.12s ease;
}
.refs-item:hover { border-color: var(--ink-soft); }
.refs-item:active { transform: translate(1px, 1px); }
.refs-item:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}
.refs-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
/* The license badge sits on the image, so attribution is visible without a
   hover — tooltips alone would hide it on touch screens. */
.refs-item-label {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 2px 5px;
  font-family: var(--font-sans);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: #fff;
  background: rgba(0, 0, 0, 0.55);
  text-align: left;
  pointer-events: none;
}
/* The picked image: the strip keeps its place in the transcript, marked as
   used rather than removed, so history still shows what was chosen. */
.refs-item.used {
  border-color: var(--season-ink);
}
.refs-item.used::after {
  content: '✓';
  position: absolute;
  top: 4px;
  right: 4px;
  width: 18px;
  height: 18px;
  line-height: 18px;
  text-align: center;
  border-radius: 50%;
  background: var(--season);
  color: var(--ink);
  font-size: 11px;
  font-weight: 700;
}
.refs-item:disabled {
  cursor: wait;
  opacity: 0.7;
}

/* A prompt over the generator's 4,096-character box: a warning, not an error —
   the reply is still useful, it just will not fit. */
.msg-prompt-warn {
  margin-top: 8px;
  padding: 6px 8px;
  border-left: 3px solid var(--danger);
  background: var(--paper);
  font-size: 11.5px;
  line-height: 1.4;
  color: var(--ink-soft);
}

/* The live readout of how long the generated prompt is against the generator's
   4,096-character box. It sits under the reply and stays quiet until it matters:
   amber inside the last 10% of the budget, red once the block is over the limit.
   Only rendered when the reply carries a prompt block, so plain answers show
   nothing. */
.msg-charcount {
  margin-top: 8px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.02em;
  color: var(--ink-soft);
}
.msg-charcount[hidden] { display: none; }
.msg-charcount.full { color: var(--warn-ink-soft); }
.msg-charcount.over { color: var(--danger-ink-strong); font-weight: 700; }

/* ---------- Drop zone ---------- */
/* Covers the chat column while files are dragged over the window. Pointer
   events off so the drop still lands on whatever is underneath. */
.drop-veil {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: none;
  align-items: center;
  justify-content: center;
  background: var(--veil);
  backdrop-filter: blur(2px);
}
.drop-veil.on { display: flex; }

.drop-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 20px;
  border: 1px dashed var(--season-ink);
  border-radius: 12px;
  background: var(--paper);
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow-pop-soft);
  animation: drop-pop 160ms ease both;
}
.drop-card .pix-ico { width: 14px; height: 14px; color: var(--season-ink); }

@keyframes drop-pop {
  from { transform: scale(0.96); opacity: 0; }
  to { transform: none; opacity: 1; }
}

body.dragging .attach-btn { border-color: var(--season-ink); background: var(--paper-2); }

/* ---------- Composer ---------- */
.composer-wrap {
  position: sticky;
  bottom: 0;
  z-index: 2;
  flex: 0 0 auto;
  padding: 8px 20px 14px;
  background: var(--composer-wrap);
}
body.empty-chat .composer-wrap {
  position: static;
  background: none;
  padding: 6px 20px 24px;
}
.composer {
  max-width: 860px;
  min-width: 0;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 7px 8px 7px 14px;
}
body.empty-chat .composer { max-width: 560px; padding: 6px 8px 6px 12px; }
body.empty-chat .composer textarea { font-size: 14px; }
.composer textarea {
  flex: 1;
  /* Without this a flex item refuses to shrink below its content width, so
     typing a long unbroken string (a URL, aaaaa...) widens the composer and
     the whole page scrolls sideways. This is the overflow-while-typing bug. */
  min-width: 0;
  resize: none;
  border: none;
  outline: none;
  background: transparent;
  color: var(--ink);
  font-size: 15px;
  line-height: 1.4;
  /* Height is owned by autoGrow() (capped at 150px), so the box grows to fit its
     text instead of scrolling. The scrollbar is shown only when the cap is
     actually reached — see autoGrow, which flips overflowY to `auto` there.
     `hidden` in the normal state is what removes the needless inner scrollbar:
     a textarea is `overflow:auto` by default, so a placeholder that wrapped to
     two lines made the empty box scrollable. */
  overflow-y: hidden;
}
.composer textarea::placeholder { color: var(--ink-soft); }
/* Length readout, sitting inside the box between the text and the send button.
   It is a flex sibling rather than an absolutely-positioned overlay, so it can
   never cover the send button or the caret. Hidden in normal use: a short brief
   has nothing worth reporting, so it only appears once the text passes 5,000
   characters (`show-count`, toggled by updateCharCount).
   It is `display: none` rather than `opacity: 0` on purpose: the readout always
   carries text ("0 / 6,000"), so leaving it in the layout stole ~90px of the
   composer — on a phone that squeezed the textarea to ~145px, wrapping the
   placeholder onto a second line and stranding the text in a narrow column. */
.char-count {
  display: none;
  flex: 0 0 auto;
  align-self: flex-end;
  padding-bottom: 1px;
  font-family: var(--font-mono);
  color: var(--ink-soft);
  font-size: 11px;
  line-height: 1;
  letter-spacing: 0.02em;
  pointer-events: none;
  user-select: none;
}
.composer.show-count .char-count { display: block; }
/* Warn before the ceiling is actually reached, and mark it clearly once it is.
   The same warm amber the low-pool state uses, so "nearly full" and "running
   out" read as the same kind of news. */
.composer.near-limit .char-count { color: var(--warn-ink-soft); }
.composer.at-limit .char-count { color: var(--danger-ink-strong); font-weight: 700; }
.send-btn {
  flex: 0 0 auto;
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--season);
  color: var(--ink);
  cursor: pointer;
}
.send-btn:hover { background: var(--season-2); }
.send-btn:active { transform: translate(1px, 1px); }
.send-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.attach-btn {
  flex: 0 0 auto;
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}
.attach-btn:hover { background: var(--paper-2); }
.attach-btn:active { transform: translate(1px, 1px); }
/* The + button's menu: one control, two kinds of file. Fixed-positioned and
   appended to <body> (like the chat row's menu) so the composer can't clip it,
   and flipped above the button because the composer lives at the bottom. */
.attach-menu {
  position: fixed;
  z-index: 90;
  min-width: 216px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px;
  box-shadow: var(--shadow-pop);
}
.attach-menu-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  padding: 7px 9px;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.attach-menu-item:hover { background: var(--paper-2); }
.attach-menu-item:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.attach-menu-ico { flex: 0 0 auto; }
.attach-menu-text { min-width: 0; }
.attach-menu-hint {
  display: block;
  margin-top: 1px;
  font-size: 11px;
  font-weight: 400;
  color: var(--ink-soft);
}
/* Voice input. The mic sits between the text and the send button, in the same
   box as the other two controls, and is only shown when speech-to-text is
   actually configured (see applyVoiceAvailability in app.js). While a recording
   runs it carries `.recording`: a tinted face and a pulse that says "the mic is
   open" without the button ever changing shape. */
.mic-btn {
  position: relative;
  flex: 0 0 auto;
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}
.mic-btn[hidden] { display: none; }
.mic-btn:hover { background: var(--paper-2); }
.mic-btn:active { transform: translate(1px, 1px); }
.mic-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.mic-btn.recording {
  background: var(--season);
  border-color: var(--season-ink);
  color: var(--ink);
  animation: mic-pulse 1.6s ease-in-out infinite;
}
/* A ring that breathes outward, not a colour swap: it stays legible in every
   season and does not compete with the voice-note bars below. */
@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(var(--pulse), 0.45); }
  50% { box-shadow: 0 0 0 5px rgba(var(--pulse), 0); }
}

/* The voice-note chip, sitting above the composer like the image previews.
   Right-aligned so it hugs the controls rather than the page edge, and width-
   capped to match the composer in both its normal and empty-chat states. */
.voice-note {
  max-width: 860px;
  margin: 0 auto 8px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 6px 8px 6px 12px;
  border: 1px solid var(--season-ink);
  border-radius: 999px;
  background: var(--paper);
  animation: voice-note-in 160ms ease both;
}
.voice-note[hidden] { display: none; }
body.empty-chat .voice-note { max-width: 560px; margin-bottom: 6px; }
@keyframes voice-note-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

/* The bars are the animation: five chunky pixel-art columns whose height is
   driven by the microphone's own level, so the chip moves with the voice rather
   than looping regardless of it. `scaleY` keeps the row's layout still. */
.voice-bars {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 3px;
  height: 18px;
}
.voice-bars span {
  width: 3px;
  height: 16px;
  border-radius: 1px;
  background: var(--season-ink);
  transform: scaleY(0.18);
  transform-origin: center;
}
.voice-time {
  flex: 0 0 auto;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink);
  letter-spacing: 0.02em;
}
.voice-status {
  flex: 0 0 auto;
  font-size: 12px;
  color: var(--ink-soft);
}
/* Transcribing lags the recording: the words for the last chunk are still
   coming back. The label says so instead of leaving a stalled-looking chip. */
.voice-note.working .voice-status { color: var(--season-ink); }
.voice-cancel {
  flex: 0 0 auto;
  width: 22px; height: 22px;
  display: grid; place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  color: var(--ink);
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
}
.voice-cancel:hover { background: var(--paper-2); }
.voice-cancel:active { transform: translate(1px, 1px); }
/* Previews track the composer's width in both states. They used to sit in a
   fixed 860px row while the empty-chat composer is only 560px wide, so the
   thumbnails spilled out past the text box on the empty-chat hero. Right
   aligned so the row hugs the send button rather than the page edge. */
.image-previews {
  max-width: 860px;
  margin: 0 auto 8px;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}
body.empty-chat .image-previews { max-width: 560px; margin-bottom: 6px; }
.preview-item {
  position: relative;
  width: 72px; height: 72px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
}
.preview-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
/* A video preview is a wider chip so its duration/frame stat fits, with the
   stat badged across the bottom of the first frame. */
.preview-item.video { width: 132px; }
.preview-badge {
  position: absolute;
  left: 2px; right: 2px; bottom: 2px;
  padding: 2px 4px;
  border-radius: 5px;
  background: rgba(20, 20, 20, 0.72);
  color: #fff;
  font-size: 10px;
  line-height: 1.2;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.preview-del {
  position: absolute;
  top: 2px; right: 2px;
  width: 20px; height: 20px;
  display: grid; place-items: center;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--thumb-close);
  color: var(--ink);
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}
.composer-hint {
  max-width: 860px;
  margin: 6px auto 0;
  text-align: center;
  color: var(--ink-soft);
  font-size: 12px;
}
body.empty-chat .composer-hint { display: none; }

/* On narrow screens the sidebar is hidden, so the legal links move under the
   composer instead of becoming unreachable. */
.composer-legal {
  display: none;
  max-width: 860px;
  margin: 8px auto 0;
  justify-content: center;
  gap: 7px;
  font-size: 11px;
  color: var(--ink-soft);
  opacity: 0.75;
}
.composer-legal a { color: inherit; text-decoration: none; border-bottom: 1px dotted var(--line); }
.composer-legal a:hover { color: var(--ink); border-bottom-style: solid; }

/* The settings row is the last control in the chat-list column: a full-width
   quiet button, with the current appearance as a small trailing hint. */
.settings-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}
.settings-btn:hover { background: var(--paper-2); }
.settings-btn .pix-ico { color: var(--ink-soft); }
.settings-btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.settings-hint { margin-left: auto; font-size: 10px; font-weight: 500; color: var(--ink-soft); }

/* Legal links, tucked under the status dot. Small and dotted so they read as
   an afterthought rather than a call to action. */
.sidebar-legal {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11px;
  color: var(--ink-soft);
  opacity: 0.75;
  transition: opacity 0.15s ease;
}
.sidebar-legal:hover { opacity: 1; }
.sidebar-legal a {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px dotted var(--line);
}
.sidebar-legal a:hover { color: var(--ink); border-bottom-style: solid; }
.sidebar-legal a:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: var(--modal-veil);
  display: flex; align-items: center; justify-content: center;
  padding: 20px; z-index: 50;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  width: min(520px, 100%);
  max-height: 84vh;
  overflow-y: auto;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
}
.modal-head { display: flex; justify-content: space-between; align-items: center; }
.modal-head h2 { margin: 0; font-family: var(--font-display); font-weight: 600; font-size: 16px; letter-spacing: 0.01em; }
.modal-title { display: flex; align-items: center; gap: 8px; }
.close-btn {
  width: 30px; height: 30px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  font-size: 14px;
  cursor: pointer;
}
/* ---------- Settings modal ---------- */
.modal.settings { width: min(440px, 100%); }
.settings-body { margin-top: 12px; }
.settings-sub {
  margin: 0 0 8px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.theme-options { display: flex; flex-direction: column; gap: 8px; }
.theme-option {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}
.theme-option:hover { background: var(--paper-2); }
.theme-option.is-active { border-color: var(--season-ink); background: var(--paper-2); }
.theme-option:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.theme-option-icon {
  width: 30px; height: 30px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink-soft);
}
.theme-option.is-active .theme-option-icon { color: var(--season-ink); border-color: var(--season-ink); }
.theme-option-icon svg { width: 15px; height: 15px; display: block; }
.theme-option-copy { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.theme-option-copy strong { font-size: 12.5px; font-weight: 700; }
.theme-option-copy span { font-size: 10.5px; line-height: 1.35; color: var(--ink-soft); }
.theme-check {
  margin-left: auto;
  width: 18px; height: 18px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 999px;
  color: var(--season-ink);
  font-size: 12px;
  font-weight: 700;
  opacity: 0;
}
.theme-option.is-active .theme-check { opacity: 1; }
.settings-note { margin: 12px 0 0; font-size: 10.5px; line-height: 1.45; color: var(--ink-soft); }
.settings-note strong { color: var(--ink); }
/* ---------- Templates modal ---------- */
.modal.templates { width: min(560px, 100%); }
.templates-body { margin-top: 10px; }
.templates-sub {
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1.5;
  margin: 0 0 10px;
}
.templates-search {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 13px;
  margin-bottom: 12px;
}
.templates-search:focus { outline: 2px solid var(--season-ink); outline-offset: 1px; }
.templates-list { display: flex; flex-direction: column; gap: 12px; }
.tpl-group-title {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 6px;
}
.tpl-group .tpl-row + .tpl-row { margin-top: 6px; }
.tpl-row {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font-sans);
  cursor: pointer;
}
.tpl-row:hover { border-color: var(--season-ink); background: var(--paper); }
.tpl-row:active { transform: translate(1px, 1px); }
.tpl-row-name { font-weight: 700; font-size: 13px; }
.tpl-row-desc { font-size: 11.5px; line-height: 1.4; color: var(--ink-soft); }
.templates-empty {
  color: var(--ink-soft);
  font-size: 13px;
  text-align: center;
  padding: 12px 0;
}

.notes-body { margin-top: 10px; }
.notes-sub { color: var(--ink-soft); font-size: 13px; margin: 0 0 12px; }
.notes-list { display: flex; flex-direction: column; gap: 8px; }
.note-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
}
.note-num { font-size: 10px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-soft); margin-bottom: 4px; }
.note-text { font-size: 14px; line-height: 1.45; word-break: break-word; }
.note-image {
  margin-top: 8px;
  max-width: 180px;
  max-height: 180px;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: block;
}
.note-del {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 6px;
  padding: 3px 7px;
  font-size: 13px;
  cursor: pointer;
}
.notes-empty { color: var(--ink-soft); font-size: 14px; }

/* ---------- Disclaimer gate ---------- */
/* Deliberately plainer than the rest of the UI: it is a legal notice, and
   dressing it up would work against the point. */
.disclaimer { width: min(480px, 100%); }
.disclaimer-body p {
  margin: 10px 0 0;
  font-size: 13px;
  line-height: 1.6;
  color: var(--ink);
}
.disclaimer-body p + p { margin-top: 9px; }
.disclaimer-link { font-weight: 600; }
.disclaimer-agree {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  margin-top: 14px;
  padding: 10px 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  font-size: 12.5px;
  line-height: 1.5;
  cursor: pointer;
}
.disclaimer-agree:hover { background: var(--paper-2); }
/* The native checkbox is kept rather than replaced with a div: it is keyboard
   operable, announces its state, and needs no ARIA to be correct. */
.disclaimer-agree input {
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  margin: 1px 0 0;
  accent-color: var(--good);
  cursor: pointer;
}
.disclaimer-agree a { color: inherit; font-weight: 600; }
.disclaimer-actions { margin-top: 12px; }
/* .pixel-btn is full-width and left-aligned by default; this is an action row. */
.disclaimer-ok {
  width: 100%;
  justify-content: center;
  background: var(--season);
  font-size: 13px;
}
.disclaimer-ok:disabled { opacity: 0.45; cursor: not-allowed; }
.disclaimer-ok:disabled:hover { background: var(--season); }

/* ---------- "Sorry for the inconvenience" notice ---------- */
.sorry { width: min(440px, 100%); }
.sorry-body p {
  margin: 10px 0 0;
  font-size: 13px;
  line-height: 1.6;
  color: var(--ink);
}

/* ---------- Toast ---------- */
/* Drops from the top edge: the composer owns the bottom of the screen, and a
   toast down there competes with the send button. */
.toast {
  position: fixed;
  left: 50%;
  top: 14px;
  transform: translate(-50%, -14px);
  background: var(--ink);
  color: var(--paper);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 600;
  /* A fixed element is not clipped by the body's overflow, so a long message
     would widen the page on its own. Cap it and let it wrap. */
  max-width: min(420px, calc(100vw - 24px));
  text-align: center;
  line-height: 1.35;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 80;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Responsive ---------- */
/* The mobile drawer backdrop is inert on desktop. */
.drawer-scrim { display: none; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .messages { padding: 16px 12px 24px; }
  .composer-wrap { padding: 8px 12px 14px; }
  .hero-line { font-size: 22px; }
  .composer-legal { display: flex; }

  /* Header: the season line is decorative and was the thing forcing the title
     onto three lines at this width. Drop it, tighten the gaps, and let the
     title truncate instead of wrapping. */
  .topbar { height: 56px; }
  .topbar-content { padding: 8px 12px; gap: 8px; }
  .topbar-lead { gap: 8px; flex: 1 1 auto; }
  .topbar h1 { font-size: 13px; }
  .topbar p { display: none; }

  /* Off-canvas drawer. The backdrop is a real element so it is part of the
     hit area: a tap meant to dismiss the drawer lands on the scrim and the
     document handler closes it, instead of falling through to a template in
     the chat behind and filling the prompt. */
  .drawer-scrim {
    position: fixed;
    inset: 0;
    z-index: 45;
    display: none;
    background: var(--drawer-veil);
    touch-action: none;
  }
  body.sidebar-open .drawer-scrim { display: block; }
  body.sidebar-open .sidebar {
    display: flex;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(300px, 84vw);
    z-index: 70;
    animation: drawer-in 180ms cubic-bezier(0.22, 1, 0.36, 1) both;
  }
}

@keyframes drawer-in {
  from { transform: translateX(-100%); }
  to { transform: none; }
}

/* No mobile override needed: the collapsed rule above is already a single 1fr,
   which is what the mobile layout uses whether or not the drawer is open. A
   fixed-position drawer is out of flow, so it is not a grid item either. */

@media (prefers-reduced-motion: reduce) {
  .drawer-in, body.sidebar-open .sidebar { animation: none; }
  /* The voice controls are the other moving thing in the composer. The clock
     and the "Listening…" / "Transcribing…" words still say what is happening,
     so stopping the pulse and the chip's entrance costs no information. */
  .mic-btn.recording { animation: none; }
  .voice-note { animation: none; }
}