:root {
  /* Primary palette — dark slate base with electric brand gradient */
  --bg-base:        #0b0f1a;
  --bg-surface:     #0f1524;
  --bg-elevated:    #151d30;
  --bg-input:       #0d1320;
  --bg-hover:       #1a2238;
  --bg-user-msg:    #162042;
  --bg-ai-msg:      #121a2e;

  --text-primary:   #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted:     #64748b;
  --text-inverse:   #0b0f1a;

  --accent:         #7cf3ff;
  --accent-hover:   #a6f8ff;
  --accent-muted:   rgba(124, 243, 255, 0.12);
  --accent-ring:    rgba(124, 243, 255, 0.32);
  --accent-grad:    linear-gradient(135deg, #7cf3ff 0%, #8b5cf6 55%, #ec4899 100%);
  --primary:        #3b82f6;
  --primary-hover:  #2563eb;

  --success: #10b981;
  --warning: #f59e0b;
  --error:   #ef4444;

  --border:        rgba(148, 163, 184, 0.12);
  --border-strong: rgba(148, 163, 184, 0.22);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 18px;
  --radius-full: 9999px;

  --shadow-sm:  0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md:  0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg:  0 20px 48px -16px rgba(0, 0, 0, 0.6);
  --shadow-glow: 0 0 24px rgba(124, 243, 255, 0.28), 0 0 48px rgba(139, 92, 246, 0.18);

  --font-sans:  'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-serif: 'Instrument Serif', Georgia, serif;
  --font-mono:  'JetBrains Mono', 'SF Mono', Menlo, Consolas, monospace;

  --ease:     cubic-bezier(0.4, 0, 0.2, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --dur-fast: 120ms;
  --dur:      200ms;
  --dur-slow: 320ms;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
}

.hidden { display: none !important; }
[hidden] { display: none !important; }

button { font-family: inherit; background: none; border: none; cursor: pointer; color: inherit; }
input, textarea, select { font-family: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: var(--radius-full); }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

svg { display: block; }

/* ============================================================ APP SHELL */
.app {
  display: flex; flex-direction: column;
  height: 100dvh;
}

/* ============================================================== TOOLBAR */
.toolbar {
  flex-shrink: 0;
  height: 56px;
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  position: relative; z-index: 20;
}

.wordmark {
  display: flex; align-items: center; gap: 10px;
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.06em;
  color: var(--text-primary);
  user-select: none;
}
.wordmark .brand-mark {
  width: 22px; height: 22px;
  filter: drop-shadow(0 0 8px rgba(124, 243, 255, 0.35));
}
.wordmark .brand-name {
  background: var(--accent-grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.project-title {
  font-size: 14px; font-weight: 500;
  color: var(--text-secondary);
  flex: 1 1 0;
  margin-left: 8px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.project-title:empty::before {
  content: 'Untitled project';
  color: var(--text-muted);
}

.toolbar-actions {
  display: flex; align-items: center; gap: 8px;
  margin-left: auto;
}

.toolbar-btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 0 12px;
  height: 34px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: 13px; font-weight: 500;
  transition: all var(--dur-fast) var(--ease);
  white-space: nowrap;
}
.toolbar-btn:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border-strong);
}
.toolbar-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.toolbar-btn.icon-only {
  width: 34px; padding: 0; justify-content: center;
}
.toolbar-btn svg {
  width: 16px; height: 16px; fill: currentColor;
}

.status-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  font-size: 11px; font-weight: 500;
  color: var(--text-secondary);
  user-select: none;
  white-space: nowrap;
}
.status-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-muted);
  transition: background var(--dur) var(--ease);
}
.status-badge.working { color: var(--accent); border-color: var(--accent-ring); }
.status-badge.working .status-dot {
  background: var(--accent);
  animation: pulseDot 1.2s var(--ease) infinite;
}
.status-badge.success { color: var(--success); }
.status-badge.success .status-dot { background: var(--success); }
.status-badge.error { color: var(--error); }
.status-badge.error .status-dot { background: var(--error); }

