:root {
  /* Sophisticated Minimalist Dark Palette */
  --bg: #0a0a0a; /* Night black */
  --surface-1: #1c130b; /* Dark chocolate surface */
  --surface-2: #271b10; /* Rich walnut surface */
  --surface-3: #342416; /* Ember card background */
  --border: #4b311d; /* Burnt umber border */

  --text: #f4eadc; /* Warm parchment text */
  --text-2: #e0c4a3; /* Secondary text */
  --text-muted: #b8926a; /* Muted text */
  --text-accent: #C19A6B; /* Accent text */

  --accent-primary: #C19A6B; /* Warm accent highlights */
  --accent-subtle: #8f6339; /* Subtle accents */
  --accent-glow: #ffcf80; /* Glow effects */
  --accent-danger: #d5744a; /* Minimal red for errors */

  /* Typography */
  --font-sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI",
    Roboto, "Helvetica Neue", Arial, "Noto Sans", "Apple Color Emoji",
    "Segoe UI Emoji";
  --font-mono: "JetBrains Mono", "IBM Plex Mono", "SFMono-Regular", Menlo,
    Consolas, monospace;

  /* Legacy mappings for compatibility */
  --panel: var(--surface-1);
  --edge: var(--border);
  --edgeHot: var(--accent-primary);
  --node: var(--accent-primary);
  --hot: var(--accent-glow);
  --pulse: var(--accent-primary);
  --muted: var(--text-muted);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.4;
  overflow: hidden;
  font-weight: 400;
  letter-spacing: -0.01em;
}

canvas {
  display: block;
}

#overlay {
  pointer-events: none;
  position: fixed;
  inset: 0;
  background: radial-gradient(
      1400px 900px at 30% 0%,
      rgba(243, 188, 110, 0.16),
      transparent 68%
    ),
    radial-gradient(
      1000px 600px at 80% 100%,
      rgba(186, 118, 60, 0.12),
      transparent 58%
    );
}

#hud {
  position: fixed;
  left: 16px;
  top: 16px;
  display: flex;
  gap: 12px;
  align-items: center;
  background: linear-gradient(
    140deg,
    rgba(216, 155, 90, 0.22),
    rgba(32, 22, 13, 0.92)
  );
  padding: 12px 16px;
  border: 1px solid rgba(216, 155, 90, 0.45);
  backdrop-filter: blur(12px);
  box-shadow: 0 20px 38px rgba(7, 3, 1, 0.65);
}

.btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  padding: 10px 18px;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: -0.01em;
  transition: all 0.18s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  text-transform: uppercase;
  white-space: nowrap;
  border-radius: 10px;
}

.btn:hover {
  background: var(--surface-1);
  border-color: var(--accent-subtle);
  transform: translateY(-1px);
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.45);
}

