/* ============== APP LAYOUT ============== */

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
}

html.feynman-embedded body {
  background: transparent;
}

html.feynman-embedded .app-header {
  display: none;
}

html.feynman-gallery-embed .app-header {
  display: none;
}

html.feynman-gallery-embed .chat-panel {
  display: none;
}

html.feynman-gallery-embed .app-main.viz-open .chat-panel {
  display: none;
}

html.feynman-gallery-embed .viz-panel,
html.feynman-gallery-embed .app-main.viz-open .viz-panel {
  flex: 1 1 auto;
  min-width: 0;
}

html.feynman-gallery-embed .viz-panel-inner {
  padding: 0;
}

html.feynman-embedded .app-main {
  opacity: 0;
  animation: embeddedFadeIn 180ms ease forwards;
}

html.feynman-gallery-embed .app-main {
  opacity: 0;
  animation: embeddedFadeIn 180ms ease forwards;
}

html.feynman-embedded .chat-panel,
html.feynman-embedded .viz-panel {
  transition: none;
}

html.feynman-gallery-embed .viz-panel {
  transition: none;
}

/* ============== HEADER ============== */

.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-divider);
  flex-shrink: 0;
}

.header-inner {
  max-width: 100%;
  margin: 0 auto;
  padding: var(--space-3) var(--space-4);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-left { display: flex; align-items: center; gap: var(--space-3); }
.header-right { display: flex; align-items: center; gap: var(--space-2); }

.logo {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--color-text);
}

.logo svg { flex-shrink: 0; }

.logo-text {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 400;
  letter-spacing: -0.01em;
}

.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  transition: all var(--transition-interactive);
}

.btn-icon:hover {
  background: var(--color-surface-offset);
  color: var(--color-text);
}

.btn-icon:active {
  background: var(--color-surface-offset-2);
}

.btn-icon [data-lucide],
.btn-icon svg {
  width: 20px;
  height: 20px;
}

/* ============== MAIN — SPLIT LAYOUT ============== */

.app-main {
  flex: 1;
  min-height: 0;
  display: flex;
  overflow: hidden;
}

/* Chat panel — left side */
.chat-panel {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: flex var(--transition-slow);
}

/* When viz panel is open, chat shrinks on desktop */
.app-main.viz-open .chat-panel {
  flex: 0 0 44%;
  min-width: 340px;
}

/* ============== WELCOME SCREEN ============== */

.welcome-screen {
  flex: 1;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: var(--space-8) var(--space-4);
  padding-bottom: var(--space-16);
  padding-top: var(--space-10);
  overflow-y: auto;
  min-height: 0;
}

/* Notebook page container */
.notebook-page {
  max-width: 540px;
  text-align: left;
  background:
    radial-gradient(circle, var(--color-divider) 0.8px, transparent 0.8px);
  background-size: 20px 20px;
  background-color: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: var(--space-8) var(--space-6);
  animation: fadeIn 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

.welcome-gallery {
  max-width: min(1320px, calc(100vw - 48px));
}

[data-theme="dark"] .notebook-page {
  background:
    radial-gradient(circle, var(--color-border) 0.8px, transparent 0.8px);
  background-size: 20px 20px;
  background-color: var(--color-surface);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .notebook-page {
    background:
      radial-gradient(circle, var(--color-border) 0.8px, transparent 0.8px);
    background-size: 20px 20px;
    background-color: var(--color-surface);
  }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Heading */
.welcome-title {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  font-weight: 400;
  color: var(--color-text);
  margin-bottom: var(--space-3);
  letter-spacing: -0.02em;
}

.notebook-rule {
  border: none;
  height: 1px;
  background: var(--color-primary);
  opacity: 0.4;
  margin: 0 0 var(--space-4) 0;
}

.welcome-subtitle {
  font-size: var(--text-base);
  color: var(--color-text-muted);
  line-height: 1.65;
  max-width: 48ch;
  margin: 0 0 var(--space-3);
}

.welcome-subtitle em {
  color: var(--color-primary);
  font-style: italic;
  font-family: var(--font-display);
}

.welcome-credential {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0 0 var(--space-8);
}

/* Example entries */
.example-label {
  font-size: var(--text-sm);
  color: var(--color-text-faint);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 500;
  margin-bottom: var(--space-4);
}

.example-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}

.example-meta {
  margin: 0;
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  letter-spacing: 0.02em;
}

.notebook-entries {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.example-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--space-3);
}

