/*
 * Scriptable Studio, styled with the Claude (Anthropic) design language.
 * Tokens: https://open-design.ai/plugins/design-system-claude/ (DESIGN.md)
 *       + https://github.com/anthropics/skills/tree/main/skills/brand-guidelines (Lora, accent colors)
 * Mobile first: base styles are for phones; min-width queries add tablet/desktop layouts.
 */

/* ---------- Tokens ---------- */
:root {
  /* Surface */
  --bg: #f5f4ed;            /* Parchment */
  --surface: #faf9f5;       /* Ivory */
  --surface-raised: #ffffff;
  --surface-warm: #e8e6dc;  /* Warm Sand */
  /* Text */
  --fg: #141413;            /* Near Black */
  --fg-2: #3d3d3a;          /* Dark Warm */
  --fg-button: #4d4c48;     /* Charcoal Warm */
  --muted: #5e5d59;         /* Olive Gray */
  --meta: #87867f;          /* Stone Gray */
  /* Border & rings */
  --border: #f0eee6;        /* Border Cream */
  --border-soft: #e8e6dc;   /* Border Warm */
  --ring: #d1cfc5;          /* Ring Warm */
  --ring-deep: #c2c0b6;     /* Ring Deep */
  /* Accent */
  --accent: #c96442;        /* Terracotta */
  --accent-soft: #d97757;   /* Coral */
  --accent-on: #faf9f5;
  --accent-hover: color-mix(in oklab, var(--accent), black 8%);
  --accent-active: color-mix(in oklab, var(--accent), black 14%);
  --accent-tint: color-mix(in oklab, var(--accent) 12%, transparent);
  /* Brand secondary accents (brand-guidelines skill) */
  --blue: #6a9bcc;
  --green: #788c5d;
  /* Semantic */
  --success: #17a34a;
  --warn: #eab308;
  --danger: #b53333;        /* Error Crimson */
  --warn-bg: #f7efd6;
  /* Type */
  --font-display: "Anthropic Serif", Lora, Georgia, "Times New Roman", serif;
  --font-body: "Anthropic Sans", system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  --font-mono: "Anthropic Mono", ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;
  --text-xs: 12px;
  --text-sm: 14px;
  --text-base: 16px;
  --text-lg: 20px;
  --text-xl: 25px;
  --text-2xl: 32px;
  --leading-body: 1.6;
  --leading-tight: 1.15;
  /* Space */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --gutter: 12px;
  /* Radius */
  --radius-xs: 6px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-pill: 9999px;
  /* Elevation */
  --elev-ring: 0 0 0 1px var(--ring);
  --elev-raised: rgba(0, 0, 0, .05) 0 4px 24px;
  --focus-ring: 0 0 0 3px rgba(56, 152, 236, .3);
  --focus-blue: #3898ec;
  /* Motion */
  --motion-fast: 150ms;
  --motion-base: 200ms;
  --ease: cubic-bezier(.2, 0, 0, 1);

  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141413;           /* Deep Dark */
    --surface: #1f1e1d;
    --surface-raised: #262624;
    --surface-warm: #30302e; /* Dark Surface */
    --fg: #faf9f5;
    --fg-2: #e8e6dc;
    --fg-button: #e8e6dc;
    --muted: #b0aea5;        /* Warm Silver */
    --meta: #87867f;
    --border: #30302e;
    --border-soft: #3a3a37;
    --ring: #3d3d3a;
    --ring-deep: #4d4c48;
    --accent-tint: color-mix(in oklab, var(--accent) 22%, transparent);
    --warn-bg: #36301c;
    --elev-raised: rgba(0, 0, 0, .35) 0 4px 24px;
  }
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font: 400 var(--text-base)/var(--leading-body) var(--font-body);
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}
body { overflow: hidden; }

h1, h2, h3 { font-family: var(--font-display); font-weight: 500; line-height: var(--leading-tight); margin: 0; color: var(--fg); }
a { color: var(--accent); text-underline-offset: 2px; }
code { font-family: var(--font-mono); font-size: .9em; }
svg { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: none; box-shadow: var(--focus-ring); border-color: var(--focus-blue); }

