:root {
  --bg: #0d0d0f;
  --panel: #141417;
  --panel2: #1b1b1f;
  --line: #2a2a30;
  --text: #ece9e2;
  --muted: #9b978d;
  --gold: #f5b301;
  --gold-dim: #b88700;
  --amber: #f0a020;   /* warnings: never red */
  --green: #3ccf8e;
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 16px/1.55 var(--font); }
a { color: var(--gold); }
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

.wordmark { font-weight: 800; letter-spacing: -0.02em; font-size: 20px; color: var(--text); white-space: nowrap; }
.wordmark span { color: var(--gold); }
.wordmark.big { font-size: clamp(30px, 8vw, 42px); }

.btn { border: 1px solid transparent; border-radius: 10px; padding: 11px 16px; font-weight: 600; }
.btn.gold { background: var(--gold); color: #111; }
.btn.gold:hover { background: #ffc423; }
.btn.outline { background: transparent; border-color: var(--line); }
.btn.outline:hover { border-color: var(--gold-dim); }
.btn.wide { width: 100%; text-align: left; }
.btn:disabled { opacity: .55; cursor: default; }
.linkbtn { background: none; border: 0; color: var(--muted); padding: 6px 0; text-decoration: underline; }
.icon { background: none; border: 0; font-size: 22px; width: 44px; height: 44px; border-radius: 10px; }
.icon:hover { background: var(--panel2); }

/* ---------- auth ---------- */
.auth { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 400px; text-align: center; }
.tag { color: var(--muted); margin: 6px 0 24px; }
.tabs { display: flex; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 4px; margin-bottom: 18px; }
.tab { flex: 1; background: none; border: 0; padding: 10px; border-radius: 9px; color: var(--muted); font-weight: 600; }
.tab.active { background: var(--panel2); color: var(--gold); }
form label { display: block; text-align: left; font-size: 14px; color: var(--muted); margin-bottom: 12px; }
input[type=email], input[type=password], #dlgInput {
  display: block; width: 100%; margin-top: 6px; padding: 12px 14px; font-size: 16px;
  background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 10px; outline: none;
}
input:focus, textarea:focus { border-color: var(--gold-dim); }
label.check { display: flex; gap: 10px; align-items: flex-start; color: var(--text); }
label.check input { width: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--gold); flex: none; }
#authForm .btn.gold, #resetForm .btn.gold { width: 100%; margin-top: 4px; }
.msg { min-height: 1.4em; color: var(--amber); font-size: 14px; margin: 4px 0 8px; text-align: left; }
.msg.ok { color: var(--green); }
.fine { color: var(--muted); font-size: 13px; margin-top: 24px; }

