:root {
  color-scheme: dark;
  --background: #0b0c0e;
  --panel: rgba(18, 19, 22, 0.88);
  --panel-solid: #121316;
  --surface-elevated: #1b1d21;
  --surface-hover: #24272c;
  --surface-selected: #30343a;
  --line: rgba(246, 240, 229, 0.09);
  --line-hover: rgba(246, 240, 229, 0.17);
  --rail: #596069;
  --text: #f6f0e5;
  --muted: #9d978e;
  --soft: #cec7bc;
  --accent: #ff795b;
  --accent-hover: #ff947b;
  --accent-2: #d6ea68;
  --focus: #ffd0c4;
  --accent-ink: #24100a;
  --shadow: rgba(0, 0, 0, 0.42);
  --card-bg: rgba(18, 19, 22, 0.9);
  --camera-bg: rgba(18, 19, 22, 0.96);
  --play-bg: rgba(91, 48, 37, 0.3);
  --play-bg-hover: rgba(118, 60, 45, 0.42);
  --accent-halo: rgba(255, 121, 91, 0.1);
  --accent-ring: rgba(255, 121, 91, 0.2);
  --glow-center: rgba(77, 74, 67, 0.13);
  --glow-center-mid: rgba(55, 53, 48, 0.06);
  --glow-secondary: rgba(214, 234, 104, 0.045);
  --glow-secondary-mid: rgba(110, 120, 57, 0.02);
  --glow-accent: rgba(255, 121, 91, 0.055);
  --glow-accent-mid: rgba(125, 57, 44, 0.025);
  --gradient-top: #121418;
  --gradient-bottom: #0b0c0e;
  --grain-mode: screen;
  --axis-x: rgba(255, 121, 91, 0.9);
  --axis-y: rgba(214, 234, 104, 0.88);
  --axis-z: rgba(246, 240, 229, 0.68);
  --layer-outline-rgb: 246, 240, 229;
  --axis-origin: rgba(11, 12, 14, 0.54);
  --tile-stroke: rgba(0, 0, 0, 0.09);
}

