/* ============================================================
   Forge IDE — styles
   Mobile-first: base styles are single-pane; ≥960px adds the
   resizable multi-pane grid. All controls ≥44px touch targets.
   ============================================================ */

/* ---------- Design tokens ---------- */
:root {
  --font-body: 'Satoshi', 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'Cascadia Mono', monospace;

  --text-xs: clamp(0.75rem, 0.7rem + 0.2vw, 0.8125rem);
  --text-sm: clamp(0.8125rem, 0.78rem + 0.2vw, 0.9375rem);
  --text-base: clamp(0.875rem, 0.84rem + 0.25vw, 1rem);
  --text-lg: clamp(1rem, 0.95rem + 0.4vw, 1.1875rem);
  --text-xl: clamp(1.125rem, 1rem + 0.8vw, 1.5rem);

  --space-1: 0.25rem; --space-2: 0.5rem; --space-3: 0.75rem; --space-4: 1rem;
  --space-6: 1.5rem; --space-8: 2rem;

  --radius-sm: 0.375rem; --radius-md: 0.5rem; --radius-lg: 0.75rem; --radius-xl: 1rem;

  --transition-interactive: 160ms cubic-bezier(0.16, 1, 0.3, 1);

  --header-h: 3.5rem;
  --nav-h: 3.75rem;
  --touch: 44px;
}

[data-theme='dark'] {
  --bg: #0d1117;
  --surface: #151a23;
  --surface-2: #1a2029;
  --surface-3: #202836;
  --border: #262f3d;
  --divider: #202734;
  --text: #d9e0ea;
  --muted: #8b96a8;
  --faint: #5f6b7d;
  --accent: #45c4d8;
  --accent-strong: #2fb3c9;
  --accent-ink: #06222a;
  --accent-soft: rgba(69, 196, 216, 0.14);
  --success: #5cc078;
  --warn: #e0b341;
  --error: #ef6a6a;
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.55);
  --code-bg: #10151d;
  --scrollbar: #2a3444;
}

[data-theme='light'] {
  --bg: #eef1f5;
  --surface: #ffffff;
  --surface-2: #f6f8fa;
  --surface-3: #eaeef3;
  --border: #d5dbe4;
  --divider: #e2e7ee;
  --text: #1a2330;
  --muted: #57627a;
  --faint: #8b95a8;
  --accent: #0e7f93;
  --accent-strong: #0a6778;
  --accent-ink: #ffffff;
  --accent-soft: rgba(14, 127, 147, 0.1);
  --success: #237a3c;
  --warn: #8a6410;
  --error: #c0392f;
  --shadow-md: 0 4px 16px rgba(30, 45, 70, 0.12);
  --shadow-lg: 0 12px 40px rgba(30, 45, 70, 0.18);
  --code-bg: #f3f5f8;
  --scrollbar: #c3ccd8;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme]) { /* same as [data-theme='light'] */ }
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: none; text-size-adjust: none; -webkit-font-smoothing: antialiased; }
html, body { height: 100%; }
body {
  display: flex;
  flex-direction: column;
  font-family: var(--font-body);
  font-size: var(--text-base);
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
}
img, svg, video, canvas { display: block; max-width: 100%; }
button { cursor: pointer; background: none; border: none; color: inherit; font: inherit; }
input, textarea, select { font: inherit; color: inherit; }
h1, h2, h3 { line-height: 1.2; text-wrap: balance; }
ul { list-style: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--radius-sm); }
::selection { background: var(--accent-soft); }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: -999px; top: 0; z-index: 300;
  background: var(--accent); color: var(--accent-ink); padding: var(--space-2) var(--space-4);
  border-radius: 0 0 var(--radius-md) 0;
}
.skip-link:focus { left: 0; }

*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 5px; border: 2px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-track { background: transparent; }