.notebook-entry.example-card {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-4);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-lg);
  text-align: left;
  cursor: pointer;
  transition: all var(--transition-interactive);
  min-height: 112px;
}

.notebook-entry.example-card:hover {
  background: var(--color-primary-subtle);
  border-color: var(--color-primary);
  box-shadow: var(--shadow-sm);
}

.notebook-entry.example-card:active {
  transform: scale(0.98);
}

.notebook-text {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  min-width: 0;
}

.example-topic {
  font-family: var(--font-display);
  font-style: italic;
  font-size: var(--text-base);
  color: var(--color-primary);
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
}

.example-text {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  line-height: 1.5;
}

/* Notebook sketches */
.notebook-sketch {
  width: 56px;
  height: auto;
  flex-shrink: 0;
  color: var(--color-text-faint);
  transition: color 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

.notebook-entry:hover .notebook-sketch {
  color: var(--color-primary);
}

.nb-scenery {
  opacity: 0.35;
}

.nb-orbit-track,
.nb-wheel,
.nb-wave,
.nb-fluid,
.nb-push-arrow,
.nb-rotation-spoke {
  opacity: 0.6;
}

/* Projectile: arc draw + ball translate */
.nb-arc {
  stroke-dasharray: 60;
  stroke-dashoffset: 60;
  fill: none;
  opacity: 0.7;
  transition: stroke-dashoffset 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

.notebook-entry:hover .nb-arc {
  stroke-dashoffset: 0;
}

.nb-ball {
  transition: transform 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

.notebook-entry:hover .nb-ball {
  transform: translate(42px, 28px);
}

/* Forces: block slides down slope */
.nb-block {
  transition: transform 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

.notebook-entry:hover .nb-block {
  transform: translateX(10px);
}

.nb-weight {
  opacity: 0.4;
}

/* Energy: dot rolls to valley */
.nb-dot {
  transition: transform 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

.notebook-entry:hover .nb-dot {
  transform: translate(16px, 27px);
}

.notebook-entry:hover .nb-orbit-track {
  stroke-dasharray: 4 3;
}

.notebook-entry:hover .nb-wave {
  stroke-dasharray: 5 3;
}

.notebook-entry:hover .nb-wheel {
  transform-origin: 30px 24px;
  transform: rotate(18deg);
}

.nb-track {
  opacity: 0.5;
}

/* Momentum: skaters push apart, arrows fade in */
.nb-skater-a,
.nb-skater-b {
  transition: transform 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

.notebook-entry:hover .nb-skater-a {
  transform: translateX(-8px);
}

.notebook-entry:hover .nb-skater-b {
  transform: translateX(8px);
}

.nb-push-arrow {
  opacity: 0;
  transition: opacity 0.4s cubic-bezier(0.16, 1, 0.3, 1) 0.15s;
}

.notebook-entry:hover .nb-push-arrow {
  opacity: 0.7;
}

/* ============== CHAT AREA ============== */

.chat-area {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
}

.chat-messages {
  max-width: var(--content-default);
  margin: 0 auto;
  padding: var(--space-6) var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

/* When viz is open, constrain messages width */
.app-main.viz-open .chat-messages {
  max-width: 100%;
  padding: var(--space-4) var(--space-3);
}

/* ============== MESSAGE BUBBLES ============== */

.message {
  display: flex;
  gap: var(--space-3);
  max-width: 85%;
  animation: messageIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes messageIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes embeddedFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.message--user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message--ai {
  align-self: flex-start;
}

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: var(--text-sm);
  font-weight: 600;
}

.message--user .message-avatar {
  background: var(--color-user-bubble);
  color: var(--color-user-text);
}

.message--ai .message-avatar {
  background: var(--color-primary-highlight);
  color: var(--color-primary);
}

.message--ai .message-avatar svg {
  width: 18px;
  height: 18px;
}

.message-content {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-xl);
  line-height: 1.65;
  font-size: var(--text-base);
}

.message--user .message-content {
  background: var(--color-user-bubble);
  color: var(--color-user-text);
  border-bottom-right-radius: var(--radius-sm);
}

.message--ai .message-content {
  background: var(--color-ai-bubble);
  color: var(--color-ai-text);
  border: 1px solid var(--color-divider);
  border-bottom-left-radius: var(--radius-sm);
}

/* Markdown within AI messages */
.message--ai .message-content p { margin-bottom: 0.75em; }
.message--ai .message-content p:last-child { margin-bottom: 0; }

.message--ai .message-content strong {
  color: var(--color-primary);
  font-weight: 600;
}

.message--ai .message-content em {
  font-family: var(--font-display);
  font-style: italic;
}

.message--ai .message-content code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.9em;
  background: var(--color-surface-offset);
  padding: 0.15em 0.35em;
  border-radius: var(--radius-sm);
}

.message--ai .message-content pre {
  background: var(--color-surface-offset);
  padding: var(--space-3);
  border-radius: var(--radius-md);
  overflow-x: auto;
  margin: 0.75em 0;
  font-family: 'JetBrains Mono', monospace;
  font-size: var(--text-sm);
  line-height: 1.5;
  white-space: pre;
}

.message--ai .message-content pre code {
  background: none;
  padding: 0;
}

.message--ai .message-content ul,
.message--ai .message-content ol {
  padding-left: 1.25em;
  margin: 0.5em 0;
}

.message--ai .message-content li {
  margin-bottom: 0.25em;
}

.message--ai .message-content blockquote {
  border-left: 3px solid var(--color-primary);
  padding-left: var(--space-3);
  color: var(--color-text-muted);
  margin: 0.75em 0;
  font-style: italic;
}

/* ============== THINKING INDICATOR ============== */

.thinking {
  display: flex;
  gap: var(--space-3);
  max-width: 85%;
  align-self: flex-start;
  animation: messageIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.thinking-dots {
  padding: var(--space-3) var(--space-4);
  background: var(--color-ai-bubble);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-xl);
  border-bottom-left-radius: var(--radius-sm);
  display: flex;
  gap: var(--space-1);
  align-items: center;
}

.thinking-dot {
  width: 6px;
  height: 6px;
  border-radius: var(--radius-full);
  background: var(--color-text-faint);
  animation: dotPulse 1.4s infinite;
}

.thinking-dot:nth-child(2) { animation-delay: 0.2s; }
.thinking-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes dotPulse {
  0%, 60%, 100% { opacity: 0.3; transform: scale(0.8); }
  30% { opacity: 1; transform: scale(1); }
}

/* ============== INPUT AREA ============== */

.input-area {
  background: var(--color-bg);
  border-top: 1px solid var(--color-divider);
  padding: var(--space-3) var(--space-4) var(--space-4);
  flex-shrink: 0;
}

.input-inner {
  max-width: var(--content-default);
  margin: 0 auto;
}

.app-main.viz-open .input-inner {
  max-width: 100%;
}

.chat-form {
  width: 100%;
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: var(--space-2);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  padding: var(--space-2) var(--space-2) var(--space-2) var(--space-4);
  transition: border-color var(--transition-interactive), box-shadow var(--transition-interactive);
}

.input-wrapper:focus-within {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px oklch(from var(--color-primary) l c h / 0.1);
}

#message-input {
  flex: 1;
  border: none;
  background: transparent;
  resize: none;
  outline: none;
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.5;
  max-height: 150px;
  padding: var(--space-1) 0;
  color: var(--color-text);
}

#message-input::placeholder {
  color: var(--color-text-faint);
}

.send-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background: var(--color-primary);
  color: var(--color-text-inverse);
  flex-shrink: 0;
  transition: all var(--transition-interactive);
}

.send-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.send-btn:not(:disabled):hover {
  background: var(--color-primary-hover);
  transform: scale(1.05);
}

.send-btn:not(:disabled):active {
  background: var(--color-primary-active);
  transform: scale(0.95);
}

.send-btn [data-lucide] {
  width: 18px;
  height: 18px;
}

.input-hint {
  text-align: center;
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  margin-top: var(--space-2);
}

/* ============== VISUALIZATION PANEL ============== */

.viz-panel {
  width: 0;
  overflow: hidden;
  border-left: 0 solid var(--color-divider);
  background: var(--color-bg);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: width var(--transition-slow), border-left-width var(--transition-slow);
}

.app-main.viz-open .viz-panel {
  width: 56%;
  border-left-width: 1px;
}

.viz-panel-inner {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  min-width: 400px;
  overflow: hidden;
}

/* Viz header with mode tabs */
.viz-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--color-divider);
  flex-shrink: 0;
  gap: var(--space-2);
}