.btn.on {
  background: linear-gradient(135deg, #7a4a20 0%, #f0b15d 100%);
  color: #fff0dc;
  border-color: #f0b15d;
  box-shadow: 0 10px 24px rgba(240, 177, 93, 0.45);
  text-shadow: 0 0 6px rgba(0, 0, 0, 0.5);
}

.btn.on:hover {
  background: linear-gradient(135deg, #875328 0%, #fecb82 100%);
  box-shadow: 0 12px 28px rgba(254, 203, 130, 0.5);
}

.btn.on:active {
  transform: translateY(0);
  box-shadow: 0 6px 18px rgba(126, 86, 45, 0.5);
}

.btn.btn-ghost {
  background: transparent;
  border-color: rgba(240, 177, 93, 0.35);
  color: var(--text-muted);
  box-shadow: none;
}

.btn.btn-ghost:hover {
  background: rgba(216, 155, 90, 0.12);
  color: var(--text);
}

.btn.btn-icon {
  padding: 8px 12px;
  font-size: 16px;
  line-height: 1;
  min-width: 36px;
  text-align: center;
}

.range {
  accent-color: var(--accent-primary);
}

input[type="range"] {
  -webkit-appearance: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  height: 16px;
  width: 16px;
  border-radius: 50%;
  background: var(--accent-primary);
  border: 2px solid var(--surface-1);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
  cursor: pointer;
}

input[type="range"]::-moz-range-thumb {
  height: 16px;
  width: 16px;
  border-radius: 50%;
  background: var(--accent-primary);
  border: 2px solid var(--surface-1);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
  cursor: pointer;
}

#panel {
  position: fixed;
  right: 16px;
  top: 16px;
  width: 320px;
  background: linear-gradient(
    160deg,
    rgba(33, 22, 13, 0.96),
    rgba(216, 155, 90, 0.14)
  );
  border: 1px solid rgba(216, 155, 90, 0.35);
  padding: 20px;
  backdrop-filter: blur(12px);
  box-shadow: 0 18px 36px rgba(8, 4, 1, 0.6);
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: calc(100vh - 32px);
  overflow: hidden;
}

#panel h4 {
  margin: 0 0 12px;
  font-family: var(--font-sans);
  font-weight: 600;
  color: var(--text);
  font-size: 16px;
  letter-spacing: -0.02em;
  text-transform: uppercase;
}

#trace {
  width: 100%;
  height: 160px;
  background: var(--bg);
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.neuron-meta {
  display: flex;
  flex-direction: column;
  gap: 10px;
  color: var(--text-2);
  flex: 1 1 auto;
  overflow-y: auto;
  padding-right: 6px;
}

.neuron-meta .meta-section {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
}

.neuron-meta .meta-heading {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.neuron-meta .meta-value {
  color: var(--text);
  font-size: 13px;
  margin-bottom: 4px;
}

.neuron-meta .meta-note {
  color: var(--text-muted);
  font-size: 11px;
  line-height: 1.4;
  margin-top: 2px;
}

.neuron-meta .meta-note.meta-note-type {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.meta-note-type .shape-separator {
  color: rgba(216, 155, 90, 0.55);
  margin: 0 2px;
}

.neuron-shape-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(216, 155, 90, 0.12);
  border: 1px solid rgba(216, 155, 90, 0.28);
  color: var(--text-muted);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}

.neuron-shape-icon {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
}

.neuron-shape-icon::before {
  content: "";
  display: block;
  width: 12px;
  height: 12px;
  background: linear-gradient(
    135deg,
    rgba(247, 196, 116, 0.9),
    rgba(210, 145, 78, 0.9)
  );
  border: 1px solid rgba(0, 0, 0, 0.4);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
  border-radius: 4px;
}

.neuron-shape-icon.shape-triangle-up::before {
  clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
  border-radius: 0;
}

.neuron-shape-icon.shape-triangle-down::before {
  clip-path: polygon(0% 0%, 100% 0%, 50% 100%);
  border-radius: 0;
}

.neuron-shape-icon.shape-diamond::before {
  clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
  border-radius: 0;
}

.neuron-shape-icon.shape-square-rounded::before {
  clip-path: none;
  border-radius: 35%;
}

.neuron-shape-icon.shape-rect-tall::before {
  width: 8px;
  height: 16px;
  border-radius: 3px;
  clip-path: none;
}

.neuron-shape-icon.shape-hexagon::before {
  clip-path: polygon(25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0% 50%);
  border-radius: 0;
}

.neuron-shape-icon.shape-circle::before {
  clip-path: none;
  border-radius: 50%;
}

.neuron-shape-icon.shape-square::before {
  clip-path: none;
  border-radius: 10%;
}

.neuron-shape-icon.shape-rect-wide::before {
  width: 16px;
  height: 8px;
  border-radius: 3px;
  clip-path: none;
}

.neuron-shape-icon.shape-trapezoid::before {
  clip-path: polygon(20% 0%, 80% 0%, 100% 100%, 0% 100%);
  border-radius: 0;
}

.neuron-shape-icon.shape-trapezoid-inverted::before {
  clip-path: polygon(0% 0%, 100% 0%, 80% 100%, 20% 100%);
  border-radius: 0;
}

.neuron-shape-icon.shape-parallelogram::before {
  clip-path: polygon(15% 0%, 100% 0%, 85% 100%, 0% 100%);
  border-radius: 0;
}

.neuron-shape-icon.shape-triangle-right::before {
  clip-path: polygon(0% 0%, 100% 50%, 0% 100%);
  border-radius: 0;
}

.neuron-shape-label {
  color: var(--text-muted);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.neuron-meta .meta-subheading {
  margin-top: 6px;
  margin-bottom: 4px;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.neuron-meta .meta-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
  font-size: 12px;
  color: var(--text-2);
}

.neuron-meta .meta-grid .meta-label {
  color: var(--text-muted);
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.06em;
}

.neuron-meta .meta-grid .meta-value {
  color: var(--text);
  font-size: 12px;
}

.neuron-meta::-webkit-scrollbar {
  width: 6px;
}

.neuron-meta::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0);
}