/* ---------- Buttons & controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  min-height: var(--touch); min-width: var(--touch); padding: 0 var(--space-3);
  border-radius: var(--radius-md); border: 1px solid transparent;
  font-size: var(--text-sm); font-weight: 500; white-space: nowrap;
  transition: background var(--transition-interactive), border-color var(--transition-interactive), color var(--transition-interactive);
}
.btn svg { width: 18px; height: 18px; flex: none; }
.btn-primary { background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.btn-primary:hover { background: var(--accent-strong); }
.btn-ghost { color: var(--muted); border-color: var(--border); background: transparent; }
.btn-ghost:hover { color: var(--text); background: var(--surface-3); }
.btn-danger { background: var(--error); color: #fff; font-weight: 700; }
.btn-danger:hover { filter: brightness(0.92); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-xs { min-height: var(--touch); padding: 0 var(--space-2); font-size: var(--text-xs); }
.icon-only { padding: 0; width: var(--touch); }
.hidden { display: none !important; }

select, input[type='text'], input[type='url'], input[type='number'], input[type='password'], input[type='search'], textarea {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 0.55rem var(--space-2); color: var(--text); min-height: var(--touch);
  font-size: var(--text-sm); width: 100%;
}
textarea { resize: vertical; line-height: 1.5; }
select:focus, input:focus, textarea:focus { border-color: var(--accent); outline: none; }

/* ---------- Header ---------- */
.app-header {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-2);
  height: var(--header-h); padding: 0 var(--space-2); flex: none;
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: relative; z-index: 40;
}
.brand { display: flex; align-items: center; gap: var(--space-2); min-width: 0; }
.brand-mark { width: 26px; height: 26px; flex: none; }
.brand-name { font-weight: 700; font-size: var(--text-lg); letter-spacing: 0.01em; }
.project-name {
  background: transparent; border: 1px solid transparent; border-radius: var(--radius-sm);
  color: var(--muted); font-family: var(--font-mono); font-size: var(--text-sm);
  min-height: var(--touch); padding: 0 var(--space-2); width: 9rem;
}
.project-name:hover, .project-name:focus { border-color: var(--border); background: var(--surface-2); color: var(--text); }
.header-actions { display: flex; align-items: center; gap: var(--space-1); flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
.header-actions::-webkit-scrollbar { display: none; }
.mode-wrap select { min-height: var(--touch); font-size: var(--text-xs); max-width: 9.5rem; }
.menu-wrap { position: relative; }
.dropdown {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 15rem;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); padding: var(--space-1); z-index: 60;
}
.dropdown button {
  display: flex; align-items: center; gap: var(--space-2); width: 100%;
  min-height: var(--touch); padding: 0 var(--space-3); border-radius: var(--radius-sm);
  font-size: var(--text-sm); color: var(--text); text-align: left;
}
.dropdown button:hover { background: var(--surface-3); }
.dropdown svg { width: 16px; height: 16px; color: var(--muted); }

/* ---------- Workbench: mobile-first single pane ---------- */
#workbench {
  flex: 1; position: relative; overflow: hidden; touch-action: pan-y;
}
.pane {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  background: var(--bg); overflow: hidden;
}
#pane-mid { display: contents; }
#pane-chat.active, #pane-editor.active, #pane-console.active, #pane-preview.active, #pane-mid.active { display: flex; }
.pane:not(.active) { display: none; }
.pane-handle { display: none; }

/* ---------- Bottom nav (mobile) ---------- */
.bottom-nav {
  display: flex; flex: none; height: var(--nav-h);
  background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  position: relative; z-index: 40;
}
.nav-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--faint); font-size: var(--text-xs); min-height: var(--touch);
}
.nav-btn svg { width: 20px; height: 20px; }
.nav-btn.active { color: var(--accent); }

