:root {
  --bg: #14121c;
  --bg-raised: #1d1a28;
  --bg-input: #251f33;
  --line: #322b44;
  --text: #ece8f4;
  --muted: #9d94b4;
  --accent: #c58bff;
  --accent-ink: #1a1024;
  --user: #2f2a46;
  --error: #ff8a8a;
  --ok: #7fe3a3;
  --radius: 16px;
}

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

/* The page shows and hides its screens with the `hidden` attribute. Any class that sets
   `display` (.gate, .app, .sheet) outranks the browser's own [hidden] rule, so without this the
   login card and both full-screen sheets stay visible on top of the chat no matter what the
   script does. Found 2026-12-01 the first time the page was opened in a real browser. */
[hidden] { display: none !important; }

html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font: 16px/1.55 ui-rounded, "Segoe UI", system-ui, -apple-system, sans-serif;
  overscroll-behavior-y: none;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--error); }

/* ------------------------------- login ------------------------------- */
.gate { display: grid; place-items: center; min-height: 100%; padding: 24px; }
.gate-card { width: 100%; max-width: 340px; text-align: center; }
.brand {
  font-size: 40px; margin: 0 0 4px; letter-spacing: .02em; font-weight: 600;
  background: linear-gradient(100deg, #c58bff, #7fd8ff);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
#login-form { display: grid; gap: 12px; margin-top: 26px; }

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

input[type=password] {
  width: 100%; padding: 15px 16px; border-radius: var(--radius);
  background: var(--bg-input); border: 1px solid var(--line); outline: none;
}
input[type=password]:focus { border-color: var(--accent); }

.primary {
  padding: 15px 18px; border: 0; border-radius: var(--radius);
  background: var(--accent); color: var(--accent-ink); font-weight: 650; cursor: pointer;
}
.primary:active { transform: translateY(1px); }
.primary:disabled { opacity: .5; }

/* -------------------------------- app -------------------------------- */
.app { display: flex; flex-direction: column; height: 100%; }

.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 8px) 10px 8px;
  border-bottom: 1px solid var(--line); background: var(--bg);
  position: sticky; top: 0; z-index: 5;
}
.title-wrap { flex: 1; display: flex; align-items: center; gap: 8px; min-width: 0; }
.title { font-weight: 600; font-size: 17px; }

.icon-btn {
  width: 40px; height: 40px; flex: 0 0 40px; display: grid; place-items: center;
  background: none; border: 0; color: var(--muted); border-radius: 12px; cursor: pointer;
}
.icon-btn:active { background: var(--bg-raised); }
.icon-btn svg { width: 22px; height: 22px; }

.pill {
  font-size: 11px; padding: 3px 9px; border-radius: 999px; white-space: nowrap;
  border: 1px solid var(--line); color: var(--muted);
}
.pill-ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.pill-wait { color: var(--muted); }
.pill-off { color: var(--error); border-color: color-mix(in srgb, var(--error) 40%, transparent); }

/* ------------------------------ thread ------------------------------- */
.thread {
  flex: 1; overflow-y: auto; padding: 16px 14px 8px;
  display: flex; flex-direction: column; gap: 14px;
  -webkit-overflow-scrolling: touch;
}

.msg { max-width: 88%; padding: 11px 14px; border-radius: var(--radius); white-space: pre-wrap; word-wrap: break-word; }
.msg-user { align-self: flex-end; background: var(--user); border-bottom-right-radius: 5px; }
.msg-ai { align-self: flex-start; background: var(--bg-raised); border-bottom-left-radius: 5px; }

.thinking {
  align-self: flex-start; max-width: 88%; font-size: 13px; color: var(--muted);
  border-left: 2px solid var(--line); padding: 2px 0 2px 10px;
  max-height: 4.6em; overflow: hidden; font-style: italic;
}

.note {
  align-self: center; font-size: 12px; color: var(--muted);
  background: var(--bg-raised); padding: 5px 12px; border-radius: 999px;
}
.note-saved { color: var(--ok); }
.note-error { color: var(--error); }