* {
  box-sizing: border-box;
}
html,
body {
  width: 100%;
  height: 100%;
  height: 100svh;
  overflow: hidden;
  overscroll-behavior: none;
}
body {
  position: fixed;
  inset: 0;
  margin: 0;
  overflow: hidden;
  color: var(--text);
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  background-color: var(--background);
  background-image:
    url("data:image/svg+xml,%3Csvg viewBox='0 0 220 220' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='grain'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.64' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23grain)' opacity='.04'/%3E%3C/svg%3E"),
    radial-gradient(
      ellipse 34% 48% at 52% 54%,
      var(--glow-center) 0%,
      var(--glow-center-mid) 38%,
      transparent 74%
    ),
    radial-gradient(
      circle at 75% 40%,
      var(--glow-secondary) 0%,
      var(--glow-secondary-mid) 34%,
      transparent 62%
    ),
    radial-gradient(
      circle at 16% 88%,
      var(--glow-accent) 0%,
      var(--glow-accent-mid) 34%,
      transparent 60%
    ),
    linear-gradient(180deg, var(--gradient-top) 0%, var(--gradient-bottom) 100%);
  background-size:
    220px 220px,
    100% 100%,
    100% 100%,
    100% 100%,
    100% 100%;
  background-blend-mode: var(--grain-mode), normal, normal, normal, normal;
  transition: background-color 0.28s ease, color 0.28s ease;
}
#app {
  position: fixed;
  inset: 0;
  z-index: 1;
  width: 100vw;
  height: 100vh;
  height: 100svh;
  overflow: hidden;
}
canvas {
  position: fixed;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.github-link {
  position: fixed;
  top: 36px;
  right: 36px;
  z-index: 4;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  backdrop-filter: blur(10px);
  transition: 0.16s ease;
}
.github-link:hover {
  color: var(--text);
  border-color: var(--line-hover);
  background: var(--surface-elevated);
}
.github-link svg {
  width: 20px;
  height: 20px;
  display: block;
}

.figure-title {
  position: fixed;
  top: 48px;
  left: 48px;
  z-index: 4;
  display: flex;
  flex-direction: column;
  gap: 4px;
  pointer-events: none;
}
.figure-title .title {
  margin: 0;
  font-size: 28px;
  line-height: 1.12;
  font-weight: 400;
  letter-spacing: -0.015em;
  color: var(--text);
}
.figure-title .subtitle {
  font-size: 12px;
  line-height: 1.35;
  letter-spacing: 0.025em;
  color: var(--muted);
}
.figure-description {
  max-width: 360px;
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
  letter-spacing: 0.01em;
}
.figure-title .path {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 5px;
  max-width: min(720px, calc(100vw - 96px));
  pointer-events: auto;
  overflow: hidden;
}
.figure-title .step {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}
.figure-title .step.active {
  color: var(--text);
}
.figure-title .sep {
  color: var(--line-hover);
  font-size: 11px;
}

.control-card {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 4;
  width: 320px;
  max-width: calc(100vw - 48px);
  max-height: calc(100vh - 48px);
  max-height: calc(100dvh - 48px);
  display: flex;
  flex-direction: column;
  gap: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card-bg);
  box-shadow: 0 18px 60px var(--shadow);
}
.control-card.collapsed {
  left: auto;
  width: auto;
}
.control-card.collapsed .card-top {
  min-height: 0;
  padding: 6px;
}
.card-top {
  min-height: 50px;
  padding: 6px 7px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-shrink: 0;
  background: transparent;
}
.control-card-body {
  --control-body-bottom-padding: 10px;
  min-width: 0;
  min-height: 0;
  max-height: var(--control-body-height, 420px);
  padding: 0 10px var(--control-body-bottom-padding);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
  opacity: 1;
  transform: translateY(0);
  transition:
    max-height 0.24s cubic-bezier(0.22, 1, 0.36, 1),
    padding-bottom 0.24s cubic-bezier(0.22, 1, 0.36, 1),
    opacity 0.16s ease,
    transform 0.24s cubic-bezier(0.22, 1, 0.36, 1);
}
.control-card-body::-webkit-scrollbar {
  display: none;
}
.control-card.collapsed .control-card-body {
  width: 0;
  max-height: 0;
  padding-right: 0;
  padding-bottom: 0;
  padding-left: 0;
  opacity: 0;
  transform: translateY(-6px);
  pointer-events: none;
}
.actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
  padding: 0;
  background: transparent;
}

button {
  appearance: none;
  border: none;
  outline: none;
  cursor: pointer;
  color: var(--text);
  background: var(--surface-elevated);
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 650;
  transition: 0.16s ease;
  line-height: 1;
}
button:hover {
  border-color: transparent;
  background: var(--surface-hover);
}
button.active {
  background: var(--surface-selected);
  border-color: transparent;
  color: var(--text);
}
button:focus-visible,
.github-link:focus-visible,
input[type="range"]:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}
.iconbtn {
  width: 34px;
  height: 34px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 9px;
  font-size: 13px;
}
.control-icon {
  width: 19px;
  height: 19px;
  display: block;
  overflow: visible;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.control-icon .play-mark {
  fill: currentColor;
  stroke: none;
}
.control-icon .pause-mark {
  opacity: 0;
}
#playBtn.playing .play-mark {
  opacity: 0;
}
#playBtn.playing .pause-mark {
  opacity: 1;
}
.collapse-vertical {
  opacity: 0;
  transition: opacity 0.14s ease;
}
.collapse-btn.expand .collapse-vertical {
  opacity: 1;
}
.actions button {
  background: transparent;
  border-color: transparent;
}
.actions button:hover {
  background: var(--surface-hover);
}
.actions button.active {
  background: var(--surface-selected);
}
.actions #playBtn,
.actions #playBtn.active {
  background: var(--play-bg);
  color: var(--accent);
}
.actions #playBtn:hover {
  background: var(--play-bg-hover);
  color: var(--accent-hover);
}
.collapse-btn {
  font-size: 18px;
}
.segmented {
  display: flex;
  gap: 4px;
  padding: 4px;
  margin-top: 2px;
  margin-bottom: 10px;
  background: var(--surface-elevated);
  border: 1px solid transparent;
  border-radius: 11px;
}
.segmented button {
  flex: 1;
  background: transparent;
  border: 1px solid transparent;
  padding: 8px 10px;
  border-radius: 9px;
  color: var(--muted);
}
.segmented button.active {
  background: var(--surface-selected);
  border-color: transparent;
  color: var(--text);
}

