:root {
  color-scheme: dark;
  --bg-0: #07080c;
  --bg-1: #0b0d12;
  --bg-2: #11141c;
  --bg-3: #181c26;
  --line: rgba(255, 255, 255, 0.07);
  --line-strong: rgba(255, 255, 255, 0.14);
  --text-0: #f4f6fb;
  --text-1: #c8ccd6;
  --text-2: #8a90a0;
  --text-3: #5d6271;
  --accent: #9ad8ff;
  --accent-2: #a07bff;
  --accent-glow: rgba(154, 216, 255, 0.55);
  --danger: #ff7b8a;
  --radius: 14px;
  --radius-sm: 9px;
  --pad: 18px;
  --shadow-1: 0 4px 18px rgba(0, 0, 0, 0.45);
  --shadow-2: 0 24px 60px rgba(0, 0, 0, 0.55);
  --easing: cubic-bezier(0.22, 0.61, 0.36, 1);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, "Inter", "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Menlo", "Consolas", monospace;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-0);
  color: var(--text-0);
  font-family: var(--font);
  font-feature-settings: "ss01", "ss02";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  height: 100%;
  overflow: hidden;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
}

/* Subtle moving aurora wash behind the UI chrome */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(60% 50% at 18% 8%, rgba(160, 123, 255, 0.16), transparent 60%),
    radial-gradient(50% 50% at 90% 100%, rgba(154, 216, 255, 0.12), transparent 60%),
    radial-gradient(40% 30% at 50% 50%, rgba(255, 255, 255, 0.03), transparent 70%);
  z-index: -1;
  pointer-events: none;
}

a { color: inherit; }
button { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }

.vh {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 8px;
  top: 8px;
  padding: 8px 14px;
  background: var(--bg-3);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  z-index: 100;
  transform: translateY(-200%);
  transition: transform 180ms var(--easing);
}
.skip-link:focus {
  transform: translateY(0);
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Layout grid */
.app {
  display: grid;
  grid-template-columns: 230px 1fr 320px;
  grid-template-rows: 64px 1fr 36px;
  grid-template-areas:
    "top   top   top"
    "rail  stage controls"
    "foot  foot  foot";
  width: 100vw;
  height: 100vh;
  height: 100dvh;
}

.top-bar {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(11, 13, 18, 0.92), rgba(11, 13, 18, 0.65));
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  z-index: 3;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  min-width: 200px;
}

.logo {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  filter: drop-shadow(0 4px 12px rgba(160, 123, 255, 0.35));
}

.brand-text { line-height: 1.15; }
.brand-name { font-weight: 700; font-size: 14px; letter-spacing: 0.01em; }
.brand-sub { font-size: 11px; color: var(--text-2); }
.brand-sub span { color: var(--text-1); font-weight: 600; }

.scene-title {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  border-left: 1px solid var(--line);
  padding-left: 18px;
}
.scene-title h1 {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.005em;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}
.scene-title p {
  font-size: 12px;
  color: var(--text-2);
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}

.top-actions { display: flex; gap: 6px; }

.ico-btn {
  appearance: none;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.02);
  color: var(--text-1);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 160ms var(--easing), color 160ms var(--easing), border-color 160ms var(--easing), transform 120ms var(--easing);
}
.ico-btn:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-0);
  border-color: var(--line-strong);
}
.ico-btn:active { transform: translateY(1px); }
.ico-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.ico-btn[aria-pressed="true"] {
  background: linear-gradient(180deg, rgba(154, 216, 255, 0.16), rgba(160, 123, 255, 0.10));
  border-color: rgba(154, 216, 255, 0.35);
  color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(154, 216, 255, 0.18), 0 0 14px rgba(154, 216, 255, 0.18);
}

.ico-btn--mobile { display: none; }

/* Scene rail */
.scene-rail {
  grid-area: rail;
  border-right: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(11, 13, 18, 0.65), rgba(7, 8, 12, 0.92));
  overflow-y: auto;
  padding: 10px 0;
  scrollbar-width: thin;
}