.viz-mode-tabs {
  display: flex;
  gap: var(--space-1);
}

.viz-tab {
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 500;
  font-family: var(--font-body);
  color: var(--color-text-muted);
  background: transparent;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition-interactive);
  white-space: nowrap;
}

.viz-tab:hover:not(:disabled) {
  background: var(--color-surface-offset);
  color: var(--color-text);
}

.viz-tab.active {
  background: var(--color-primary-highlight);
  color: var(--color-primary);
  border-color: var(--color-primary);
}

.viz-tab:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.viz-close-btn {
  flex-shrink: 0;
}

/* Canvas container */
.viz-canvas-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
  min-height: 0;
}

.viz-canvas-wrap canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* Zoom controls overlay — bottom-right of canvas */
.viz-zoom-controls {
  position: absolute;
  bottom: 12px;
  right: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 10;
}

.viz-zoom-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  color: var(--color-text-muted);
  cursor: pointer;
  transition: all var(--transition-interactive);
  box-shadow: var(--shadow-sm);
}

.viz-zoom-btn:hover {
  background: var(--color-surface-offset);
  color: var(--color-text);
  border-color: var(--color-border);
}

.viz-zoom-btn:active {
  transform: scale(0.92);
}

.viz-zoom-btn [data-lucide] {
  width: 14px;
  height: 14px;
}

