:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --text: #1f1f22;
  --muted: #7b7a80;
  --line: #e4e2dc;
  --you: #1d6b3a;
  --ada: #6b3f8f;
  --you-bg: #e8f2ec;
  --script: #3b6ea5;
  --script-bg: #eef3f9;
  --live: #555459;
  --accent: #6b3f8f;
  --accent-text: #ffffff;
  --warn: #a2471c;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17171a;
    --surface: #212125;
    --text: #e9e8ec;
    --muted: #8f8e96;
    --line: #2f2f35;
    --you: #7fcf9b;
    --ada: #c9a2e8;
    --you-bg: #1f2c24;
    --script: #8fb5e0;
    --script-bg: #1c2430;
    --live: #b9b8be;
    --accent: #9d6cc4;
    --accent-text: #ffffff;
    --warn: #f0a07a;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}
button { font: inherit; cursor: pointer; }

/* --- header --- */
.top {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px 0;
  padding-top: max(10px, env(safe-area-inset-top));
}
.title { font-weight: 700; font-size: 18px; color: var(--ada); }
.tabs { display: flex; gap: 4px; flex: 1; }
.tabs button {
  border: 0;
  background: none;
  color: var(--muted);
  padding: 8px 10px;
  border-bottom: 2px solid transparent;
}
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.ghost {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 14px;
  white-space: nowrap;
}
.status {
  padding: 6px 16px 8px;
  font-size: 13px;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.status.warn { color: var(--warn); }
.actions { display: flex; gap: 6px; }
.reading {
  padding: 0 16px 8px;
  margin-top: -4px;
  font-size: 13px;
  color: var(--script);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.reading[hidden] { display: none; }

/* --- logs --- */
main { flex: 1; min-height: 0; position: relative; }
.log {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  padding: 8px 16px 24px;
  -webkit-overflow-scrolling: touch;
}
.log[hidden] { display: none; }
.entry { margin: 14px 0; max-width: 46rem; }
.ts { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.who { font-weight: 700; margin-right: 6px; }
.person .who { color: var(--you); }
.ai .who { color: var(--ada); }
.body { white-space: pre-wrap; overflow-wrap: anywhere; }
.person .body-wrap {
  background: var(--you-bg);
  border-radius: 12px;
  padding: 8px 12px;
  display: inline-block;
}
.script .body {
  font-size: 13px;
  color: var(--script);
  background: var(--script-bg);
  border-radius: 8px;
  padding: 8px 10px;
}
.live .body { color: var(--live); }
.note { text-align: center; color: var(--muted); font-size: 13px; margin: 8px 0; }

/* --- composer --- */
.composer {
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--bg);
}
.composer[hidden] { display: none; }
.composer textarea {
  flex: 1;
  resize: none;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 9px 12px;
  max-height: 40vh;
}
.composer textarea:focus, .login input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.composer button, .login button {
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-text);
  padding: 0 18px;
  font-weight: 600;
}
.composer button:disabled { opacity: 0.5; }
.logout { position: absolute; right: 16px; bottom: 0; visibility: hidden; }
.link { border: 0; background: none; color: var(--muted); font-size: 13px; text-decoration: underline; }

/* the log-out link sits under the pause button on the Thinking tab */
body.thinking .logout { visibility: visible; position: static; text-align: right; padding: 8px 16px; padding-bottom: max(8px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }

@media (max-width: 520px) {
  .top { flex-wrap: wrap; row-gap: 4px; }
  .tabs { order: 3; flex-basis: 100%; }
  .title { flex: 1; }
}

/* --- login --- */
.login-page { align-items: center; justify-content: center; padding: 16px; }
.login {
  width: 100%;
  max-width: 340px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.login h1 { margin: 0 0 8px; color: var(--ada); font-size: 24px; }
.login label { font-size: 14px; color: var(--muted); }
.login input {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
}
.login button { padding: 10px; }
.login-msg { margin: 0; min-height: 1.2em; font-size: 14px; color: var(--warn); }
