/* ==========================================================================
   SortFlow Design Tokens & CSS Reset
   ========================================================================== */

:root {
  /* Color Palette - Light Mode */
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  
  --accent-color: #6366f1;       /* Indigo 500 */
  --accent-hover: #4f46e5;       /* Indigo 600 */
  --accent-light: #e0e7ff;       /* Indigo 100 */
  --accent-glow: rgba(99, 102, 241, 0.15);
  
  --border-color: #e2e8f0;       /* Slate 200 */
  --border-focus: #94a3b8;
  
  /* State-specific Pill Colors */
  --pill-normal: #ffffff;
  --pill-normal-text: #334155;
  --pill-compare: #fef08a;       /* Pastel Yellow */
  --pill-compare-text: #854d0e;
  --pill-swap: #fca5a5;          /* Pastel Red */
  --pill-swap-text: #991b1b;
  --pill-pivot: #d8b4fe;         /* Pastel Purple */
  --pill-pivot-text: #6b21a8;
  --pill-sorted: #bbf7d0;        /* Pastel Green */
  --pill-sorted-text: #166534;
  --pill-highlight: #bfdbfe;     /* Pastel Blue */
  --pill-highlight-text: #1e40af;
  
  /* Fonts */
  --font-main: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  
  /* Border Radius (Chunky Aesthetic) */
  --radius-sm: 0.5rem;
  --radius-md: 1rem;
  --radius-lg: 1.5rem;
  --radius-xl: 2.25rem;
  
  /* Shadows */
  --shadow-sm: 0 2px 8px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 10px 25px -5px rgba(15, 23, 42, 0.06), 0 8px 16px -6px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 20px 40px -10px rgba(15, 23, 42, 0.1), 0 12px 20px -8px rgba(15, 23, 42, 0.08);
  --shadow-glow: 0 0 24px rgba(99, 102, 241, 0.25);
  
  --transition-speed: 0.3s;
}

body.dark-theme {
  /* Color Palette - Dark Mode */
  --bg-primary: #090d16;
  --bg-secondary: #111827;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  
  --accent-color: #818cf8;       /* Indigo 400 */
  --accent-hover: #6366f1;       /* Indigo 500 */
  --accent-light: #1e1b4b;       /* Indigo 950 */
  --accent-glow: rgba(129, 140, 248, 0.2);
  
  --border-color: #1f2937;       /* Slate 800 */
  --border-focus: #4b5563;
  
  /* State-specific Pill Colors - Dark Mode */
  --pill-normal: #1f2937;
  --pill-normal-text: #e2e8f0;
  --pill-compare: #eab308;       /* Saturated Yellow */
  --pill-compare-text: #1e1b4b;
  --pill-swap: #ef4444;          /* Saturated Red */
  --pill-swap-text: #ffffff;
  --pill-pivot: #a855f7;         /* Saturated Purple */
  --pill-pivot-text: #ffffff;
  --pill-sorted: #22c55e;        /* Saturated Green */
  --pill-sorted-text: #ffffff;
  --pill-highlight: #3b82f6;     /* Saturated Blue */
  --pill-highlight-text: #ffffff;
  
  /* Shadows - Dark Mode */
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 10px 25px -5px rgba(0, 0, 0, 0.4), 0 8px 16px -6px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 20px 40px -10px rgba(0, 0, 0, 0.5), 0 12px 20px -8px rgba(0, 0, 0, 0.4);
  --shadow-glow: 0 0 24px rgba(129, 140, 248, 0.3);
}

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

body {
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-main);
  line-height: 1.5;
  transition: background-color 0.4s ease, color 0.4s ease;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 2rem 1rem;
}

/* ==========================================================================
   App Container & Header Layout
   ========================================================================== */

.app-container {
  width: 100%;
  max-width: 1280px;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0;
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.logo-dot {
  width: 1.25rem;
  height: 1.25rem;
  background-color: var(--accent-color);
  border-radius: 50%;
  box-shadow: var(--shadow-glow);
  animation: logoPulse 2s infinite ease-in-out;
}

@keyframes logoPulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.3); opacity: 0.8; }
}