.overline {
  font-size: 11px;
  letter-spacing: .5px;
  text-transform: uppercase;
  color: var(--meta);
  font-weight: 500;
}
.hint { color: var(--meta); font-size: var(--text-xs); line-height: 1.5; margin: 0; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 44px;              /* touch target */
  padding: 0 var(--space-4) 0 var(--space-3);
  border: 0;
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  transition: background var(--motion-fast) var(--ease), box-shadow var(--motion-fast) var(--ease), transform var(--motion-fast) var(--ease);
}
.btn:active:not(:disabled) { transform: scale(.98); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-sm { min-height: 36px; font-size: var(--text-sm); padding: 0 var(--space-3) 0 10px; border-radius: var(--radius-sm); }
.btn-sm svg { width: 16px; height: 16px; }
.btn-block { width: 100%; justify-content: flex-start; }

.btn-primary { background: var(--accent); color: var(--accent-on); box-shadow: 0 0 0 1px var(--accent); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-primary:active:not(:disabled) { background: var(--accent-active); }
.btn-sand { background: var(--surface-warm); color: var(--fg-button); box-shadow: var(--elev-ring); }
.btn-sand:hover:not(:disabled) { box-shadow: 0 0 0 1px var(--ring-deep); }
.btn-ghost { background: transparent; color: var(--fg-2); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-warm); }
.danger-text { color: var(--danger); }

.icon-btn {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--fg-2);
}
.icon-btn:hover { background: var(--surface-warm); }

.btn-row { display: flex; flex-wrap: wrap; gap: var(--space-2); }

.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--danger);
  position: absolute;
  top: 8px; right: 8px;
  box-shadow: 0 0 0 2px var(--bg);
}
.status-dot.ok { background: var(--success); }
.sidebar .status-dot { position: static; margin-left: auto; box-shadow: none; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

/* ---------- Inputs ---------- */
input:not([type=range]):not([type=file]), select, textarea {
  background: var(--surface-raised);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  padding: 10px var(--space-3);
  font-size: var(--text-base); /* 16px prevents iOS zoom on focus */
  color: var(--fg);
  transition: box-shadow var(--motion-fast) var(--ease), border-color var(--motion-fast) var(--ease);
}
input::placeholder, textarea::placeholder { color: var(--meta); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--focus-blue); box-shadow: var(--focus-ring); }

.field { display: flex; flex-direction: column; gap: 6px; font-size: var(--text-sm); font-weight: 500; color: var(--fg-2); }
.field-label { font-size: var(--text-sm); font-weight: 500; color: var(--fg-2); margin-bottom: calc(-1 * var(--space-1)); }
.field output { color: var(--accent); font-weight: 600; }
.range-labels { display: flex; justify-content: space-between; font-size: var(--text-xs); color: var(--meta); font-weight: 400; }
input[type=range] { accent-color: var(--accent); width: 100%; }

.search {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0 var(--space-3);
  background: var(--surface-raised);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  color: var(--meta);
  flex: none;
}
.search:focus-within { border-color: var(--focus-blue); box-shadow: var(--focus-ring); }
.search input { flex: 1; min-width: 0; border: 0 !important; box-shadow: none !important; background: transparent !important; padding: 10px 0 !important; }

/* ---------- App shell ---------- */
.app { display: flex; height: 100dvh; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.sidebar { display: none; }

.brand { display: flex; align-items: center; gap: 10px; font-family: var(--font-display); font-weight: 500; font-size: 18px; color: var(--fg); }
.brand-mark {
  display: grid; place-items: center;
  width: 30px; height: 30px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-on);
  flex: none;
}
.brand-mark svg { width: 17px; height: 17px; fill: currentColor; stroke: none; }

.appbar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: calc(env(safe-area-inset-top) + 8px) var(--gutter) 8px;
  padding-left: max(var(--gutter), env(safe-area-inset-left));
  padding-right: max(var(--gutter), env(safe-area-inset-right));
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.brand-compact .brand-name { display: none; }
.appbar-actions { margin-left: auto; display: flex; gap: 2px; }

.segmented {
  display: flex;
  padding: 3px;
  gap: 2px;
  background: var(--surface-warm);
  border-radius: var(--radius-md);
}
.segmented button {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 6px 12px;
  border-radius: 9px;
  font-size: var(--text-sm);
  font-weight: 500;
}
.segmented button svg { width: 16px; height: 16px; }
.segmented button[aria-selected="true"] { background: var(--surface-raised); color: var(--fg); box-shadow: 0 1px 2px rgba(0, 0, 0, .08), var(--elev-ring); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }

