:root {
  color-scheme: dark;
  --ink: #e9f2f7;
  --muted: #8b9aa7;
  --faint: #53616d;
  --line: rgba(168, 206, 222, 0.16);
  --line-strong: rgba(168, 206, 222, 0.3);
  --panel: rgba(10, 14, 20, 0.66);
  --panel-solid: #0a0e14;
  --accent: #ffd37a;
  --accent-cool: #8be9ff;
  --radius: 16px;
  --sans: 'Avenir Next', 'Segoe UI', Helvetica, Arial, sans-serif;
  --serif: 'Iowan Old Style', 'Palatino Linotype', Palatino, 'Book Antiqua', Georgia, serif;
  --mono: 'SFMono-Regular', 'Cascadia Mono', Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: #05070b;
  color: var(--ink);
  font-family: var(--sans);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.atmosphere {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.aura {
  position: absolute;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.2;
}

.aura-one {
  width: 54vw;
  height: 54vw;
  left: -12vw;
  top: -20vw;
  background: #145d7f;
}

.aura-two {
  width: 46vw;
  height: 46vw;
  right: -12vw;
  bottom: -20vw;
  background: #7a4126;
}

.grain {
  position: absolute;
  inset: -50%;
  opacity: 0.06;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.8'/%3E%3C/svg%3E");
  animation: grain 8s steps(6) infinite;
}

.room {
  position: relative;
  width: 100vw;
  height: 100dvh;
  min-height: 620px;
  isolation: isolate;
}

#sky,
#space {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#sky {
  z-index: -1;
}

#space {
  z-index: 0;
  cursor: crosshair;
  touch-action: none;
}

.topbar {
  position: absolute;
  z-index: 4;
  top: 0;
  left: 0;
  right: 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 24px;
  padding: 24px 32px;
  background: linear-gradient(to bottom, rgba(4, 7, 11, 0.8), transparent);
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  width: max-content;
  color: var(--ink);
  text-decoration: none;
}

.brand-mark {
  width: 38px;
  height: 38px;
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.1;
  opacity: 0.95;
}

.brand-mark circle {
  stroke: none;
}

.brand-copy {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.brand-name {
  font-family: var(--serif);
  font-size: 18px;
  letter-spacing: 0.02em;
}

.brand-note {
  color: var(--muted);
  font-size: 9px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}

.preset-nav {
  display: flex;
  gap: 3px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(6, 10, 15, 0.58);
  backdrop-filter: blur(18px);
}

.preset {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: background 180ms ease, color 180ms ease;
}

.preset:hover {
  color: var(--ink);
}

.preset.active {
  background: rgba(255, 236, 191, 0.12);
  color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(255, 211, 122, 0.18);
}

.preset-glyph {
  position: relative;
  width: 14px;
  height: 14px;
  border: 1px solid currentColor;
  border-radius: 50%;
  opacity: 0.8;
}

.glyph-orrery::after {
  content: '';
  position: absolute;
  inset: 4px;
  border-radius: 50%;
  background: currentColor;
}

.glyph-galaxy {
  border: 0;
  background: conic-gradient(from 40deg, transparent 10%, currentColor 20%, transparent 32%, transparent 60%, currentColor 72%, transparent 84%);
  transform: rotate(-20deg);
}

.glyph-binary::before,
.glyph-binary::after {
  content: '';
  position: absolute;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  top: 4px;
}

.glyph-binary::before { left: 1px; }
.glyph-binary::after { right: 1px; }

.glyph-collision {
  border: 1px dashed currentColor;
}

.glyph-collision::before,
.glyph-collision::after {
  content: '';
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  top: 3px;
}

.glyph-collision::before { left: -2px; }
.glyph-collision::after { right: -2px; }

.top-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
}

.icon-button,
.pause-button,
.collapse-button {
  border: 1px solid var(--line);
  background: rgba(6, 10, 15, 0.58);
  backdrop-filter: blur(18px);
  cursor: pointer;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 37px;
  height: 37px;
  padding: 0;
  border-radius: 50%;
  color: var(--muted);
  transition: color 160ms ease, border-color 160ms ease;
}

.icon-button:hover {
  color: var(--ink);
  border-color: var(--line-strong);
}

.icon-button svg,
.pause-button svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-button svg path[fill] {
  fill: currentColor;
}

.sound-off,
#sound[aria-pressed='true'] .sound-on {
  display: none;
}

#sound[aria-pressed='true'] .sound-off {
  display: block;
}

.pause-button {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 37px;
  padding: 0 15px;
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
}

.pause-button:hover {
  color: var(--ink);
  border-color: var(--line-strong);
}

.play-icon {
  display: none;
}

#pause[aria-pressed='true'] .pause-icon {
  display: none;
}