@keyframes pulseDot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.5; transform: scale(1.4); }
}

.hamburger {
  position: relative;
  display: block;
  width: 16px; height: 2px;
  background: currentColor;
  border-radius: 2px;
  transition: all var(--dur-fast) var(--ease);
}
.hamburger::before, .hamburger::after {
  content: '';
  position: absolute; left: 0;
  width: 100%; height: 2px;
  background: currentColor;
  border-radius: 2px;
  transition: all var(--dur-fast) var(--ease);
}
.hamburger::before { top: -5px; }
.hamburger::after  { top: 5px; }
.toolbar-btn.active .hamburger                { background: transparent; }
.toolbar-btn.active .hamburger::before        { transform: rotate(45deg); top: 0; }
.toolbar-btn.active .hamburger::after         { transform: rotate(-45deg); top: 0; }

/* ================================================================ MAIN */
.main-container {
  flex: 1;
  display: flex;
  min-height: 0;
  position: relative;
}

/* ============================================================ SIDEBAR */
.sidebar {
  width: 340px;
  flex-shrink: 0;
  display: flex; flex-direction: column;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  transition: transform var(--dur-slow) var(--ease);
}
.sidebar.closed { transform: translateX(-100%); width: 0; border: none; }
.sidebar-header {
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}
.sidebar-header h2 {
  font-size: 14px; font-weight: 600;
  color: var(--text-primary);
  letter-spacing: 0.02em;
}
.sidebar-close {
  width: 28px; height: 28px;
  display: none; align-items: center; justify-content: center;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: 20px; line-height: 1;
  transition: background var(--dur-fast) var(--ease);
}
.sidebar-close:hover { background: var(--bg-hover); color: var(--text-primary); }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex; flex-direction: column; gap: 10px;
}
.empty-chat {
  margin: auto;
  text-align: center;
  color: var(--text-muted);
  padding: 32px 16px;
}
.empty-chat p { margin: 4px 0; font-size: 13px; }
.empty-chat .empty-hint { font-size: 12px; color: var(--text-muted); opacity: 0.7; }

