:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-muted: #f3f3f3;
  --surface-elevated: rgba(255, 255, 255, 0.96);
  --line: #d8d8d8;
  --line-strong: #111111;
  --text: #111111;
  --muted: #666666;
  --subtle: #8a8a8a;
  --shadow: 0 24px 72px rgba(0, 0, 0, 0.06);
  --grid-line-a: rgba(17, 17, 17, 0.05);
  --grid-line-b: rgba(17, 17, 17, 0.035);
  --drop-bg: linear-gradient(180deg, rgba(0, 0, 0, 0.012), rgba(0, 0, 0, 0.03));
  --overlay-bg: rgba(255, 255, 255, 0.8);
  --video-frame: #f2f2f2;
  --canvas-bg: #f3f3f3;
  --canvas-line: #d4d4d4;
  --canvas-start: rgba(17, 17, 17, 0.12);
  --canvas-mid: rgba(17, 17, 17, 0.28);
  --canvas-end: rgba(17, 17, 17, 0.18);
  --menu-hover: #ececec;
  --menu-selected: #e7e7e7;
  --radius: 24px;
  --radius-sm: 18px;
  --font-ui: Arial, sans-serif;
}

html[data-theme="dark"] {
  --bg: #0c0c0c;
  --surface: #101010;
  --surface-muted: #171717;
  --surface-elevated: rgba(12, 12, 12, 0.96);
  --line: #323232;
  --line-strong: #f3f3f3;
  --text: #f3f3f3;
  --muted: #a7a7a7;
  --subtle: #7b7b7b;
  --shadow: 0 30px 90px rgba(0, 0, 0, 0.32);
  --grid-line-a: rgba(255, 255, 255, 0.08);
  --grid-line-b: rgba(255, 255, 255, 0.045);
  --drop-bg: linear-gradient(180deg, rgba(255, 255, 255, 0.025), rgba(255, 255, 255, 0.05));
  --overlay-bg: rgba(10, 10, 10, 0.78);
  --video-frame: #0f0f0f;
  --canvas-bg: #121212;
  --canvas-line: #2a2a2a;
  --canvas-start: rgba(255, 255, 255, 0.12);
  --canvas-mid: rgba(255, 255, 255, 0.28);
  --canvas-end: rgba(255, 255, 255, 0.18);
  --menu-hover: #202020;
  --menu-selected: #252525;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  letter-spacing: -0.01em;
  transition:
    background 180ms ease,
    color 180ms ease;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(to right, var(--grid-line-a) 1px, transparent 1px),
    linear-gradient(to bottom, var(--grid-line-b) 1px, transparent 1px);
  background-size: 96px 96px;
  opacity: 0;
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.74), rgba(0, 0, 0, 0.14));
}

button,
input,
select {
  font: inherit;
}

img {
  display: block;
  max-width: 100%;
}

[hidden] {
  display: none !important;
}

.app-shell {
  position: relative;
  z-index: 1;
  width: min(1480px, calc(100vw - 40px));
  margin: 0 auto;
  padding: 24px 0 40px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
  padding: 4px 0 18px;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  min-width: 0;
}

.brand img {
  width: 28px;
  height: auto;
}

html[data-theme="dark"] .brand img {
  filter: invert(1);
}

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

.theme-toggle,
.language-toggle {
  appearance: none;
  cursor: pointer;
  transition:
    transform 160ms ease,
    box-shadow 160ms ease,
    border-color 160ms ease,
    background 160ms ease,
    color 160ms ease;
}

.theme-toggle:hover,
.language-toggle:hover,
.theme-toggle:focus-visible,
.language-toggle:focus-visible {
  transform: translateY(-1px);
}

.theme-toggle {
  padding: 0;
  border: 0;
  background: transparent;
}

.theme-toggle-track {
  position: relative;
  display: block;
  width: 84px;
  height: 46px;
  border-radius: 999px;
}

.theme-toggle-knob {
  position: absolute;
  top: 5px;
  left: 5px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  transition:
    transform 180ms ease,
    background 180ms ease;
}

html[data-theme="light"] .theme-toggle-track {
  background: #111111;
  border: 2px solid #111111;
}

html[data-theme="light"] .theme-toggle-knob {
  background: #ffffff;
  transform: translateX(0);
}

html[data-theme="dark"] .theme-toggle-track {
  background: #ffffff;
  border: 2px solid #ffffff;
}

html[data-theme="dark"] .theme-toggle-knob {
  background: #111111;
  transform: translateX(42px);
}

