/* ================================================================
   JS Execution Visualizer — Deep Dark + Glassmorphism Theme
   ================================================================ */

/* ===== Reset ===== */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  /* Core palette — deep space dark */
  --bg-base: #07080d;
  --bg-surface: #0c0e16;
  --bg-elevated: #11131d;
  --bg-card: rgba(14, 17, 28, 0.65);
  --bg-card-solid: #0e111c;
  --bg-hover: rgba(255, 255, 255, 0.04);
  --bg-input: #0a0c14;

  /* Borders */
  --border: rgba(255, 255, 255, 0.06);
  --border-light: rgba(255, 255, 255, 0.10);
  --border-glow: rgba(99, 102, 241, 0.25);

  /* Text */
  --text-1: #e8eaed;
  --text-2: #9ca3af;
  --text-3: #5c6370;

  /* Accent — indigo / cyan spectrum */
  --accent: #818cf8;
  --accent-bright: #a5b4fc;
  --accent-dim: rgba(129, 140, 248, 0.12);
  --accent-glow: rgba(129, 140, 248, 0.20);

  /* Semantic colors */
  --green: #34d399;
  --green-dim: rgba(52, 211, 153, 0.12);
  --green-glow: rgba(52, 211, 153, 0.25);
  --cyan: #22d3ee;
  --cyan-dim: rgba(34, 211, 238, 0.12);
  --yellow: #fbbf24;
  --yellow-dim: rgba(251, 191, 36, 0.12);
  --yellow-glow: rgba(251, 191, 36, 0.25);
  --red: #f87171;
  --red-dim: rgba(248, 113, 113, 0.12);
  --red-glow: rgba(248, 113, 113, 0.25);
  --purple: #c084fc;
  --purple-dim: rgba(192, 132, 252, 0.12);
  --orange: #fb923c;
  --orange-dim: rgba(251, 146, 60, 0.12);
  --pink: #f472b6;

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Cascadia Code', 'Fira Code', 'Consolas', monospace;

  /* Shape */
  --radius: 10px;
  --radius-lg: 14px;
  --radius-sm: 6px;

  /* Motion */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --duration: 0.2s;
}

