:root {
  --bg: #101410;
  --bg-side: #0c100e;
  --bg-elev: #18201c;
  --line: rgba(214, 206, 188, 0.12);
  --text: #e7efe9;
  --muted: #8d9b94;
  --faint: #66736c;
  --accent: #d4a054;
  --accent-ink: #2a1c0a;
  --mint: #8dceb0;
  --user: #24312b;
  --danger: #e38b7b;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.28);
  --sidebar: 292px;
  --inset: 16px;
  --font-ui: "Outfit", "Segoe UI", sans-serif;
  --font-prose: "Literata", "Iowan Old Style", Georgia, serif;
  --msg-size: 1rem;
  --mono: "Cascadia Code", "Consolas", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body {
  box-sizing: border-box;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  height: 100%;
}
body {
  margin: 0;
  height: 100dvh;
  overflow: hidden;
  overflow-wrap: break-word;
  background:
    radial-gradient(900px 420px at 10% -10%, rgba(212, 160, 84, 0.08), transparent 55%),
    radial-gradient(700px 380px at 100% 0%, rgba(141, 206, 176, 0.06), transparent 50%),
    var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-weight: 380;
}

button, textarea, input { font: inherit; color: inherit; }
button { cursor: pointer; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.shell {
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
  box-sizing: border-box;
  width: 100%;
  max-width: 100%;
  height: 100%;
  min-width: 0;
  padding-top: env(safe-area-inset-top);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px 14px 16px;
  background: var(--bg-side);
  border-right: 1px solid var(--line);
  min-width: 0;
  min-height: 0;
}

.brand { display: flex; gap: 12px; align-items: center; padding: 4px 6px 2px; }
.mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: #101410 url("/static/apple-touch-icon.png") center/cover;
  border: 1px solid var(--line);
  flex: none;
}
.brand-name { font-weight: 600; letter-spacing: 0.01em; }
.brand-sub { color: var(--faint); font-size: 12px; margin-top: 1px; }

.new-chat, .send, .ghost, .text-btn, .mode-btn, .effort-btn, .icon-btn, .suggest, .quiet {
  border: 1px solid transparent;
  background: transparent;
}

.new-chat {
  border-color: var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  text-align: left;
  background: rgba(212, 160, 84, 0.08);
  color: var(--accent);
}
.new-chat:hover { background: rgba(212, 160, 84, 0.14); }

.side-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 10px;
  min-width: 0;
  max-width: 100%;
}
.side-actions .text-btn {
  flex: 1 1 auto;
  min-width: 0;
  white-space: normal;
}
.chat-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow: auto;
  min-height: 0;
  flex: 1;
  min-width: 0;
  max-width: 100%;
  padding-right: 2px;
}
.folder-block { min-width: 0; max-width: 100%; }
.folder-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  min-width: 0;
  max-width: 100%;
  padding: 10px 8px 2px;
  color: var(--faint);
  font-size: 12px;
}
.folder-head span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.folder-rename {
  flex: 1 1 auto;
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--faint);
  font-size: 12px;
  padding: 2px 4px;
  white-space: normal;
  text-align: left;
}
.move-chat {
  grid-column: 1 / -1;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  background: #121816;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 13px;
}

.chat-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
  align-items: center;
  width: 100%;
  min-width: 0;
  border-radius: 10px;
  padding: 8px 8px 8px 10px;
  color: var(--muted);
  text-align: left;
}
.chat-item.is-active { background: var(--bg-elev); color: var(--text); }
.chat-item:hover { background: rgba(255, 255, 255, 0.03); }
.chat-item span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}
.chat-item .drop {
  opacity: 0;
  border: 0;
  background: transparent;
  color: var(--faint);
  padding: 2px 6px;
  border-radius: 6px;
}
.chat-item:hover .drop, .chat-item:focus-within .drop { opacity: 1; }
.chat-item .drop:hover { color: var(--danger); }

