:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #eeebe4;
  --text: #1d1b18;
  --muted: #6d675d;
  --line: #dedad1;
  --accent: #a86a12;
  --accent-text: #ffffff;
  --user: #2a2724;
  --user-text: #f6f4ef;
  --danger: #b3261e;
  --tool: #5c6b4f;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121110;
    --surface: #1c1a18;
    --surface-2: #26231f;
    --text: #ece8e1;
    --muted: #9b948a;
    --line: #322e29;
    --accent: #e0a84b;
    --accent-text: #1a1408;
    --user: #e9e4db;
    --user-text: #1a1815;
    --danger: #f2867c;
    --tool: #a9b99a;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121110; --surface: #1c1a18; --surface-2: #26231f; --text: #ece8e1; --muted: #9b948a;
  --line: #322e29; --accent: #e0a84b; --accent-text: #1a1408; --user: #e9e4db; --user-text: #1a1815;
  --danger: #f2867c; --tool: #a9b99a; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}
[hidden] { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.screen { height: 100dvh; display: flex; flex-direction: column; }

/* sign-in */
#signin { align-items: center; justify-content: center; padding: 24px 16px calc(24px + env(safe-area-inset-bottom)); }
.signin-box { width: 100%; max-width: 360px; text-align: center; }
.signin-box h1 { font-size: 28px; font-weight: 650; margin: 12px 0 28px; letter-spacing: -0.01em; }
.signin-box form { text-align: left; display: flex; flex-direction: column; gap: 6px; }
.mark { display: block; margin: 0 auto; }
.hint { color: var(--muted); font-size: 14px; margin: 0 0 10px; }
.field-label { font-size: 13px; color: var(--muted); margin-top: 8px; }
input {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); outline: none; font-size: 16px;
}
input:focus, textarea:focus { border-color: var(--accent); }
.primary {
  background: var(--accent); color: var(--accent-text); border: 0; border-radius: 12px;
  padding: 12px 18px; font-weight: 600;
}
.primary.big { width: 100%; padding: 15px; font-size: 17px; margin-top: 14px; }
.primary:disabled { opacity: .55; }
.error { color: var(--danger); font-size: 14px; min-height: 1.4em; margin: 14px 0 0; }