html, body {
  height: 100%;
  font-family: var(--font-sans);
  background: var(--bg-base);
  color: var(--text-1);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ===== Ambient Background ===== */
.ambient {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(100px);
  opacity: 0.10;
  animation: blobFloat 20s ease-in-out infinite alternate;
}

.blob-1 {
  width: 500px; height: 500px;
  background: radial-gradient(circle, #6366f1, transparent 70%);
  top: -120px; left: -100px;
}

.blob-2 {
  width: 400px; height: 400px;
  background: radial-gradient(circle, #06b6d4, transparent 70%);
  bottom: -80px; right: -60px;
  animation-delay: -7s;
}

.blob-3 {
  width: 350px; height: 350px;
  background: radial-gradient(circle, #a855f7, transparent 70%);
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  animation-delay: -14s;
  opacity: 0.06;
}

@keyframes blobFloat {
  0%   { transform: translate(0, 0) scale(1); }
  33%  { transform: translate(30px, -20px) scale(1.05); }
  66%  { transform: translate(-20px, 15px) scale(0.95); }
  100% { transform: translate(10px, -10px) scale(1.02); }
}

/* ===== Glass Utility ===== */
.glass {
  background: var(--bg-card);
  backdrop-filter: blur(16px) saturate(1.2);
  -webkit-backdrop-filter: blur(16px) saturate(1.2);
  border: 1px solid var(--border);
}

/* ===== Header ===== */
header {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: rgba(12, 14, 22, 0.80);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  width: 36px; height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: linear-gradient(135deg, rgba(99,102,241,0.15), rgba(6,182,212,0.15));
  border: 1px solid rgba(99,102,241,0.2);
}

header h1 {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  background: linear-gradient(135deg, #e8eaed 0%, #818cf8 50%, #22d3ee 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.subtitle {
  font-size: 0.7rem;
  color: var(--text-3);
  margin-top: 1px;
}

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

.kbd-hints {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.68rem;
  color: var(--text-3);
}

.kbd {
  padding: 2px 7px;
  border-radius: 4px;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 0.62rem;
  color: var(--text-2);
  margin-right: 2px;
}

/* ===== Main Layout ===== */
main {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  height: calc(100vh - 62px);
}

/* ===== Panel Commons ===== */
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: rgba(255,255,255,0.02);
  border-bottom: 1px solid var(--border);
  min-height: 38px;
  flex-shrink: 0;
}

.panel-title-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot.green  { background: var(--green);  box-shadow: 0 0 6px var(--green-glow); }
.dot.purple { background: var(--purple); box-shadow: 0 0 6px rgba(192,132,252,0.3); }
.dot.cyan   { background: var(--cyan);   box-shadow: 0 0 6px rgba(34,211,238,0.3); }
.dot.orange { background: var(--orange); box-shadow: 0 0 6px rgba(251,146,60,0.3); }
.dot.red    { background: var(--red);    box-shadow: 0 0 6px rgba(248,113,113,0.3); }

.panel-title {
  font-size: 0.7rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-2);
}

.panel-body {
  flex: 1;
  padding: 10px 14px;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 20px;
  padding: 0 6px;
  font-size: 0.65rem;
  font-weight: 700;
  font-family: var(--font-mono);
  border-radius: 10px;
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid rgba(129,140,248,0.15);
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--text-3);
  font-size: 0.72rem;
  text-align: center;
  padding: 18px;
}

/* ===== Buttons ===== */
button {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  font-size: 0.72rem;
  font-weight: 600;
  font-family: var(--font-sans);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--duration) var(--ease);
  background: var(--bg-elevated);
  color: var(--text-1);
  outline: none;
}

button:hover { background: var(--bg-hover); border-color: var(--border-light); }
button:active { transform: scale(0.96); }

.btn-run {
  background: linear-gradient(135deg, #059669, #10b981);
  border-color: rgba(16,185,129,0.4);
  color: #fff;
  box-shadow: 0 0 16px rgba(16,185,129,0.15);
}
.btn-run:hover {
  background: linear-gradient(135deg, #10b981, #34d399);
  box-shadow: 0 0 24px rgba(16,185,129,0.25);
}

.btn-step {
  background: linear-gradient(135deg, #4f46e5, #6366f1);
  border-color: rgba(99,102,241,0.4);
  color: #fff;
  box-shadow: 0 0 16px rgba(99,102,241,0.15);
}
.btn-step:hover {
  background: linear-gradient(135deg, #6366f1, #818cf8);
  box-shadow: 0 0 24px rgba(99,102,241,0.25);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-2);
}
.btn-ghost:hover {
  background: rgba(255,255,255,0.05);
  color: var(--text-1);
}

.btn-icon {
  padding: 4px 6px;
  border: none;
  background: transparent;
  color: var(--text-3);
}
.btn-icon:hover { color: var(--text-1); background: var(--bg-hover); }

/* ===== Speed Slider ===== */
.speed-control {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: 4px;
}

.speed-label {
  font-size: 0.62rem;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}

#speed-slider {
  -webkit-appearance: none;
  width: 60px;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  outline: none;
}

#speed-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 0 8px var(--accent-glow);
}

/* ===== Editor Section ===== */
.editor-section {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--bg-surface);
}

.editor-wrapper {
  flex: 1;
  position: relative;
  overflow: hidden;
}

.line-numbers {
  position: absolute;
  top: 0; left: 0;
  width: 44px;
  height: 100%;
  padding: 14px 6px 14px 0;
  text-align: right;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  line-height: 1.7;
  color: var(--text-3);
  background: rgba(12,14,22,0.6);
  border-right: 1px solid var(--border);
  user-select: none;
  overflow: hidden;
  z-index: 2;
}

.line-numbers .line-num {
  display: block;
  height: 1.7em;
  transition: color 0.15s;
}

.line-numbers .line-num.active {
  color: var(--accent-bright);
  font-weight: 700;
  text-shadow: 0 0 8px var(--accent-glow);
}

#code-editor {
  width: 100%;
  height: 100%;
  padding: 14px 16px 14px 58px;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  line-height: 1.7;
  background: var(--bg-input);
  color: var(--text-1);
  border: none;
  outline: none;
  resize: none;
  tab-size: 2;
  white-space: pre;
  overflow: auto;
  caret-color: var(--accent);
}