.sidebar-foot { display: flex; flex-direction: column; gap: 8px; }
.mode {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 3px;
  border-radius: 12px;
  background: #121816;
  border: 1px solid var(--line);
}
.mode-btn {
  border-radius: 9px;
  padding: 8px 6px;
  color: var(--muted);
  font-size: 13px;
}
.mode-btn.is-on { background: var(--bg-elev); color: var(--text); }
.mode-hint { margin: 0; color: var(--faint); font-size: 12px; line-height: 1.4; padding: 0 4px; }
.text-btn {
  text-align: left;
  color: var(--muted);
  padding: 6px 4px;
  font-size: 13px;
}
.text-btn:hover { color: var(--text); }
.balance {
  margin: 0;
  padding: 0 4px;
  color: var(--faint);
  font-size: 12px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.stage {
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 0;
}
.stage > * {
  min-width: 0;
  max-width: 100%;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  box-sizing: border-box;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  padding: 14px 22px;
  border-bottom: 1px solid transparent;
}
.top-title {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 100%;
  font-size: 14px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.meter {
  box-sizing: border-box;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  margin: 0;
  padding: 0 22px 4px;
  color: var(--faint);
  font-size: 12px;
  line-height: 1.45;
  overflow-wrap: break-word;
}
.earlier {
  display: block;
  margin: 0 auto 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 14px;
  color: var(--muted);
  background: transparent;
}
.earlier:hover { color: var(--text); }
[hidden] { display: none !important; }
.status {
  flex: none;
  margin-left: auto;
  font-size: 12px;
  color: var(--mint);
  letter-spacing: 0.02em;
}
.status.is-off { color: var(--accent); }
.menu-btn { display: none; flex-direction: column; gap: 4px; padding: 8px; }
.menu-btn span {
  display: block;
  width: 16px;
  height: 1.5px;
  background: var(--text);
}

.transcript {
  flex: 1 1 auto;
  overflow-x: hidden;
  overflow-y: auto;
  box-sizing: border-box;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 0;
  padding: 12px var(--inset) 24px;
}

.empty {
  max-width: min(680px, 100%);
  min-width: 0;
  margin: 12vh auto 0;
}
.empty h1 {
  font-family: var(--font-prose);
  font-weight: 620;
  font-size: 42px;
  letter-spacing: -0.03em;
  margin: 0 0 10px;
}
.empty p { margin: 0; color: var(--muted); max-width: min(46ch, 100%); line-height: 1.5; }
.suggestions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 22px; }
.suggest {
  border-color: var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.02);
  font-size: 13px;
}
.suggest:hover { color: var(--text); border-color: rgba(212, 160, 84, 0.45); }