/* Empty state overlay */
.viz-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  pointer-events: none;
}

.viz-empty p {
  font-size: var(--text-sm);
  color: var(--color-text-faint);
  max-width: 200px;
  text-align: center;
  line-height: 1.5;
}

.viz-empty.hidden {
  display: none;
}

/* Retry button in viz panel */
.viz-retry-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  background: var(--color-primary);
  color: var(--color-text-inverse);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  border: none;
  pointer-events: auto;
  transition: all var(--transition-interactive);
  margin-top: 4px;
}

.viz-retry-btn:hover {
  background: var(--color-primary-hover);
  transform: scale(1.02);
}

.viz-retry-btn:active {
  transform: scale(0.97);
}

.viz-retry-btn [data-lucide] {
  width: 14px;
  height: 14px;
}

.viz-retry-btn.hidden {
  display: none;
}

.viz-retry-btn.loading {
  opacity: 0.6;
  pointer-events: none;
}

.viz-retry-btn.loading [data-lucide] {
  animation: spin 1s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* Playback controls */
.viz-controls {
  border-top: 1px solid var(--color-divider);
  padding: var(--space-3);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.viz-controls-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
}

.viz-controls-secondary {
  gap: var(--space-3);
}

.viz-ctrl-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  color: var(--color-text-muted);
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  cursor: pointer;
  transition: all var(--transition-interactive);
}

.viz-ctrl-btn:hover {
  background: var(--color-surface-offset);
  color: var(--color-text);
  border-color: var(--color-border);
}

.viz-ctrl-btn:active {
  transform: scale(0.95);
}

.viz-ctrl-btn [data-lucide] {
  width: 16px;
  height: 16px;
}

.viz-ctrl-play {
  width: 44px;
  height: 44px;
  background: var(--color-primary);
  color: var(--color-text-inverse);
  border-color: var(--color-primary);
}

.viz-ctrl-play:hover {
  background: var(--color-primary-hover);
  color: var(--color-text-inverse);
  border-color: var(--color-primary-hover);
}

.viz-ctrl-play [data-lucide] {
  width: 20px;
  height: 20px;
}

/* Speed select */
.viz-speed-label {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  display: flex;
  align-items: center;
  gap: var(--space-1);
  flex-shrink: 0;
}

.viz-speed-select {
  font-family: var(--font-body);
  font-size: var(--text-xs);
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-sm);
  padding: 2px 4px;
  cursor: pointer;
}

/* Scrubber / timeline */
.viz-scrubber-wrap {
  flex: 1;
  min-width: 100px;
}

.viz-scrubber {
  width: 100%;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--color-surface-offset);
  border-radius: var(--radius-full);
  cursor: pointer;
  outline: none;
}

.viz-scrubber::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: var(--radius-full);
  background: var(--color-primary);
  cursor: pointer;
  border: 2px solid var(--color-bg);
  box-shadow: var(--shadow-sm);
}

.viz-scrubber::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: var(--radius-full);
  background: var(--color-primary);
  cursor: pointer;
  border: 2px solid var(--color-bg);
  box-shadow: var(--shadow-sm);
}

/* Status bar */
.viz-status {
  border-top: 1px solid var(--color-divider);
  padding: var(--space-1) var(--space-3);
  flex-shrink: 0;
}