#code-editor::placeholder { color: var(--text-3); }
#code-editor::selection { background: var(--accent-dim); }

.highlight-overlay {
  position: absolute;
  top: 0;
  left: 44px;
  right: 0;
  height: 100%;
  pointer-events: none;
  overflow: hidden;
  z-index: 1;
}

.line-highlight {
  position: absolute;
  left: 0; right: 0;
  height: 1.7em;
  transition: top 0.12s var(--ease), opacity 0.15s var(--ease);
}

.line-highlight.current {
  background: linear-gradient(90deg, var(--accent-dim), transparent 70%);
  border-left: 3px solid var(--accent);
  box-shadow: inset 0 0 20px var(--accent-dim);
}

.line-highlight.executed {
  background: linear-gradient(90deg, var(--green-dim), transparent 50%);
  border-left: 2px solid var(--green);
  opacity: 0.35;
}

.line-highlight.error {
  background: linear-gradient(90deg, var(--red-dim), transparent 70%);
  border-left: 3px solid var(--red);
  box-shadow: inset 0 0 20px var(--red-dim);
}

/* ===== Status Bar ===== */
.status-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 14px;
  font-size: 0.68rem;
  font-family: var(--font-mono);
  color: var(--text-3);
  background: rgba(12,14,22,0.6);
  border-top: 1px solid var(--border);
}

.status-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--text-3);
  flex-shrink: 0;
  transition: all var(--duration);
}

.status-bar.running .status-dot { background: var(--green); box-shadow: 0 0 6px var(--green-glow); animation: statusPulse 1.2s ease infinite; }
.status-bar.error .status-dot   { background: var(--red);   box-shadow: 0 0 6px var(--red-glow); }
.status-bar.done .status-dot    { background: var(--accent); box-shadow: 0 0 6px var(--accent-glow); }

.status-bar.running .status-text { color: var(--green); }
.status-bar.error .status-text   { color: var(--red); }
.status-bar.done .status-text    { color: var(--accent-bright); }

@keyframes statusPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ===== Visualization Section ===== */
.viz-section {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  gap: 1px;
  background: var(--border);
}

.viz-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--border);
}

.viz-row-top {
  flex: 1.1;
  min-height: 0;
}

.viz-panel {
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  min-height: 0;
}

.chart-panel {
  flex: 0.8;
  min-height: 0;
}

#console-panel {
  flex: 1;
  min-height: 0;
}

/* ===== Call Stack ===== */
.stack-frame {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  margin-bottom: 5px;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  animation: slideIn 0.2s var(--ease);
}

.stack-frame.active {
  border-color: var(--accent);
  background: var(--accent-dim);
  box-shadow: 0 0 16px var(--accent-dim), inset 0 0 12px var(--accent-dim);
}

.stack-frame.popping { animation: slideOut 0.2s var(--ease) forwards; }

.stack-frame-icon {
  width: 22px; height: 22px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.6rem;
  font-weight: 800;
  flex-shrink: 0;
  font-family: var(--font-mono);
}

.stack-frame-icon.global {
  background: var(--purple-dim);
  color: var(--purple);
  border: 1px solid rgba(192,132,252,0.2);
}

.stack-frame-icon.func {
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid rgba(129,140,248,0.2);
}

.stack-frame-name { font-weight: 600; color: var(--text-1); }
.stack-frame-line { margin-left: auto; color: var(--text-3); font-size: 0.62rem; }

/* ===== Memory / Variables ===== */
.scope-group {
  margin-bottom: 10px;
  animation: fadeIn 0.2s var(--ease);
}