/* ---------- Chat pane ---------- */
.pane-chat { background: var(--bg); }
.chat-header {
  display: flex; align-items: center; gap: var(--space-2); flex: none;
  padding: var(--space-2) var(--space-3); border-bottom: 1px solid var(--border);
  background: var(--surface); min-height: 48px;
}
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--faint); flex: none; }
.status-dot.ok { background: var(--success); box-shadow: 0 0 6px var(--success); }
.status-dot.err { background: var(--error); }
.status-dot.busy { background: var(--warn); animation: pulse 1s infinite alternate; }
@keyframes pulse { to { opacity: 0.4; } }
.chat-status-text { font-size: var(--text-xs); color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-header-actions { margin-left: auto; }
.chat-messages {
  flex: 1; overflow-y: auto; padding: var(--space-3);
  display: flex; flex-direction: column; gap: var(--space-3);
  scroll-behavior: smooth;
}
.msg { max-width: 100%; display: flex; flex-direction: column; gap: var(--space-2); }
.msg-role {
  display: flex; align-items: center; gap: var(--space-2);
  font-size: var(--text-xs); color: var(--muted); font-weight: 700;
}
.msg-role svg { width: 15px; height: 15px; }
.msg-body { font-size: var(--text-base); line-height: 1.55; overflow-wrap: anywhere; }
.msg-body p { margin: 0 0 var(--space-2); }
.msg-body p:last-child { margin: 0; }
.msg-body ul, .msg-body ol { margin: 0 0 var(--space-2); padding-left: 1.2rem; }
.msg-body li { margin: 2px 0; }
.msg-body strong { color: var(--text); }
.msg-body code.inline {
  font-family: var(--font-mono); font-size: 0.86em; background: var(--surface-3);
  padding: 1px 5px; border-radius: 4px; color: var(--accent);
}
.chat-composer { flex: none; border-top: 1px solid var(--border); background: var(--surface); padding: var(--space-2); }
.chat-quickbar { display: flex; gap: var(--space-1); align-items: center; flex-wrap: wrap; margin-bottom: var(--space-2); }
.chip-toggle {
  display: inline-flex; align-items: center; gap: 6px; min-height: var(--touch);
  padding: 0 var(--space-2); border: 1px solid var(--border); border-radius: var(--radius-full);
  font-size: var(--text-xs); color: var(--muted); cursor: pointer;
}
.chip-toggle input { accent-color: var(--accent); width: 15px; height: 15px; }
.chip-toggle svg { width: 14px; height: 14px; }
.chip-toggle:has(input:checked) { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.composer-row { display: flex; gap: var(--space-2); align-items: flex-end; }
#chat-input {
  flex: 1; min-height: var(--touch); max-height: 9rem; line-height: 1.45;
  padding: 0.6rem var(--space-3); font-size: var(--text-base); border-radius: var(--radius-lg);
}
.composer-row .btn { flex: none; }

/* Chat code blocks */
.codeblock {
  border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden;
  background: var(--code-bg);
}
.codeblock-head {
  display: flex; align-items: center; gap: var(--space-2); padding: 0 var(--space-2);
  background: var(--surface-3); border-bottom: 1px solid var(--border);
  min-height: 40px; font-size: var(--text-xs); color: var(--muted);
}
.codeblock-lang { font-family: var(--font-mono); color: var(--accent); font-weight: 600; }
.codeblock-file { font-family: var(--font-mono); }
.codeblock-actions { margin-left: auto; display: flex; gap: var(--space-1); }
.codeblock-actions button {
  min-height: 44px; min-width: 44px; padding: 0 10px; border-radius: var(--radius-sm);
  font-size: var(--text-xs); color: var(--muted); display: inline-flex; align-items: center; gap: 4px;
}
.codeblock-actions button:hover { color: var(--text); background: var(--surface-2); }
.codeblock-actions button.applied { color: var(--success); }
.codeblock-actions svg { width: 14px; height: 14px; }
.codeblock pre {
  overflow-x: auto; padding: var(--space-3); margin: 0;
  font-family: var(--font-mono); font-size: var(--text-xs); line-height: 1.55;
}
.codeblock code { font-family: inherit; }

/* ---------- Editor pane ---------- */
.pane-editor { background: var(--surface); }
.editor-toolbar {
  display: flex; align-items: center; gap: 2px; flex: none; min-height: 48px;
  padding: 0 var(--space-1); border-bottom: 1px solid var(--border); background: var(--surface);
  overflow-x: auto; scrollbar-width: none;
}
.editor-toolbar::-webkit-scrollbar { display: none; }
.editor-tools { margin-left: auto; display: flex; gap: 2px; }
.file-tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; flex: 1; }
.file-tabs::-webkit-scrollbar { display: none; }
.file-tab {
  display: flex; align-items: center; gap: var(--space-2); flex: none;
  min-height: var(--touch); padding: 0 var(--space-3); border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  font-size: var(--text-xs); color: var(--muted); font-family: var(--font-mono);
  border: 1px solid transparent; border-bottom: none; margin-bottom: -1px;
}
.file-tab.active { color: var(--text); background: var(--surface-2); border-color: var(--border); }
.file-tab .close-x { opacity: 0.5; display: inline-flex; min-width: 32px; min-height: 32px; align-items: center; justify-content: center; margin-right: -6px; }
.file-tab .close-x:hover { opacity: 1; color: var(--error); }
.editor-body { flex: 1; display: flex; min-height: 0; }
.file-tree {
  width: 11rem; flex: none; overflow-y: auto; padding: var(--space-2);
  border-right: 1px solid var(--border); background: var(--surface-2);
}
.ft-item {
  display: flex; align-items: center; gap: var(--space-2); width: 100%;
  min-height: var(--touch); padding: 0 var(--space-2); border-radius: var(--radius-sm);
  font-family: var(--font-mono); font-size: var(--text-xs); color: var(--muted); text-align: left;
}
.ft-item:hover { background: var(--surface-3); color: var(--text); }
.ft-item.active { background: var(--accent-soft); color: var(--accent); }
.ft-item svg { width: 14px; height: 14px; flex: none; }
.ft-item .ft-name { flex: 1; min-width: 0; overflow: visible; text-overflow: clip; white-space: nowrap; }
.ft-item .ft-del { margin-left: auto; opacity: 0; color: var(--error); min-width: 44px; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }
.ft-item:hover .ft-del { opacity: 0.7; }
.editor-host { flex: 1; min-width: 0; position: relative; }
.editor-host .CodeMirror { height: 100%; font-family: var(--font-mono); font-size: 13px; }
.editor-host .CodeMirror-linenumber { color: var(--faint); }
.editor-empty {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--faint); font-size: var(--text-sm);
}