.logo-area h1 {
  font-size: 1.75rem;
  font-weight: 800;
  letter-spacing: -0.05em;
  background: linear-gradient(135deg, var(--text-primary) 30%, var(--accent-color));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.badge {
  font-size: 0.75rem;
  font-weight: 700;
  background-color: var(--accent-light);
  color: var(--accent-color);
  padding: 0.25rem 0.75rem;
  border-radius: var(--radius-xl);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

/* Theme Switcher Button */
.theme-btn {
  background-color: var(--bg-secondary);
  border: 2px solid var(--border-color);
  width: 3rem;
  height: 3rem;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
  transition: all var(--transition-speed) cubic-bezier(0.4, 0, 0.2, 1);
}

.theme-btn:hover {
  transform: scale(1.1) rotate(15deg);
  border-color: var(--accent-color);
}

.theme-btn .icon-sun {
  display: block;
  font-size: 1.25rem;
}
.theme-btn .icon-moon {
  display: none;
  font-size: 1.25rem;
}

body.dark-theme .theme-btn .icon-sun {
  display: none;
}
body.dark-theme .theme-btn .icon-moon {
  display: block;
}

/* ==========================================================================
   Panel Containers (Chunky Styling)
   ========================================================================== */

.panel {
  background-color: var(--bg-secondary);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-md);
  transition: border-color var(--transition-speed) ease, box-shadow var(--transition-speed) ease;
}

.panel:hover {
  border-color: var(--border-focus);
  box-shadow: var(--shadow-lg);
}

/* ==========================================================================
   Preset & Input Panel
   ========================================================================== */

.preset-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  align-items: center;
}

@media (max-width: 768px) {
  .preset-panel {
    grid-template-columns: 1fr;
    gap: 1.5rem;
  }
}