/* Chat message bubbles */
.chat-msg {
  animation: msgIn var(--dur-slow) var(--ease-out);
  display: flex; flex-direction: column; gap: 6px;
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.chat-msg-user {
  align-items: flex-end;
}
.chat-msg-user .chat-bubble {
  background: var(--bg-user-msg);
  border: 1px solid var(--border-strong);
  color: var(--text-primary);
  align-self: flex-end;
}
.chat-msg-ai .chat-bubble {
  background: var(--bg-ai-msg);
  border: 1px solid var(--border);
  color: var(--text-primary);
}
.chat-bubble {
  max-width: 92%;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.chat-bubble p  { margin: 0 0 6px 0; }
.chat-bubble p:last-child { margin-bottom: 0; }
.chat-bubble strong { color: var(--accent); }
.chat-bubble code {
  font-family: var(--font-mono);
  font-size: 12px;
  background: rgba(148, 163, 184, 0.12);
  padding: 1px 6px;
  border-radius: 4px;
}

/* Brief card — visible + editable interpretation */
.brief-card {
  background: linear-gradient(180deg, rgba(124, 243, 255, 0.04), rgba(139, 92, 246, 0.04));
  border: 1px solid var(--accent-ring);
  border-radius: var(--radius-lg);
  padding: 14px;
  display: flex; flex-direction: column; gap: 10px;
}
.brief-card-head {
  display: flex; align-items: center; gap: 8px;
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}
.brief-card-head svg { width: 14px; height: 14px; fill: currentColor; }
.brief-card-label { flex: 1; }
.brief-textarea {
  width: 100%;
  min-height: 90px;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 13px;
  line-height: 1.5;
  resize: vertical;
  transition: border-color var(--dur-fast) var(--ease);
}
.brief-textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}
.brief-actions {
  display: flex; gap: 8px; align-items: center;
}
.brief-btn {
  padding: 8px 14px;
  border-radius: var(--radius-md);
  font-size: 13px; font-weight: 600;
  transition: all var(--dur-fast) var(--ease);
}
.brief-btn.primary {
  background: var(--accent-grad);
  color: var(--text-inverse);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.25);
}
.brief-btn.primary:hover { filter: brightness(1.08); }
.brief-btn.secondary {
  background: var(--bg-elevated);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.brief-btn.secondary:hover { background: var(--bg-hover); color: var(--text-primary); }
.brief-countdown {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* Edit card with diff summary */
.edit-card {
  background: var(--bg-ai-msg);
  border: 1px solid var(--border);
  border-left: 3px solid var(--success);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-size: 13px;
}
.edit-card.partial { border-left-color: var(--warning); }
.edit-card.failure { border-left-color: var(--error); }
.edit-card-title {
  font-weight: 600;
  margin-bottom: 6px;
  display: flex; align-items: center; gap: 6px;
}
.edit-card-title svg { width: 14px; height: 14px; fill: currentColor; }
.edit-diff-list {
  margin-top: 6px;
  list-style: none;
  display: flex; flex-direction: column; gap: 4px;
  font-family: var(--font-mono);
  font-size: 11px;
}
.edit-diff-item {
  padding: 4px 8px;
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  display: flex; align-items: center; gap: 8px;
  overflow: hidden;
}
.edit-diff-file {
  color: var(--accent);
  flex-shrink: 0;
}
.edit-diff-arrow { color: var(--text-muted); flex-shrink: 0; }
.edit-diff-text {
  flex: 1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.edit-diff-item.failed { border-left: 2px solid var(--error); }
.edit-retry-btn {
  margin-top: 8px;
  padding: 6px 12px;
  font-size: 12px; font-weight: 500;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  color: var(--text-primary);
}
.edit-retry-btn:hover { background: var(--bg-hover); }

/* Error card */
.error-card {
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text-primary);
}
.error-card-title {
  font-weight: 600;
  color: var(--error);
  margin-bottom: 4px;
  display: flex; align-items: center; gap: 6px;
}
.error-card-title svg { width: 14px; height: 14px; fill: currentColor; }

/* Options chips (clarifying questions) */
.options-card { display: flex; flex-direction: column; gap: 8px; }
.options-question { font-size: 13px; color: var(--text-primary); }
.options-choices { display: flex; flex-wrap: wrap; gap: 8px; }
.option-chip {
  padding: 6px 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-full);
  font-size: 12px; color: var(--text-primary);
  transition: all var(--dur-fast) var(--ease);
}
.option-chip:hover { background: var(--accent-muted); border-color: var(--accent); color: var(--accent); }

/* Typing indicator */
.typing-bubble {
  display: inline-flex; gap: 4px;
  padding: 10px 14px;
  background: var(--bg-ai-msg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  align-self: flex-start;
}
.typing-bubble span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-muted);
  animation: typing 1.2s var(--ease) infinite;
}
.typing-bubble span:nth-child(2) { animation-delay: 0.15s; }
.typing-bubble span:nth-child(3) { animation-delay: 0.3s; }
@keyframes typing {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30%           { opacity: 1;   transform: translateY(-3px); }
}

.sidebar-footer {
  flex-shrink: 0;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-surface);
}
.project-stats {
  display: flex; gap: 8px;
  font-size: 11px;
  color: var(--text-muted);
}
.stats-sep { opacity: 0.4; }

/* ============================================================ WORKSPACE */
.workspace {
  flex: 1;
  min-width: 0;
  display: flex;
  position: relative;
  background: var(--bg-base);
}

/* ============================================================= WELCOME */
.welcome-screen {
  flex: 1;
  overflow-y: auto;
  padding: 40px 32px;
  display: flex; align-items: center; justify-content: center;
}
.welcome-content {
  width: 100%;
  max-width: 780px;
  display: flex; flex-direction: column; gap: 40px;
}
.welcome-hero {
  text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 18px;
}
.hero-logo svg {
  width: 96px; height: 96px;
  filter: drop-shadow(var(--shadow-glow));
  animation: heroFloat 6s var(--ease) infinite;
}
@keyframes heroFloat {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-6px); }
}
.hero-title {
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: clamp(32px, 6vw, 52px);
  line-height: 1.05;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}