.empty { margin: auto; text-align: center; color: var(--muted); padding: 30px; max-width: 300px; }

/* ----------------------------- composer ------------------------------ */
.voice-hint {
  text-align: center; font-size: 13px; color: var(--accent);
  padding: 6px 14px 0;
}

/* Thinking-mode chips. Sit directly above the composer so the choice is visible at the moment
   she is about to ask for something, not buried in a settings screen. */
.modebar {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  padding: 6px 12px 0;
}
.chip {
  font: inherit; font-size: 12px; line-height: 1;
  padding: 7px 12px; border-radius: 999px; cursor: pointer;
  color: var(--muted); background: transparent;
  border: 1px solid var(--line);
}
.chip-on {
  color: var(--bg); background: var(--accent);
  border-color: var(--accent); font-weight: 600;
}
.mode-note { font-size: 11px; color: var(--muted); margin-left: 2px; }
.chip-voice { margin-left: auto; }

.composer {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 8px 10px calc(env(safe-area-inset-bottom) + 10px);
  border-top: 1px solid var(--line); background: var(--bg);
}

#input {
  flex: 1; resize: none; max-height: 140px; padding: 12px 14px;
  background: var(--bg-input); border: 1px solid var(--line);
  border-radius: var(--radius); outline: none;
}
#input:focus { border-color: var(--accent); }

.mic, .send {
  width: 46px; height: 46px; flex: 0 0 46px; display: grid; place-items: center;
  border: 0; border-radius: 50%; cursor: pointer; background: var(--bg-input); color: var(--text);
}
.mic svg, .send svg { width: 22px; height: 22px; }
.send { background: var(--accent); color: var(--accent-ink); }
.mic.listening { background: var(--accent); color: var(--accent-ink); animation: pulse 1.4s ease-in-out infinite; }
.mic.speaking { background: #7fd8ff; color: var(--accent-ink); }
.mic.unavailable { opacity: .35; }

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 55%, transparent); }
  50%      { box-shadow: 0 0 0 11px transparent; }
}
@media (prefers-reduced-motion: reduce) { .mic.listening { animation: none; } }

/* ------------------------------ sheets ------------------------------- */
.sheet {
  position: fixed; inset: 0; background: var(--bg); z-index: 20;
  display: flex; flex-direction: column;
}
.lib-list { flex: 1; overflow-y: auto; padding: 8px 12px calc(env(safe-area-inset-bottom) + 16px); }

.lib-item {
  width: 100%; text-align: left; background: var(--bg-raised); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 13px 15px; margin-bottom: 10px; cursor: pointer;
  display: block; color: inherit;
}
.lib-item:active { border-color: var(--accent); }
.lib-title { font-weight: 600; display: block; margin-bottom: 3px; }
.lib-meta { font-size: 12px; color: var(--muted); }
.badge-ready { color: var(--ok); }

/* who she is talking to: the header name is a button, the picker is a sheet of cards */
.who {
  display: inline-flex; align-items: center; gap: 2px; min-width: 0;
  font: inherit; color: inherit; background: transparent; border: 0; padding: 4px 2px; cursor: pointer;
}
.who svg { width: 18px; height: 18px; color: var(--muted); flex: none; }
.lib-item.chosen { border-color: var(--accent); }
.lib-item.chosen .lib-title::after { content: " · here now"; color: var(--accent); font-weight: 400; font-size: 12px; }
.comp-foot { padding: 0 16px calc(env(safe-area-inset-bottom) + 16px); margin: 0; text-align: center; }

.script-body {
  flex: 1; overflow-y: auto; margin: 0; padding: 16px 16px 8px;
  white-space: pre-wrap; word-wrap: break-word; font: 15px/1.6 ui-monospace, "Cascadia Mono", monospace;
}
.viewer-actions {
  padding: 12px 16px calc(env(safe-area-inset-bottom) + 16px);
  border-top: 1px solid var(--line); display: grid; gap: 8px;
}
.viewer-actions .primary:disabled { background: var(--bg-input); color: var(--muted); }