.input-group, .presets-group {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

label {
  font-size: 0.875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
}

.input-wrapper {
  display: flex;
  gap: 0.5rem;
}

input[type="text"] {
  flex: 1;
  background-color: var(--bg-primary);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.875rem 1.25rem;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 500;
  transition: all var(--transition-speed) ease;
}

input[type="text"]:focus {
  outline: none;
  border-color: var(--accent-color);
  box-shadow: 0 0 0 4px var(--accent-light);
}

/* Buttons Styles */
.btn {
  font-family: var(--font-main);
  font-size: 0.95rem;
  font-weight: 700;
  padding: 0.875rem 1.5rem;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 2px solid transparent;
}

.btn:active {
  transform: scale(0.96);
}

.btn-primary {
  background-color: var(--accent-color);
  color: #ffffff;
  box-shadow: 0 4px 12px var(--accent-glow);
}

.btn-primary:hover {
  background-color: var(--accent-hover);
  transform: translateY(-2px);
}

.btn-outline {
  background-color: transparent;
  border-color: var(--border-color);
  color: var(--text-primary);
}

.btn-outline:hover {
  border-color: var(--accent-color);
  color: var(--accent-color);
  background-color: var(--accent-light);
  transform: translateY(-2px);
}

.preset-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.preset-buttons .btn {
  padding: 0.625rem 1.125rem;
  font-size: 0.875rem;
}

/* ==========================================================================
   Main Grid Layout
   ========================================================================== */

.main-content {
  display: grid;
  grid-template-columns: 7fr 5fr;
  gap: 1.5rem;
  align-items: start;
}

@media (max-width: 899px) {
  .main-content {
    grid-template-columns: 1fr;
  }
}

.visualizer-column {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.code-column {
  position: sticky;
  top: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* ==========================================================================
   Tabs (Algorithm Selector)
   ========================================================================== */

.algo-tabs {
  display: flex;
  background-color: var(--border-color);
  padding: 0.375rem;
  border-radius: var(--radius-xl);
  gap: 0.25rem;
}

.algo-tab {
  flex: 1;
  border: none;
  background: transparent;
  padding: 0.875rem 1rem;
  font-family: var(--font-main);
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-secondary);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.algo-tab.active {
  background-color: var(--bg-secondary);
  color: var(--accent-color);
  box-shadow: var(--shadow-sm);
}

/* ==========================================================================
   Narration Bubble (Friendly Explanation Widget)
   ========================================================================== */

.narration-bubble {
  background-color: var(--accent-light);
  border: 2px dashed var(--accent-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  position: relative;
  overflow: hidden;
}

.narration-bubble::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  background-color: var(--accent-color);
}

.narration-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.narration-icon {
  font-size: 1.25rem;
}

.narration-header h4 {
  font-size: 1rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent-color);
}

#narration-text {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.6;
}

/* ==========================================================================
   Visualizer Boards & Sub-shelves
   ========================================================================== */

.visual-board {
  min-height: 200px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 1.5rem;
  position: relative;
  overflow: visible;
}

/* The Array Container */
.array-container {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 0.875rem;
  width: 100%;
  padding: 1.5rem 0.5rem;
  min-height: 140px;
  transition: all 0.4s ease;
}

/* The Capsule Pills (Chunky modern capsules) */
.pill-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  position: relative;
  transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.pill {
  width: 3.75rem;
  height: 3.75rem;
  background-color: var(--pill-normal);
  color: var(--pill-normal-text);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-lg);
  font-size: 1.25rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
  transition: all 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.pill-index {
  font-size: 0.75rem;
  font-weight: 800;
  font-family: var(--font-mono);
  color: var(--text-secondary);
  background-color: var(--bg-primary);
  padding: 0.125rem 0.5rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
}

/* State Styling Classes for Pills */
.pill.state-normal {
  background-color: var(--pill-normal);
  color: var(--pill-normal-text);
}

.pill.state-compare {
  background-color: var(--pill-compare);
  color: var(--pill-compare-text);
  border-color: #eab308;
  transform: scale(1.1) translateY(-6px);
  box-shadow: 0 10px 15px -3px rgba(234, 179, 8, 0.2);
}

.pill.state-swap {
  background-color: var(--pill-swap);
  color: var(--pill-swap-text);
  border-color: #ef4444;
  transform: scale(1.12) translateY(-6px);
  box-shadow: 0 10px 15px -3px rgba(239, 68, 68, 0.35);
  animation: swapShake 0.4s ease;
}

@keyframes swapShake {
  0%, 100% { transform: scale(1.12) translateY(-6px) rotate(0deg); }
  25% { transform: scale(1.12) translateY(-6px) rotate(-5deg); }
  75% { transform: scale(1.12) translateY(-6px) rotate(5deg); }
}

.pill.state-pivot {
  background-color: var(--pill-pivot);
  color: var(--pill-pivot-text);
  border-color: #a855f7;
  transform: scale(1.08) translateY(-4px);
  box-shadow: 0 8px 12px -3px rgba(168, 85, 247, 0.3);
}

.pill.state-sorted {
  background-color: var(--pill-sorted);
  color: var(--pill-sorted-text);
  border-color: #22c55e;
  box-shadow: 0 4px 6px -1px rgba(34, 197, 94, 0.15);
}

.pill.state-highlight {
  background-color: var(--pill-highlight);
  color: var(--pill-highlight-text);
  border-color: #3b82f6;
  box-shadow: 0 4px 6px -1px rgba(59, 130, 246, 0.15);
}

/* Utility visibility classes */
.hidden {
  display: none !important;
}

/* ==========================================================================
   Merge Sort Shelves Sub-View
   ========================================================================== */

.shelf-container {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  width: 100%;
  padding-top: 1.5rem;
  border-top: 2px dashed var(--border-color);
  animation: slideIn 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.shelf-group {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  background-color: var(--bg-primary);
  padding: 0.875rem 1.25rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
}

.shelf-label {
  font-size: 0.85rem;
  font-weight: 800;
  color: var(--text-secondary);
  min-width: 150px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.shelf-pills {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.shelf-pills .pill {
  width: 2.75rem;
  height: 2.75rem;
  font-size: 0.95rem;
  border-radius: var(--radius-md);
}

.shelf-pills .pill-wrapper {
  gap: 0.25rem;
}

.shelf-pills .pill-index {
  font-size: 0.65rem;
}

/* ==========================================================================
   Heap Sort Tree Sub-View
   ========================================================================== */

.tree-container {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  padding-top: 1rem;
  border-top: 2px dashed var(--border-color);
  animation: slideIn 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

#heap-svg {
  overflow: visible;
  max-width: 500px;
}

.node-group {
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  cursor: default;
}

.node-circle {
  stroke-width: 2.5;
  transition: fill 0.3s, stroke 0.3s, r 0.3s;
}

.node-text {
  font-family: var(--font-main);
  font-weight: 800;
  font-size: 14px;
  text-anchor: middle;
  dominant-baseline: central;
  transition: fill 0.3s;
}

.node-index {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 9px;
  text-anchor: middle;
  dominant-baseline: central;
}

.node-link {
  stroke-width: 3;
  stroke-linecap: round;
  transition: stroke 0.3s, stroke-dasharray 0.3s;
}

/* ==========================================================================
   Playback Controls & Speed Panel
   ========================================================================== */

.playback-bar {
  background-color: var(--bg-secondary);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow-md);
  transition: border-color var(--transition-speed) ease, box-shadow var(--transition-speed) ease;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.playback-bar:hover {
  border-color: var(--border-focus);
  box-shadow: var(--shadow-lg);
}

.playback-bar-content {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  width: 100%;
}

.playback-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1rem;
}

.btn-icon {
  width: 3.5rem;
  height: 3.5rem;
  border-radius: 50%;
  background-color: var(--bg-primary);
  border: 2px solid var(--border-color);
  font-size: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-icon:hover {
  border-color: var(--accent-color);
  background-color: var(--accent-light);
  transform: scale(1.08);
}

.btn-play {
  width: 4.25rem;
  height: 4.25rem;
  background-color: var(--accent-color);
  border-color: transparent;
  color: #ffffff;
  box-shadow: 0 6px 16px var(--accent-glow);
}

.btn-play:hover {
  background-color: var(--accent-hover);
  transform: scale(1.1);
  box-shadow: 0 8px 24px rgba(99, 102, 241, 0.3);
}

.btn-play .play-icon {
  font-size: 1.5rem;
  margin-left: 2px;
}

/* Timeline/Slider Stepper */
.timeline-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.timeline-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-secondary);
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  cursor: pointer;
  width: 100%;
}

input[type="range"]:focus {
  outline: none;
}

input[type="range"]::-webkit-slider-runnable-track {
  background-color: var(--border-color);
  height: 0.5rem;
  border-radius: 9999px;
  transition: background-color var(--transition-speed);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  background-color: var(--accent-color);
  height: 1.25rem;
  width: 1.25rem;
  border-radius: 50%;
  margin-top: -0.375rem;
  border: 2px solid var(--bg-secondary);
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s, background-color 0.15s;
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.25);
  background-color: var(--accent-hover);
}

/* Speed Controls */
.speed-group {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.speed-group label {
  min-width: 60px;
}

.speed-group input[type="range"] {
  flex: 1;
}

#speed-value {
  font-size: 0.875rem;
  font-weight: 800;
  font-family: var(--font-mono);
  color: var(--accent-color);
  background-color: var(--accent-light);
  padding: 0.25rem 0.625rem;
  border-radius: var(--radius-sm);
}

/* ==========================================================================
   Variables Tracker Card Panel
   ========================================================================== */

.variables-panel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  background-color: var(--bg-secondary);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
}