.neuron-meta::-webkit-scrollbar-thumb {
  background: rgba(216, 155, 90, 0.3);
  border-radius: 4px;
}

.neuron-meta::-webkit-scrollbar-thumb:hover {
  background: rgba(216, 155, 90, 0.45);
}

.neuron-meta {
  scrollbar-width: thin;
  scrollbar-color: rgba(216, 155, 90, 0.3) transparent;
}

.neuron-meta .meta-placeholder {
  color: var(--text-muted);
  font-style: italic;
  font-size: 12px;
}

#err {
  position: fixed;
  left: 16px;
  bottom: 16px;
  background: linear-gradient(
    135deg,
    rgba(216, 155, 90, 0.35),
    rgba(33, 22, 13, 0.95)
  );
  color: var(--text);
  padding: 12px 16px;
  font-family: var(--font-sans);
  font-weight: 500;
  display: none;
  border: 1px solid rgba(216, 155, 90, 0.35);
}

#err[data-tone="error"] {
  background: linear-gradient(
    135deg,
    rgba(213, 116, 74, 0.9),
    rgba(111, 41, 24, 0.9)
  );
  border-color: rgba(213, 116, 74, 0.6);
}

#controls {
  position: fixed;
  left: 16px;
  top: 150px;
  width: 320px;
  background: linear-gradient(
    165deg,
    rgba(32, 21, 12, 0.96),
    rgba(216, 155, 90, 0.16)
  );
  border: 1px solid rgba(216, 155, 90, 0.35);
  padding: 20px;
  backdrop-filter: blur(12px);
  box-shadow: 0 20px 40px rgba(7, 3, 1, 0.62);
  max-height: calc(100vh - 170px);
  overflow-y: auto; /* allow scroll when needed */
  overflow-x: hidden;
  scrollbar-width: none; /* Firefox hide */
  -ms-overflow-style: none; /* IE/Edge */
  padding-bottom: 12px;
}

#controls::-webkit-scrollbar {
  display: none;
}

.control-group {
  margin-bottom: 16px;
}

.control-group label {
  display: block;
  margin-bottom: 6px;
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.control-group input[type="range"] {
  width: 100%;
  accent-color: var(--accent-primary);
  background: var(--surface-2);
}

.toggle {
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 8px 12px;
  cursor: pointer;
  display: inline-block;
  margin: 2px;
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.01em;
  transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}

.toggle.active {
  background: var(--accent-primary);
  color: var(--bg);
  border-color: var(--accent-primary);
}

/* Consistent button spacing inside the controls panel */
#controls .btn {
  display: block;
  width: 100%;
  margin: 8px 0;
}

/* Disabled control state when locked by preset */
#controls input[disabled] {
  opacity: 0.4;
  pointer-events: none;
}
#controls label.locked {
  color: var(--text-muted);
}

/* Lesson Modal Styles */
.lesson-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.85);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(8px);
}