.workspace { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr); }
.workspace[data-view="chat"] .script-pane,
.workspace[data-view="code"] .chat-pane { display: none; }
.chat-pane, .script-pane { min-height: 0; min-width: 0; display: flex; flex-direction: column; }

/* ---------- Chat ---------- */
.messages {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--space-5) var(--gutter) var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}
.messages > * { width: 100%; max-width: 720px; margin-inline: auto; }

.welcome { display: flex; flex-direction: column; gap: var(--space-4); padding-top: var(--space-2); }
.hero-mark svg { width: 34px; height: 34px; fill: var(--accent); stroke: none; }
.welcome h1 { font-size: 30px; }
.lede { margin: 0; color: var(--muted); font-size: var(--text-base); }

.setup-card { display: flex; gap: var(--space-3); padding: var(--space-4); box-shadow: var(--elev-raised); }
.setup-icon { display: grid; place-items: center; width: 40px; height: 40px; border-radius: var(--radius-md); background: var(--accent-tint); color: var(--accent); flex: none; }
.setup-body { display: flex; flex-direction: column; gap: var(--space-2); min-width: 0; }
.setup-body h2 { font-size: var(--text-lg); }
.setup-body p { margin: 0; color: var(--muted); font-size: var(--text-sm); }

.example-grid { display: grid; grid-template-columns: 1fr; gap: var(--space-2); margin-top: calc(-1 * var(--space-2)); }
.example {
  display: flex;
  gap: var(--space-3);
  align-items: flex-start;
  text-align: left;
  padding: var(--space-3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--fg);
  transition: box-shadow var(--motion-fast) var(--ease), border-color var(--motion-fast) var(--ease);
}
.example:hover { border-color: var(--ring); box-shadow: var(--elev-raised); }
.ex-icon { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; flex: none; color: #faf9f5; }
.ex-icon svg { width: 17px; height: 17px; }
.example strong { display: block; font-weight: 500; font-size: 15px; line-height: 1.35; }
.example small { display: block; color: var(--meta); font-size: var(--text-xs); line-height: 1.45; margin-top: 2px; }
.kind-widget { background: var(--accent-soft); }
.kind-shortcut { background: var(--blue); }
.kind-app { background: var(--green); }
.kind-auto { background: var(--fg-button); }

.steps { list-style: none; margin: var(--space-2) 0 0; padding: 0; display: grid; gap: var(--space-3); }
.steps li { display: flex; gap: var(--space-3); align-items: baseline; font-size: var(--text-sm); color: var(--muted); }
.steps li span {
  flex: none; width: 24px; height: 24px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 12px; font-weight: 600;
  background: var(--surface-warm); color: var(--fg-button);
}
.steps strong { color: var(--fg); font-weight: 500; margin-right: 4px; }

/* Messages: user = sand bubble (sans), assistant = no bubble, serif body like claude.ai */
.msg { overflow-wrap: anywhere; }
.msg.user {
  align-self: flex-end;
  width: auto;
  max-width: min(85%, 600px);
  margin-right: max(0px, calc((100% - 720px) / 2));
  background: var(--surface-warm);
  color: var(--fg);
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  white-space: pre-wrap;
  font-size: 15px;
  line-height: 1.5;
}
.msg.assistant {
  font-family: var(--font-display);
  font-size: 17px;
  line-height: var(--leading-body);
  color: var(--fg);
}
.msg.assistant p { margin: 0 0 12px; }
.msg.assistant > :last-child { margin-bottom: 0; }
.msg.assistant ul { margin: 0 0 12px; padding-left: 22px; }
.msg.assistant li { margin-bottom: 4px; }
.msg.assistant h3 { font-size: var(--text-lg); margin: 4px 0 8px; }
.msg.assistant strong { font-weight: 600; }
.msg.assistant code { font-size: 14px; background: var(--surface-warm); padding: 1px 5px; border-radius: 5px; }
.msg-error, .msg-notice {
  display: flex; gap: var(--space-2); align-items: flex-start;
  font-family: var(--font-body);
  font-size: var(--text-sm);
  line-height: 1.5;
  color: var(--danger);
  background: color-mix(in oklab, var(--danger) 8%, transparent);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
  margin-top: var(--space-2);
}
.msg-notice { color: var(--fg-2); background: var(--warn-bg); }
.msg-error svg, .msg-notice svg { width: 16px; height: 16px; margin-top: 2px; }
.msg-meta { display: flex; align-items: center; gap: 6px; margin-top: var(--space-2); font-family: var(--font-body); font-size: var(--text-xs); color: var(--meta); }
.msg-meta svg { width: 13px; height: 13px; }

.version-chip {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  margin: 4px 0 14px;
  padding: 10px var(--space-3);
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  color: var(--fg);
  transition: box-shadow var(--motion-fast) var(--ease), border-color var(--motion-fast) var(--ease);
}
.version-chip:hover { box-shadow: var(--elev-raised); }
.vc-icon { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; background: var(--accent-tint); color: var(--accent); flex: none; }
.version-chip .vc-text { min-width: 0; }
.version-chip strong { display: block; font-size: 15px; font-weight: 500; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.version-chip small { display: block; font-size: var(--text-xs); color: var(--meta); }
.vc-open { margin-left: auto; font-size: var(--text-sm); color: var(--accent); font-weight: 500; white-space: nowrap; }
.version-chip.active { border-color: var(--accent-soft); }
.version-chip.streaming .vc-icon { animation: pulse 1.2s infinite var(--ease); }

.typing { display: inline-flex; gap: 6px; padding: 8px 0; }
.typing i { width: 8px; height: 8px; border-radius: 50%; background: var(--accent-soft); animation: pulse 1.2s infinite var(--ease); }
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }
@keyframes pulse { 0%, 100% { opacity: .35; transform: scale(.85); } 50% { opacity: 1; transform: scale(1); } }

/* Composer: floating card like claude.ai */
.composer {
  padding: var(--space-2) var(--gutter) calc(env(safe-area-inset-bottom) + var(--space-3));
}
.composer-card {
  max-width: 720px;
  margin: 0 auto;
  background: var(--surface-raised);
  border: 1px solid var(--border-soft);
  border-radius: 20px;
  box-shadow: var(--elev-raised);
  padding: var(--space-2) var(--space-2) var(--space-2) var(--space-3);
  transition: border-color var(--motion-fast) var(--ease), box-shadow var(--motion-fast) var(--ease);
}
.composer-card:focus-within { border-color: var(--ring-deep); }
.kind-chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding: 2px 0 6px; }
.kind-chips::-webkit-scrollbar { display: none; }
.kind-chip {
  display: inline-flex; align-items: center; gap: 6px;
  flex: none;
  padding: 5px 11px 5px 8px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-soft);
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}
.kind-chip svg { width: 15px; height: 15px; }
.kind-chip[aria-checked="true"] { background: var(--accent-tint); border-color: transparent; color: var(--accent); }
#prompt {
  display: block;
  width: 100%;
  border: 0 !important;
  box-shadow: none !important;
  background: transparent !important;
  padding: 6px 0 !important;
  resize: none;
  max-height: 40vh;
  line-height: 1.5;
}
.composer-bar { display: flex; align-items: center; gap: var(--space-2); }
.model-pill {
  display: inline-flex; align-items: center; gap: 6px;
  min-width: 0;
  max-width: 70%;
  height: 32px;
  padding: 0 8px;
  margin-left: -6px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  font-size: 13px;
}
.model-pill:hover { background: var(--surface-warm); color: var(--fg); }
.model-pill span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-pill svg { width: 15px; height: 15px; }
.kbd-hint { display: none; margin-left: auto; font-size: var(--text-xs); color: var(--meta); }
.send-btn {
  margin-left: auto;
  display: grid; place-items: center;
  width: 36px; height: 36px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-on);
  transition: background var(--motion-fast) var(--ease);
}
.send-btn:hover { background: var(--accent-hover); }
.send-btn svg { stroke-width: 2.25; }
.send-btn.stop { background: var(--fg); color: var(--bg); }
.send-btn.stop svg { fill: currentColor; stroke: none; }