.variables-panel h3 {
  font-size: 1rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
}

.variables-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  min-height: 50px;
  align-items: center;
}

.variable-card {
  background-color: var(--bg-primary);
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.625rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  animation: varPop 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes varPop {
  from { transform: scale(0.8); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.var-name {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.var-value {
  font-family: var(--font-mono);
  font-weight: 800;
  color: var(--accent-color);
  font-size: 0.95rem;
  background-color: var(--accent-light);
  padding: 0.125rem 0.5rem;
  border-radius: var(--radius-sm);
}

.no-vars-msg {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  font-style: italic;
}

/* ==========================================================================
   Pseudo-code Stepper Panels (Right Column)
   ========================================================================== */

.code-box {
  display: none;
  background-color: var(--bg-secondary);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-md);
}

.code-box.active {
  display: flex;
  flex-direction: column;
}

.code-box-header {
  background-color: var(--bg-primary);
  border-bottom: 2px solid var(--border-color);
  padding: 1rem 1.5rem;
}

.code-box-header h3 {
  font-size: 1rem;
  font-weight: 800;
  color: var(--text-primary);
}

.procedure-block {
  padding: 1rem 0;
  border-bottom: 1px dashed var(--border-color);
}

.procedure-block:last-child {
  border-bottom: none;
}

.procedure-title {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.875rem;
  color: var(--accent-color);
  padding: 0.25rem 1.5rem 0.5rem 1.5rem;
  letter-spacing: -0.01em;
}

.code-lines {
  display: flex;
  flex-direction: column;
}

.code-line {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.3125rem 1.5rem;
  color: var(--text-secondary);
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  white-space: pre-wrap;
  border-left: 4px solid transparent;
  transition: all 0.25s ease;
}

.line-num {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  opacity: 0.5;
  min-width: 1rem;
  text-align: right;
  user-select: none;
}

/* Running Highlighted Code Line */
.code-line.line-running {
  background-color: var(--accent-light);
  color: var(--text-primary);
  font-weight: 600;
  border-left-color: var(--accent-color);
  transform: translateX(4px);
  box-shadow: inset 2px 0 0 rgba(99, 102, 241, 0.05);
}

/* ==========================================================================
   Footer Styling
   ========================================================================== */

.app-footer {
  text-align: center;
  padding: 1rem 0 2rem 0;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  border-top: 2px solid var(--border-color);
  margin-top: 1rem;
}

/* ==========================================================================
   Desktop Layout — Two-column grid, CENTERED, no visible scrollbars.
   ========================================================================== */
@media (min-width: 900px) {
  body {
    height: 100dvh;
    overflow: hidden;
    padding: 0.5rem 1rem;
    justify-content: center;
    align-items: stretch;
  }

  .app-container {
    height: 100%;
    overflow: hidden;
    gap: 0.5rem;
    margin: 0 auto;
  }

  /* --- Header --- */
  .app-header { padding: 0.15rem 0; flex-shrink: 0; }
  .logo-area h1 { font-size: 1.4rem; }
  .badge { font-size: 0.65rem; padding: 0.15rem 0.5rem; }

  /* --- Presets --- */
  .preset-panel { flex-shrink: 0; padding: 0.5rem 1rem; gap: 1rem; }

  /* --- Main two-column grid (keeps base 7fr 5fr) --- */
  .main-content {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    gap: 1rem;
    align-items: stretch;
  }

  /* --- Left: Visualizer --- */
  .visualizer-column {
    height: 100%;
    overflow: hidden;
    gap: 0.5rem;
  }

  .algo-tabs { flex-shrink: 0; padding: 0.2rem; }
  .algo-tab { padding: 0.5rem 0.75rem; font-size: 0.85rem; }

  .narration-bubble { flex-shrink: 0; padding: 0.5rem 1rem; }
  .narration-header h4 { font-size: 0.85rem; }
  #narration-text { font-size: 0.85rem; line-height: 1.4; }

  .visual-board {
    flex: 1;
    min-height: 0;
    padding: 0.75rem;
    gap: 0.75rem;
    overflow-y: auto;
    scrollbar-width: none;
  }
  .visual-board::-webkit-scrollbar { display: none; }

  .array-container { padding: 0.25rem; min-height: 80px; align-content: center; }
  .pill { width: 3rem; height: 3rem; font-size: 1.1rem; }

  .shelf-container { padding-top: 0.5rem; gap: 0.5rem; flex-shrink: 0; }
  .shelf-group { padding: 0.35rem 0.75rem; }

  .tree-container { padding-top: 0.25rem; flex: 1; min-height: 0; }
  #heap-svg { height: 100%; max-height: 200px; }

  /* --- Right: Code + Variables --- */
  .code-column {
    height: 100%;
    overflow: hidden;
    position: relative;
    top: 0;
    gap: 0.5rem;
    display: flex;
    flex-direction: column;
  }

  .code-box {
    flex: 1;
    min-height: 0;
    display: none;
    flex-direction: column;
    overflow-y: auto;
    scrollbar-width: none;
  }
  .code-box::-webkit-scrollbar { display: none; }

  .code-box.active { display: flex; }

  .code-box-header { padding: 0.5rem 1rem; flex-shrink: 0; }
  .code-box-header h3 { font-size: 0.9rem; }

  .procedure-block { padding: 0.25rem 0; flex-shrink: 0; }
  .procedure-title { padding: 0.15rem 1rem; font-size: 0.75rem; }
  .code-line { padding: 0.175rem 1rem; font-size: 0.75rem; gap: 0.5rem; }
  .line-num { font-size: 0.6rem; min-width: 0.85rem; }

  /* --- Variables: pinned below code --- */
  .variables-panel { flex-shrink: 0; padding: 0.5rem 1rem; gap: 0.35rem; }
  .variables-panel h3 { font-size: 0.8rem; }
  .variables-grid { min-height: auto; gap: 0.35rem; }
  .variable-card { padding: 0.2rem 0.5rem; gap: 0.35rem; }
  .var-name { font-size: 0.75rem; }
  .var-value { font-size: 0.8rem; padding: 0.1rem 0.3rem; }
  .no-vars-msg { font-size: 0.75rem; }

  /* --- Playback bar --- */
  .playback-bar { flex-shrink: 0; padding: 0.35rem 1rem; gap: 0; }
  .playback-bar-content { flex-direction: row; align-items: center; gap: 1.25rem; }
  .playback-bar .speed-group { flex: 1; min-width: 130px; }
  .playback-bar .speed-group label { font-size: 0.7rem; min-width: 40px; }
  #speed-value { font-size: 0.75rem; padding: 0.1rem 0.35rem; }
  .playback-bar .playback-controls { flex: 0 0 auto; }
  .btn-icon { width: 2.5rem; height: 2.5rem; font-size: 1rem; }
  .btn-play { width: 3rem; height: 3rem; }
  .btn-play .play-icon { font-size: 1.1rem; }
  .playback-bar .timeline-group { flex: 2; min-width: 200px; }
  .timeline-labels { font-size: 0.75rem; }

  /* --- Footer --- */
  .app-footer {
    padding: 0.25rem 0;
    margin-top: 0;
    flex-shrink: 0;
    font-size: 0.75rem;
    border-top: 1px solid var(--border-color);
  }
}

/* Mobile-friendly specific adjustments */
@media (max-width: 899px) {
  body {
    padding: 1rem 0.5rem;
  }
  
  .panel {
    padding: 1rem;
  }

  .preset-panel {
    grid-template-columns: 1fr;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
  }
  
  .input-group, .presets-group {
    gap: 0.35rem;
  }
  
  label {
    font-size: 0.75rem;
  }
  
  input[type="text"] {
    padding: 0.5rem 0.75rem;
    font-size: 0.9rem;
  }
  
  .preset-buttons .btn {
    padding: 0.375rem 0.625rem;
    font-size: 0.75rem;
  }

  .logo-area h1 {
    font-size: 1.35rem;
  }
  
  .badge {
    font-size: 0.65rem;
    padding: 0.15rem 0.5rem;
  }
  
  .theme-btn {
    width: 2.25rem;
    height: 2.25rem;
  }

  .algo-tabs {
    padding: 0.25rem;
  }
  
  .algo-tab {
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
  }

  .narration-bubble {
    padding: 0.75rem 1rem;
  }
  
  #narration-text {
    font-size: 0.95rem;
  }

  .pill {
    width: 2.25rem;
    height: 2.25rem;
    font-size: 0.85rem;
  }

  .visual-board {
    min-height: auto;
    padding: 0.75rem 0.5rem;
    overflow-y: auto;
    scrollbar-width: none;
  }
  .visual-board::-webkit-scrollbar { display: none; }

  .array-container {
    gap: 0.375rem;
    padding: 0.5rem;
  }

  .shelf-container {
    gap: 0.75rem;
    padding-top: 0.75rem;
  }

  .shelf-group {
    padding: 0.5rem 0.75rem;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }

  .shelf-label {
    min-width: auto;
    font-size: 0.75rem;
  }

  .shelf-pills .pill {
    width: 2.25rem;
    height: 2.25rem;
    font-size: 0.8rem;
  }

  .btn {
    padding: 0.625rem 1rem;
    font-size: 0.85rem;
  }

  .btn-icon {
    width: 2.75rem;
    height: 2.75rem;
    font-size: 1rem;
  }

  .btn-play {
    width: 3.5rem;
    height: 3.5rem;
  }

  #heap-svg {
    height: 230px;
    max-width: 100%;
    width: 100%;
    pointer-events: none; /* Let touch events pass through to allow scrolling */
  }

  .tree-container {
    width: 100%;
  }

  /* No redundant visual-board overflow here, use the auto one above */

  .playback-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
    padding: 0.35rem 0.75rem;
    gap: 0.35rem;
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
    box-shadow: 0 -2px 12px rgba(0,0,0,0.1);
  }

  .playback-bar-content {
    flex-direction: row;
    gap: 0.75rem;
    align-items: center;
  }

  .playback-controls {
    gap: 0.35rem;
  }

  .btn-icon {
    width: 2rem;
    height: 2rem;
    font-size: 0.8rem;
  }

  .btn-play {
    width: 2.5rem;
    height: 2.5rem;
  }

  .btn-play .play-icon {
    font-size: 0.9rem;
  }

  .speed-group { display: none; }

  .timeline-group {
    flex: 1;
    min-width: 0;
  }

  .timeline-labels {
    font-size: 0.65rem;
  }

  /* Push page content up so it's not hidden behind fixed bar */
  .app-footer {
    padding-bottom: 4rem;
  }

  .variables-panel {
    padding: 0.75rem 1rem;
    gap: 0.5rem;
  }

  .variable-card {
    padding: 0.35rem 0.65rem;
    gap: 0.5rem;
  }

  .var-name {
    font-size: 0.8rem;
  }

  .var-value {
    font-size: 0.85rem;
    padding: 0.1rem 0.35rem;
  }

  .code-line {
    padding: 0.25rem 0.75rem;
    font-size: 0.8rem;
    gap: 0.5rem;
  }

  .procedure-title {
    padding: 0.25rem 0.75rem;
    font-size: 0.8rem;
  }

  /* Hide all scrollbars on mobile — scroll works, bar invisible */
  body,
  .code-box,
  .code-column,
  .visual-board,
  .main-content,
  .app-container {
    scrollbar-width: none;
  }
  body::-webkit-scrollbar,
  .code-box::-webkit-scrollbar,
  .code-column::-webkit-scrollbar,
  .visual-board::-webkit-scrollbar,
  .main-content::-webkit-scrollbar,
  .app-container::-webkit-scrollbar {
    display: none;
  }
}