/* ---------- Console pane ---------- */
.pane-console { background: var(--surface); }
.console-toolbar {
  display: flex; align-items: center; gap: var(--space-2); flex: none; min-height: 48px;
  padding: 0 var(--space-2); border-bottom: 1px solid var(--border); background: var(--surface);
}
.console-title { display: flex; align-items: center; gap: 6px; font-size: var(--text-xs); font-weight: 700; color: var(--muted); }
.console-title svg { width: 15px; height: 15px; }
.console-filters { display: flex; gap: 2px; }
.filter-btn {
  min-height: 44px; padding: 0 var(--space-3); border-radius: var(--radius-sm);
  font-size: var(--text-xs); color: var(--muted);
}
.filter-btn.active { background: var(--surface-3); color: var(--text); }
.console-actions { margin-left: auto; display: flex; gap: var(--space-1); align-items: center; }
.console-output {
  flex: 1; overflow-y: auto; padding: var(--space-2);
  font-family: var(--font-mono); font-size: var(--text-xs); line-height: 1.6;
}
.con-entry { display: flex; gap: var(--space-2); padding: 2px 0; border-bottom: 1px solid var(--divider); }
.con-entry .con-time { color: var(--faint); flex: none; }
.con-entry .con-level { flex: none; font-weight: 700; width: 3.2rem; }
.con-entry .con-text { overflow-wrap: anywhere; white-space: pre-wrap; }
.con-entry.log .con-level { color: var(--muted); }
.con-entry.info .con-level { color: var(--accent); }
.con-entry.warn .con-level { color: var(--warn); }
.con-entry.warn .con-text { color: var(--warn); }
.con-entry.error .con-level { color: var(--error); }
.con-entry.error .con-text { color: var(--error); }
.con-entry.system .con-level { color: var(--success); }
.con-empty { color: var(--faint); padding: var(--space-3); }