.language-toggle {
  min-height: 46px;
  min-width: 78px;
  padding: 0 18px;
  border: 2px solid var(--text);
  border-radius: 999px;
  background: var(--bg);
  color: var(--text);
  font-size: 1.18rem;
  line-height: 1;
  letter-spacing: -0.04em;
}

.hero {
  width: 100%;
  padding: 10px 0 20px;
  border-bottom: 1px solid var(--line);
}

.hero-copy {
  width: 100%;
  overflow: visible;
  padding-right: clamp(16px, 2.3vw, 34px);
}

.hero h1 {
  display: block;
  margin: 0;
  padding-bottom: 0.12em;
  font-size: clamp(6rem, 20vw, 14rem);
  line-height: 0.88;
  letter-spacing: -0.085em;
  font-weight: 700;
  white-space: nowrap;
}

.lede {
  max-width: 34rem;
  margin: 0;
  color: var(--muted);
  font-size: 1.02rem;
  line-height: 1.55;
}

.eyebrow,
.panel-kicker,
.reference-kicker,
.action-label,
.format-caption,
.telemetry-label {
  margin: 0;
  color: var(--subtle);
  font-size: 0.72rem;
  line-height: 1;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.action-bar {
  display: grid;
  grid-template-columns: minmax(260px, 0.74fr) minmax(0, 1.26fr);
  gap: 24px;
  align-items: end;
  padding: 18px 0 30px;
}

.action-bar-copy {
  max-width: 28rem;
}

.action-label {
  margin-bottom: 10px;
}

.action-note {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.hero-actions {
  display: grid;
  grid-template-columns: minmax(220px, 1.15fr) minmax(150px, auto) minmax(210px, 1fr) minmax(190px, auto);
  gap: 12px;
  align-items: stretch;
}

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-elevated);
  box-shadow: var(--shadow);
  transition:
    background 180ms ease,
    border-color 180ms ease,
    color 180ms ease;
}

.action-pill,
.preset-chip,
.tiny-button,
.transport-button,
.format-trigger {
  appearance: none;
  border-radius: 999px;
  color: var(--text);
  font-family: inherit;
  letter-spacing: -0.03em;
  transition:
    transform 160ms ease,
    box-shadow 160ms ease,
    border-color 160ms ease,
    background 160ms ease,
    color 160ms ease;
}

.action-pill,
.preset-chip,
.tiny-button,
.transport-button {
  border: 1.5px solid var(--line-strong);
  background: var(--surface);
}

.action-pill:hover,
.preset-chip:hover,
.tiny-button:hover,
.transport-button:hover,
.format-trigger:hover,
.action-pill:focus-visible,
.preset-chip:focus-visible,
.tiny-button:focus-visible,
.transport-button:focus-visible,
.format-trigger:focus-visible {
  transform: translateY(-1px);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.08);
}

.action-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 72px;
  padding: 0 22px;
  font-size: 1rem;
  white-space: nowrap;
}

.action-pill.primary {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}

.action-pill.ghost {
  border-color: var(--line);
}

.export-button {
  position: relative;
  overflow: hidden;
  isolation: isolate;
  border-color: var(--line-strong);
  background: var(--surface);
}

.export-button-progress {
  position: absolute;
  inset: 0;
  z-index: 0;
  border-radius: inherit;
  background: var(--text);
  pointer-events: none;

  transform-origin: left center;
  transform: scaleX(0);
  opacity: 0;

  will-change: transform, opacity, filter;
  transition:
    transform 140ms linear,
    opacity 180ms ease,
    filter 260ms ease;
}

.export-button-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 100%;
  padding: 0 22px;
  white-space: nowrap;
  pointer-events: none;
}

.export-button-label-base {
  position: relative;
  z-index: 1;
  color: var(--text);
}

.export-button-label-fill {
  position: absolute;
  inset: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  color: var(--bg);
  pointer-events: none;

  opacity: 0;
  clip-path: inset(0 100% 0 0 round 999px);

  will-change: clip-path, opacity;
  transition:
    clip-path 140ms linear,
    opacity 180ms ease;
}

.export-button.is-exporting .export-button-progress,
.export-button.is-exporting .export-button-label-fill,
.export-button.is-export-complete .export-button-progress,
.export-button.is-export-complete .export-button-label-fill {
  opacity: 1;
}

.export-button.is-exporting:disabled,
.export-button.is-export-complete:disabled,
.export-button.is-export-settling:disabled {
  opacity: 1;
  cursor: progress;
}

.export-button.is-export-settling .export-button-progress {
  filter: blur(6px);
  transform: scaleX(1.02);
  opacity: 0;
}