.msg {
  box-sizing: border-box;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  margin: 0 auto 22px;
  overflow-wrap: break-word;
}
.msg.user {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  min-width: 0;
}
.msg-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-top: 4px;
  font-family: var(--font-ui);
  font-size: 12px;
  line-height: 1.2;
}
.post-num {
  color: var(--faint);
  font-family: var(--font-ui);
  font-size: 12px;
  line-height: 1;
}
.quiet {
  padding: 0;
  color: var(--faint);
  font-size: 12px;
  font-family: var(--font-ui);
}
.quiet.reroll {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  font-size: 12px;
  line-height: 0;
}
.quiet.reroll svg {
  display: block;
  width: 16px;
  height: 16px;
  flex: none;
}
.versions {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: min(420px, 100%);
  max-height: 36vh;
  margin-top: 6px;
  overflow: auto;
}
.versions button {
  display: block;
  width: 100%;
  padding: 8px 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: left;
  color: var(--muted);
  font-size: 14px;
}
.versions button.is-on { color: var(--text); }
.quiet:hover { color: var(--text); }
.edit-note {
  margin: 0 0 6px;
  color: var(--faint);
  font-size: 12px;
  line-height: 1.4;
}
.edit-note .quiet { margin-left: 8px; }
.bubble {
  box-sizing: border-box;
  max-width: min(640px, 100%);
  min-width: 0;
  overflow-wrap: break-word;
  background: var(--user);
  border: 1px solid var(--line);
  border-radius: 16px 16px 6px 16px;
  padding: 10px 14px;
  white-space: pre-wrap;
  font-size: var(--msg-size);
  line-height: 1.45;
}
.msg.assistant .prose {
  box-sizing: border-box;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow-wrap: break-word;
  font-family: var(--font-prose);
  font-size: var(--msg-size);
  line-height: 1.55;
  letter-spacing: -0.01em;
}
.prose p {
  max-width: 100%;
  min-width: 0;
  margin: 0 0 0.8em;
  overflow-wrap: break-word;
}
.prose p:last-child { margin-bottom: 0; }
.prose h1, .prose h2, .prose h3 {
  font-family: var(--font-ui);
  letter-spacing: -0.02em;
  margin: 1.1em 0 0.4em;
}
.prose ul, .prose ol { margin: 0.3em 0 0.9em; padding-left: 1.2em; }
.prose li { margin: 0.2em 0; }
.prose a { color: var(--accent); }
.prose code {
  font-family: var(--mono);
  font-size: 0.86em;
  background: #1c2622;
  border-radius: 6px;
  padding: 0.1em 0.35em;
}
.prose pre {
  max-width: 100%;
  min-width: 0;
  margin: 0.8em 0;
  background: #0c1210;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow-x: auto;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}
.prose pre code {
  display: block;
  max-width: 100%;
  padding: 12px 14px;
  background: transparent;
  line-height: 1.45;
  font-size: 13.5px;
  white-space: inherit;
  overflow-wrap: inherit;
  word-break: inherit;
}
.code-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 10px 0;
  color: var(--faint);
  font-family: var(--font-ui);
  font-size: 12px;
}
.code-head button {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
}
.think {
  margin: 0 0 12px;
  border-left: 2px solid rgba(212, 160, 84, 0.55);
  padding: 2px 0 2px 12px;
  color: var(--muted);
  font-family: var(--font-ui);
  font-size: 13.5px;
  line-height: 1.45;
}
.think summary { cursor: pointer; color: var(--accent); margin-bottom: 6px; }
.think p { margin: 0; max-width: 100%; min-width: 0; white-space: pre-wrap; overflow-wrap: break-word; }
.thinking {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
  color: var(--mint);
  font-family: var(--font-ui);
  font-size: 13.5px;
  letter-spacing: 0.01em;
}
.thinking::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  flex: none;
  animation: think-pulse 1.4s ease-out infinite;
}
@keyframes think-pulse {
  0% { box-shadow: 0 0 0 0 rgba(212, 160, 84, 0.45); }
  70% { box-shadow: 0 0 0 7px rgba(212, 160, 84, 0); }
  100% { box-shadow: 0 0 0 0 rgba(212, 160, 84, 0); }
}
.msg-error,
.broken {
  margin-top: 8px;
  color: var(--danger);
  font-family: var(--font-ui);
  font-size: 14px;
}
.cursor {
  display: inline-block;
  width: 7px;
  height: 1em;
  margin-left: 2px;
  background: var(--accent);
  vertical-align: text-bottom;
  animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.composer {
  box-sizing: border-box;
  width: auto;
  max-width: 100%;
  min-width: 0;
  align-self: stretch;
  margin: 0 var(--inset) calc(18px + env(safe-area-inset-bottom));
  background: rgba(18, 24, 22, 0.92);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 10px 12px 8px;
  box-shadow: var(--shadow);
}
.composer textarea {
  display: block;
  box-sizing: border-box;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  resize: none;
  border: 0;
  outline: none;
  background: transparent;
  min-height: 28px;
  max-height: 180px;
  line-height: 1.45;
}
.composer-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  box-sizing: border-box;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  gap: 8px 12px;
  margin-top: 4px;
}
.composer-bar > * { min-width: 0; }
.effort {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  margin-top: 8px;
  padding: 3px;
  border-radius: 12px;
  background: #121816;
  border: 1px solid rgba(141, 206, 176, 0.45);
}
body.is-think #effort {
  display: flex !important;
}
.effort-btn {
  flex: 1 1 0;
  box-sizing: border-box;
  min-width: 0;
  max-width: 100%;
  min-height: 36px;
  border-radius: 9px;
  padding: 8px 6px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.2;
  text-align: center;
  white-space: normal;
  overflow-wrap: break-word;
}
.effort-btn.is-on {
  background: var(--bg-elev);
  color: var(--mint);
}
.hint { color: var(--faint); font-size: 12px; }
.send {
  flex: 0 0 auto;
  box-sizing: border-box;
  max-width: 100%;
  margin-left: auto;
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 999px;
  padding: 8px 14px;
  font-weight: 600;
  white-space: nowrap;
}
.send:disabled { opacity: 0.45; cursor: default; }
.send.stop { background: transparent; color: var(--text); border-color: var(--line); }