.hero-accent {
  background: var(--accent-grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  font-style: italic;
}
.hero-sub {
  font-size: 15px;
  color: var(--text-secondary);
  max-width: 480px;
}

.quick-actions h3,
.recent-projects h3 {
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 12px;
  text-align: center;
}
.action-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
}
.action-card {
  position: relative;
  padding: 18px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  display: flex; flex-direction: column; align-items: flex-start; gap: 6px;
  text-align: left;
  transition: all var(--dur) var(--ease);
  overflow: hidden;
}
.action-card::before {
  content: '';
  position: absolute; inset: 0;
  background: var(--accent-grad);
  opacity: 0;
  transition: opacity var(--dur) var(--ease);
  pointer-events: none;
  z-index: 0;
}
.action-card > * { position: relative; z-index: 1; }
.action-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent-ring);
  box-shadow: var(--shadow-md);
}
.action-card:hover::before { opacity: 0.05; }
.action-card svg {
  width: 24px; height: 24px;
  fill: var(--accent);
  margin-bottom: 6px;
}
.action-card .action-title {
  font-size: 14px; font-weight: 600;
  color: var(--text-primary);
}
.action-card .action-sub {
  font-size: 12px;
  color: var(--text-muted);
}

.project-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}
.project-card {
  padding: 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--dur-fast) var(--ease);
  text-align: left;
  display: flex; flex-direction: column; gap: 4px;
}
.project-card:hover { border-color: var(--accent-ring); background: var(--bg-hover); }
.project-card-title {
  font-size: 13px; font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.project-card-meta {
  font-size: 11px;
  color: var(--text-muted);
}

/* ============================================================ EDITOR */
.code-editor {
  flex: 1;
  display: flex; flex-direction: column;
  min-height: 0;
}
.editor-header {
  flex-shrink: 0;
  display: flex; align-items: center;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  padding: 0 8px;
  min-height: 40px;
}
.file-tabs {
  flex: 1;
  display: flex; align-items: center; gap: 2px;
  overflow-x: auto;
  scrollbar-width: none;
}
.file-tabs::-webkit-scrollbar { display: none; }
.file-tab {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 10px 6px 12px;
  height: 32px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  color: var(--text-secondary);
  font-size: 12px;
  font-family: var(--font-mono);
  transition: all var(--dur-fast) var(--ease);
  white-space: nowrap;
  position: relative;
}
.file-tab:hover { background: var(--bg-hover); color: var(--text-primary); }
.file-tab.active {
  background: var(--bg-base);
  color: var(--accent);
}
.file-tab.active::after {
  content: '';
  position: absolute; left: 0; right: 0; bottom: -1px;
  height: 2px;
  background: var(--accent);
}
.file-tab-close {
  width: 18px; height: 18px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 3px;
  color: var(--text-muted);
  font-size: 14px; line-height: 1;
  transition: background var(--dur-fast) var(--ease);
}
.file-tab-close:hover { background: var(--bg-hover); color: var(--text-primary); }

.editor-actions { display: flex; gap: 4px; }
.editor-btn {
  width: 28px; height: 28px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  transition: all var(--dur-fast) var(--ease);
}
.editor-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.editor-btn svg { width: 14px; height: 14px; fill: currentColor; }

.editor-container {
  flex: 1;
  min-height: 0;
  background: var(--bg-base);
}
.monaco-loading {
  height: 100%;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted);
  font-size: 13px;
}