.export-button.is-export-settling .export-button-label-fill {
  opacity: 0;
}

.upload-pill {
  position: relative;
  overflow: hidden;
}

.upload-pill input {
  position: absolute;
  inset: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.format-picker {
  position: relative;
  display: grid;
  gap: 5px;
  min-height: 72px;
  padding: 12px 18px 14px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--surface);
  transition:
    background 180ms ease,
    border-color 180ms ease;
}

.native-select {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
}

.format-caption {
  margin-bottom: 2px;
}

.format-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 28px;
  padding: 0;
  border: 0;
  background: transparent;
  text-align: left;
  box-shadow: none;
}

#exportFormatValue {
  font-size: 1.06rem;
  line-height: 1.1;
  letter-spacing: -0.04em;
}

.format-caret {
  width: 10px;
  height: 10px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg) translateY(-2px);
}

.format-menu {
  position: absolute;
  left: 12px;
  right: auto;
  top: calc(100% + 10px);
  z-index: 20;
  width: min(184px, calc(100vw - 52px));
  padding: 6px 0;
  border: 2px solid var(--line-strong);
  border-radius: 20px;
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.format-option {
  appearance: none;
  display: block;
  width: 100%;
  padding: 6px 16px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
  font-size: 0.96rem;
  line-height: 1.28;
  letter-spacing: -0.05em;
  cursor: pointer;
}

.format-option:hover,
.format-option:focus-visible {
  outline: none;
  background: var(--menu-hover);
  box-shadow: none;
}

.format-option[aria-selected="true"] {
  background: var(--menu-selected);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(340px, 0.88fr);
  gap: 22px;
}

.preview-panel,
.controls-panel {
  padding: 24px;
}

.preview-panel {
  position: relative;
}

.controls-panel {
  display: grid;
  align-content: start;
  gap: 18px;
}

.controls-intro {
  padding-bottom: 2px;
}

.controls-note {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.panel-head,
.block-head,
.map-head,
.video-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.block-head {
  margin-bottom: 16px;
}

.panel-heading,
.block-head > div,
.map-head > div {
  display: grid;
  gap: 8px;
}

.panel-head h2,
.block-head h3,
.map-head h3 {
  margin: 0;
  font-weight: 700;
  line-height: 1.02;
  letter-spacing: -0.06em;
}

.panel-head h2 {
  font-size: clamp(1.54rem, 2vw, 2.14rem);
}

.block-head h3,
.map-head h3 {
  font-size: 1.32rem;
}

.badge-row,
.map-stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 0.84rem;
}

.drop-zone {
  display: grid;
  place-items: center;
  min-height: 360px;
  margin-top: 20px;
  padding: 24px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: var(--drop-bg);
  transition:
    border-color 180ms ease,
    background 180ms ease,
    transform 180ms ease;
}

.drop-zone.is-over {
  transform: translateY(-1px);
}

.drop-copy {
  max-width: 36rem;
  text-align: center;
}

.drop-title {
  margin: 0;
  font-size: 1.2rem;
  line-height: 1.35;
  letter-spacing: -0.03em;
}

.drop-note {
  margin: 12px 0 0;
  color: var(--muted);
  line-height: 1.55;
}

.player-shell {
  margin-top: 20px;
  animation: fade-up 240ms ease;
}

.hidden {
  display: none;
}

.transport-bar {
  margin-bottom: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--surface-muted);
}

.transport-group {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.transport-button {
  min-height: 42px;
  padding: 0 15px;
  border-color: var(--line);
  font-size: 0.92rem;
}

.transport-button.strong {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}

.preview-stack {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(280px, 0.9fr);
  gap: 14px;
  align-items: start;
}

.video-card-primary {
  grid-row: 1 / span 2;
}

.drop-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 20px;
  border: 1px dashed transparent;
  border-radius: 26px;
  background: var(--overlay-bg);
  backdrop-filter: blur(6px);
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 180ms ease,
    border-color 180ms ease;
}

.drop-overlay.is-active {
  opacity: 1;
  border-color: var(--line-strong);
}

.drop-overlay-copy {
  max-width: 28rem;
  text-align: center;
}

.video-card {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--surface);
}

.video-stage {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--video-frame);
  aspect-ratio: 16 / 9;
}

.video-stage video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000000;
}

.preview-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  background: transparent;
}

.preview-video-underlay {
  opacity: 0.92;
}

.reference-copy {
  display: grid;
  gap: 8px;
}

.reference-copy strong {
  font-size: 0.92rem;
  line-height: 1.3;
  letter-spacing: -0.02em;
}