.scope-label {
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-3);
  margin-bottom: 5px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}

.var-entry {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  margin-bottom: 3px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  transition: all 0.2s var(--ease);
}

.var-entry.new     { animation: flashGreen 0.6s var(--ease); }
.var-entry.updated { animation: flashYellow 0.6s var(--ease); }

.var-name   { color: var(--cyan); font-weight: 600; min-width: 50px; }
.var-equals { color: var(--text-3); font-size: 0.65rem; }
.var-value  { color: var(--yellow); word-break: break-all; flex: 1; }

.var-value.string    { color: var(--green); }
.var-value.number    { color: var(--orange); }
.var-value.boolean   { color: var(--purple); }
.var-value.undefined { color: var(--text-3); font-style: italic; }
.var-value.function  { color: var(--accent); }

.var-type {
  margin-left: auto;
  font-size: 0.58rem;
  color: var(--text-3);
  background: rgba(255,255,255,0.04);
  padding: 1px 5px;
  border-radius: 3px;
  flex-shrink: 0;
}

/* ===== Console ===== */
.console-body {
  font-family: var(--font-mono);
  font-size: 0.74rem;
}

.console-line {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 3px 0;
  border-bottom: 1px solid rgba(255,255,255,0.02);
  animation: fadeIn 0.15s var(--ease);
}

.console-line:last-child { border-bottom: none; }

.console-prefix {
  color: var(--text-3);
  flex-shrink: 0;
  user-select: none;
}

.console-text { color: var(--text-1); word-break: break-all; }

.console-line.error .console-prefix,
.console-line.error .console-text { color: var(--red); }
.console-line.warn .console-text  { color: var(--yellow); }
.console-line.info .console-prefix { color: var(--accent); }

/* ===== Chart ===== */
.chart-body {
  position: relative;
  padding: 6px 10px;
}

.chart-body canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.chart-body .empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chart-legend {
  display: flex;
  gap: 10px;
  font-size: 0.6rem;
  color: var(--text-3);
}

.chart-legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

.chart-legend-swatch {
  width: 8px; height: 8px;
  border-radius: 2px;
}

/* ===== Animations ===== */
@keyframes slideIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes slideOut {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(6px); }
}

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

@keyframes flashGreen {
  0%   { background: rgba(52,211,153,0.2); border-color: var(--green); box-shadow: 0 0 10px var(--green-dim); }
  100% { background: var(--bg-elevated); border-color: var(--border); box-shadow: none; }
}

@keyframes flashYellow {
  0%   { background: rgba(251,191,36,0.2); border-color: var(--yellow); box-shadow: 0 0 10px var(--yellow-dim); }
  100% { background: var(--bg-elevated); border-color: var(--border); box-shadow: none; }
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.14); }

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

/* --- Tablet landscape / small desktop (<=1200px) --- */
@media (max-width: 1200px) {
  header { padding: 10px 18px; }
  header h1 { font-size: 1rem; }
  .subtitle { display: none; }
  .kbd-hints { gap: 6px; font-size: 0.62rem; }
  .kbd { font-size: 0.58rem; padding: 2px 5px; }

  .controls { gap: 5px; }
  button { padding: 5px 10px; font-size: 0.68rem; }
  #speed-slider { width: 50px; }

  .chart-legend { gap: 6px; font-size: 0.55rem; }
  .chart-legend-item { gap: 3px; }
}

/* --- Tablet portrait / narrow (<=1000px) — stack to single column --- */
@media (max-width: 1000px) {
  html, body { overflow: auto; }

  main {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
    height: auto;
    min-height: calc(100vh - 56px);
  }

  .editor-section {
    border-right: none;
    border-bottom: 1px solid var(--border);
    min-height: 40vh;
    max-height: 50vh;
  }

  .viz-section {
    min-height: 50vh;
    background: var(--bg-surface);
    gap: 0;
  }

  .viz-row { gap: 0; }
  .viz-row-top { flex: none; min-height: 200px; }
  .chart-panel  { flex: none; min-height: 160px; }
  #console-panel { flex: none; min-height: 140px; }

  .kbd-hints { display: none; }
}