.lesson-modal-content {
  background: linear-gradient(
    170deg,
    rgba(32, 21, 12, 0.96),
    rgba(216, 155, 90, 0.18)
  );
  border: 1px solid rgba(216, 155, 90, 0.3);
  padding: 32px;
  width: 100%;
  max-width: 800px;
  max-height: 85vh;
  overflow-y: auto;
  color: var(--text);
  position: relative;
  box-shadow: 0 24px 48px rgba(8, 3, 1, 0.55);
  font-family: var(--font-sans);
}

.lesson-modal-content h1,
.lesson-modal-content h2,
.lesson-modal-content h3 {
  color: var(--text);
  margin-top: 24px;
  margin-bottom: 16px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.lesson-modal-content h1 {
  color: var(--accent-primary);
  margin-top: 0;
  font-size: 28px;
  text-transform: uppercase;
}

.lesson-modal-content h2 {
  color: var(--text);
  font-size: 20px;
}

.lesson-modal-content h3 {
  color: var(--text-2);
  font-size: 16px;
}

.lesson-modal-content p {
  margin-bottom: 16px;
  line-height: 1.6;
  color: var(--text-2);
}

.lesson-modal-content ul,
.lesson-modal-content ol {
  margin: 16px 0;
  padding-left: 24px;
  color: var(--text-2);
}

.lesson-modal-content li {
  margin-bottom: 8px;
}

.lesson-modal-content code {
  background: var(--bg);
  padding: 3px 8px;
  color: var(--text-accent);
  font-family: var(--font-mono);
  font-size: 12px;
  border: 1px solid var(--border);
}

.lesson-modal-content .close-btn {
  position: absolute;
  top: 20px;
  right: 20px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 18px;
  width: 36px;
  height: 36px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  transition: all 0.15s ease;
}

.lesson-modal-content .close-btn:hover {
  background: var(--accent-danger);
  color: var(--text);
}

#lessonPanel {
  left: 16px;
  top: 100px;
  display: flex;
  gap: 12px;
  align-items: center;
  background: linear-gradient(
    160deg,
    rgba(34, 23, 13, 0.95),
    rgba(216, 155, 90, 0.15)
  );
  padding: 12px 16px;
  border: 1px solid rgba(216, 155, 90, 0.4);
  backdrop-filter: blur(12px);
  box-shadow: 0 14px 30px rgba(8, 4, 2, 0.6);
  position: fixed;
  z-index: 10;
}

/* Center top preset bar */
#presetBar {
  position: fixed;
  top: 16px;
  left: 55%;
  transform: translateX(-50%);
  display: flex;
  gap: 12px;
  align-items: center;
  background: linear-gradient(
    150deg,
    rgba(32, 22, 13, 0.95),
    rgba(216, 155, 90, 0.12)
  );
  padding: 12px 18px;
  border: 1px solid rgba(216, 155, 90, 0.35);
  backdrop-filter: blur(12px);
  box-shadow: 0 14px 30px rgba(7, 3, 2, 0.55);
  z-index: 14;
}

#templateActions {
  display: flex;
  gap: 8px;
  margin-left: 16px;
}

/* Bottom center status bar */
#statusBar {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 12px;
  align-items: center;
  background: linear-gradient(
    140deg,
    rgba(216, 155, 90, 0.18),
    rgba(32, 22, 13, 0.92)
  );
  padding: 8px 20px;
  border: 1px solid rgba(216, 155, 90, 0.35);
  backdrop-filter: blur(12px);
  box-shadow: 0 20px 36px rgba(9, 4, 1, 0.55);
  font-family: var(--font-sans);
  font-size: 12px;
  color: var(--text-2);
  border-radius: 999px;
  z-index: 12;
}

.nav-emoji {
  cursor: pointer;
  margin-left: 4px;
}