.preset-block {
  margin-bottom: 10px;
}
.preset-label {
  display: block;
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 7px;
}
.preset-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.preset-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 8px 6px;
  min-width: 0;
  background: var(--surface-elevated);
  border: 1px solid transparent;
  border-radius: 12px;
}
.preset-btn:hover {
  background: var(--surface-hover);
}
.preset-btn.active {
  background: var(--surface-selected);
  border-color: transparent;
}
.preset-thumb {
  width: 52px;
  height: 52px;
  border-radius: 9px;
  border: 1px solid transparent;

  background-position:
    0 0,
    6px 6px;
  background-size: 12px 12px;
  overflow: hidden;
  display: grid;
  place-items: center;
}
.preset-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
}
.preset-name {
  font-size: 10px;
  color: var(--soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.scrub {
  margin-bottom: 10px;
}
.rail-wrap {
  position: relative;
  height: 18px;
  --progress-thumb-size: 16px;
  --timeline-progress: 0;
}
.rail {
  position: absolute;
  left: calc(var(--progress-thumb-size) / 2);
  right: calc(var(--progress-thumb-size) / 2);
  top: 8px;
  height: 2px;
  border-radius: 999px;
  background: var(--rail);
}
.fill {
  position: absolute;
  left: calc(var(--progress-thumb-size) / 2);
  top: 8px;
  width: calc((100% - var(--progress-thumb-size)) * var(--timeline-progress));
  height: 2px;
  border-radius: 999px;
  background: var(--accent);
}
#progress {
  position: relative;
  width: 100%;
  height: 18px;
  margin: 0;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
}
#progress::-webkit-slider-runnable-track {
  height: 2px;
  background: transparent;
}
#progress::-moz-range-track {
  height: 2px;
  background: transparent;
}
#progress::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  margin-top: -6px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--panel);
  box-shadow: 0 0 0 3px var(--accent-ring);
}
#progress::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--panel);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.card-bottom {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 6px;
}
.card-bottom .right {
  display: flex;
  gap: 3px;
  padding: 3px;
  border-radius: 12px;
  background: var(--surface-elevated);
}
.card-bottom .right button {
  background: transparent;
  border-color: transparent;
  color: var(--soft);
}
.card-bottom .right .tool-icon-btn {
  width: 34px;
  height: 34px;
  padding: 0;
  display: grid;
  place-items: center;
}
.card-bottom .right button:hover {
  background: var(--surface-hover);
}
.card-bottom .right button.active {
  background: var(--surface-selected);
  color: var(--text);
}

.camera-pop {
  position: fixed;
  right: 24px;
  bottom: calc(34px + var(--control-expanded-height, 370px));
  z-index: 4;
  width: 320px;
  max-width: calc(100vw - 48px);
  padding: 12px;
  border-radius: 14px;
  background: var(--camera-bg);
  border: 1px solid var(--line);
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
  box-shadow: none;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: 0.16s ease;
}
.camera-pop.open {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
.camera-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 10px;
  font-size: 12px;
  color: var(--soft);
}
.camera-rows {
  display: grid;
  gap: 10px;
}
.camera-row {
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 10px;
  align-items: center;
}
.camera-row label {
  font-size: 11px;
  color: var(--muted);
}
.camera-row input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