.viz-status-text {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
}

/* ============== FOOTER ============== */

.app-footer {
  text-align: center;
  padding: var(--space-1) var(--space-4) var(--space-2);
  background: var(--color-bg);
  flex-shrink: 0;
}

.app-footer a {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  text-decoration: none;
  transition: color var(--transition-interactive);
}

.app-footer a:hover {
  color: var(--color-text-muted);
}

/* ============== RESPONSIVE ============== */

@media (max-width: 900px) {
  /* On smaller screens, viz panel becomes overlay */
  .viz-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 0;
    z-index: 200;
    border-left: 0 solid var(--color-divider);
    box-shadow: none;
    transition: width var(--transition-slow), box-shadow var(--transition-slow);
  }

  .app-main.viz-open .viz-panel {
    width: 100%;
    border-left-width: 0;
    box-shadow: var(--shadow-lg);
  }

  .viz-panel-inner {
    min-width: 0;
  }

  /* Chat panel stays full width when viz open on mobile */
  .app-main.viz-open .chat-panel {
    flex: 1;
    min-width: 0;
  }
}

@media (max-width: 640px) {
  .header-inner { padding: var(--space-2) var(--space-3); }
  .logo-text { font-size: var(--text-base); }

  .welcome-screen {
    padding: var(--space-6) var(--space-3);
    padding-bottom: var(--space-12);
    align-items: flex-start;
    padding-top: var(--space-10);
  }

  .notebook-page {
    padding: var(--space-6) var(--space-4);
    border-left: none;
    border-right: none;
    border-radius: 0;
  }

  .welcome-gallery {
    max-width: 100%;
  }

  .welcome-title { font-size: var(--text-xl); }

  .notebook-sketch { width: 44px; }

  .notebook-entry.example-card {
    gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
  }

  .example-header {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-1);
  }

  .example-grid {
    grid-template-columns: 1fr;
  }

  .message { max-width: 92%; }
  .chat-messages { padding: var(--space-4) var(--space-3); }
  .input-area { padding: var(--space-2) var(--space-3) var(--space-3); }
  .input-hint { display: none; }
}

@media (max-width: 1120px) and (min-width: 641px) {
  .example-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* ============== VIZ LOADING SPINNER ============== */

.viz-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  z-index: 5;
  background: var(--color-bg);
}

.viz-loading.hidden {
  display: none;
}

.viz-loading-spinner {
  width: 56px;
  height: 56px;
  animation: spinnerPulse 2s ease-in-out infinite;
}

.spinner-ring {
  width: 100%;
  height: 100%;
}

@keyframes spinnerPulse {
  0%, 100% { opacity: 0.7; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.05); }
}

.viz-loading-text {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text-muted);
  text-align: center;
  animation: loadingTextPulse 2s ease-in-out infinite;
}

.viz-loading-subtext {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  text-align: center;
}

@keyframes loadingTextPulse {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

/* Scene loaded flash effect */
.viz-canvas-wrap.scene-loaded-flash {
  animation: sceneFlash 0.6s ease-out;
}

@keyframes sceneFlash {
  0% { box-shadow: inset 0 0 30px rgba(196, 122, 26, 0.3); }
  100% { box-shadow: inset 0 0 0px rgba(196, 122, 26, 0); }
}

/* ============== SCROLLBAR ============== */

.chat-area::-webkit-scrollbar,
.app-main::-webkit-scrollbar { width: 6px; }

.chat-area::-webkit-scrollbar-track,
.app-main::-webkit-scrollbar-track { background: transparent; }

.chat-area::-webkit-scrollbar-thumb,
.app-main::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: var(--radius-full);
}

/* ============== DEVELOPER DEBUG PANEL ============== */

.debug-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 9999;
  background: #1a1a1e;
  color: #ccc;
  font-family: 'JetBrains Mono', 'SF Mono', 'Fira Code', Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  flex-direction: column;
  max-height: 55vh;
  border-top: 2px solid #3b3b42;
  box-shadow: 0 -4px 24px rgba(0,0,0,0.4);
}

.debug-panel.open {
  transform: translateY(0);
}

.debug-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  background: #25252b;
  border-bottom: 1px solid #3b3b42;
  flex-shrink: 0;
  cursor: pointer;
  user-select: none;
}

.debug-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.debug-header-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.debug-title {
  font-weight: 600;
  color: #e8e6e1;
  font-size: 12px;
}