#pause[aria-pressed='true'] .play-icon {
  display: block;
  fill: currentColor;
}

.intro {
  position: absolute;
  z-index: 2;
  top: 117px;
  left: 36px;
  width: min(420px, 40vw);
  pointer-events: none;
}

.eyebrow {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.19em;
  text-transform: uppercase;
}

.live-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #9dffb0;
  box-shadow: 0 0 9px #9dffb0;
  animation: blink 3.2s ease-in-out infinite;
}

.separator {
  color: var(--faint);
}

.intro h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(48px, 6vw, 82px);
  font-weight: 400;
  letter-spacing: -0.045em;
  line-height: 0.96;
  text-shadow: 0 2px 40px rgba(0, 0, 0, 0.45);
}

.intro-copy {
  max-width: 280px;
  margin: 15px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.telemetry {
  position: absolute;
  z-index: 2;
  top: 120px;
  right: 36px;
  display: flex;
  flex-direction: column;
  gap: 0;
  width: 172px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.metric {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 7px 0;
  border-bottom: 1px solid rgba(168, 206, 222, 0.08);
}

.metric-label {
  color: var(--faint);
  font-size: 9px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.metric-value {
  color: var(--ink);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
}

.metric-wide {
  display: block;
  padding-top: 11px;
}

.metric-wide .metric-label {
  display: block;
  margin-bottom: 7px;
}

.stability {
  display: flex;
  align-items: center;
  gap: 9px;
}

.stability-bar {
  display: block;
  flex: 1;
  height: 2px;
  overflow: hidden;
  background: rgba(168, 206, 222, 0.13);
}

.stability-bar span {
  display: block;
  width: 100%;
  height: 100%;
  background: linear-gradient(to right, #ff9ecb, #ffd37a, #9dffb0);
  transform-origin: left;
  transition: transform 600ms ease;
}

.instrument {
  position: absolute;
  z-index: 3;
  right: 28px;
  bottom: 30px;
  width: 282px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  backdrop-filter: blur(24px) saturate(120%);
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.32);
}

.instrument-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 17px 12px;
  border-bottom: 1px solid rgba(168, 206, 222, 0.1);
  color: var(--muted);
  font-size: 9px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.collapse-button {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border-radius: 50%;
  color: var(--muted);
}

.collapse-button svg {
  width: 13px;
  height: 13px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  transition: transform 180ms ease;
}

.instrument.collapsed .collapse-button svg {
  transform: rotate(180deg);
}

.instrument-body {
  display: grid;
  gap: 17px;
  padding: 16px 17px 17px;
}

.instrument.collapsed .instrument-body {
  display: none;
}

.control {
  display: block;
}

.control-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 9px;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.08em;
}

.control-label output {
  color: var(--ink);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0;
}

input[type='range'] {
  width: 100%;
  height: 14px;
  margin: 0;
  appearance: none;
  background: transparent;
  cursor: pointer;
}

input[type='range']::-webkit-slider-runnable-track {
  height: 2px;
  background: linear-gradient(to right, var(--accent-cool) var(--fill, 50%), rgba(168, 206, 222, 0.17) var(--fill, 50%));
}

input[type='range']::-moz-range-track {
  height: 2px;
  background: rgba(168, 206, 222, 0.17);
}

input[type='range']::-moz-range-progress {
  height: 2px;
  background: var(--accent-cool);
}

input[type='range']::-webkit-slider-thumb {
  width: 11px;
  height: 11px;
  margin-top: -4.5px;
  appearance: none;
  border: 2px solid #081018;
  border-radius: 50%;
  background: var(--accent-cool);
  box-shadow: 0 0 0 3px rgba(139, 233, 255, 0.13);
}

input[type='range']::-moz-range-thumb {
  width: 9px;
  height: 9px;
  border: 2px solid #081018;
  border-radius: 50%;
  background: var(--accent-cool);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
  padding: 2px;
  border: 1px solid rgba(168, 206, 222, 0.12);
  border-radius: 7px;
  background: rgba(0, 0, 0, 0.18);
}

.segmented button {
  padding: 6px 4px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--faint);
  font-size: 10px;
  cursor: pointer;
  transition: background 160ms ease, color 160ms ease;
}

.segmented button:hover {
  color: var(--ink);
}

.segmented button.active {
  background: rgba(139, 233, 255, 0.11);
  color: var(--accent-cool);
}

.new-universe {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 10px 11px;
  border: 1px solid rgba(255, 211, 122, 0.22);
  border-radius: 8px;
  background: rgba(255, 211, 122, 0.06);
  color: var(--accent);
  font-size: 11px;
  cursor: pointer;
  transition: background 160ms ease, border-color 160ms ease;
}

.new-universe:hover {
  background: rgba(255, 211, 122, 0.11);
  border-color: rgba(255, 211, 122, 0.38);
}

.new-universe svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.new-universe kbd {
  margin-left: auto;
  padding: 1px 5px;
  border: 1px solid rgba(255, 211, 122, 0.22);
  border-radius: 4px;
  color: rgba(255, 211, 122, 0.65);
  font-family: var(--mono);
  font-size: 9px;
}

.gesture-hint {
  position: absolute;
  z-index: 2;
  left: 36px;
  bottom: 31px;
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.01em;
  pointer-events: none;
  transition: opacity 600ms ease;
}

.gesture-hint strong {
  color: var(--ink);
  font-weight: 500;
}

.gesture-hint.faded {
  opacity: 0.28;
}

.gesture-icon {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 50%;
}

.gesture-icon svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.1;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.hint-key {
  padding-left: 12px;
  border-left: 1px solid var(--line);
  color: var(--faint);
  font-family: var(--mono);
  font-size: 9px;
}

.motion-grid {
  position: absolute;
  z-index: 3;
  left: 50%;
  bottom: 31px;
  display: flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(6, 10, 15, 0.5);
  backdrop-filter: blur(18px);
  transform: translateX(-50%);
}

.mode {
  padding: 7px 13px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--faint);
  font-size: 10px;
  letter-spacing: 0.08em;
  cursor: pointer;
  transition: color 160ms ease, background 160ms ease;
}