/* ============================================================ PREVIEW */
.preview-area {
  flex: 1;
  display: flex; flex-direction: column;
  min-height: 0;
  background: var(--bg-base);
}
.preview-header {
  flex-shrink: 0;
  display: flex; align-items: center;
  padding: 8px 12px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  min-height: 44px;
  gap: 8px;
}
.preview-controls {
  display: flex; align-items: center; gap: 8px;
  flex: 1;
  flex-wrap: wrap;
}
.device-selector {
  display: flex;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 2px;
}
.device-btn {
  width: 32px; height: 28px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  transition: all var(--dur-fast) var(--ease);
}
.device-btn:hover { color: var(--text-primary); }
.device-btn.active {
  background: var(--accent-muted);
  color: var(--accent);
}
.device-btn svg { width: 14px; height: 14px; fill: currentColor; }

.preview-btn {
  width: 32px; height: 32px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: all var(--dur-fast) var(--ease);
  background: var(--bg-elevated);
}
.preview-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.preview-btn svg { width: 16px; height: 16px; fill: currentColor; }

.error-banner {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 12px;
  margin-left: auto;
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: var(--radius-md);
  color: var(--error);
  font-size: 12px;
  max-width: 420px;
}
.error-banner svg { width: 14px; height: 14px; fill: currentColor; flex-shrink: 0; }
.error-banner #errorText {
  flex: 1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.error-fix-btn {
  padding: 4px 10px;
  background: var(--error);
  color: white;
  border-radius: var(--radius-sm);
  font-size: 11px; font-weight: 600;
  transition: background var(--dur-fast) var(--ease);
}
.error-fix-btn:hover { background: #dc2626; }

.preview-frame {
  flex: 1;
  min-height: 0;
  position: relative;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  background:
    linear-gradient(180deg, var(--bg-base), var(--bg-base)),
    repeating-linear-gradient(45deg, transparent 0 19px, rgba(148,163,184,0.03) 19px 20px);
  overflow: auto;
}
.preview-frame iframe {
  width: 100%;
  height: 100%;
  border: none;
  background: #ffffff;
  box-shadow: var(--shadow-md);
  border-radius: var(--radius-md);
  transition: width var(--dur-slow) var(--ease), height var(--dur-slow) var(--ease);
}
.preview-frame[data-device='tablet'] iframe {
  width: 768px;
  max-width: 100%;
  height: min(100%, 1024px);
  max-height: 100%;
}
.preview-frame[data-device='mobile'] iframe {
  width: 390px;
  max-width: 100%;
  height: min(100%, 844px);
  max-height: 100%;
}

/* ============================================================ STREAMING */
.stream-overlay {
  position: absolute;
  top: 60px; left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  pointer-events: none;
  animation: streamIn var(--dur-slow) var(--ease-out);
}
@keyframes streamIn {
  from { opacity: 0; transform: translate(-50%, -8px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}
.stream-pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--accent-ring);
  border-radius: var(--radius-full);
  color: var(--text-primary);
  font-size: 12px; font-weight: 500;
  box-shadow: var(--shadow-md), var(--shadow-glow);
  backdrop-filter: blur(8px);
}
.stream-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent-grad);
  animation: streamPulse 1.2s var(--ease) infinite;
}
@keyframes streamPulse {
  0%, 100% { transform: scale(1);   opacity: 1; }
  50%      { transform: scale(1.3); opacity: 0.6; }
}

/* ============================================================ INPUT PANEL */
.input-panel {
  flex-shrink: 0;
  padding: 12px 16px 18px;
  background: linear-gradient(180deg, rgba(11,15,26,0), var(--bg-base) 30%);
  border-top: 1px solid var(--border);
  position: relative;
  z-index: 15;
}
.input-container { max-width: 100%; }
.input-wrapper {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 8px 8px 8px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.input-wrapper:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}
.message-input {
  flex: 1;
  min-height: 24px;
  max-height: 200px;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
  resize: none;
  padding: 6px 0;
}
.message-input::placeholder { color: var(--text-muted); }