/* ---------- Script pane ---------- */
.script-scroll {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--space-4) var(--gutter) calc(env(safe-area-inset-bottom) + var(--space-6));
}
#scriptContent, .empty-state { max-width: 760px; margin: 0 auto; }
#scriptContent { display: flex; flex-direction: column; gap: var(--space-3); }

.empty-state { text-align: center; padding: 15vh var(--space-4) 0; display: flex; flex-direction: column; align-items: center; gap: var(--space-3); }
.empty-state h2 { font-size: var(--text-xl); }
.empty-state p { margin: 0; color: var(--muted); max-width: 380px; }
.empty-art { display: grid; place-items: center; width: 64px; height: 64px; border-radius: var(--radius-lg); background: var(--surface-warm); color: var(--muted); }
.empty-art svg { width: 28px; height: 28px; }

.script-header { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3); }
.script-icon {
  display: grid; place-items: center;
  width: 48px; height: 48px;
  border-radius: 12px;
  color: #fff;
  flex: none;
  background: var(--icon-color, #3f51b5);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .08);
}
.script-icon svg { width: 22px; height: 22px; stroke-width: 2; }
.script-title { flex: 1; min-width: 0; }
.name-input {
  width: calc(100% + 6px);
  font-family: var(--font-display) !important;
  font-size: var(--text-lg) !important;
  font-weight: 500;
  border-color: transparent !important;
  background: transparent !important;
  padding: 2px 6px !important;
  margin-left: -6px;
  border-radius: var(--radius-sm) !important;
}
.name-input:hover { background: var(--surface-warm) !important; }
.name-input:focus { background: var(--surface-raised) !important; border-color: var(--focus-blue) !important; }
.script-meta { font-size: var(--text-xs); color: var(--meta); display: flex; flex-wrap: wrap; gap: 2px 10px; }
.script-meta .tag { display: inline-flex; align-items: center; gap: 4px; }
.script-meta .tag svg { width: 12px; height: 12px; }

.version-select { position: relative; display: flex; align-items: center; color: var(--fg-button); flex: none; }
.version-select svg { position: absolute; left: 9px; width: 15px; height: 15px; pointer-events: none; }
.version-select select {
  appearance: none;
  -webkit-appearance: none;
  padding: 7px 10px 7px 29px !important;
  font-size: var(--text-sm) !important;
  border-radius: var(--radius-sm) !important;
  background: var(--surface-warm) !important;
  border-color: transparent !important;
  color: var(--fg-button) !important;
  max-width: 110px;
}

.action-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-2); }
.action-grid .span-2 { grid-column: span 2; }