/* ---------- Preview pane ---------- */
.pane-preview { background: var(--surface-2); }
.preview-toolbar {
  display: flex; align-items: center; gap: var(--space-2); flex: none; min-height: 48px;
  padding: 0 var(--space-2); border-bottom: 1px solid var(--border); background: var(--surface);
}
.device-group { display: flex; gap: 2px; }
.device-btn {
  min-width: var(--touch); min-height: var(--touch); border-radius: var(--radius-sm);
  color: var(--muted); display: inline-flex; align-items: center; justify-content: center;
}
.device-btn.active { background: var(--accent-soft); color: var(--accent); }
.device-btn svg { width: 17px; height: 17px; }
.preview-actions { margin-left: auto; display: flex; gap: 2px; }
.preview-stage { flex: 1; overflow: auto; display: flex; align-items: flex-start; justify-content: center; padding: var(--space-3); }
.preview-frame {
  background: #fff; border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  transition: width 200ms ease, height 200ms ease; overflow: hidden; flex: none;
}
.preview-frame.device-desktop { width: 100%; height: 100%; max-width: 100%; }
.preview-frame.device-mobile { width: 390px; height: 844px; }
.preview-frame.device-tablet { width: 820px; height: 1180px; }
#preview-iframe { width: 100%; height: 100%; border: 0; background: #fff; }
[data-theme='dark'] #preview-iframe { background: #fff; }

/* ---------- Desktop: resizable multi-pane grid ---------- */
@media (min-width: 960px) {
  .bottom-nav { display: none; }
  .desktop-only { display: inline-flex; }
  #workbench {
    display: grid;
    grid-template-columns: minmax(240px, var(--w-chat, 380px)) 7px minmax(280px, 1fr) 7px minmax(260px, var(--w-preview, 430px));
    grid-template-rows: 1fr;
  }
  .pane { position: static; display: flex !important; }
  #pane-chat { grid-column: 1; grid-row: 1; }
  .pane-handle[data-handle="chat"] { grid-column: 2; grid-row: 1; }
  #pane-mid { display: flex; flex-direction: column; position: static; grid-column: 3; grid-row: 1; }
  .pane-handle[data-handle="preview"] { grid-column: 4; grid-row: 1; }
  #pane-preview { grid-column: 5; grid-row: 1; }
  .pane-handle {
    display: block; position: relative; z-index: 5; background: var(--bg); flex: none;
  }
  .pane-handle-v { width: 7px; cursor: col-resize; }
  .pane-handle-h { height: 7px; cursor: row-resize; }
  .pane-handle::after {
    content: ''; position: absolute; inset: 0; margin: auto; border-radius: 3px;
    background: var(--border); opacity: 0; transition: opacity var(--transition-interactive);
  }
  .pane-handle-v::after { width: 3px; height: 36px; top: 0; bottom: 0; }
  .pane-handle-h::after { height: 3px; width: 36px; left: 0; right: 0; }
  .pane-handle:hover::after, .pane-handle:focus-visible::after { opacity: 1; background: var(--accent); }
  #pane-mid { --h-console: 220px; }
  #pane-editor { flex: 1 1 auto; min-height: 120px; }
  #pane-console { flex: none; height: var(--h-console, 220px); min-height: 100px; }
}

/* ---------- Drawer (settings) ---------- */
.drawer-backdrop, .modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(4, 8, 14, 0.55);
  display: flex; align-items: stretch; justify-content: flex-end;
}
.modal-backdrop { align-items: center; justify-content: center; padding: var(--space-3); }
.drawer {
  width: min(30rem, 100%); height: 100%; background: var(--surface);
  border-left: 1px solid var(--border); display: flex; flex-direction: column;
  animation: slide-in 200ms cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes slide-in { from { transform: translateX(40px); opacity: 0; } }
.drawer-head, .modal-head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-2);
  padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--border); flex: none;
}
.drawer-head h2, .modal-head h2 { display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-lg); }
.drawer-head svg, .modal-head svg { width: 19px; height: 19px; color: var(--accent); }
.drawer-body { flex: 1; overflow-y: auto; padding: var(--space-4); }
.settings-section { margin-bottom: var(--space-6); }
.settings-section h3 { font-size: var(--text-sm); color: var(--accent); margin-bottom: var(--space-3); text-transform: uppercase; letter-spacing: 0.06em; }
.settings-section h3 small { color: var(--muted); text-transform: none; letter-spacing: 0; font-weight: 400; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--space-3); font-size: var(--text-sm); }
.field > span { color: var(--muted); font-size: var(--text-xs); }
.field.checkbox { flex-direction: row; align-items: center; gap: var(--space-2); }
.field.checkbox input { width: 18px; height: 18px; accent-color: var(--accent); }
.field-row { display: flex; gap: var(--space-2); margin-bottom: var(--space-3); }
.field-row input { flex: 1; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 var(--space-4); }
.hint { color: var(--muted); font-size: var(--text-xs); line-height: 1.5; margin-bottom: var(--space-3); }
.hint code { font-family: var(--font-mono); background: var(--surface-3); padding: 1px 5px; border-radius: 4px; }
.hw-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-2); margin-bottom: var(--space-2); }
.hw-item { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-md); padding: var(--space-2) var(--space-3); display: flex; flex-direction: column; gap: 2px; }
.hw-label { font-size: var(--text-xs); color: var(--muted); }
.hw-value { font-family: var(--font-mono); font-size: var(--text-sm); color: var(--text); }
.danger h3 { color: var(--error); }
input[type='range'] { accent-color: var(--accent); min-height: 0; padding: 0; border: none; background: transparent; }
output { font-family: var(--font-mono); color: var(--accent); font-size: var(--text-xs); align-self: center; }