.debug-badge {
  background: #3b3b42;
  color: #aaa;
  padding: 1px 7px;
  border-radius: 8px;
  font-size: 10px;
}

.debug-total-time {
  color: #7ec699;
  font-size: 11px;
}

.debug-clear-btn {
  background: none;
  border: 1px solid #3b3b42;
  color: #888;
  padding: 2px 8px;
  border-radius: 4px;
  font-family: inherit;
  font-size: 10px;
  cursor: pointer;
}

.debug-clear-btn:hover { color: #ccc; border-color: #555; }

.debug-copy-btn {
  background: rgba(224, 160, 64, 0.08);
  border: 1px solid rgba(224, 160, 64, 0.35);
  color: #e0a040;
  padding: 2px 8px;
  border-radius: 4px;
  font-family: inherit;
  font-size: 10px;
  cursor: pointer;
}

.debug-copy-btn:hover {
  background: rgba(224, 160, 64, 0.14);
  border-color: rgba(224, 160, 64, 0.55);
}

.debug-close-btn {
  background: none;
  border: none;
  color: #888;
  cursor: pointer;
  display: flex;
  align-items: center;
  padding: 2px;
}

.debug-close-btn:hover { color: #e8e6e1; }

.debug-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px 16px;
}

.debug-body::-webkit-scrollbar { width: 6px; }
.debug-body::-webkit-scrollbar-track { background: transparent; }
.debug-body::-webkit-scrollbar-thumb { background: #3b3b42; border-radius: 4px; }

.debug-empty {
  color: #555;
  text-align: center;
  padding: 20px;
  font-style: italic;
}

.debug-empty.hidden { display: none; }

/* Stage section */
.debug-stage {
  margin-bottom: 4px;
  border: 1px solid #2a2a30;
  border-radius: 6px;
  overflow: hidden;
}

.debug-stage.has-error {
  border-color: #6b2828;
}

.debug-stage-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  background: #22222a;
  cursor: pointer;
  user-select: none;
  gap: 8px;
}

.debug-stage-header:hover {
  background: #28282f;
}

.debug-stage.has-error .debug-stage-header {
  background: #2d1a1a;
}

.debug-stage-name {
  font-weight: 600;
  color: #88c0d0;
  flex: 1;
}

.debug-stage.has-error .debug-stage-name {
  color: #e06c75;
}

.debug-stage-time {
  color: #7ec699;
  font-size: 11px;
  flex-shrink: 0;
}

.debug-stage-status {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 4px;
  flex-shrink: 0;
}

.debug-stage-status.ok {
  background: #1a3a1a;
  color: #7ec699;
}

.debug-stage-status.error {
  background: #3a1a1a;
  color: #e06c75;
}

.debug-stage-chevron {
  color: #555;
  transition: transform 0.2s;
  flex-shrink: 0;
}

.debug-stage.expanded .debug-stage-chevron {
  transform: rotate(90deg);
}

.debug-stage-body {
  display: none;
  padding: 8px 10px;
  border-top: 1px solid #2a2a30;
  background: #1c1c22;
}

.debug-stage.expanded .debug-stage-body {
  display: block;
}

/* Sub-sections within a stage */
.debug-section {
  margin-bottom: 8px;
}

.debug-section-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #666;
  margin-bottom: 3px;
  font-weight: 600;
}

.debug-section-label.error-label {
  color: #e06c75;
}

.debug-code {
  background: #16161b;
  border: 1px solid #2a2a30;
  border-radius: 4px;
  padding: 6px 8px;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 300px;
  overflow-y: auto;
  font-size: 11px;
  line-height: 1.45;
}

.debug-code::-webkit-scrollbar { width: 4px; height: 4px; }
.debug-code::-webkit-scrollbar-thumb { background: #3b3b42; border-radius: 2px; }

.debug-code.error-box {
  border-color: #4a2020;
  color: #e06c75;
  background: #1e1214;
}

/* JSON syntax highlights */
.debug-code .json-key { color: #88c0d0; }
.debug-code .json-string { color: #a3be8c; }
.debug-code .json-number { color: #d08770; }
.debug-code .json-boolean { color: #b48ead; }
.debug-code .json-null { color: #666; }

/* Separator between scene/prediction pipeline logs */
.debug-separator {
  padding: 4px 0;
  margin: 8px 0;
  border-top: 1px dashed #3b3b42;
  color: #666;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