.callout {
  display: flex; flex-direction: column; gap: 6px;
  padding: var(--space-3);
  border-radius: var(--radius-md);
  background: var(--warn-bg);
  color: var(--fg-2);
  font-size: var(--text-sm);
}
.callout div { display: flex; gap: var(--space-2); align-items: flex-start; }
.callout svg { width: 16px; height: 16px; color: #b7791f; margin-top: 3px; }
.callout code { background: rgba(0, 0, 0, .06); padding: 0 4px; border-radius: 4px; }

.code-card { overflow: hidden; display: flex; flex-direction: column; }
.code-toolbar {
  display: flex; align-items: center; gap: 2px;
  padding: 4px 4px 4px var(--space-3);
  border-bottom: 1px solid var(--border);
}
.file-name { display: inline-flex; align-items: center; gap: 6px; min-width: 0; font-family: var(--font-mono); font-size: 13px; color: var(--fg-2); }
.file-name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-name svg { width: 15px; height: 15px; color: var(--meta); }
.code-stats { display: none; margin-left: auto; margin-right: 4px; font-size: var(--text-xs); color: var(--meta); white-space: nowrap; }
.code-toolbar #copyBtn { margin-left: auto; }
.code-wrap { display: flex; min-height: 240px; max-height: 60vh; background: var(--surface-raised); }
#codeView, #codeEdit {
  flex: 1;
  margin: 0;
  overflow: auto;
  font: 13px/1.6 var(--font-mono);
  tab-size: 2;
}
#codeView code { display: block; padding: var(--space-3) var(--space-4); min-width: max-content; background: transparent; color: var(--fg-2); font-size: 13px; }
#codeEdit { border: 0 !important; border-radius: 0 !important; box-shadow: none !important; padding: var(--space-3) var(--space-4) !important; resize: none; white-space: pre; font-size: 13px !important; background: var(--surface-raised); }