/* Popover nav controls near status bar; hidden by default */
#navControls.nav-pop {
  position: fixed;
  bottom: 60px;
  left: 50%;
  transform: translateX(-50%);
  display: none;
  flex-direction: column;
  gap: 6px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 20px;
  backdrop-filter: blur(14px);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.45);
  width: auto;
  min-width: 240px;
  max-width: min(340px, calc(100% - 48px));
  z-index: 20;
}

#navControls.nav-pop.is-visible {
  display: flex;
}

#statusBar:hover + #navControls.nav-pop {
  display: flex;
}

#navControls.nav-pop:hover {
  display: flex;
}

#lessonPanel select,
#presetSelect {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 10px 14px;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, #f0b15d 50%),
    linear-gradient(135deg, #f0b15d 50%, transparent 50%),
    linear-gradient(to right, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0));
  background-position: calc(100% - 18px) calc(50% - 2px),
    calc(100% - 14px) calc(50% - 2px), 0 0;
  background-size: 6px 6px, 6px 6px, 100%;
  background-repeat: no-repeat;
  max-width: 270px;
}

#lessonPanel select option,
#presetSelect option {
  background: var(--surface-1);
  color: var(--text);
  padding: 8px;
}

#lessonPanel select:focus,
#presetSelect:focus {
  outline: none;
  border-color: #f0b15d;
  box-shadow: 0 0 0 2px rgba(240, 177, 93, 0.25);
}

#lessonPanel select:hover,
#presetSelect:hover {
  border-color: #f0b15d;
}

#lessonPanel label {
  color: var(--text-2);
  font-family: var(--font-sans);
  font-weight: 500;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

#navControls {
  right: 16px;
  top: 300px;
  background: linear-gradient(
    155deg,
    rgba(33, 22, 13, 0.95),
    rgba(216, 155, 90, 0.1)
  );
  border: 1px solid rgba(216, 155, 90, 0.28);
  padding: 16px;
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 11px;
  line-height: 1.4;
  backdrop-filter: blur(12px);
  max-width: 200px;
  position: fixed;
  z-index: 10;
  box-shadow: 0 16px 34px rgba(8, 3, 1, 0.58);
}

#navControls h5 {
  margin: 0 0 8px 0;
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.nav-tip {
  margin: 4px 0;
  color: var(--text-2);
  font-size: 11px;
}

.nav-tip strong {
  color: var(--text-accent);
  font-family: var(--font-mono);
  font-size: 10px;
}

#three-canvas {
  position: fixed;
  inset: 0;
  z-index: 0;
  cursor: grab;
}

#three-canvas:active {
  cursor: grabbing;
}

/* Template Configuration Panel Styles */
.config-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.config-item {
  background: rgba(216, 155, 90, 0.05);
  border: 1px solid rgba(216, 155, 90, 0.2);
  border-radius: 8px;
  padding: 10px;
}

.config-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}

.config-item-details {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.config-subitem {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: var(--text-2);
  padding: 2px 0;
}

.config-input {
  background: var(--surface-1);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 2px 6px;
  border-radius: 4px;
  width: 50px;
  text-align: right;
  font-family: var(--font-mono);
  font-size: 11px;
}

.config-input:focus {
  outline: none;
  border-color: var(--accent-primary);
}

.config-label {
  display: flex;
  align-items: center;
  gap: 6px;
}

.config-label-text {
  max-width: 140px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* =========================================
   MOBILE RESPONSIVE STYLES
   ========================================= */

/* Mobile Bottom Sheet */
.mobile-bottom-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(
    to top,
    rgba(28, 19, 11, 0.98),
    rgba(28, 19, 11, 0.94) 60%,
    rgba(216, 155, 90, 0.08)
  );
  border-top: 1px solid rgba(216, 155, 90, 0.4);
  border-radius: 20px 20px 0 0;
  backdrop-filter: blur(16px);
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.5);
  z-index: 100;
  transform: translateY(calc(100% - 64px));
  /* Faster, snappier transition */
  transition: transform 0.18s cubic-bezier(0.25, 0.1, 0.25, 1);
  display: none;
  max-height: 85vh;
  will-change: transform;
}