/* top bar */
.bar {
  display: flex; align-items: center; gap: 4px;
  padding: calc(6px + env(safe-area-inset-top)) 8px 6px;
  border-bottom: 1px solid var(--line); background: var(--bg);
}
.bar h1 {
  flex: 1; margin: 0; font-size: 17px; font-weight: 600; text-align: center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.icon-btn {
  width: 44px; height: 44px; display: grid; place-items: center; flex: none;
  border: 0; background: none; border-radius: 12px; color: var(--text);
}
.icon-btn:active { background: var(--surface-2); }
.text-btn { border: 0; background: none; color: var(--accent); font-weight: 600; padding: 10px 8px; }

/* thread */
#thread { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 16px 16px 8px; overscroll-behavior: contain; }
.empty { text-align: center; color: var(--muted); margin-top: 22vh; }
.empty img { opacity: .9; }
#messages { list-style: none; margin: 0 auto; padding: 0; max-width: 720px; display: flex; flex-direction: column; gap: 14px; }
.msg { max-width: 100%; overflow-wrap: anywhere; }
.msg.user {
  align-self: flex-end; max-width: 85%;
  background: var(--user); color: var(--user-text);
  padding: 10px 14px; border-radius: 18px 18px 4px 18px; white-space: pre-wrap;
}
.msg.user .photos { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.msg.user .photos img { width: 96px; height: 96px; object-fit: cover; border-radius: 10px; }
.msg.user .photo-note { font-size: 13px; opacity: .75; }
.msg.assistant { align-self: stretch; }
.msg.assistant .body > :first-child { margin-top: 0; }
.msg.assistant .body > :last-child { margin-bottom: 0; }
.msg.assistant p { margin: 0 0 .7em; }
.msg.assistant ul, .msg.assistant ol { margin: 0 0 .7em; padding-left: 1.3em; }
.msg.assistant h3, .msg.assistant h4 { font-size: 16px; margin: .9em 0 .3em; }
.msg.assistant a { color: var(--accent); }
.msg.assistant code { font: 14px ui-monospace, "SF Mono", Menlo, monospace; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
.msg.assistant pre { background: var(--surface-2); padding: 10px 12px; border-radius: 10px; overflow-x: auto; }
.msg.assistant pre code { background: none; padding: 0; }
.msg.error-msg { color: var(--danger); font-size: 14px; }

.tools { font-size: 13px; color: var(--tool); margin-bottom: 6px; }
.tools summary { cursor: pointer; list-style: none; display: inline-flex; align-items: center; gap: 6px; }
.tools summary::-webkit-details-marker { display: none; }
.tools ul { margin: 6px 0 0; padding-left: 18px; color: var(--muted); }
.activity { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); }
.spinner {
  width: 14px; height: 14px; border-radius: 50%; flex: none;
  border: 2px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }

.ask {
  border: 1px solid var(--line); background: var(--surface); border-radius: 14px; padding: 12px 14px;
}
.ask h3 { margin: 0 0 6px; font-size: 15px; }
.ask pre { font: 13px ui-monospace, Menlo, monospace; background: var(--surface-2); padding: 8px 10px; border-radius: 8px; white-space: pre-wrap; margin: 0 0 10px; max-height: 40vh; overflow: auto; }
.ask .choices { display: flex; flex-wrap: wrap; gap: 8px; }
.ask .choices button { border: 1px solid var(--line); background: var(--surface-2); border-radius: 10px; padding: 9px 12px; font-weight: 600; font-size: 14px; }
.ask .choices button.yes { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.ask .choices button.no { color: var(--danger); }
.ask .done { color: var(--muted); font-size: 14px; }

/* composer */
#composer {
  border-top: 1px solid var(--line); background: var(--bg);
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
}
.composer-row { display: flex; align-items: flex-end; gap: 4px; max-width: 720px; margin: 0 auto; }
#input {
  flex: 1; resize: none; max-height: 40vh; min-height: 44px;
  padding: 10px 14px; border: 1px solid var(--line); border-radius: 22px; background: var(--surface);
  outline: none; font-size: 16px; line-height: 1.4;
}
.send {
  width: 44px; height: 44px; flex: none; border: 0; border-radius: 50%;
  background: var(--accent); color: var(--accent-text); display: grid; place-items: center;
}
.send:disabled { opacity: .4; }
.send.stop { background: var(--text); color: var(--bg); }
.send.stop svg { fill: currentColor; stroke: none; }
#attachments { display: flex; gap: 8px; max-width: 720px; margin: 0 auto 8px; overflow-x: auto; }
.thumb { position: relative; flex: none; }
.thumb img { width: 64px; height: 64px; object-fit: cover; border-radius: 10px; display: block; }
.thumb button {
  position: absolute; top: -6px; right: -6px; width: 24px; height: 24px; border-radius: 50%;
  border: 0; background: var(--text); color: var(--bg); font-size: 15px; line-height: 1; padding: 0;
}

/* drawer */
#scrim { position: fixed; inset: 0; background: rgb(0 0 0 / .35); z-index: 10; }
#drawer {
  position: fixed; top: 0; bottom: 0; left: 0; width: min(86vw, 340px); z-index: 11;
  background: var(--surface); display: flex; flex-direction: column;
  padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 0 40px rgb(0 0 0 / .2);
}
.drawer-head, .dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 8px 6px 16px; }
.drawer-head h2, .dialog-head h2 { font-size: 17px; margin: 0; }
#sessions { list-style: none; margin: 0; padding: 0 8px; overflow-y: auto; flex: 1; }
#sessions li { display: flex; align-items: center; border-radius: 10px; }
#sessions li.current { background: var(--surface-2); }
#sessions .open { flex: 1; min-width: 0; text-align: left; border: 0; background: none; padding: 10px 8px; }
#sessions .open strong { display: block; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#sessions .open small { color: var(--muted); font-size: 12px; }
#sessions .del { border: 0; background: none; color: var(--muted); width: 40px; height: 40px; flex: none; font-size: 18px; }
.tag { font-size: 11px; border: 1px solid var(--line); border-radius: 6px; padding: 0 5px; margin-left: 4px; color: var(--muted); }
.drawer-foot { border-top: 1px solid var(--line); padding: 6px 8px; display: flex; justify-content: space-between; }

/* devices dialog */
dialog {
  border: 0; border-radius: 16px; padding: 0 16px 16px; width: min(92vw, 420px);
  background: var(--surface); color: var(--text);
}
dialog::backdrop { background: rgb(0 0 0 / .4); }
.dialog-head { padding: 12px 0 4px; }
#passkeys { list-style: none; margin: 0 0 14px; padding: 0; }
#passkeys li { display: flex; align-items: center; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--line); }
#passkeys li div { flex: 1; min-width: 0; }
#passkeys small { color: var(--muted); display: block; font-size: 12px; }
#passkeys button { border: 0; background: none; color: var(--danger); font-weight: 600; }
.inline { display: flex; gap: 8px; margin-top: 6px; }
.inline input { flex: 1; min-width: 0; }