.input-actions { display: flex; gap: 4px; align-items: center; }
.input-btn {
  width: 34px; height: 34px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-secondary);
  border-radius: var(--radius-md);
  transition: all var(--dur-fast) var(--ease);
}
.input-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.input-btn.recording { color: var(--error); background: rgba(239, 68, 68, 0.1); }
.input-btn.primary {
  background: var(--accent-grad);
  color: var(--text-inverse);
}
.input-btn.primary:hover { filter: brightness(1.1); }
.input-btn.primary:disabled { opacity: 0.4; cursor: not-allowed; filter: none; }
.input-btn svg { width: 18px; height: 18px; fill: currentColor; }

/* File attachments */
.file-attachments {
  display: flex; gap: 6px; flex-wrap: wrap;
  padding: 0 0 8px;
}
.attachment-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 8px 4px 4px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 11px;
  color: var(--text-secondary);
  max-width: 200px;
}
.attachment-chip img {
  width: 24px; height: 24px;
  border-radius: var(--radius-sm);
  object-fit: cover;
}
.attachment-chip-name {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.attachment-remove {
  width: 18px; height: 18px;
  border-radius: 50%;
  font-size: 14px; line-height: 1;
  color: var(--text-muted);
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.attachment-remove:hover { background: var(--bg-hover); color: var(--error); }

/* Audio visualizer */
.audio-visualizer {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 14px;
  margin-bottom: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--accent-ring);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.audio-visualizer canvas {
  flex: 1;
  height: 36px;
  min-width: 0;
}
.recording-status {
  display: flex; align-items: center; gap: 8px;
  color: var(--error);
  font-size: 12px; font-weight: 500;
  white-space: nowrap;
}
.recording-indicator {
  width: 10px; height: 10px;
  position: relative;
}
.recording-pulse {
  position: absolute;
  top: 0; left: 0;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--error);
  animation: recordingPulse 1.2s var(--ease) infinite;
}
@keyframes recordingPulse {
  0%, 100% { transform: scale(1);   opacity: 1; }
  50%      { transform: scale(1.6); opacity: 0.4; }
}

/* ============================================================ TOAST */
.toast {
  position: fixed;
  bottom: 120px; left: 50%;
  transform: translateX(-50%);
  padding: 10px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  display: flex; align-items: center; gap: 8px;
  animation: toastIn var(--dur-slow) var(--ease-out);
  max-width: 90vw;
}
@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 20px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error   { border-left: 3px solid var(--error); }
.toast.info    { border-left: 3px solid var(--accent); }

/* ============================================================ FULLSCREEN */
.preview-area.fullscreen {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: var(--bg-base);
}

/* ============================================================ RESPONSIVE */
@media (max-width: 960px) {
  .sidebar {
    position: absolute;
    top: 0; left: 0; bottom: 0;
    width: min(340px, 85vw);
    z-index: 50;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.closed { transform: translateX(-100%); width: min(340px, 85vw); border-right: 1px solid var(--border); }
  .sidebar-close { display: inline-flex; }

  .toolbar-btn .btn-label { display: none; }
  .toolbar-btn.icon-only { display: inline-flex; }

  .wordmark .brand-name { display: none; }
  .project-title { font-size: 13px; }

  .welcome-screen { padding: 28px 18px; }
  .action-grid { grid-template-columns: repeat(2, 1fr); }

  .preview-frame { padding: 8px; }
}

@media (max-width: 520px) {
  .action-grid { grid-template-columns: 1fr; }
  .status-badge { display: none; }
  .hero-title { font-size: clamp(28px, 9vw, 40px); }
}

/* ============================================================================
   v2 — Account, credits, quality tiers, modals, deploy
   ========================================================================== */

.account-btn .btn-label { max-width: 120px; overflow: hidden; text-overflow: ellipsis; }
.account-btn img.account-avatar-mini {
  width: 20px; height: 20px; border-radius: var(--radius-full); display: block;
}

.menu-popover {
  position: fixed;
  z-index: 90;
  min-width: 260px;
  max-width: 320px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.menu-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  font-size: 13px; font-weight: 500;
  color: var(--text-primary);
  text-align: left;
  transition: background var(--dur-fast) var(--ease);
}
.menu-item:hover { background: var(--bg-hover); }
.menu-item svg { width: 16px; height: 16px; fill: var(--text-secondary); flex: none; }
.menu-item.primary { background: var(--accent-muted); color: var(--accent); }
.menu-item.primary svg { fill: var(--accent); }
.menu-item.primary:hover { background: rgba(124, 243, 255, 0.2); }
.menu-item.locked { opacity: 0.55; }

.account-menu-header {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px 12px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 6px;
}
.account-avatar { width: 34px; height: 34px; border-radius: var(--radius-full); background: var(--bg-hover); }
.account-meta { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.account-name { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.account-email { font-size: 11px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.plan-badge {
  font-size: 10px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  padding: 3px 8px; border-radius: var(--radius-full);
  background: var(--bg-hover); color: var(--text-secondary);
}
.plan-badge.pro { background: var(--accent-grad); color: var(--text-inverse); }

.credits-block { padding: 8px 12px 10px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.credits-row { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-secondary); margin-bottom: 6px; }
.credits-row span:last-child { color: var(--text-primary); font-weight: 600; }
.credits-bar { height: 6px; border-radius: var(--radius-full); background: var(--bg-input); overflow: hidden; }
.credits-bar-fill { height: 100%; border-radius: var(--radius-full); background: var(--accent-grad); width: 0%; transition: width var(--dur-slow) var(--ease-out); }
.credits-hint { font-size: 11px; color: var(--text-muted); margin-top: 6px; }

.credits-chip {
  font-size: 11px; color: var(--text-secondary);
  padding: 1px 8px; border-radius: var(--radius-full);
  background: var(--bg-input); border: 1px solid var(--border);
  transition: border-color var(--dur-fast) var(--ease);
}
.credits-chip:hover { border-color: var(--accent-ring); color: var(--text-primary); }
.credits-chip.low { color: var(--warning); border-color: rgba(245, 158, 11, 0.4); }

.quality-btn { width: auto !important; padding: 0 10px; gap: 6px; font-size: 12px; font-weight: 600; color: var(--text-secondary); }
.quality-btn svg { width: 14px; height: 14px; }
.quality-btn.tier-advanced, .quality-btn.tier-max { color: var(--accent); }

.quality-option {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: var(--radius-md); text-align: left; width: 100%;
  transition: background var(--dur-fast) var(--ease);
}
.quality-option:hover { background: var(--bg-hover); }
.quality-option .q-meta { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.quality-option .q-name { font-size: 13px; font-weight: 600; }
.quality-option .q-desc { font-size: 11px; color: var(--text-muted); }
.quality-option .q-cost { font-size: 11px; color: var(--text-secondary); white-space: nowrap; }
.quality-option.active { background: var(--accent-muted); }
.quality-option.active .q-name { color: var(--accent); }
.quality-option.locked { opacity: 0.6; }
.quality-option .q-lock { width: 14px; height: 14px; fill: var(--text-muted); flex: none; }

.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(4, 7, 14, 0.72);
  backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal {
  width: 100%; max-width: 480px; max-height: 90vh; overflow-y: auto;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  padding: 24px;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.modal-head h2 { font-size: 20px; font-weight: 700; }
.modal-close { font-size: 22px; color: var(--text-muted); width: 32px; height: 32px; border-radius: var(--radius-md); }
.modal-close:hover { background: var(--bg-hover); color: var(--text-primary); }
.modal-sub { font-size: 13px; color: var(--text-secondary); margin-bottom: 16px; line-height: 1.55; }
.modal-fine { font-size: 11px; color: var(--text-muted); margin-top: 12px; text-align: center; }
.modal-primary-btn {
  width: 100%; padding: 12px 16px; border-radius: var(--radius-md);
  background: var(--accent-grad); color: var(--text-inverse);
  font-weight: 700; font-size: 14px;
  transition: filter var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.modal-primary-btn:hover { filter: brightness(1.1); }
.modal-primary-btn:disabled { opacity: 0.5; cursor: wait; }

.pro-perks { list-style: none; margin: 0 0 18px; display: flex; flex-direction: column; gap: 10px; }
.pro-perks li {
  font-size: 13px; color: var(--text-secondary); line-height: 1.5;
  padding-left: 26px; position: relative;
}
.pro-perks li::before {
  content: ''; position: absolute; left: 0; top: 3px;
  width: 16px; height: 16px; border-radius: var(--radius-full);
  background: var(--accent-muted);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%237cf3ff'%3E%3Cpath d='M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41L9 16.17z'/%3E%3C/svg%3E");
  background-size: 10px; background-position: center; background-repeat: no-repeat;
}
.pro-perks strong { color: var(--text-primary); }

.deploy-form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.deploy-form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-secondary); }
.deploy-form label.wide, .deploy-form details, .deploy-form label.checkbox { grid-column: 1 / -1; }
.deploy-form input[type="text"], .deploy-form input[type="password"] {
  background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 9px 12px; font-size: 13px; outline: none;
  transition: border-color var(--dur-fast) var(--ease);
}
.deploy-form input:focus { border-color: var(--accent-ring); }
.deploy-form label.checkbox { flex-direction: row; align-items: center; gap: 8px; font-size: 13px; }
.deploy-advanced summary { font-size: 12px; color: var(--text-secondary); cursor: pointer; margin: 4px 0 8px; }
.deploy-advanced label { margin-bottom: 10px; }
.deploy-status { margin-top: 12px; font-size: 12px; color: var(--text-secondary); white-space: pre-line; line-height: 1.6; }
.deploy-status.error { color: var(--error); }
.deploy-status.success { color: var(--success); }
.deploy-status a { font-weight: 600; }

/* Build progress card in chat */
.build-progress-card {
  background: var(--bg-ai-msg); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 12px 14px;
  display: flex; flex-direction: column; gap: 8px; max-width: 100%;
}
.build-progress-row { display: flex; align-items: center; gap: 10px; font-size: 12.5px; color: var(--text-secondary); }
.build-progress-row .bp-dot {
  width: 8px; height: 8px; border-radius: var(--radius-full); flex: none;
  background: var(--text-muted);
}
.build-progress-row.active .bp-dot { background: var(--accent); animation: pulse-dot 1.2s ease-in-out infinite; }
.build-progress-row.done .bp-dot { background: var(--success); }
.build-progress-row.done { color: var(--text-primary); }
@keyframes pulse-dot { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

.capability-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.capability-chip {
  font-size: 11px; font-weight: 600; padding: 3px 10px;
  border-radius: var(--radius-full);
  background: var(--accent-muted); color: var(--accent);
  border: 1px solid var(--accent-ring);
}

/* Collapsed build-plan card + Google sign-in host */
.brief-card.collapsed { padding-bottom: 10px; opacity: 0.85; }
.brief-collapsed-text {
  font-size: 12px; color: var(--text-muted); line-height: 1.5;
  overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.gis-host { display: flex; justify-content: center; padding: 8px 10px 10px; }

/* ===== Mobile & layout fixes (v2.1) ===== */

/* Flex centering clipped the top of overflowing content; margin:auto centers
   when short AND scrolls correctly when tall. */
.welcome-screen { align-items: flex-start; justify-content: flex-start; }
.welcome-content { margin: auto; }

/* Editor header: tabs must be shrinkable/scrollable, actions never clipped. */
.file-tabs { min-width: 0; }
.editor-actions { flex-shrink: 0; }

/* Upgrade modal contextual line */
.modal-context {
  font-size: 12.5px; color: var(--accent);
  background: var(--accent-muted);
  border-radius: var(--radius-md);
  padding: 8px 12px; margin-bottom: 14px;
}

@media (max-width: 640px) {
  /* Input bar: textarea gets the full first row; actions sit below, right-aligned. */
  .input-wrapper { flex-wrap: wrap; }
  .message-input { flex: 1 1 100%; order: -1; }
  .input-actions { margin-left: auto; }
}