/* Syntax colors from the brand accents */
.hljs-keyword, .hljs-built_in, .hljs-literal { color: var(--accent); }
.hljs-string, .hljs-regexp, .hljs-template-variable { color: var(--green); }
.hljs-number, .hljs-attr { color: var(--blue); }
.hljs-title, .hljs-title.function_, .hljs-title.class_ { color: var(--fg); font-weight: 500; }
.hljs-comment { color: var(--meta); font-style: italic; }
.hljs-subst, .hljs-params, .hljs-property { color: var(--fg-2); }
@media (prefers-color-scheme: dark) {
  .hljs-keyword, .hljs-built_in, .hljs-literal { color: var(--accent-soft); }
  .hljs-string, .hljs-regexp, .hljs-template-variable { color: #a3b88a; }
  .hljs-number, .hljs-attr { color: #8fb6dd; }
}

.disclosure summary {
  display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  cursor: pointer;
  list-style: none;
  font-weight: 500;
  font-size: 15px;
  min-height: 48px;
}
.disclosure summary::-webkit-details-marker { display: none; }
.disclosure summary > svg:first-child { color: var(--muted); }
.disclosure summary .chev { margin-left: auto; color: var(--meta); transition: transform var(--motion-base) var(--ease); }
.disclosure[open] summary .chev { transform: rotate(180deg); }
.disclosure-body { padding: 0 var(--space-4) var(--space-4); display: flex; flex-direction: column; gap: var(--space-3); }

.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch {
  width: 32px; height: 32px;
  border-radius: 50%;
  border: 0;
  background: var(--c);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .1);
  transition: transform var(--motion-fast) var(--ease);
}
.swatch[aria-checked="true"] { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--fg); }
.swatch:hover { transform: scale(1.08); }

.install-steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: var(--space-2); font-size: var(--text-sm); color: var(--muted); }
.install-steps strong { color: var(--fg); font-weight: 500; }
.install-steps em { font-style: normal; color: var(--fg-2); font-weight: 500; }
.install-steps code { background: var(--surface-warm); padding: 1px 5px; border-radius: 4px; color: var(--fg-2); }
.run-row { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.run-url { font-size: var(--text-xs); color: var(--meta); word-break: break-all; }

/* ---------- Sheets (dialogs): bottom sheet on phones, centered modal on larger screens ---------- */
dialog.sheet {
  border: 0;
  padding: 0;
  margin: auto auto 0;
  width: 100%;
  max-width: 100%;
  max-height: 92dvh;
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  background: var(--surface);
  color: var(--fg);
  box-shadow: var(--elev-raised);
}
dialog.sheet-tall { height: 92dvh; }
dialog.sheet[open] { animation: sheet-in var(--motion-base) var(--ease); }
dialog::backdrop { background: rgba(20, 20, 19, .4); backdrop-filter: blur(2px); }
@keyframes sheet-in { from { transform: translateY(24px); opacity: 0; } }

.sheet-body {
  display: flex; flex-direction: column; gap: var(--space-4);
  padding: var(--space-3) var(--space-4) calc(env(safe-area-inset-bottom) + var(--space-4));
  height: 100%;
  max-height: inherit;
  overflow-y: auto;
}
.sheet-body::before {
  content: "";
  align-self: center;
  width: 36px; height: 5px;
  border-radius: 3px;
  background: var(--ring);
  margin-bottom: -4px;
  flex: none;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-right: -8px; }
.sheet-head h2 { font-size: var(--text-xl); }
.sheet-section { display: flex; flex-direction: column; gap: var(--space-3); padding-top: var(--space-4); border-top: 1px solid var(--border); }
.sheet-foot { display: flex; justify-content: flex-end; gap: var(--space-2); padding-top: var(--space-2); }
.sheet-foot .btn { flex: 1; justify-content: center; }

.key-status { display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-sm); color: var(--muted); flex-wrap: wrap; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: var(--radius-pill); font-size: var(--text-xs); font-weight: 500; }
.pill.ok { background: color-mix(in oklab, var(--success) 14%, transparent); color: var(--success); }
.pill.missing { background: color-mix(in oklab, var(--danger) 12%, transparent); color: var(--danger); }