.key-dialog {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #161c19;
  color: var(--text);
  width: min(460px, calc(100% - 28px));
  padding: 22px;
  box-shadow: var(--shadow);
}
.key-dialog::backdrop { background: rgba(6, 8, 7, 0.72); }
.key-dialog h2 { margin: 0 0 8px; font-size: 22px; font-weight: 600; }
.key-dialog p { color: var(--muted); line-height: 1.5; font-size: 14px; }
.key-dialog a { color: var(--accent); }
.key-dialog label { display: block; font-size: 13px; margin-bottom: 6px; }
.key-dialog input,
.key-dialog textarea {
  width: 100%;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #101614;
  padding: 10px 12px;
  outline: none;
}
.key-dialog textarea {
  min-height: 140px;
  resize: vertical;
  line-height: 1.45;
}
.key-dialog input:focus,
.key-dialog textarea:focus { border-color: rgba(212, 160, 84, 0.7); }
.form-error { color: var(--danger) !important; min-height: 1.2em; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.ghost {
  border-color: var(--line);
  border-radius: 999px;
  padding: 8px 14px;
}

.backdrop {
  display: none;
}

@media (max-width: 860px) {
  .shell {
    display: block;
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    height: 100%;
    height: 100dvh;
    overflow-x: hidden;
  }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(320px, 88%);
    max-width: 100%;
    z-index: 20;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow);
  }
  .sidebar.is-open { transform: none; }
  .menu-btn { display: flex; flex: none; }
  .stage {
    width: 100%;
    max-width: 100%;
    height: 100%;
  }
  .topbar { padding: 10px 12px; }
  .meter { padding: 0 12px 4px; }
  .transcript {
    padding: 8px var(--inset) 16px;
    scrollbar-gutter: auto;
  }
  .composer {
    width: auto;
    max-width: 100%;
    margin-left: var(--inset);
    margin-right: var(--inset);
  }
  .effort-btn { font-size: 12.5px; padding: 8px 4px; }
  .empty { margin-top: 8vh; }
  .empty h1 { font-size: 32px; }
  .hint { display: none; }
  body.nav-open::before {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 15;
  }
}

.gate {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(24px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}
body:has(.gate) {
  height: auto;
  min-height: 100%;
  overflow: auto;
}
.gate-card { width: min(420px, 100%); }
.gate-card h1 {
  font-family: var(--font-prose);
  font-weight: 620;
  font-size: 36px;
  letter-spacing: -0.03em;
  margin: 0 0 18px;
}
.gate-card label {
  display: block;
  font-size: 13px;
  margin-bottom: 6px;
  color: var(--muted);
}
.gate-card input {
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #101614;
  padding: 12px 14px;
  font-size: 16px;
  outline: none;
}
.gate-card input:focus { border-color: rgba(212, 160, 84, 0.7); }
.gate-card .send {
  width: 100%;
  margin: 14px 0 0;
  padding: 12px 14px;
}
.gate-card .form-error { margin: 10px 0 0; }
@media (max-width: 860px) {
  .gate-card h1 { font-size: 32px; }
}

@media (prefers-reduced-motion: reduce) {
  .cursor, .thinking::before { animation: none; }
  .sidebar { transition: none; }
}