.decode-status {
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-size: 0.82rem;
  letter-spacing: 0.02em;
  background: var(--surface-muted);
}

.decode-status-idle {
  color: var(--muted);
}

.decode-status-live,
.decode-status-error {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}

.decode-status-warning {
  background: var(--surface-muted);
  color: var(--text);
}

.player-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.toggle-chip {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--text);
  font-size: 0.92rem;
  line-height: 1.3;
}

.toggle-chip input,
input[type="range"] {
  accent-color: var(--text);
}

.toggle-chip.wide {
  width: 100%;
  justify-content: flex-start;
  min-height: 48px;
  padding: 12px 14px;
  border-radius: 18px;
}

.map-panel,
.control-block {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--surface-muted);
}

.render-lab-block {
  border-style: dashed;
}

.render-lab-block .controls-note {
  margin: 0 0 16px;
}

.render-lab-grid {
  margin-bottom: 16px;
}

.map-panel {
  margin-top: 18px;
}

#mutationCanvas {
  display: block;
  width: 100%;
  height: auto;
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--canvas-bg);
}

.preset-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.preset-chip {
  min-height: 48px;
  padding: 0 14px;
  border-color: var(--line);
  border-radius: 18px;
  font-size: 0.98rem;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.slider-stack {
  display: grid;
  gap: 14px;
  margin: 14px 0;
}

.field,
.slider-field {
  display: grid;
  gap: 10px;
}

.field span,
.slider-head span {
  font-size: 0.86rem;
  color: var(--muted);
}

.field select,
.field input[type="number"] {
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  outline: none;
  background: var(--surface);
  color: var(--text);
  letter-spacing: -0.02em;
}

.seed-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.tiny-button {
  min-width: 84px;
  padding: 0 14px;
  border-color: var(--line);
}

.slider-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

output {
  color: var(--text);
  font-weight: 700;
  letter-spacing: -0.03em;
}

input[type="range"] {
  width: 100%;
}

.telemetry-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.telemetry-card {
  display: grid;
  gap: 8px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
}

.telemetry-card strong {
  font-size: 1.14rem;
  letter-spacing: -0.04em;
}

.status-line {
  margin: 16px 0 0;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  line-height: 1.55;
}

.theme-toggle:focus-visible,
.language-toggle:focus-visible,
.action-pill:focus-visible,
.preset-chip:focus-visible,
.tiny-button:focus-visible,
.transport-button:focus-visible,
.toggle-chip:focus-within,
.field select:focus-visible,
.field input[type="number"]:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(127, 127, 127, 0.18);
}

.format-trigger:hover,
.format-trigger:focus-visible {
  transform: none;
  box-shadow: none;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  transform: none;
  box-shadow: none;
}

@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 1240px) {
  .action-bar {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 1120px) {
  .workspace,
  .preview-stack {
    grid-template-columns: 1fr;
  }

  .video-card-primary {
    grid-row: auto;
  }
}

@media (max-width: 920px) {
  .hero-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  body::before {
    background-size: 64px 64px;
    opacity: 0.24;
  }

  .app-shell {
    width: min(1480px, calc(100vw - 24px));
    padding: 16px 0 28px;
  }

  .topbar {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
  }

  .topbar-tools {
    justify-content: flex-end;
  }

  .hero {
    padding: 8px 0 16px;
  }

  .hero h1 {
    font-size: clamp(4rem, 21vw, 8rem);
    line-height: 0.9;
  }

  .preview-panel,
  .controls-panel {
    padding: 18px;
  }

  .hero-actions,
  .preset-grid,
  .field-grid,
  .telemetry-grid {
    grid-template-columns: 1fr;
  }

  .panel-head,
  .block-head,
  .map-head,
  .video-card-head {
    flex-direction: column;
  }

  .badge-row,
  .map-stats {
    justify-content: flex-start;
  }

  .transport-group {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .toggle-chip {
    width: 100%;
    justify-content: flex-start;
  }
}

@media (max-width: 520px) {
  .transport-group {
    grid-template-columns: 1fr;
  }

  .brand img {
    width: 24px;
  }

  .theme-toggle-track {
    width: 76px;
    height: 42px;
  }

  .theme-toggle-knob {
    top: 5px;
    left: 5px;
    width: 28px;
    height: 28px;
  }

  html[data-theme="dark"] .theme-toggle-knob {
    transform: translateX(34px);
  }

  .language-toggle {
    min-height: 42px;
    min-width: 70px;
    padding: 0 16px;
    font-size: 1.05rem;
  }

  .video-stage video {
    min-height: 220px;
  }
}