/* --- Mobile landscape (<=768px) --- */
@media (max-width: 768px) {
  header {
    padding: 8px 14px;
    flex-wrap: wrap;
    gap: 6px;
  }

  .logo-icon { width: 30px; height: 30px; }
  .logo-icon svg { width: 18px; height: 18px; }
  header h1 { font-size: 0.9rem; }

  .header-right { display: none; }

  .panel-header { padding: 6px 10px; min-height: 34px; }
  .panel-title { font-size: 0.64rem; letter-spacing: 0.05em; }
  .dot { width: 6px; height: 6px; }

  .controls { gap: 4px; flex-wrap: wrap; }

  button {
    padding: 4px 9px;
    font-size: 0.66rem;
    gap: 4px;
    border-radius: 5px;
  }
  button svg { width: 12px; height: 12px; }

  .speed-control { margin-left: 0; }
  .speed-label { font-size: 0.58rem; }
  #speed-slider { width: 44px; height: 3px; }
  #speed-slider::-webkit-slider-thumb { width: 10px; height: 10px; }

  .editor-section { min-height: 35vh; max-height: 45vh; }

  .line-numbers {
    width: 36px;
    font-size: 0.68rem;
    padding: 10px 4px 10px 0;
  }

  #code-editor {
    padding: 10px 12px 10px 48px;
    font-size: 0.72rem;
  }

  .highlight-overlay { left: 36px; }

  .status-bar { padding: 4px 10px; font-size: 0.62rem; }

  .viz-row-top {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .viz-row-top > .viz-panel { min-height: 140px; }
  .chart-panel { min-height: 140px; }
  #console-panel { min-height: 120px; }

  .panel-body { padding: 8px 10px; }
  .badge { min-width: 18px; height: 18px; font-size: 0.6rem; padding: 0 5px; }

  .stack-frame { padding: 5px 8px; gap: 6px; font-size: 0.66rem; margin-bottom: 4px; }
  .stack-frame-icon { width: 18px; height: 18px; font-size: 0.54rem; }
  .stack-frame-line { font-size: 0.58rem; }

  .var-entry { padding: 4px 6px; gap: 4px; font-size: 0.66rem; }
  .var-name { min-width: 40px; }
  .var-type { font-size: 0.54rem; padding: 1px 4px; }

  .scope-label { font-size: 0.58rem; margin-bottom: 4px; }

  .console-body { font-size: 0.68rem; }
  .console-line { gap: 6px; padding: 2px 0; }

  .chart-legend { gap: 5px; font-size: 0.52rem; flex-wrap: wrap; }
  .chart-legend-swatch { width: 6px; height: 6px; }
  .chart-body { padding: 4px 6px; }

  .empty-state { padding: 12px; font-size: 0.66rem; gap: 6px; }
  .empty-state svg { width: 22px; height: 22px; }
}