.mobile-bottom-sheet.expanded {
  transform: translateY(0);
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 4px 0;
}

.sheet-handle {
  width: 48px;
  height: 5px;
  background: rgba(216, 155, 90, 0.6);
  border-radius: 3px;
  cursor: grab;
  /* Larger touch target */
  padding: 10px 24px;
  background-clip: content-box;
}

.sheet-handle:active {
  cursor: grabbing;
  background: rgba(216, 155, 90, 0.9);
  background-clip: content-box;
}

.sheet-collapse-btn {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(216, 155, 90, 0.15);
  border: 1px solid rgba(216, 155, 90, 0.3);
  color: var(--accent-glow);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.12s ease;
  touch-action: manipulation;
}

.sheet-collapse-btn:active {
  background: rgba(216, 155, 90, 0.3);
  transform: translateY(-50%) scale(0.92);
}

.sheet-collapse-btn svg {
  fill: currentColor;
  transition: transform 0.15s ease;
}

.mobile-bottom-sheet.expanded .sheet-collapse-btn svg {
  transform: rotate(180deg);
}

.mobile-tab-bar {
  display: flex;
  justify-content: space-around;
  padding: 4px 12px 8px;
  border-bottom: 1px solid rgba(216, 155, 90, 0.15);
  gap: 8px;
}

.mobile-tab {
  flex: 1;
  padding: 12px 10px;
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  transition: all 0.12s ease;
  border-radius: 8px;
  background: transparent;
  border: 1px solid transparent;
  cursor: pointer;
  min-height: 44px;
  touch-action: manipulation;
}

.mobile-tab.active {
  color: var(--accent-glow);
  background: rgba(216, 155, 90, 0.15);
  border-color: rgba(216, 155, 90, 0.3);
}

.sheet-content {
  padding: 16px;
  overflow-y: auto;
  max-height: calc(85vh - 80px);
  scrollbar-width: thin;
  scrollbar-color: rgba(216, 155, 90, 0.3) transparent;
}

.sheet-content::-webkit-scrollbar {
  width: 6px;
}

.sheet-content::-webkit-scrollbar-track {
  background: transparent;
}

