/* ---------- Design tokens ---------- */
:root {
  --font: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --radius: 14px;
  --radius-lg: 26px;
  --sidebar-w: 268px;
  --content-w: 768px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}
[data-theme="light"] {
  color-scheme: light;
  --bg: #ffffff;
  --bg-side: #f9f9f9;
  --bg-elev: #ffffff;
  --bg-soft: #f5f5f5;
  --bg-hover: #ececec;
  --bg-active: #e3e3e3;
  --bubble: #f0f0f0;
  --text: #0d0d0d;
  --text-2: #5d5d5d;
  --text-3: #8f8f8f;
  --border: #e1e1e1;
  --border-strong: #d4d4d4;
  --accent: #0d0d0d;
  --accent-text: #ffffff;
  --brand: #cc6a4c;
  --code-bg: #f7f7f8;
  --code-head: #ececec;
  --danger: #d93025;
  --danger-bg: #fdecea;
  --success: #188038;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.06);
  --shadow-lg: 0 12px 48px rgba(0,0,0,.16);
}
[data-theme="dark"] {
  color-scheme: dark;
  --bg: #212121;
  --bg-side: #171717;
  --bg-elev: #2a2a2a;
  --bg-soft: #2f2f2f;
  --bg-hover: #2f2f2f;
  --bg-active: #383838;
  --bubble: #303030;
  --text: #ececec;
  --text-2: #b4b4b4;
  --text-3: #8a8a8a;
  --border: #363636;
  --border-strong: #474747;
  --accent: #ececec;
  --accent-text: #171717;
  --brand: #e08a6d;
  --code-bg: #171717;
  --code-head: #2a2a2a;
  --danger: #f28b82;
  --danger-bg: #3b2321;
  --success: #81c995;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.3);
  --shadow-lg: 0 12px 48px rgba(0,0,0,.55);
}

/* ---------- Reset / base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; background: var(--bg); }
body {
  margin: 0;
  font: 16px/1.65 var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
  overscroll-behavior: none;
}
/* iOS standalone can paint the area outside the layout from the root page.
   Keep it identical to the current theme instead of exposing a light/grey
   browser or manifest background around the app. */
html { color-scheme: light; }
html[data-theme="dark"] { color-scheme: dark; }
html, body, .layout, .main, .topbar { background-color: var(--bg); }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
button:disabled { cursor: default; }
input, textarea, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 6px; }
.icon { display: block; flex-shrink: 0; }
[hidden] { display: none !important; }
::selection { background: color-mix(in srgb, var(--brand) 30%, transparent); }
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }

/* ---------- Shared controls ---------- */
.kbd {
  font: 11px/1 var(--mono);
  color: var(--text-3);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 3px 5px;
  margin-left: auto;
}
.icon-btn {
  width: 36px; height: 36px;
  display: inline-grid; place-items: center;
  border-radius: 10px;
  color: var(--text-2);
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.icon-btn:active { background: var(--bg-active); }
.icon-btn.round { border-radius: 50%; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 16px;
  border-radius: 999px;
  font-size: 14px; font-weight: 500;
  border: 1px solid var(--border-strong);
  transition: background .15s, opacity .15s, transform .1s;
}
.btn:hover { background: var(--bg-hover); }
.btn:active { transform: scale(.98); }
button:not(:disabled):active { transform: scale(.97); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.btn.primary:hover { opacity: .88; }
.btn.danger { color: var(--danger); }
.btn.small { height: 32px; padding: 0 12px; font-size: 13px; }
.btn:disabled { opacity: .5; }

.spinner {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--border-strong); border-top-color: var(--text-2);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade-up { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