/* --- Mobile portrait (<=480px) --- */
@media (max-width: 480px) {
  header {
    padding: 6px 10px;
  }

  .logo { gap: 7px; }
  .logo-icon { width: 26px; height: 26px; border-radius: 7px; }
  .logo-icon svg { width: 15px; height: 15px; }
  header h1 { font-size: 0.8rem; }

  .panel-header { padding: 5px 8px; min-height: 30px; }
  .panel-title { font-size: 0.6rem; }
  .panel-title-group { gap: 5px; }

  .controls { gap: 3px; }

  /* Icon-only buttons on very small screens */
  .btn-run span,
  .btn-step span { display: none; }
  button { padding: 5px 8px; }
  .btn-ghost { padding: 5px 7px; }

  .speed-control { gap: 4px; }
  #speed-slider { width: 36px; }

  .editor-section { min-height: 30vh; max-height: 40vh; }

  .line-numbers {
    width: 30px;
    font-size: 0.62rem;
    padding: 8px 3px 8px 0;
  }

  #code-editor {
    padding: 8px 8px 8px 40px;
    font-size: 0.66rem;
  }

  .highlight-overlay { left: 30px; }

  .status-bar { padding: 3px 8px; font-size: 0.58rem; gap: 5px; }
  .status-dot { width: 5px; height: 5px; }

  .viz-row-top > .viz-panel { min-height: 120px; }
  .chart-panel { min-height: 120px; }
  #console-panel { min-height: 100px; }

  .panel-body { padding: 6px 8px; }

  .stack-frame { padding: 4px 6px; gap: 5px; font-size: 0.62rem; }
  .stack-frame-icon { width: 16px; height: 16px; font-size: 0.5rem; border-radius: 4px; }

  .var-entry { padding: 3px 5px; font-size: 0.62rem; gap: 3px; }
  .var-name { min-width: 32px; }
  .var-type { font-size: 0.5rem; }
  .var-equals { font-size: 0.58rem; }

  .scope-label { font-size: 0.54rem; }

  .console-body { font-size: 0.62rem; }

  .chart-legend { font-size: 0.48rem; gap: 4px; }
  .chart-legend-swatch { width: 5px; height: 5px; }

  .empty-state { padding: 10px; font-size: 0.6rem; }
  .empty-state svg { width: 18px; height: 18px; }

  .badge { min-width: 16px; height: 16px; font-size: 0.55rem; padding: 0 4px; border-radius: 8px; }
}

/* --- Tiny screens (<=360px) --- */
@media (max-width: 360px) {
  header h1 { font-size: 0.72rem; }
  .logo-icon { display: none; }

  .speed-control { display: none; }

  .editor-section { min-height: 28vh; max-height: 38vh; }

  #code-editor { font-size: 0.6rem; padding: 6px 6px 6px 36px; }
  .line-numbers { width: 26px; font-size: 0.56rem; padding: 6px 2px 6px 0; }
  .highlight-overlay { left: 26px; }

  .panel-header { padding: 4px 6px; min-height: 26px; }
  .panel-title { font-size: 0.56rem; }
  .dot { width: 5px; height: 5px; }

  button { padding: 4px 6px; }
  button svg { width: 11px; height: 11px; }
}

/* --- Height-constrained (short viewports / landscape phones) --- */
@media (max-height: 500px) {
  header { padding: 4px 12px; }
  .logo-icon { display: none; }
  header h1 { font-size: 0.85rem; }
  .subtitle { display: none; }

  main { height: calc(100vh - 36px); }

  .panel-header { min-height: 28px; padding: 4px 10px; }
  .panel-title { font-size: 0.6rem; }

  .status-bar { padding: 2px 10px; font-size: 0.58rem; }

  .empty-state { padding: 6px; }
  .empty-state svg { display: none; }
}

@media (max-height: 500px) and (max-width: 1000px) {
  .editor-section { min-height: 45vh; max-height: 55vh; }
  .viz-row-top > .viz-panel { min-height: 100px; }
  .chart-panel { min-height: 100px; }
  #console-panel { min-height: 80px; }
}

/* --- High-DPI touch refinements --- */
@media (hover: none) and (pointer: coarse) {
  button { min-height: 36px; min-width: 36px; }
  .btn-icon { min-height: 32px; min-width: 32px; padding: 6px; }
  #speed-slider { height: 6px; }
  #speed-slider::-webkit-slider-thumb { width: 18px; height: 18px; }

  .stack-frame { padding: 8px 10px; }
  .var-entry { padding: 6px 8px; }
  .console-line { padding: 4px 0; }
}

/* --- Print --- */
@media print {
  .ambient, .blob { display: none; }
  header { background: #fff; color: #000; border-bottom: 1px solid #ccc; }
  header h1 { -webkit-text-fill-color: #000; background: none; }
  body { background: #fff; color: #000; }
  .glass { background: #f8f8f8; backdrop-filter: none; border-color: #ddd; }
  button { display: none; }
  .speed-control { display: none; }
  .kbd-hints { display: none; }
}