/* ---------- app layout ---------- */
.app { display: flex; height: 100vh; height: 100dvh; }
.sidebar { width: 280px; flex: none; background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 14px 12px; gap: 12px; }
.side-top { display: flex; align-items: center; justify-content: space-between; min-height: 44px; padding: 0 4px; }
.chat-list { flex: 1; overflow-y: auto; margin: 0 -4px; padding: 0 4px; }
.chat-item { display: flex; align-items: center; border-radius: 10px; }
.chat-item:hover, .chat-item.active { background: var(--panel2); }
.chat-item.active .chat-open { color: var(--gold); }
.chat-open { flex: 1; min-width: 0; text-align: left; background: none; border: 0; padding: 11px 10px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 15px; }
.chat-act { background: none; border: 0; color: var(--muted); width: 36px; height: 40px; border-radius: 8px; font-size: 15px; flex: none; }
.chat-act:hover { color: var(--text); background: var(--line); }
.side-bottom { border-top: 1px solid var(--line); padding-top: 10px; font-size: 13px; color: var(--muted); }
.who { display: flex; justify-content: space-between; gap: 8px; align-items: center; margin-bottom: 6px; }
.who #whoEmail { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plan { color: var(--gold); border: 1px solid var(--gold-dim); border-radius: 999px; padding: 1px 8px; text-transform: uppercase; font-size: 11px; font-weight: 700; }
.side-links { display: flex; gap: 14px; align-items: center; }
.side-links a { color: var(--muted); }
.list-empty { color: var(--muted); font-size: 14px; padding: 10px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 6px; padding: 8px 12px; border-bottom: 1px solid var(--line); min-height: 56px; }
.topbar h1 { flex: 1; font-size: 16px; font-weight: 600; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.messages { flex: 1; overflow-y: auto; padding: 20px 16px 8px; overscroll-behavior: contain; }
.empty { height: 100%; display: grid; place-content: center; text-align: center; color: var(--muted); gap: 4px; }
.msg-row { max-width: 780px; margin: 0 auto 18px; display: flex; }
.msg-row.user { justify-content: flex-end; }
.bubble { max-width: 100%; overflow-wrap: anywhere; }
.msg-row.user .bubble { background: var(--panel2); border: 1px solid var(--line); padding: 10px 14px; border-radius: 18px 18px 4px 18px; white-space: pre-wrap; max-width: 85%; }
.msg-row.assistant .bubble { width: 100%; }
.bubble p { margin: 0 0 .8em; }
.bubble p:last-child { margin-bottom: 0; }
.bubble pre { position: relative; background: #0a0a0c; border: 1px solid var(--line); border-radius: 10px; padding: 36px 14px 14px; overflow-x: auto; font-size: 14px; }
.bubble code { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; }
.bubble :not(pre) > code { background: var(--panel2); padding: 1px 6px; border-radius: 6px; font-size: .92em; }
.bubble pre code.hljs { background: none; padding: 0; }
/* never red: swap the code theme's red/pink tokens for purple, gold and amber */
.hljs-keyword, .hljs-doctag, .hljs-template-tag, .hljs-template-variable, .hljs-type, .hljs-variable.language_,
.hljs-meta .hljs-keyword { color: #c4a7ff !important; }
.hljs-deletion { color: var(--amber) !important; background: rgba(240,160,32,.12) !important; }
.hljs-selector-tag, .hljs-built_in { color: #f5c542 !important; }
.copy { position: absolute; top: 6px; right: 6px; background: var(--panel2); border: 1px solid var(--line); color: var(--muted);
  border-radius: 7px; font-size: 12px; padding: 3px 9px; }
.bubble table { border-collapse: collapse; display: block; overflow-x: auto; }
.bubble th, .bubble td { border: 1px solid var(--line); padding: 6px 10px; }
.bubble blockquote { border-left: 3px solid var(--gold-dim); margin: 0 0 .8em; padding-left: 12px; color: var(--muted); }
.bubble a { word-break: break-all; }
.note { color: var(--amber); }
.cursor::after { content: "▍"; color: var(--gold); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.composer-bar { display: flex; justify-content: space-between; align-items: center; gap: 8px;
  max-width: 780px; width: calc(100% - 24px); margin: 6px auto 0; min-height: 28px; font-size: 13px; color: var(--muted); }
.usage.low { color: var(--amber); }
.chip { background: var(--panel); border: 1px solid var(--line); color: var(--muted); border-radius: 999px; padding: 3px 12px; font-size: 13px; font-weight: 600; }
.chip[aria-pressed=true] { border-color: var(--gold); color: var(--gold); }
.composer { display: flex; gap: 8px; align-items: flex-end; max-width: 780px; width: calc(100% - 24px); margin: 8px auto 0;
  background: var(--panel); border: 1px solid var(--line); border-radius: 22px; padding: 6px 6px 6px 16px; }
.composer:focus-within { border-color: var(--gold-dim); }
#input { flex: 1; resize: none; border: 0; outline: none; background: none; color: var(--text); font: 16px/1.5 var(--font);
  padding: 8px 0; max-height: 200px; }
.send { width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--gold); color: #111; font-size: 17px; flex: none; }
.send:disabled { background: var(--line); color: var(--muted); }
.send.stop { background: var(--text); }
.disclaimer { text-align: center; color: var(--muted); font-size: 12px; margin: 6px 12px calc(8px + env(safe-area-inset-bottom)); }

dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; width: min(92vw, 400px); }
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog h2 { margin: 0 0 8px; font-size: 18px; }
dialog p { color: var(--muted); margin: 0 0 14px; }
.dlg-btns { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }

.gate { position: fixed; inset: 0; z-index: 50; background: var(--bg); display: grid; place-items: center; padding: 24px 16px; text-align: center; }
.gate-btns { display: flex; gap: 10px; justify-content: center; margin-top: 14px; }
.gate-btns .btn { min-width: 130px; }
.linkbtn.small { font-size: 12px; padding: 8px 0 0; }
.msg-tools { display: flex; gap: 14px; margin-top: 6px; }
.msg-tools button { background: none; border: 0; color: var(--muted); font-size: 13px; padding: 4px 0; }
.msg-tools button:hover { color: var(--gold); }

.btn.center { text-align: center; margin-bottom: 10px; }
.plans-dlg { width: min(94vw, 720px); max-height: 90dvh; overflow-y: auto; }
.plans-head { display: flex; justify-content: space-between; align-items: center; }
.plans-head h2 { margin: 0; font-size: 22px; }
.plans-note { color: var(--gold) !important; min-height: 0; }
.plans { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-top: 8px; }
.plan-card { border: 1px solid var(--line); border-radius: 14px; padding: 16px; display: flex; flex-direction: column; gap: 6px; background: var(--bg); }
.plan-card.best { border-color: var(--gold); }
.plan-card h3 { margin: 0; font-size: 18px; }
.plan-card .price { font-size: 28px; font-weight: 800; }
.plan-card .price small { font-size: 14px; color: var(--muted); font-weight: 500; }
.plan-card ul { margin: 4px 0 10px; padding-left: 18px; color: var(--muted); font-size: 14px; flex: 1; }
.plan-card .btn { width: 100%; }
.test-badge { display: inline-block; color: #111; background: var(--amber); border-radius: 6px; font-size: 12px; font-weight: 700; padding: 1px 8px; margin-left: 6px; }

.only-mobile { display: none; }
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 9; }

@media (max-width: 820px) {
  .only-mobile { display: inline-grid; place-items: center; }
  .sidebar { position: fixed; z-index: 10; inset: 0 auto 0 0; width: min(84vw, 320px); transform: translateX(-100%);
    transition: transform .2s ease; padding-top: calc(14px + env(safe-area-inset-top)); }
  .sidebar.open { transform: none; }
  .topbar { padding-top: calc(8px + env(safe-area-inset-top)); }
  .messages { padding: 16px 12px 8px; }
  .chat-act { width: 40px; height: 44px; }
}

/* Guest trial */
.signup-prompt { text-align: center; margin: 0 16px 8px; color: var(--gold); font-weight: 600; font-size: 15px; }
.signup-prompt .linkbtn { color: var(--gold); font-weight: 700; }
#authBack { display: inline-block; margin-top: 8px; }
.app.guest .side-bottom #deleteAccount,
.app.guest #logout { display: none; }