/* ==========================================================================
   Inline Boolean Comparison Badges
   ========================================================================== */

.comparison-badge {
  display: inline-flex;
  align-items: center;
  font-size: 0.75rem;
  font-weight: 800;
  padding: 0.15rem 0.45rem;
  border-radius: var(--radius-sm);
  margin-left: 0.75rem;
  font-family: var(--font-main);
  animation: badgePop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  vertical-align: middle;
}

.comparison-badge.eval-true {
  background-color: var(--pill-sorted);
  color: var(--pill-sorted-text);
  border: 1px solid #22c55e;
}

.comparison-badge.eval-false {
  background-color: var(--pill-swap);
  color: var(--pill-swap-text);
  border: 1px solid #ef4444;
}

@keyframes badgePop {
  from { transform: scale(0.6) translateY(2px); opacity: 0; }
  to { transform: scale(1) translateY(0); opacity: 1; }
}

/* Developer Credit Link styles */
.credit-link {
  color: var(--accent-color);
  text-decoration: none;
  font-weight: 700;
  position: relative;
  transition: color var(--transition-speed);
}

.credit-link::after {
  content: '';
  position: absolute;
  width: 100%;
  transform: scaleX(0);
  height: 2px;
  bottom: -2px;
  left: 0;
  background-color: var(--accent-color);
  transform-origin: bottom right;
  transition: transform 0.25s ease-out;
}