@media (max-width: 740px) {
  .figure-title {
    left: max(24px, env(safe-area-inset-left));
    right: max(68px, calc(env(safe-area-inset-right) + 48px));
    top: max(24px, env(safe-area-inset-top));
    max-width: none;
  }
  .github-link {
    top: max(20px, env(safe-area-inset-top));
    right: max(20px, env(safe-area-inset-right));
    width: 36px;
    height: 36px;
  }
  .figure-title .title {
    font-size: 23px;
  }
  .figure-title .subtitle {
    font-size: 11px;
  }
  .figure-description {
    max-width: 300px;
    margin-top: 6px;
    font-size: 11px;
    line-height: 1.45;
  }
  .figure-title .path {
    width: fit-content;
    max-width: 100%;
    gap: 7px;
    overflow: visible;
    scrollbar-width: none;
  }
  .figure-title .path::-webkit-scrollbar {
    display: none;
  }
  .figure-title .step {
    min-width: auto;
    flex: 0 0 auto;
    font-size: 11px;
    text-align: left;
  }
  .figure-title .sep {
    flex: 0 0 auto;
  }
  .control-card {
    right: max(16px, env(safe-area-inset-right));
    bottom: max(16px, calc(env(safe-area-inset-bottom) + 16px));
    left: max(16px, env(safe-area-inset-left));
    width: auto;
    max-width: none;
    max-height: calc(100svh - 120px);
    max-height: calc(100dvh - 120px);
  }
  .control-card-body {
    --control-body-bottom-padding: 7px;
    padding-right: 7px;
    padding-left: 7px;
    padding-bottom: var(--control-body-bottom-padding);
  }
  .camera-pop {
    right: max(20px, env(safe-area-inset-right));
    left: max(20px, env(safe-area-inset-left));
    top: 76px;
    bottom: auto;
    width: auto;
    max-width: none;
    max-height: calc(100vh - 164px);
    max-height: calc(100dvh - 164px);
    overflow-y: auto;
  }
  button {
    min-height: 36px;
    padding: 8px 10px;
  }
  .iconbtn {
    width: 36px;
    height: 36px;
  }
  .actions {
    gap: 3px;
  }
  .segmented {
    margin-bottom: 7px;
    padding: 3px;
  }
  .segmented button {
    padding: 7px 9px;
  }
  .preset-block {
    margin-bottom: 7px;
  }
  .preset-label {
    font-size: 9px;
    margin-bottom: 5px;
  }
  .preset-strip {
    gap: 5px;
  }
  .preset-btn {
    padding: 5px 4px;
    gap: 4px;
  }
  .preset-thumb {
    width: 36px;
    height: 36px;
    border-radius: 8px;
  }
  .preset-name {
    font-size: 9px;
  }
  .scrub {
    margin-bottom: 6px;
  }
  .rail-wrap {
    height: 22px;
    --progress-thumb-size: 18px;
  }
  .rail,
  .fill {
    top: 10px;
  }
  #progress {
    height: 22px;
  }
  #progress::-webkit-slider-thumb {
    margin-top: -7px;
    width: 18px;
    height: 18px;
  }
  #progress::-moz-range-thumb {
    width: 18px;
    height: 18px;
  }
  .card-bottom {
    margin-top: 6px;
  }
}

@media (max-width: 390px) {
  .card-bottom {
    align-items: stretch;
  }
  .card-bottom .right {
    width: 100%;
  }
  .card-bottom .right button {
    flex: 1;
  }
  .card-bottom .right .tool-icon-btn {
    flex: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  body,
  button,
  .control-card-body,
  .camera-pop {
    transition-duration: 0.01ms !important;
  }
}
