:root {
  color-scheme: dark;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  background: #070808;
  color: #e8ece6;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  max-width: 100%;
}

html {
  overflow: hidden;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
}

button,
input {
  font: inherit;
}

.app-shell {
  position: fixed;
  inset: 0;
  display: grid;
  width: 100vw;
  max-width: 100vw;
  min-width: 0;
  overflow: hidden;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 360px);
  background: #050606;
}

.scene-stage {
  position: relative;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: #000;
}

#flameCanvas {
  width: 100%;
  max-width: 100%;
  height: 100%;
  min-width: 0;
  display: block;
  background: #000;
  cursor: grab;
  touch-action: none;
  user-select: none;
}

#flameCanvas.is-dragging {
  cursor: grabbing;
}

.about-overlay,
.vhs-static {
  position: absolute;
  inset: 0;
}

.about-overlay {
  z-index: 3;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 12px;
  padding: clamp(16px, 3vw, 34px);
  overflow: hidden;
  background: #030404;
  opacity: 0;
  pointer-events: none;
}

.about-overlay[hidden] {
  display: none;
}

.scene-stage.is-about-open .about-overlay {
  opacity: 1;
  pointer-events: auto;
}

.about-scroll {
  display: grid;
  grid-template-rows: minmax(160px, 42vh) minmax(0, 1fr);
  min-height: 0;
  gap: 12px;
  overflow: hidden;
}

.about-image-frame {
  position: relative;
  min-width: 0;
  min-height: 0;
  margin: 0;
  overflow: hidden;
  border: 1px solid rgba(159, 240, 215, 0.22);
  border-radius: 8px;
  background: #000;
}

.about-image-frame::before,
.about-image-frame::after,
.vhs-static {
  pointer-events: none;
}

.about-image-frame::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  background:
    linear-gradient(rgba(255, 255, 255, 0.06) 50%, rgba(0, 0, 0, 0.1) 50%),
    linear-gradient(90deg, rgba(255, 73, 88, 0.08), rgba(83, 238, 255, 0.05), rgba(125, 230, 201, 0.08));
  background-size:
    100% 4px,
    6px 100%;
  mix-blend-mode: screen;
  opacity: 0.42;
}

.about-image-frame::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  border: 1px solid rgba(255, 255, 255, 0.06);
  box-shadow: inset 0 0 60px rgba(0, 0, 0, 0.75);
}

#aboutImage {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  opacity: 0;
  filter: saturate(0.9) contrast(1.12);
}

.scene-stage.is-about-open #aboutImage {
  opacity: 1;
}

.scene-stage.is-about-entering #aboutImage {
  animation: vhsImageIn 700ms steps(4, end) both;
}

.about-content {
  min-height: 0;
  overflow-y: auto;
  padding: clamp(14px, 2vw, 20px);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: rgba(9, 10, 10, 0.86);
  color: #e8ece6;
  line-height: 1.55;
  scrollbar-color: rgba(159, 240, 215, 0.55) rgba(255, 255, 255, 0.08);
}

.about-content h1,
.about-content h2,
.about-content h3 {
  margin: 0 0 10px;
  color: #f4f0dc;
  letter-spacing: 0;
}

.about-content h1 {
  font-size: clamp(26px, 4vw, 42px);
  font-weight: 800;
}

.about-content h2 {
  margin-top: 22px;
  font-size: clamp(17px, 2vw, 22px);
  font-weight: 760;
}

.about-content h3 {
  margin-top: 16px;
  font-size: 15px;
}

.about-content p {
  margin: 0 0 15px;
  color: #d8ded6;
  font-size: clamp(14px, 1.45vw, 17px);
}

.about-content a {
  color: #9ff0d7;
  text-decoration-color: rgba(159, 240, 215, 0.44);
  text-underline-offset: 3px;
}

.about-content hr {
  height: 1px;
  margin: 18px 0 0;
  border: 0;
  background: rgba(255, 255, 255, 0.14);
}

.about-close {
  justify-self: end;
  min-width: 88px;
  background: #271c1d;
}

.about-close:hover {
  border-color: rgba(255, 177, 157, 0.52);
  background: #352426;
}