#scene-list {
  list-style: none;
  margin: 0;
  padding: 0 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.scene-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid transparent;
  cursor: pointer;
  text-align: left;
  width: 100%;
  color: var(--text-1);
  transition: background 160ms var(--easing), border-color 160ms var(--easing), color 160ms var(--easing);
}
.scene-item:hover {
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-0);
}
.scene-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.scene-item[aria-selected="true"] {
  background: linear-gradient(180deg, rgba(154, 216, 255, 0.08), rgba(160, 123, 255, 0.05));
  border-color: rgba(154, 216, 255, 0.22);
  color: var(--text-0);
  box-shadow: inset 0 0 0 1px rgba(154, 216, 255, 0.06);
}
.scene-item[aria-selected="true"] .scene-thumb {
  box-shadow: 0 0 0 1px rgba(154, 216, 255, 0.4), 0 6px 18px rgba(154, 216, 255, 0.16);
}

.scene-thumb {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  flex-shrink: 0;
  border: 1px solid var(--line);
  background: var(--bg-2);
  position: relative;
  overflow: hidden;
  transition: box-shadow 220ms var(--easing);
}
.scene-thumb svg, .scene-thumb canvas {
  width: 100%; height: 100%;
  display: block;
}

.scene-meta {
  flex: 1;
  min-width: 0;
}
.scene-meta strong {
  display: block;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.005em;
}
.scene-meta span {
  display: block;
  font-size: 11px;
  color: var(--text-2);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.scene-num {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-3);
  padding: 2px 6px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
}

/* Stage */
.stage {
  grid-area: stage;
  position: relative;
  overflow: hidden;
  background: #000;
}
.stage:focus { outline: none; }

#canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: #000;
  cursor: crosshair;
}

.hint {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(10, 12, 18, 0.55);
  border: 1px solid var(--line);
  color: var(--text-2);
  font-size: 11px;
  letter-spacing: 0.02em;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  pointer-events: none;
  opacity: 1;
  transition: opacity 600ms var(--easing);
}
.hint.fade { opacity: 0; }
.hint span { white-space: nowrap; }

.paused-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 50% 50%, rgba(0, 0, 0, 0.4), rgba(0, 0, 0, 0.65));
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms var(--easing);
}
.paused-overlay.visible { opacity: 1; }
.paused-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 22px;
  border-radius: 14px;
  background: rgba(11, 13, 18, 0.85);
  border: 1px solid var(--line-strong);
  color: var(--text-0);
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.01em;
  box-shadow: var(--shadow-2);
}

/* Controls panel */
.controls {
  grid-area: controls;
  border-left: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(11, 13, 18, 0.55), rgba(7, 8, 12, 0.92));
  overflow-y: auto;
  padding: 14px 16px 24px;
  scrollbar-width: thin;
}

.ctl-section {
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}
.ctl-section:last-child { border-bottom: 0; }

.ctl-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 12px;
}
.ctl-head h2 {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--text-1);
}
.ctl-sub {
  font-size: 11px;
  color: var(--text-3);
  letter-spacing: 0.04em;
}

.palette-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.swatch {
  height: 46px;
  border-radius: 10px;
  border: 1px solid var(--line);
  cursor: pointer;
  padding: 0;
  position: relative;
  overflow: hidden;
  background: var(--bg-2);
  transition: transform 140ms var(--easing), box-shadow 180ms var(--easing);
}
.swatch:hover { transform: translateY(-1px); }
.swatch:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.swatch::after {
  content: attr(data-label);
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 3px 6px;
  font-size: 10px;
  letter-spacing: 0.04em;
  color: #fff;
  background: linear-gradient(180deg, transparent, rgba(0, 0, 0, 0.55));
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
}
.swatch[aria-checked="true"] {
  box-shadow: 0 0 0 2px var(--accent), 0 6px 18px rgba(154, 216, 255, 0.25);
}

