:root {
  --green: #4dff9b; --dim: #2e8b5a; --bright: #c9ffe4; --bg: #04120a; --panel: #071a0f;
  --rgb: 77, 255, 155; --danger: #ff5a5a; --warn: #ffc24d;
  --font: "DejaVu Sans Mono", ui-monospace, Menlo, Consolas, monospace;
}
/* Phosphor themes — same palette names as the Pi kiosk so both heads can wear the same colour.
   Set on <html> by a tiny script in <head> (before first paint, so there's no flash of the old
   colour) and remembered in localStorage. The background is tinted to match, or cyan text over a
   green-tinted black reads muddy. */
:root[data-theme="cyan"]    { --green: #4de6ff; --dim: #2e7c8b; --bright: #c4f6ff; --bg: #041216; --panel: #07181f; --rgb: 77, 230, 255; }
:root[data-theme="amber"]   { --green: #ffc24d; --dim: #8b6a2e; --bright: #ffe9b0; --bg: #121004; --panel: #1a1607; --rgb: 255, 194, 77; }
:root[data-theme="magenta"] { --green: #ff6ec7; --dim: #8b3f6d; --bright: #ffc4e8; --bg: #120410; --panel: #1a0718; --rgb: 255, 110, 199; }
:root[data-theme="blue"]    { --green: #6ea8ff; --dim: #3f5f8b; --bright: #c4d8ff; --bg: #04091a; --panel: #070f22; --rgb: 110, 168, 255; }
:root[data-theme="white"]   { --green: #cfe6ff; --dim: #7d8a99; --bright: #ffffff; --bg: #090d11; --panel: #10161c; --rgb: 207, 230, 255; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
.hidden { display: none !important; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--green); font-family: var(--font);
  display: flex; flex-direction: column; height: 100dvh; -webkit-text-size-adjust: 100%; }

/* header */
header { display: flex; align-items: center; gap: 10px; padding: 10px 14px;
  border-bottom: 1px solid rgba(var(--rgb), 0.3); background: var(--panel); flex-shrink: 0; }
.brand { font-weight: 700; color: var(--bright); letter-spacing: 1px; flex: 1; font-size: 15px; }
.iconbtn { font-family: var(--font); font-size: 17px; background: transparent; color: var(--green);
  border: 1px solid rgba(var(--rgb), 0.4); border-radius: 8px; padding: 4px 11px; cursor: pointer; }
.iconbtn:active { background: rgba(var(--rgb), 0.2); }
.syncdot { width: 9px; height: 9px; border-radius: 50%; background: var(--dim); }
.syncdot.ok { background: var(--green); box-shadow: 0 0 6px var(--green); }
.syncdot.pending { background: var(--warn); box-shadow: 0 0 6px var(--warn); }
.syncdot.err { background: var(--danger); box-shadow: 0 0 6px var(--danger); }

/* screens */
.screen { flex: 1; overflow-y: auto; display: flex; flex-direction: column;
  width: 100%; max-width: 860px; margin: 0 auto; }
.screen.hidden { display: none; }
.screen-head { display: flex; align-items: center; gap: 10px; padding: 14px 14px 6px; }
.screen-head h1 { font-size: 20px; margin: 0; flex: 1; color: var(--bright); letter-spacing: 1px; }

/* home tiles */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; padding: 14px; }
@media (min-width: 620px) { .tiles { grid-template-columns: repeat(3, 1fr); } }
.tile { background: var(--panel); border: 1px solid rgba(var(--rgb), 0.3); border-radius: 12px;
  padding: 14px; text-align: left; font-family: var(--font); color: var(--green); cursor: pointer;
  min-height: 84px; display: flex; flex-direction: column; gap: 3px; }
.tile:active { background: rgba(var(--rgb), 0.12); }
.tile.primary { border-color: var(--green); background: rgba(var(--rgb), 0.14); grid-column: span 2; min-height: 64px; }
.tile.wide { grid-column: 1 / -1; min-height: 0; }
.tile-label { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--dim); }
.tile-num { font-size: 26px; font-weight: 700; color: var(--bright); }
.tile-num.txt { font-size: 17px; }
.tile-sub { font-size: 12px; color: var(--dim); line-height: 1.35; }

/* chat */
.log { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 13px; }
.empty { color: var(--dim); text-align: center; margin: auto; line-height: 1.6; font-size: 14px; padding: 20px; }
.msg { display: flex; flex-direction: column; gap: 4px; max-width: 92%; }
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.buddy { align-self: flex-start; }
.bubble { padding: 10px 13px; border-radius: 12px; white-space: pre-wrap; line-height: 1.5; font-size: 15px; }
.msg.user .bubble { background: rgba(var(--rgb), 0.16); color: var(--bright); border: 1px solid rgba(var(--rgb), 0.4); }
.msg.buddy .bubble { background: var(--panel); border: 1px solid rgba(var(--rgb), 0.25); }
.bubble.thinking { color: var(--dim); }
.meta { font-size: 10px; color: var(--dim); text-transform: uppercase; letter-spacing: 1px; }
.frame-strip { display: flex; gap: 6px; flex-wrap: wrap; }
.frame-thumb { max-width: 130px; max-height: 100px; border: 1px solid var(--green); border-radius: 5px; }
.inv-actions { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; }
.inv-lead { font-size: 10px; text-transform: uppercase; letter-spacing: 1px; color: var(--dim); }
.inv-chip { font-size: 12px; padding: 2px 8px; border-radius: 10px; border: 1px solid var(--green);
  color: var(--bright); background: rgba(var(--rgb), 0.16); }

/* composer */
/* Two rows: the message field spans the FULL width on its own line, controls sit beneath it.
   Sharing a line with the buttons squeezed the text to ~12 characters — unreadable for the long
   questions this field exists to hold. */
.composer { display: flex; flex-wrap: wrap; gap: 7px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid rgba(var(--rgb), 0.3); background: var(--panel); align-items: center; flex-shrink: 0; }
/* Right-hand thumb cluster: [flip] [mic] [Send]. The auto margin belongs to whichever of them
   comes first, so it moves to flip when the camera is live and back to the mic when it isn't —
   otherwise two auto margins split the gap and strand flip in the middle. */
.composer #talk { margin-left: auto; }
.composer #camflip { margin-left: auto; }
.composer #camflip:not(.hidden) ~ #talk { margin-left: 0; }
/* speaker state, inline beside its button — it used to be a toast that landed on the text box */
.speak-flag { font-size: 12px; color: var(--green); letter-spacing: 0.5px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; min-width: 0; animation: flag-in 0.18s ease-out; }
.speak-flag.hidden { display: none; }

/* pedal bindings (Settings) */
.pedal-row { display: flex; align-items: center; gap: 7px; margin-bottom: 6px; }
.pedal-key { flex-shrink: 0; min-width: 74px; font-size: 13px; color: var(--bright); }
.pedal-row select { flex: 1; min-width: 0; font-size: 13px; padding: 7px; }
.pedal-row .qbtn { flex-shrink: 0; }

/* theme swatches (Settings) */
.swatches { display: flex; flex-wrap: wrap; gap: 9px; }
.swatch { width: 40px; height: 40px; border-radius: 50%; cursor: pointer; padding: 0;
  border: 2px solid rgba(var(--rgb), 0.35); background: var(--sw); position: relative; }
.swatch.on { border-color: var(--bright); box-shadow: 0 0 0 3px rgba(var(--rgb), 0.25); }
.swatch.on::after { content: "✓"; position: absolute; inset: 0; display: grid; place-items: center;
  color: #04120a; font-weight: 700; font-size: 17px; }

/* usage + cost breakdown (Settings) */
.usage-models { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.usage-head { color: var(--dim); font-size: 12px; letter-spacing: 0.5px; margin-top: 4px; }
.usage-row { display: flex; align-items: baseline; gap: 8px; }
.usage-model { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.usage-tok { color: var(--dim); font-size: 12px; white-space: nowrap; }
.usage-row b { color: var(--bright); font-weight: 400; white-space: nowrap; }
.usage-row { cursor: pointer; }
.price-edit { border: 1px dashed rgba(var(--rgb), 0.4); border-radius: 9px; padding: 9px; margin: 4px 0; }
.price-fields { display: flex; gap: 6px; align-items: center; margin-top: 6px; }
.price-fields input { flex: 1; min-width: 0; padding: 7px; font-size: 15px; }
.price-fields .menu-btn { flex-shrink: 0; padding: 7px 10px; font-size: 13px; }
.hint.warn { color: var(--warn); }
@keyframes flag-in { from { opacity: 0; transform: translateX(-4px); } to { opacity: 1; transform: none; } }
/* The message field grows with what you've typed (JS sets the height) and then scrolls, so a
   long question is fully readable and editable before you send it. 16px keeps iOS from zooming. */
.composer textarea { flex: 1 0 100%; min-width: 0; font-family: var(--font); font-size: 16px; padding: 11px;
  border-radius: 9px; background: rgba(var(--rgb), 0.07); color: var(--green); border: 1px solid rgba(var(--rgb), 0.4);
  resize: none; overflow-y: auto; line-height: 1.4; max-height: 40vh; display: block;
  min-height: 0; }   /* beat the global textarea min-height — this one starts at one line */
.composer button { font-family: var(--font); font-size: 15px; font-weight: 700; padding: 11px 13px;
  border-radius: 9px; background: rgba(var(--rgb), 0.16); color: var(--bright);
  border: 1px solid var(--green); cursor: pointer; }
.composer button.icon { padding: 10px 11px; line-height: 0; }
.composer button:disabled { opacity: 0.4; }
.composer button.on, .composer button.recording { background: var(--danger); border-color: var(--danger); color: #fff; }

/* icon buttons: stroke-drawn SVGs in currentColor (green idle, white-on-red when active) —
   deliberately NOT emoji, which render as colored bitmaps and fight the CRT look */
.composer button.icon svg { width: 21px; height: 21px; display: block; }
#talk svg.dot { display: none; }
#talk.recording svg.mic { display: none; }
#talk.recording svg.dot { display: block; }              /* held = a record dot, not a mic */
#speaker svg .x { display: none; }
#speaker:not(.on) svg .w { display: none; }              /* muted = slash instead of waves */
#speaker:not(.on) svg .x { display: block; }

/* The chat area doubles as the viewfinder: the feed fills it and messages sit on top. You're
   holding a part up to the camera, so the picture deserves the space — a thumbnail in the corner
   is the wrong way round. */
.stage { position: relative; flex: 1; min-height: 0; display: flex; }
.camstage { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
  background: #000; z-index: 0; animation: cam-in 0.22s ease-out; }
.camstage.hidden { display: none; }
@keyframes cam-in { from { opacity: 0; } to { opacity: 1; } }
/* Messages float above the feed. While it's live they need a solid backdrop — thin text over
   moving video is unreadable, and this is where answers land. */
.stage .log { position: relative; z-index: 1; }
.stage.live .bubble { background: rgba(2, 10, 8, 0.82); border: 1px solid rgba(var(--rgb), 0.45); }
.stage.live .msg.user .bubble { background: rgba(var(--rgb), 0.24); border-color: rgba(var(--rgb), 0.6); }
.stage.live .meta { color: var(--bright); text-shadow: 0 1px 3px #000; }
.stage.live .empty { display: none; }        /* don't cover the shot with placeholder copy */

/* lists / cards */
.list { display: flex; flex-direction: column; gap: 9px; padding: 10px 14px 30px; }
.card { background: var(--panel); border: 1px solid rgba(var(--rgb), 0.28); border-radius: 11px;
  padding: 13px; margin: 10px 14px; display: flex; flex-direction: column; gap: 8px; }
.label { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--dim); }
.hint { font-size: 12px; color: var(--dim); line-height: 1.45; }
.hint.pad { padding: 0 14px; }
.row { background: var(--panel); border: 1px solid rgba(var(--rgb), 0.28); border-radius: 10px; padding: 11px 13px; }
.row-top { display: flex; align-items: center; gap: 9px; }
.row-name { font-size: 15px; color: var(--bright); flex: 1; }
.row-sub { font-size: 12px; color: var(--dim); margin-top: 4px; line-height: 1.4; }
.qty { display: flex; align-items: center; gap: 7px; }
.qbtn { font-family: var(--font); font-size: 17px; width: 34px; height: 34px; border-radius: 8px;
  background: rgba(var(--rgb), 0.1); color: var(--green); border: 1px solid rgba(var(--rgb), 0.4); cursor: pointer; }
.qnum { min-width: 30px; text-align: center; font-size: 16px; color: var(--bright); }
.badge { font-size: 10px; text-transform: uppercase; letter-spacing: 1px; padding: 2px 7px;
  border-radius: 9px; border: 1px solid var(--dim); color: var(--dim); }
.badge.project { border-color: var(--green); color: var(--green); }
.badge.star { border-color: var(--warn); color: var(--warn); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; padding: 4px 14px; }
.chip { font-family: var(--font); font-size: 12px; padding: 5px 11px; border-radius: 13px;
  background: rgba(var(--rgb), 0.07); color: var(--green); border: 1px solid rgba(var(--rgb), 0.35); cursor: pointer; }
.chip.on { background: rgba(var(--rgb), 0.22); color: var(--bright); border-color: var(--green); }
.kv { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.kv div { display: flex; justify-content: space-between; gap: 10px; }
.kv b { color: var(--bright); font-weight: 400; }

/* inputs / buttons */
textarea, input[type=text], input[type=number], select {
  font-family: var(--font); font-size: 16px; padding: 10px; border-radius: 9px; width: 100%;
  background: rgba(var(--rgb), 0.07); color: var(--green); border: 1px solid rgba(var(--rgb), 0.4); }
textarea { min-height: 74px; resize: vertical; }
.menu-btn { font-family: var(--font); font-size: 14px; font-weight: 700; letter-spacing: 1px;
  padding: 10px 14px; border-radius: 9px; background: rgba(var(--rgb), 0.14); color: var(--bright);
  border: 1px solid var(--green); cursor: pointer; }
.menu-btn.wide { width: 100%; }
.menu-btn:disabled { opacity: 0.5; }
.menu-btn.danger { color: var(--danger); border-color: var(--danger); background: rgba(255,90,90,0.12); }

/* overlay + toast */
.overlay { position: fixed; inset: 0; background: rgba(2, 10, 6, 0.86); display: flex;
  align-items: center; justify-content: center; padding: 16px; z-index: 20; }
.overlay.hidden { display: none; }
.overlay-box { background: var(--panel); border: 1px solid var(--green); border-radius: 13px;
  padding: 16px; width: 100%; max-width: 420px; max-height: 86dvh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 9px; }
.overlay-head { display: flex; align-items: center; gap: 10px; }
.overlay-head span { flex: 1; color: var(--bright); font-size: 16px; letter-spacing: 1px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: 84px; z-index: 30;
  background: rgba(var(--rgb), 0.18); color: var(--bright); border: 1px solid var(--green);
  border-radius: 9px; padding: 10px 15px; font-size: 14px; max-width: 90vw; text-align: center; }
.toast.hidden { display: none; }

/* login */
.login-wrap { margin: auto; text-align: center; padding: 24px; }
.login-wrap input { max-width: 250px; }
.login-err { color: var(--danger); font-size: 13px; min-height: 18px; margin: 8px 0; }

/* session controls: a TOOLBAR at the top of the chat — temporal window + mode. Lives above
   the log so the reading area (and the newest answer at the bottom) stays clear. */
.controls { display: flex; gap: 8px; align-items: center; padding: 8px 12px; flex-wrap: wrap;
  background: var(--panel); border-bottom: 1px solid rgba(var(--rgb), 0.3); flex-shrink: 0; }
.seg { display: flex; border: 1px solid rgba(var(--rgb), 0.35); border-radius: 9px; overflow: hidden; flex: 1; min-width: 0; }
.seg button { flex: 1; font-family: var(--font); font-size: 11px; padding: 7px 4px; background: transparent;
  color: var(--dim); border: 0; border-right: 1px solid rgba(var(--rgb), 0.2); cursor: pointer; white-space: nowrap; }
.seg button:last-child { border-right: 0; }
.seg button.on { background: rgba(var(--rgb), 0.2); color: var(--bright); }
.chat-mode { width: auto; font-size: 12px; padding: 6px 8px; }
.campip #camflip { right: 34px; }

/* Focus parks here rather than on nothing: a page with no focused element can stop receiving
   hardware-keyboard events on iOS, which kills the pedal until reload. Not a text field, so no
   on-screen keyboard appears. */
.key-anchor { position: fixed; top: 0; left: 0; width: 1px; height: 1px; opacity: 0;
  border: 0; padding: 0; background: transparent; pointer-events: none; }
.key-anchor:focus { outline: none; }
.pedal-debug { position: fixed; top: 0; left: 0; right: 0; z-index: 60; font-size: 11px;
  line-height: 1.5; padding: 6px 8px; background: rgba(0,0,0,0.85); color: var(--green);
  border-bottom: 1px solid var(--green); max-height: 42vh; overflow-y: auto; white-space: pre-wrap; }
.pedal-debug.hidden { display: none; }
.srow-check { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; margin-top: 6px; }
.srow-check input { width: auto; flex-shrink: 0; margin-top: 2px; }

.row-sub.warn { color: var(--warn); }

/* dream preflight dials */
.dial { margin-bottom: 12px; }
.dial-row { display: flex; justify-content: space-between; font-size: 11px; color: var(--dim);
  letter-spacing: 0.4px; margin-bottom: 2px; }
.dial input[type=range] { width: 100%; accent-color: var(--green); margin: 0; padding: 0; }
.dial-val { font-size: 12px; color: var(--bright); margin-top: 2px; }

/* --- attached stills: shown above the composer, like a message app ------------------- */
.attach-strip { display: flex; gap: 8px; padding: 8px 10px 0; flex-wrap: wrap; }
.attach-strip.hidden { display: none; }
.attach-item { position: relative; line-height: 0; }
.attach-item img {
  width: 68px; height: 68px; object-fit: cover;
  border: 1px solid var(--green); border-radius: 6px;
}
/* the ✕ overlaps the corner rather than sitting beside it, so four thumbs still fit a phone */
.attach-x {
  position: absolute; top: -7px; right: -7px; width: 22px; height: 22px; padding: 0;
  border: 1px solid var(--green); border-radius: 50%;
  background: var(--bg); color: var(--green);
  font-size: 12px; line-height: 20px; cursor: pointer;
}
.attach-x:active { background: var(--green); color: var(--bg); }

/* --- Dream Sequence reader ----------------------------------------------------------- */
.seq-wave { margin-bottom: 12px; }
.seq-wave .seq-text { white-space: pre-wrap; line-height: 1.55; font-size: 14px; margin-top: 6px; }
.seq-wave.final { border-color: var(--green); }

/* --- the round table (preflight) + invite picker ------------------------------------- */
.seats { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0; }
.seat-chip { display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--green);
  border-radius: 999px; padding: 5px 6px 5px 12px; font-size: 13px; }
.seat-x { border: none; background: none; color: var(--green); cursor: pointer; font-size: 12px;
  width: 20px; height: 20px; border-radius: 50%; border: 1px solid var(--dim); padding: 0; }
.invite-picker { border: 1px solid var(--dim); border-radius: 8px; margin: 8px 0; overflow: hidden; }
.invite-picker.hidden { display: none; }
.invite-row { display: block; width: 100%; text-align: left; background: none; border: none;
  border-bottom: 1px solid var(--dim); color: var(--green); padding: 10px 12px; cursor: pointer; }
.invite-row:last-child { border-bottom: none; }
.invite-row:active { background: var(--green); color: var(--bg); }
.invite-name { display: block; font-weight: 600; }
.invite-sub { display: block; font-size: 12px; color: var(--dim); margin-top: 2px; }

/* --- dream preflight modal (in the chat) ---------------------------------------------
   Phone: a bottom sheet. Desktop: a centered dialog with the dials and the table side by
   side. Either way the header and the Begin row are PINNED — the body scrolls between
   them, so ▶ is always reachable and nothing hangs off the frame. */
.dream-modal { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.72); z-index: 60;
  display: flex; align-items: flex-end; justify-content: center; }
.dream-modal.hidden { display: none; }
.dream-panel { box-sizing: border-box; display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--green); border-bottom: none;
  border-radius: 14px 14px 0 0; width: 100%; max-height: 88dvh; overflow: hidden; }
.dream-head { flex: 0 0 auto; display: flex; justify-content: space-between; align-items: center;
  font-weight: 700; padding: 12px 16px 8px; border-bottom: 1px solid var(--dim); }
.dream-body { flex: 1 1 auto; overflow-y: auto; overscroll-behavior: contain;
  padding: 10px 16px; }
.dream-col + .dream-col { margin-top: 12px; }
.dream-foot { flex: 0 0 auto; display: flex; flex-direction: column; gap: 8px;
  align-items: stretch; padding: 10px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--dim); background: var(--panel); }
.dream-foot textarea { flex: 1 1 auto; margin: 0; min-height: 0; height: 46px; resize: none; }
.dream-foot .menu-btn.primary { flex: 0 0 auto; width: auto; margin: 0; white-space: nowrap; }
.icon-x { background: none; border: 1px solid var(--dim); color: var(--green);
  border-radius: 50%; width: 28px; height: 28px; cursor: pointer; }
.menu-btn.primary { border-color: var(--green); font-weight: 700; }
/* room to breathe: centered dialog + two columns */
@media (min-width: 720px) {
  .dream-modal { align-items: center; padding: 24px; }
  .dream-foot { flex-direction: row; align-items: flex-end; }
  .dream-panel { width: min(880px, 100%); max-height: min(86dvh, 760px);
    border-bottom: 1px solid var(--green); border-radius: 14px; }
  .dream-body { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 28px;
    align-items: start; padding: 14px 20px; }
  .dream-col + .dream-col { margin-top: 0; }
}

/* --- tile icons (Pip-Boy monoline) --------------------------------------------------- */
.tile { position: relative; }
.tile .tile-label { padding-right: 30px; }   /* keep long labels clear of the icon */
.tile-ico { position: absolute; top: 10px; right: 12px; width: 22px; height: 22px;
  color: rgba(var(--rgb), 0.55); pointer-events: none; }
.tile-ico svg { width: 100%; height: 100%; display: block; }