.vhs-static {
  z-index: 5;
  background:
    repeating-radial-gradient(circle at 35% 45%, rgba(255, 255, 255, 0.2) 0 1px, transparent 1px 3px),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.18) 0 1px, transparent 1px 6px),
    linear-gradient(90deg, rgba(255, 73, 88, 0.16), rgba(83, 238, 255, 0.14), rgba(255, 217, 153, 0.1));
  mix-blend-mode: screen;
  opacity: 0;
  transform: translate3d(0, 0, 0);
}

.scene-stage.is-about-transitioning .vhs-static {
  animation: vhsStaticBurst 760ms steps(5, end) both;
}

.scene-stage.is-about-entering #flameCanvas {
  animation: fractalVhsOut 760ms steps(4, end) both;
}

.scene-stage.is-about-exiting .about-overlay {
  animation: aboutVhsOut 760ms steps(4, end) both;
}

.scene-stage.is-about-open:not(.is-about-entering) #flameCanvas {
  opacity: 0;
}

.control-panel {
  height: 100vh;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow-y: auto;
  padding: 18px;
  border-left: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(18, 19, 18, 0.94);
  backdrop-filter: blur(16px);
}

.panel-header,
.row,
.axis-row,
.metrics div {
  display: flex;
  align-items: center;
  gap: 10px;
}

.panel-header {
  justify-content: space-between;
  margin-bottom: 12px;
}

h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 650;
  letter-spacing: 0;
}

h2,
h3 {
  margin: 0;
  letter-spacing: 0;
}

h2 {
  color: #e8ece6;
  font-size: 14px;
  font-weight: 650;
}

h3 {
  color: #d9ded7;
  font-size: 12px;
  font-weight: 650;
}

#backendBadge {
  padding: 3px 8px;
  border: 1px solid rgba(125, 230, 201, 0.4);
  border-radius: 999px;
  color: #9ff0d7;
  font-size: 12px;
}

.status {
  min-height: 38px;
  margin-bottom: 14px;
  padding: 8px 10px;
  border-radius: 6px;
  background: #26221c;
  color: #ffd999;
  font-size: 13px;
  line-height: 1.35;
}

.status.ready {
  background: #17231f;
  color: #9ff0d7;
}

.status.error {
  background: #331b1d;
  color: #ffb2a8;
}

.control-group {
  padding: 12px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.split {
  justify-content: space-between;
}

label,
output,
.metrics span {
  color: #b8beb5;
  font-size: 13px;
}

input[type="range"] {
  width: 100%;
  min-height: 28px;
  accent-color: #7de6c9;
}

input[type="number"] {
  width: 100%;
  margin-top: 5px;
  padding: 6px 8px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 6px;
  background: #090a0a;
  color: #f3f5ef;
}

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

.button-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 7px;
  margin-top: 9px;
}

.mobile-point-presets {
  display: none;
}

.danger-point-presets {
  margin-top: 9px;
}

.danger-point-presets:not([open]) .button-row {
  display: none;
}

.danger-point-presets summary {
  min-height: 36px;
  padding: 8px 10px;
  border: 1px solid rgba(255, 217, 153, 0.22);
  border-radius: 6px;
  background: #221d18;
  color: #ffd999;
  cursor: pointer;
  font-size: 13px;
  font-weight: 650;
  list-style-position: inside;
}

.danger-point-presets[open] summary {
  border-color: rgba(255, 177, 157, 0.45);
  background: #2b1f1d;
}

button {
  min-height: 32px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 6px;
  background: #202626;
  color: #eef3ec;
  cursor: pointer;
}