/* ---------- Modals ---------- */
.modal {
  width: min(34rem, 100%); max-height: min(46rem, 92dvh); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-xl); display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg); overflow: hidden;
}
.modal-wide { width: min(48rem, 100%); }
.modal-body { padding: var(--space-4); overflow-y: auto; }

/* ---------- App store ---------- */
.store-tabs { display: flex; gap: 2px; padding: var(--space-2) var(--space-4) 0; }
.store-tab {
  min-height: var(--touch); padding: 0 var(--space-4); border-radius: var(--radius-md) var(--radius-md) 0 0;
  color: var(--muted); font-weight: 600; font-size: var(--text-sm);
}
.store-tab.active { color: var(--text); background: var(--surface-2); }
.store-toolbar { display: flex; gap: var(--space-2); padding: var(--space-3) var(--space-4); }
#store-browse, #store-publish, #store-main { display: flex; flex-direction: column; min-height: 0; }
#store-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr)); gap: var(--space-3);
  padding: 0 var(--space-4) var(--space-4); overflow-y: auto; flex: 1; align-content: start;
}
.app-card {
  display: flex; flex-direction: column; gap: var(--space-2); text-align: left;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: var(--space-3); cursor: pointer; min-height: var(--touch);
  transition: border-color var(--transition-interactive), transform var(--transition-interactive);
}
.app-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.app-icon { font-size: 1.6rem; }
.app-name { font-weight: 700; font-size: var(--text-sm); }
.app-desc { font-size: var(--text-xs); color: var(--muted); line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.app-meta { display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-xs); color: var(--muted); }
.stars { color: var(--warn); letter-spacing: 1px; }
.app-author { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.store-publish-form { padding: var(--space-4); }
.rating-input { display: flex; gap: 2px; }
.rating-input button { font-size: 1.4rem; min-height: var(--touch); min-width: var(--touch); color: var(--faint); line-height: 1; }
.rating-input button.on { color: var(--warn); }
.comment { border-top: 1px solid var(--divider); padding: var(--space-3) 0; }
.comment-head { display: flex; gap: var(--space-2); align-items: baseline; font-size: var(--text-xs); color: var(--muted); }
.comment-stars { color: var(--warn); }
.comment-text { font-size: var(--text-sm); margin-top: 2px; }
.store-detail-head { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-4); }
.store-detail-icon { font-size: 2.2rem; }
.detail-actions { margin-left: auto; display: flex; gap: var(--space-2); }