.model-row {
  display: flex; align-items: center; gap: var(--space-3);
  width: 100%;
  padding: var(--space-3);
  text-align: left;
  background: var(--surface-raised);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
}
.model-row:hover { border-color: var(--ring-deep); }
.model-row > svg:first-child { color: var(--accent); }
.model-row span { flex: 1; min-width: 0; }
.model-row strong { display: block; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-row small { display: block; color: var(--meta); font-size: var(--text-xs); }
.model-row .chev { transform: rotate(-90deg); color: var(--meta); }

.model-list { display: flex; flex-direction: column; gap: 2px; margin-top: calc(-1 * var(--space-2)); }
.model-option {
  display: flex; align-items: center; gap: var(--space-3);
  width: 100%;
  padding: 10px var(--space-3);
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
}
.model-option:hover { background: var(--surface-warm); }
.model-option[aria-selected="true"] { border-color: var(--accent-soft); background: var(--accent-tint); }
.mo-text { flex: 1; min-width: 0; }
.mo-text strong { display: block; font-weight: 500; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mo-text small { display: block; font-size: var(--text-xs); color: var(--meta); font-family: var(--font-mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mo-price { text-align: right; font-size: var(--text-xs); color: var(--meta); white-space: nowrap; }
.mo-price b { display: block; font-weight: 500; color: var(--fg-2); }
.mo-price .free { color: var(--success); }
.model-option > svg { color: var(--accent); visibility: hidden; }
.model-option[aria-selected="true"] > svg { visibility: visible; }

/* ---------- Cloud & sharing ---------- */
.cloud-row { display: flex; gap: var(--space-3); align-items: flex-start; font-size: var(--text-sm); color: var(--muted); }
.cloud-row svg { color: var(--accent); margin-top: 2px; }
.cloud-row strong { color: var(--fg); font-weight: 500; word-break: break-all; }
.share-on { display: flex; flex-direction: column; gap: var(--space-2); }

/* Account */
.sheet-text { margin: 0; color: var(--muted); font-size: var(--text-sm); }
.sheet-text strong { color: var(--fg); font-weight: 500; overflow-wrap: anywhere; }
.account-row { display: flex; align-items: center; gap: var(--space-3); }
.account-avatar { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; background: var(--accent-tint); color: var(--accent); flex: none; }
.account-text { flex: 1; min-width: 0; font-size: var(--text-sm); }
.account-text small { display: block; color: var(--meta); font-size: var(--text-xs); }
.account-text strong { display: block; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.passkey-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.passkey-list li { display: flex; align-items: center; gap: var(--space-3); padding: 6px 0 6px var(--space-2); border-radius: var(--radius-md); background: var(--surface-raised); box-shadow: var(--elev-ring); }
.passkey-list li.hint { padding: 0; background: none; box-shadow: none; }
.passkey-list li > svg { color: var(--accent); }
.pk-text { flex: 1; min-width: 0; font-size: var(--text-sm); }
.pk-text strong { display: block; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pk-text small { display: block; color: var(--meta); font-size: var(--text-xs); }
.pk-text .synced { color: var(--success); }
.passkey-list .icon-btn:disabled { opacity: .35; cursor: not-allowed; }
.passkey-list .icon-btn:not(:disabled):hover { color: var(--danger); }
.device-code { display: flex; flex-direction: column; gap: var(--space-2); padding: var(--space-3); border-radius: var(--radius-md); background: var(--accent-tint); }
.device-code code { font-size: 26px; font-weight: 600; letter-spacing: 3px; color: var(--fg); user-select: all; }

.auth-step { display: flex; flex-direction: column; gap: var(--space-4); }
.auth-submit { width: 100%; }
.auth-tip { padding: var(--space-3); border-radius: var(--radius-md); background: var(--surface-warm); font-size: var(--text-sm); color: var(--fg-2); line-height: 1.5; }
.auth-tip strong { font-weight: 600; }
.auth-tip em { font-style: normal; font-weight: 500; }
.auth-error { margin: 0; padding: 10px var(--space-3); border-radius: var(--radius-md); background: color-mix(in oklab, var(--danger) 10%, transparent); color: var(--danger); font-size: var(--text-sm); }
.auth-restart { align-self: center; }
#deviceCodeInput { font-family: var(--font-mono); letter-spacing: 2px; text-transform: uppercase; }
.link-btn { border: 0; padding: 0; background: none; color: var(--accent); font-weight: 500; text-decoration: underline; text-underline-offset: 2px; }
.share-url {
  display: block;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  background: var(--surface-warm);
  color: var(--fg-2);
  font-size: var(--text-xs);
  word-break: break-all;
}
.setup-note { display: flex; flex-direction: column; gap: var(--space-2); padding-top: var(--space-3); border-top: 1px solid var(--border); font-size: var(--text-sm); color: var(--muted); }
.setup-note strong { color: var(--fg); font-weight: 500; }
.setup-note code { background: var(--surface-warm); padding: 1px 5px; border-radius: 4px; color: var(--fg-2); }
.sync-state { display: inline-flex; align-items: center; gap: 4px; }
.sync-state svg { width: 12px; height: 12px; }
.sync-state.error { color: var(--danger); }

/* ---------- Library ---------- */
.library-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.library-list li { display: flex; align-items: center; border-radius: var(--radius-md); }
.library-list li:hover, .library-list li.current { background: var(--surface-warm); }
.lib-open {
  flex: 1; min-width: 0;
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-2);
  border: 0; background: transparent; text-align: left;
  border-radius: var(--radius-md);
}
.lib-icon { width: 32px; height: 32px; border-radius: 8px; background: var(--c); flex: none; display: grid; place-items: center; color: #fff; }
.lib-icon svg { width: 16px; height: 16px; }
.lib-text { min-width: 0; }
.lib-text strong { display: block; font-weight: 500; font-size: var(--text-sm); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib-text small { display: block; font-size: var(--text-xs); color: var(--meta); }
.lib-del { opacity: .55; }
.lib-del:hover { opacity: 1; color: var(--danger); }
.library-empty { color: var(--meta); font-size: var(--text-sm); padding: var(--space-4) var(--space-2); text-align: center; line-height: 1.5; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 112px);
  transform: translateX(-50%);
  background: var(--fg);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: var(--radius-pill);
  font-size: var(--text-sm);
  font-weight: 500;
  z-index: 100;
  width: max-content;
  max-width: calc(100vw - 32px);
  text-align: center;
  box-shadow: var(--elev-raised);
}

/* =================== Tablet (≥ 640px) =================== */
@media (min-width: 640px) {
  :root { --gutter: 20px; }
  .brand-compact .brand-name { display: inline; }
  .appbar .segmented { margin-left: var(--space-4); }
  .example-grid { grid-template-columns: 1fr 1fr; }
  .steps { grid-template-columns: repeat(3, 1fr); }
  .steps li { flex-direction: column; gap: var(--space-2); }
  .welcome h1 { font-size: 36px; }
  .action-grid { grid-template-columns: 1.4fr 1fr 1fr; }
  .action-grid .span-2 { grid-column: auto; }
  .kbd-hint { display: inline; }
  .kbd-hint + .send-btn, .kbd-hint + .send-btn + .send-btn { margin-left: 0; }
  .code-stats { display: inline; }
  .code-toolbar #copyBtn { margin-left: 0; }

  dialog.sheet {
    margin: auto;
    width: min(560px, calc(100vw - 48px));
    border-radius: var(--radius-xl);
    max-height: 85dvh;
  }
  dialog.sheet-tall { height: min(720px, 85dvh); }
  .sheet-body { padding: var(--space-5) var(--space-6) var(--space-6); }
  .sheet-body::before { display: none; }
  .sheet-foot .btn { flex: none; }
}

/* =================== Desktop (≥ 992px): chat + script side by side =================== */
@media (min-width: 992px) {
  .segmented { display: none; }
  .workspace { grid-template-columns: minmax(380px, 1fr) minmax(0, 1.15fr); }
  .workspace[data-view] .chat-pane, .workspace[data-view] .script-pane { display: flex; }
  .script-pane { border-left: 1px solid var(--border); background: var(--surface); }
  .script-pane .card { background: var(--bg); }
  .code-wrap { max-height: none; min-height: 320px; height: 52vh; }
  .welcome { padding-top: 4vh; }
}

/* =================== Wide (≥ 1200px): add sidebar like claude.ai =================== */
@media (min-width: 1200px) {
  .sidebar {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    width: 272px;
    flex: none;
    padding: var(--space-4) var(--space-3);
    background: var(--bg);
    border-right: 1px solid var(--border);
  }
  .sidebar .brand { padding: 2px var(--space-2) var(--space-2); }
  .sidebar .overline { padding: var(--space-2) var(--space-2) 0; }
  .sidebar .library-list { flex: 1; min-height: 0; }
  .sidebar-footer { border-top: 1px solid var(--border); padding-top: var(--space-2); }
  .appbar { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