.credit-link:hover {
  color: var(--accent-hover);
}

.credit-link:hover::after {
  transform: scaleX(1);
  transform-origin: bottom left;
}

/* ==========================================================================
   Size Warning Overlay (Screen too small)
   ========================================================================== */

.size-warning {
  display: none; /* hidden by default */
}

/* Trigger if screen is extremely small (e.g., width < 320px or height < 500px in landscape) */
@media (max-width: 330px), (max-height: 480px) and (orientation: landscape) {
  .app-container {
    display: none !important;
  }

  .size-warning {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100dvh;
    width: 100vw;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    text-align: center;
    padding: 2rem;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 9999;
  }

  .warning-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
    max-width: 280px;
  }

  .expand-graphic {
    width: 100px;
    height: 100px;
    animation: pulse 2s infinite ease-in-out;
  }

  .expand-svg {
    width: 100%;
    height: 100%;
    fill: none;
    stroke: var(--accent-color);
    stroke-width: 4;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  .dotted-rect {
    stroke: var(--text-secondary);
    stroke-dasharray: 6, 6;
    stroke-width: 3;
  }

  .arrow-top-left, .arrow-bottom-right {
    stroke: var(--accent-color);
    animation: expandArrows 1.5s infinite alternate ease-in-out;
  }

  .size-warning h2 {
    font-size: 1.4rem;
    color: var(--text-primary);
    margin: 0;
  }

  .size-warning p {
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.4;
    margin: 0;
  }

  @keyframes expandArrows {
    0% { transform: scale(0.9); transform-origin: center; }
    100% { transform: scale(1.1); transform-origin: center; }
  }

  @keyframes pulse {
    0% { opacity: 0.8; }
    50% { opacity: 1; }
    100% { opacity: 0.8; }
  }
}