.mode:hover {
  color: var(--muted);
}

.mode.active {
  color: var(--ink);
  background: rgba(168, 206, 222, 0.1);
}

.toast {
  position: absolute;
  z-index: 8;
  left: 50%;
  bottom: 88px;
  padding: 9px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: rgba(8, 13, 19, 0.92);
  color: var(--ink);
  font-size: 11px;
  opacity: 0;
  transform: translate(-50%, 8px);
  transition: opacity 180ms ease, transform 180ms ease;
  pointer-events: none;
}

.toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

@keyframes grain {
  0% { transform: translate(0, 0); }
  20% { transform: translate(-2%, 3%); }
  40% { transform: translate(3%, -2%); }
  60% { transform: translate(-3%, -3%); }
  80% { transform: translate(2%, 2%); }
  100% { transform: translate(0, 0); }
}

@media (max-width: 900px) {
  .topbar {
    grid-template-columns: 1fr auto;
    padding: 18px 20px;
  }

  .preset-nav {
    position: absolute;
    top: 70px;
    left: 20px;
    right: 20px;
    justify-content: center;
  }

  .preset {
    flex: 1;
    justify-content: center;
    padding-inline: 7px;
  }

  .intro {
    top: 140px;
    left: 22px;
    width: 60vw;
  }

  .telemetry {
    top: 144px;
    right: 22px;
    width: 126px;
  }

  .instrument {
    right: 18px;
    bottom: 20px;
    width: 258px;
  }

  .gesture-hint {
    left: 22px;
    bottom: 20px;
  }

  .motion-grid {
    display: none;
  }

  .hint-key {
    display: none;
  }
}

@media (max-width: 620px) {
  .room {
    min-height: 560px;
  }

  .brand-note,
  .telemetry {
    display: none;
  }

  .brand-mark {
    width: 31px;
    height: 31px;
  }

  .brand-name {
    font-size: 16px;
  }

  .topbar {
    padding: 14px 14px;
  }

  .top-actions {
    gap: 6px;
  }

  .icon-button {
    width: 34px;
    height: 34px;
  }

  .pause-button {
    height: 34px;
    padding: 0 11px;
  }

  .pause-button span {
    display: none;
  }

  .preset-nav {
    top: 58px;
    left: 12px;
    right: 12px;
    gap: 0;
  }

  .preset {
    gap: 5px;
    padding: 7px 5px;
    font-size: 10px;
  }

  .preset-glyph {
    display: none;
  }

  .intro {
    top: 108px;
    left: 17px;
    width: 90vw;
  }

  .intro h1 {
    font-size: 49px;
  }

  .intro-copy {
    max-width: 225px;
    font-size: 12px;
  }

  .instrument {
    right: 12px;
    bottom: 12px;
    left: 12px;
    width: auto;
  }

  .instrument-body {
    grid-template-columns: 1fr 1fr;
    gap: 13px;
  }

  .instrument-body .control:first-child,
  .instrument-body .new-universe {
    grid-column: 1 / -1;
  }

  .gesture-hint {
    display: none;
  }

  .toast {
    bottom: 255px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .grain,
  .live-dot {
    animation: none;
  }

  * {
    transition-duration: 0.01ms !important;
  }
}