button:hover {
  background: #2c3433;
  border-color: rgba(125, 230, 201, 0.4);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.about-launch {
  padding-bottom: 0;
}

.about-launch button {
  width: 100%;
  min-height: 38px;
  border-color: rgba(159, 240, 215, 0.26);
  color: #9ff0d7;
  text-transform: lowercase;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.axis-row {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 42px;
  margin: 8px 0;
}

.function-editor-header {
  margin-bottom: 8px;
}

.function-list {
  display: grid;
  gap: 8px;
}

.function-card {
  min-width: 0;
  border: 1px solid rgba(255, 255, 255, 0.11);
  border-radius: 6px;
  background: #101312;
}

.function-card[open] {
  border-color: rgba(125, 230, 201, 0.28);
}

.function-summary {
  display: flex;
  min-height: 38px;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  color: #eef3ec;
  cursor: pointer;
  font-size: 13px;
  font-weight: 650;
}

.function-summary-values {
  display: inline-flex;
  min-width: 0;
  align-items: center;
  gap: 7px;
  color: #b8beb5;
  font-size: 12px;
  font-weight: 500;
}

.function-color-swatch {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 50%;
}

.function-body {
  display: grid;
  gap: 12px;
  padding: 0 10px 12px;
}

.function-parameter-group {
  display: grid;
  gap: 8px;
  min-width: 0;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

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

.parameter-field {
  display: grid;
  min-width: 0;
  gap: 6px;
}

.parameter-field-label {
  color: #b8beb5;
  font-size: 12px;
}

.parameter-field input {
  min-width: 0;
  margin-top: 0;
  padding: 6px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 6px;
  background: #090a0a;
  color: #f3f5ef;
  font-size: 12px;
}

.parameter-spinner {
  --parameter-normalized: 0.5;
  position: relative;
  min-width: 0;
  min-height: 46px;
  border: 1px solid rgba(125, 230, 201, 0.18);
  border-radius: 6px;
  background: #090a0a;
  cursor: ew-resize;
  outline: none;
  overflow: hidden;
  touch-action: pan-y;
  user-select: none;
}

.parameter-spinner:focus-visible {
  border-color: rgba(125, 230, 201, 0.7);
  box-shadow: 0 0 0 2px rgba(125, 230, 201, 0.16);
}

.parameter-spinner.is-spinning {
  border-color: rgba(159, 240, 215, 0.58);
}

.parameter-spinner-track {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, rgba(125, 230, 201, 0.18), transparent 42%, rgba(255, 217, 153, 0.16)),
    repeating-linear-gradient(
      90deg,
      rgba(255, 255, 255, 0.18) 0,
      rgba(255, 255, 255, 0.18) 1px,
      transparent 1px,
      transparent 12px
    );
  background-position:
    0 0,
    calc(var(--parameter-normalized) * -120px) 0;
}

.parameter-spinner-marker {
  position: absolute;
  top: 5px;
  bottom: 5px;
  left: calc(var(--parameter-normalized) * 100%);
  width: 2px;
  background: #9ff0d7;
  box-shadow: 0 0 16px rgba(125, 230, 201, 0.7);
  transform: translateX(-1px);
}

.parameter-spinner-value {
  position: absolute;
  top: 50%;
  left: 50%;
  min-width: 58px;
  padding: 3px 7px;
  border-radius: 999px;
  background: rgba(5, 6, 6, 0.74);
  color: #f4f0dc;
  font-size: 13px;
  font-weight: 650;
  text-align: center;
  transform: translate(-50%, -50%);
}

.function-color-picker {
  display: grid;
  gap: 5px;
}

.function-color-picker input[type="color"] {
  width: 100%;
  min-width: 0;
  min-height: 40px;
  padding: 2px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 6px;
  background: #090a0a;
  cursor: pointer;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.metrics div {
  justify-content: space-between;
  min-width: 0;
  padding: 8px;
  border-radius: 6px;
  background: #101312;
}

.metrics strong {
  max-width: 150px;
  overflow: hidden;
  color: #f4f0dc;
  font-size: 13px;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 820px) {
  body {
    min-width: 0;
    overflow: hidden;
    overflow-x: hidden;
  }

  .app-shell {
    position: fixed;
    width: 100vw;
    width: 100dvw;
    max-width: 100vw;
    max-width: 100dvw;
    height: 100vh;
    height: 100dvh;
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 50%) minmax(0, 50%);
  }

  .scene-stage,
  .control-panel {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  .about-overlay {
    padding: 12px;
  }

  .about-scroll {
    grid-template-rows: minmax(96px, 32%) minmax(0, 1fr);
    gap: 8px;
  }

  .about-content {
    padding: 12px;
  }

  .about-content h1 {
    font-size: 22px;
  }

  .about-content h2 {
    margin-top: 16px;
    font-size: 16px;
  }

  .about-content p {
    font-size: 13px;
  }

  .control-panel {
    height: 100%;
    min-height: 0;
    padding: 14px max(14px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom))
      max(14px, env(safe-area-inset-left));
    overflow-y: auto;
    overscroll-behavior: contain;
    border-left: 0;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    -webkit-overflow-scrolling: touch;
  }

  .button-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .desktop-point-presets {
    display: none;
  }

  .mobile-point-presets {
    display: block;
  }

  button,
  input[type="number"] {
    min-height: 40px;
  }

  .metrics strong {
    max-width: 96px;
    font-size: 12px;
  }
}

@media (max-width: 420px) {
  .app-shell {
    grid-template-rows: minmax(0, 50%) minmax(0, 50%);
  }

  .panel-header {
    margin-bottom: 10px;
  }

  .status {
    font-size: 12px;
  }

  .button-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .axis-row {
    grid-template-columns: 42px minmax(0, 1fr) 38px;
  }

  .parameter-grid {
    grid-template-columns: 1fr;
  }

  .metrics {
    gap: 6px;
  }

  .metrics div {
    padding: 7px;
  }
}

@keyframes vhsStaticBurst {
  0% {
    opacity: 0;
    transform: translateX(0);
  }
  10% {
    opacity: 0.82;
    transform: translateX(-2%);
  }
  22% {
    opacity: 0.38;
    transform: translateX(1.4%);
  }
  36% {
    opacity: 0.9;
    transform: translateX(3%);
  }
  55% {
    opacity: 0.46;
    transform: translateX(-1.5%);
  }
  72% {
    opacity: 0.7;
    transform: translateX(0.7%);
  }
  100% {
    opacity: 0;
    transform: translateX(0);
  }
}

@keyframes fractalVhsOut {
  0% {
    opacity: 1;
    filter: none;
    transform: translateX(0);
  }
  18% {
    opacity: 0.7;
    filter: contrast(1.8) saturate(0.4) hue-rotate(22deg);
    transform: translateX(-8px) skewX(2deg);
  }
  32% {
    opacity: 1;
    filter: contrast(0.8) saturate(1.6);
    transform: translateX(10px) skewX(-3deg);
  }
  50% {
    opacity: 0.22;
    filter: grayscale(1) brightness(1.6);
    transform: translateX(-4px);
  }
  68% {
    opacity: 0.58;
    filter: contrast(2.2);
    transform: translateX(6px);
  }
  100% {
    opacity: 0;
    filter: brightness(0.2);
    transform: translateX(0);
  }
}

@keyframes vhsImageIn {
  0% {
    opacity: 0;
    filter: brightness(0.2) contrast(2) saturate(0);
    transform: translateX(14px) scale(1.02);
  }
  16% {
    opacity: 0.18;
    filter: brightness(1.7) contrast(2.4) saturate(1.5) hue-rotate(-18deg);
    transform: translateX(-10px) scale(1.03);
  }
  34% {
    opacity: 0.72;
    filter: brightness(0.7) contrast(1.8);
    transform: translateX(8px) scale(1.01);
  }
  48% {
    opacity: 0.3;
    filter: brightness(2.3) grayscale(1);
    transform: translateX(-4px);
  }
  72% {
    opacity: 0.9;
    filter: brightness(1.05) contrast(1.3) saturate(0.9);
    transform: translateX(2px);
  }
  100% {
    opacity: 1;
    filter: saturate(0.9) contrast(1.12);
    transform: translateX(0) scale(1);
  }
}

@keyframes aboutVhsOut {
  0% {
    opacity: 1;
    filter: none;
    transform: translateX(0);
  }
  35% {
    opacity: 0.35;
    filter: contrast(2.1) saturate(0.2);
    transform: translateX(12px);
  }
  58% {
    opacity: 0.68;
    filter: brightness(1.7);
    transform: translateX(-8px);
  }
  100% {
    opacity: 0;
    filter: brightness(0);
    transform: translateX(0);
  }
}