.slider {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}
.slider:last-child { margin-bottom: 0; }
.slider label {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-1);
  letter-spacing: 0.01em;
}
.slider output {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-2);
  font-weight: 400;
}
.ctl-help {
  font-size: 11px;
  color: var(--text-3);
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  width: 100%;
  height: 22px;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent) 0 var(--p, 50%), var(--bg-3) var(--p, 50%) 100%);
}
input[type="range"]::-moz-range-track {
  height: 4px;
  border-radius: 999px;
  background: var(--bg-3);
}
input[type="range"]::-moz-range-progress {
  height: 4px;
  border-radius: 999px;
  background: var(--accent);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  margin-top: -6px;
  border: 0;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5), 0 0 0 2px rgba(154, 216, 255, 0.0);
  transition: box-shadow 160ms var(--easing);
}
input[type="range"]:hover::-webkit-slider-thumb {
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5), 0 0 0 4px rgba(154, 216, 255, 0.18);
}
input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  border: 0;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
}
input[type="range"]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
  border-radius: 999px;
}

.audio-status {
  font-size: 12px;
  color: var(--text-2);
  margin-bottom: 10px;
  line-height: 1.5;
}
.audio-meter {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  height: 8px;
}
.audio-bar {
  background: var(--bg-3);
  border-radius: 999px;
  position: relative;
  overflow: hidden;
}
.audio-bar::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transform-origin: left center;
  transform: scaleX(var(--lvl, 0));
  transition: transform 90ms linear;
}

.about p {
  font-size: 12px;
  color: var(--text-1);
  line-height: 1.55;
  margin-bottom: 8px;
}
.about p.muted { color: var(--text-3); }

/* Footer */
.footer {
  grid-area: foot;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  border-top: 1px solid var(--line);
  background: rgba(7, 8, 12, 0.85);
  color: var(--text-3);
  font-size: 11px;
  letter-spacing: 0.02em;
}
.footer-meta { display: flex; gap: 14px; align-items: center; }
.fps {
  font-family: var(--mono);
  color: var(--text-2);
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 64px;
  transform: translate(-50%, 20px);
  padding: 11px 18px;
  border-radius: 12px;
  background: rgba(11, 13, 18, 0.95);
  border: 1px solid var(--line-strong);
  color: var(--text-0);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-2);
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms var(--easing), transform 220ms var(--easing);
  z-index: 50;
  max-width: 90vw;
}
.toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* Scrollbars (webkit) */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.07);
  border-radius: 999px;
}
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.12); }
::-webkit-scrollbar-track { background: transparent; }

/* Fullscreen tweak */
.app.fullscreen .top-bar,
.app.fullscreen .scene-rail,
.app.fullscreen .controls,
.app.fullscreen .footer {
  display: none;
}
.app.fullscreen {
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;
  grid-template-areas: "stage";
}

/* Responsive — narrow screens */
@media (max-width: 1100px) {
  .app {
    grid-template-columns: 200px 1fr 280px;
  }
  .scene-meta span { display: none; }
}

@media (max-width: 880px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: 60px 1fr 36px;
    grid-template-areas:
      "top"
      "stage"
      "foot";
  }
  .scene-title { display: none; }
  .scene-rail {
    position: absolute;
    inset: 60px 0 auto 0;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    background: rgba(7, 8, 12, 0.92);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    padding: 10px;
    z-index: 4;
  }
  #scene-list {
    flex-direction: row;
    gap: 8px;
    overflow-x: auto;
    padding: 0 4px 4px;
  }
  .scene-item {
    flex-shrink: 0;
    flex-direction: column;
    align-items: flex-start;
    width: 130px;
    padding: 8px;
  }
  .scene-item .scene-thumb {
    width: 100%;
    height: 60px;
  }
  .scene-meta span { display: block; }
  .scene-num { display: none; }

  .controls {
    position: fixed;
    right: 0;
    top: 60px;
    bottom: 36px;
    width: min(340px, 90vw);
    border-left: 1px solid var(--line-strong);
    z-index: 5;
    transform: translateX(110%);
    transition: transform 220ms var(--easing);
    box-shadow: -16px 0 40px rgba(0, 0, 0, 0.5);
  }
  .controls.open { transform: translateX(0); }

  .ico-btn--mobile { display: grid; }
  .brand-sub { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
  }
  .hint { transition: none; }
}