/* ---------- Snapshots ---------- */
.snapshot-list { display: flex; flex-direction: column; gap: var(--space-2); }
.snapshot-item {
  display: flex; align-items: center; gap: var(--space-3); padding: var(--space-2) var(--space-3);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-md);
  font-size: var(--text-sm);
}
.snapshot-item .snap-time { color: var(--muted); font-size: var(--text-xs); font-family: var(--font-mono); }
.snapshot-item .snap-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Prompt builder ---------- */
.builder-step textarea { width: 100%; }
.builder-step h3 { font-size: var(--text-base); margin-bottom: var(--space-3); }
.pb-examples, .chip-grid { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-3); }
.chip {
  min-height: var(--touch); padding: 0 var(--space-3); border-radius: var(--radius-full);
  border: 1px solid var(--border); color: var(--muted); font-size: var(--text-sm);
}
.chip:hover { border-color: var(--accent); color: var(--text); }
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.pb-features-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); flex-wrap: wrap; }
.builder-nav { display: flex; align-items: center; gap: var(--space-2); margin-top: var(--space-4); }
.pb-dots { display: flex; gap: 6px; margin: 0 auto; }
.pb-dots span { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.pb-dots span.on { background: var(--accent); }

/* ---------- QR ---------- */
.qr-body { display: flex; flex-direction: column; align-items: center; gap: var(--space-3); }
.qr-code { background: #fff; padding: var(--space-4); border-radius: var(--radius-md); }
.qr-url { font-family: var(--font-mono); font-size: var(--text-sm); color: var(--accent); word-break: break-all; }
.qr-instructions { max-width: 26rem; }

/* ---------- Toasts ---------- */
.toast-root {
  position: fixed; bottom: calc(var(--nav-h) + 12px); left: 50%; transform: translateX(-50%);
  z-index: 200; display: flex; flex-direction: column; gap: var(--space-2); align-items: center;
  pointer-events: none; padding: 0 var(--space-3); width: max-content; max-width: 92vw;
}
.toast {
  display: flex; align-items: center; gap: var(--space-2);
  background: var(--surface-3); color: var(--text); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: var(--space-2) var(--space-4);
  font-size: var(--text-sm); box-shadow: var(--shadow-lg); max-width: 92vw;
}
.toast.success { border-color: var(--success); }
.toast.error { border-color: var(--error); }
.toast svg { width: 16px; height: 16px; flex: none; }

/* Confirm dialog */
.confirm-box {
  position: fixed; inset: 0; z-index: 210; display: flex; align-items: center; justify-content: center;
  background: rgba(4, 8, 14, 0.55); padding: var(--space-4);
}
.confirm-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: var(--space-4); width: min(26rem, 100%); box-shadow: var(--shadow-lg);
}
.confirm-card h3 { margin-bottom: var(--space-2); font-size: var(--text-base); }
.confirm-card p { color: var(--muted); font-size: var(--text-sm); margin-bottom: var(--space-4); }
.confirm-card .confirm-actions { display: flex; gap: var(--space-2); justify-content: flex-end; }
.confirm-card pre {
  font-family: var(--font-mono); font-size: var(--text-xs); background: var(--code-bg);
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: var(--space-2);
  max-height: 10rem; overflow: auto; margin-bottom: var(--space-3); white-space: pre-wrap;
}

/* ---------- Responsive tweaks ---------- */
@media (max-width: 959px) {
  .btn span { display: none; }          /* icons only in header on phones */
  .project-name { width: 7rem; }
  .mode-wrap select { max-width: 7.5rem; }
  .desktop-only { display: none !important; }
  .file-tree { width: 8.5rem; }
}
@media (max-width: 560px) {
  .brand-name { display: none; }
  .field-grid { grid-template-columns: 1fr; }
  .preview-stage { padding: var(--space-2); }
  .preview-frame.device-tablet { width: 100%; height: 900px; }
  .console-filters { display: none; }
}

/* CodeMirror theme harmonization */
.CodeMirror { background: var(--code-bg); color: var(--text); }
.CodeMirror-gutters { background: var(--code-bg); border-right: 1px solid var(--divider); }
.CodeMirror-cursor { border-left: 2px solid var(--accent); }
.CodeMirror-selected { background: rgba(69, 196, 216, 0.15) !important; }
.CodeMirror-activeline-background { background: rgba(255, 255, 255, 0.03); }
.cm-s-material-darker .CodeMirror-matchingbracket { color: var(--accent) !important; }
[data-theme='light'] .CodeMirror-activeline-background { background: rgba(0, 0, 0, 0.03); }

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