.sheet-content::-webkit-scrollbar-thumb {
  background: rgba(216, 155, 90, 0.3);
  border-radius: 3px;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

/* Mobile control groups - more touch-friendly */
.mobile-bottom-sheet .control-group {
  padding: 14px 0;
  border-bottom: 1px solid rgba(216, 155, 90, 0.1);
  margin-bottom: 0;
}

.mobile-bottom-sheet .control-group:last-child {
  border-bottom: none;
}

.mobile-bottom-sheet .control-group label {
  font-size: 14px;
  margin-bottom: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.mobile-bottom-sheet .control-group label span {
  color: var(--accent-glow);
  font-weight: 600;
}

/* Larger touch targets for sliders on mobile */
.mobile-bottom-sheet input[type="range"] {
  height: 12px;
  margin: 14px 0;
  -webkit-appearance: none;
  appearance: none;
  background: rgba(216, 155, 90, 0.2);
  border-radius: 6px;
  cursor: pointer;
  touch-action: pan-x;
}

.mobile-bottom-sheet input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, #d89b5a, #f0b15d);
  border: 2px solid rgba(255, 255, 255, 0.3);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  cursor: pointer;
}

.mobile-bottom-sheet input[type="range"]::-moz-range-thumb {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, #d89b5a, #f0b15d);
  border: 2px solid rgba(255, 255, 255, 0.3);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  cursor: pointer;
}

.mobile-bottom-sheet input[type="range"]::-webkit-slider-runnable-track {
  height: 12px;
  border-radius: 6px;
}

.mobile-bottom-sheet input[type="range"]::-moz-range-track {
  height: 12px;
  border-radius: 6px;
  background: rgba(216, 155, 90, 0.2);
}

.mobile-bottom-sheet .btn {
  padding: 14px 16px;
  font-size: 14px;
  margin: 0;
  min-height: 44px;
  touch-action: manipulation;
  flex: 1;
}

.mobile-btn-row {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.mobile-btn-row .btn {
  flex: 1;
}

.btn-toggle {
  background: transparent;
  border: 1px solid rgba(216, 155, 90, 0.4);
}

.btn-toggle.active {
  background: rgba(216, 155, 90, 0.25);
  border-color: var(--accent-primary);
  color: var(--accent-glow);
}

.btn-accent {
  background: linear-gradient(135deg, rgba(216, 155, 90, 0.3), rgba(216, 155, 90, 0.15));
  border: 1px solid rgba(216, 155, 90, 0.5);
}

/* Inspector Stats */
.inspector-stats {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
}

.stat-card {
  flex: 1;
  padding: 12px;
  background: var(--surface-2);
  border-radius: 10px;
  border: 1px solid rgba(216, 155, 90, 0.15);
}

.stat-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.stat-value {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
}

/* Voltage Trace with Axis */
.trace-container {
  display: flex;
  gap: 6px;
  margin-top: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 10px 10px 0;
}

.trace-y-axis {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 4px 0;
  width: 28px;
  text-align: right;
}

.trace-y-axis .axis-label {
  font-size: 9px;
  color: var(--text-muted);
  font-family: monospace;
}

.trace-canvas-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.trace-canvas-wrapper canvas {
  width: 100%;
  height: 120px;
  border-radius: 6px;
}

.trace-x-axis {
  display: flex;
  justify-content: space-between;
  padding: 4px 4px 0;
  font-size: 9px;
  color: var(--text-muted);
}

.trace-legend {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-top: 8px;
  font-size: 10px;
  color: var(--text-muted);
}

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

.legend-line {
  width: 16px;
  height: 2px;
  border-radius: 1px;
}

.legend-voltage {
  background: var(--accent-primary);
}

.legend-threshold {
  background: var(--accent-danger);
  opacity: 0.6;
}

.legend-spike {
  background: rgba(255, 120, 120, 0.5);
}

/* Mini Status Pill */
.mobile-status-pill {
  position: fixed;
  bottom: 80px;
  left: 16px;
  padding: 10px 16px;
  background: rgba(28, 19, 11, 0.92);
  border: 1px solid rgba(216, 155, 90, 0.35);
  border-radius: 24px;
  backdrop-filter: blur(12px);
  font-size: 12px;
  color: var(--text-2);
  z-index: 99;
  display: none;
  align-items: center;
  gap: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.pill-btn {
  background: rgba(216, 155, 90, 0.2);
  border: 1px solid rgba(216, 155, 90, 0.4);
  color: var(--accent-glow);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.1s ease;
  touch-action: manipulation;
}

.pill-btn:active {
  background: rgba(216, 155, 90, 0.5);
  transform: scale(0.92);
}

.pill-btn.playing {
  background: linear-gradient(135deg, #7a4a20, #f0b15d);
  border-color: #f0b15d;
}

/* Floating Action Button */
.mobile-fab {
  position: fixed;
  bottom: 80px;
  right: 16px;
  width: 60px;
  height: 60px;
  border-radius: 18px;
  background: linear-gradient(135deg, #7a4a20, #f0b15d);
  border: 1px solid rgba(240, 177, 93, 0.6);
  box-shadow: 0 8px 24px rgba(240, 177, 93, 0.4);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 99;
  cursor: pointer;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
  touch-action: manipulation;
}

.mobile-fab:active {
  transform: scale(0.9);
  box-shadow: 0 4px 12px rgba(240, 177, 93, 0.3);
}

.mobile-fab svg {
  width: 24px;
  height: 24px;
  fill: #fff0dc;
}

/* Touch gesture tutorial overlay */
.gesture-tutorial {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.gesture-tutorial.visible {
  display: flex;
}

.gesture-card {
  background: linear-gradient(
    160deg,
    rgba(32, 21, 12, 0.98),
    rgba(216, 155, 90, 0.12)
  );
  border: 1px solid rgba(216, 155, 90, 0.35);
  border-radius: 20px;
  padding: 32px 24px;
  max-width: 320px;
  text-align: center;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.5);
}

.gesture-card h3 {
  color: var(--accent-primary);
  font-size: 18px;
  margin: 0 0 20px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.gesture-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid rgba(216, 155, 90, 0.15);
}

.gesture-item:last-of-type {
  border-bottom: none;
}

.gesture-icon {
  width: 48px;
  height: 48px;
  background: rgba(216, 155, 90, 0.15);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  flex-shrink: 0;
}

.gesture-text {
  text-align: left;
}

.gesture-text strong {
  display: block;
  color: var(--text);
  font-size: 14px;
  margin-bottom: 2px;
}

.gesture-text span {
  color: var(--text-muted);
  font-size: 12px;
}

.gesture-dismiss {
  margin-top: 24px;
  padding: 14px 32px;
  background: linear-gradient(135deg, #7a4a20, #f0b15d);
  border: 1px solid rgba(240, 177, 93, 0.6);
  border-radius: 12px;
  color: #fff0dc;
  font-weight: 600;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  cursor: pointer;
  transition: all 0.2s ease;
}

.gesture-dismiss:active {
  transform: scale(0.98);
}

/* =========================================
   MEDIA QUERIES
   ========================================= */

/* Mobile: up to 767px */
@media (max-width: 767px) {
  /* Hide desktop panels */
  #hud,
  #controls,
  #presetBar,
  #panel,
  #statusBar,
  #navControls,
  #lessonPanel {
    display: none !important;
  }

  /* Show mobile components */
  .mobile-bottom-sheet,
  .mobile-fab,
  .mobile-status-pill {
    display: flex;
  }

  .mobile-bottom-sheet {
    display: block;
  }

  /* Full-screen canvas */
  #three-canvas {
    touch-action: none;
  }

  /* Ensure overlay doesn't interfere */
  #overlay {
    pointer-events: none;
  }

  /* Error banner adjustments */
  #err {
    left: 16px;
    right: 16px;
    bottom: 150px;
    width: auto;
  }

  /* Safe area padding for notched devices */
  .mobile-bottom-sheet {
    padding-bottom: env(safe-area-inset-bottom, 0);
  }

  .mobile-status-pill,
  .mobile-fab {
    bottom: calc(80px + env(safe-area-inset-bottom, 0));
  }
}

/* Tablet: 768px to 1023px */
@media (min-width: 768px) and (max-width: 1023px) {
  /* Narrower panels for tablet */
  #controls {
    width: 280px;
    left: 12px;
  }

  #panel {
    width: 280px;
    right: 12px;
  }

  #presetBar {
    left: 50%;
  }

  /* Hide mobile components */
  .mobile-bottom-sheet,
  .mobile-fab,
  .mobile-status-pill,
  .gesture-tutorial {
    display: none !important;
  }
}

/* Desktop: 1024px+ */
@media (min-width: 1024px) {
  /* Hide mobile components */
  .mobile-bottom-sheet,
  .mobile-fab,
  .mobile-status-pill,
  .gesture-tutorial {
    display: none !important;
  }
}

/* Landscape mobile adjustments */
@media (max-width: 767px) and (orientation: landscape) {
  .mobile-bottom-sheet {
    max-height: 70vh;
  }

  .sheet-content {
    max-height: calc(70vh - 80px);
  }

  .mobile-status-pill,
  .mobile-fab {
    bottom: calc(56px + env(safe-area-inset-bottom, 0));
  }

  .mobile-bottom-sheet {
    transform: translateY(calc(100% - 56px));
  }
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
  .mobile-bottom-sheet {
    transition: none;
  }

  .mobile-fab,
  .mobile-tab,
  .pill-btn {
    transition: none;
  }
}
