:root {
  color-scheme: dark;
  --bg: #080b10;
  --surface: #0e1219;
  --surface-2: #121821;
  --surface-3: #171e28;
  --line: rgba(232, 240, 255, 0.1);
  --line-strong: rgba(232, 240, 255, 0.18);
  --text: #edf2f7;
  --muted: #8e9aaa;
  --faint: #5f6a78;
  --accent: #55e6d8;
  --danger: #ff746c;
  --topbar: 58px;
  font-family:
    Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
  background: var(--bg);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
}

button,
select,
input {
  font: inherit;
}

button,
a,
select,
input[type="range"] {
  -webkit-tap-highlight-color: transparent;
}

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

.topbar {
  position: relative;
  z-index: 20;
  height: var(--topbar);
  display: grid;
  grid-template-columns: 260px 1fr 260px;
  align-items: center;
  gap: 18px;
  padding: 0 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(10, 13, 18, 0.94);
  backdrop-filter: blur(20px);
}

.instrument-brand {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
}

.instrument-brand strong,
.instrument-brand small {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.instrument-brand strong {
  font-size: 15px;
  letter-spacing: -0.02em;
}

.instrument-brand small {
  margin-top: 1px;
  color: var(--muted);
  font: 9px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.instrument-mark {
  position: relative;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border: 1px solid color-mix(in srgb, var(--accent) 38%, transparent);
  border-radius: 50%;
  box-shadow: inset 0 0 20px color-mix(in srgb, var(--accent) 9%, transparent);
}

.instrument-mark::before,
.instrument-mark::after,
.instrument-mark i {
  content: "";
  position: absolute;
  border-radius: 999px;
  background: var(--accent);
}

.instrument-mark::before {
  width: 5px;
  height: 5px;
  box-shadow: 0 0 12px var(--accent);
}

.instrument-mark::after {
  width: 19px;
  height: 1px;
  opacity: 0.7;
  transform: rotate(-28deg);
}

.instrument-mark i:nth-child(1) {
  width: 2px;
  height: 2px;
  translate: 9px -5px;
}

.instrument-mark i:nth-child(2) {
  width: 2px;
  height: 2px;
  translate: -8px 6px;
}

.instrument-mark i:nth-child(3) {
  width: 1px;
  height: 1px;
  translate: 4px 10px;
}

.toolbar-center {
  justify-self: center;
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.scenario-picker {
  height: 34px;
  min-width: 190px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
}

.scenario-picker span {
  color: var(--faint);
  font: 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.scenario-picker select {
  min-width: 0;
  flex: 1;
  border: 0;
  outline: 0;
  color: var(--text);
  background: transparent;
  font-size: 12px;
}

.tool-button,
.universe-trigger {
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--text);
  background: var(--surface);
  cursor: pointer;
  transition:
    border-color 160ms ease,
    background 160ms ease,
    transform 160ms ease;
}

.tool-button {
  padding: 0 11px;
  font-size: 11px;
}

.tool-button:hover,
.universe-trigger:hover {
  border-color: var(--line-strong);
  background: var(--surface-2);
}

.tool-button:active,
.universe-trigger:active {
  transform: translateY(1px);
}

.tool-button.primary {
  display: flex;
  align-items: center;
  gap: 6px;
  border-color: color-mix(in srgb, var(--accent) 42%, var(--line));
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
}

.play-icon {
  width: 10px;
  color: var(--accent);
  font-size: 10px;
}

.universe-trigger {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 10px 0 12px;
  font-size: 11px;
}

.orbit-icon {
  color: var(--accent);
  font-size: 17px;
  line-height: 1;
}

.studio {
  height: calc(100svh - var(--topbar));
  display: grid;
  grid-template-columns: 258px minmax(360px, 1fr) 286px;
  overflow: hidden;
}

.experiment-rail,
.inspector {
  position: relative;
  z-index: 5;
  min-width: 0;
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
  background: var(--surface);
}

.experiment-rail {
  border-right: 1px solid var(--line);
}

.inspector {
  border-left: 1px solid var(--line);
}

.rail-section,
.inspector-head,
.readout-head {
  padding: 18px 17px;
  border-bottom: 1px solid var(--line);
}

.identity-section {
  padding-top: 22px;
}

.eyebrow,
.section-label {
  margin: 0 0 8px;
  color: var(--accent);
  font: 9px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.section-label {
  color: var(--faint);
}

.identity-section h1,
.inspector h2,
.universe-head h2 {
  margin: 0;
  letter-spacing: -0.035em;
}

.identity-section h1 {
  font-size: 25px;
  line-height: 1.02;
}

.identity-section > p:last-child,
.interaction-copy,
.scope-section p,
.scope-section li {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.55;
}

.identity-section > p:last-child {
  margin: 11px 0 0;
}

.interaction-copy,
.scope-section p {
  margin: 0;
}

.scope-section ul {
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}

.scope-section li {
  position: relative;
  padding: 6px 0 6px 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.scope-section li::before {
  content: "—";
  position: absolute;
  left: 0;
  color: var(--faint);
}

.preset-list {
  display: grid;
  gap: 4px;
}

.preset-list button {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid transparent;
  border-radius: 6px;
  color: inherit;
  text-align: left;
  background: transparent;
  cursor: pointer;
}

.preset-list button:hover,
.preset-list button.active {
  border-color: var(--line);
  background: var(--surface-2);
}

.preset-list button.active {
  border-left-color: var(--accent);
}

.preset-list strong,
.preset-list span {
  display: block;
}

.preset-list strong {
  font-size: 11px;
  font-weight: 600;
}

.preset-list span {
  margin-top: 3px;
  color: var(--faint);
  font-size: 9px;
  line-height: 1.35;
}

.workspace {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  isolation: isolate;
  background:
    radial-gradient(circle at 50% 50%, color-mix(in srgb, var(--accent) 5%, transparent), transparent 58%),
    #090d13;
}

.workspace::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background:
    linear-gradient(to bottom, rgba(255, 255, 255, 0.018) 1px, transparent 1px) 0 0 / 100% 3px,
    radial-gradient(circle at center, transparent 55%, rgba(0, 0, 0, 0.28));
  mix-blend-mode: screen;
  opacity: 0.35;
}

#simulationCanvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
  touch-action: none;
}

.workspace-hud {
  position: absolute;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 8px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 5px;
  color: var(--muted);
  background: rgba(8, 11, 16, 0.72);
  backdrop-filter: blur(8px);
  font: 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.workspace-hud.top-left {
  top: 12px;
  left: 12px;
}

.workspace-hud.top-right {
  top: 12px;
  right: 12px;
}

.workspace-hud.bottom-left {
  bottom: 12px;
  left: 12px;
  max-width: min(420px, calc(100% - 96px));
  line-height: 1.35;
  text-transform: none;
}

.live-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent);
  animation: live-pulse 1.8s ease-in-out infinite;
}

.live-dot[data-tone="paused"] {
  background: #87909d;
  box-shadow: none;
  animation: none;
}

.live-dot[data-tone="warn"],
.live-dot[data-tone="warning"] {
  background: #f2bf62;
  box-shadow: 0 0 12px rgba(242, 191, 98, 0.48);
}

.live-dot[data-tone="preview"],
.live-dot[data-tone="accent"] {
  background: var(--accent);
  box-shadow: 0 0 12px color-mix(in srgb, var(--accent) 48%, transparent);
}

.live-dot[data-tone="error"] {
  background: var(--danger);
  box-shadow: 0 0 10px var(--danger);
  animation: none;
}

.workspace-signature {
  position: absolute;
  right: 13px;
  bottom: 10px;
  z-index: 3;
  color: rgba(255, 255, 255, 0.22);
  font: 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.12em;
}

.inspector-head h2 {
  font-size: 20px;
}

.controls-root {
  padding: 4px 17px 16px;
}

.control {
  position: relative;
  display: block;
  padding: 13px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.055);
}

.control-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
}

.control-label {
  color: #dce3ec;
  font-size: 11px;
  font-weight: 550;
}

.control-value {
  color: var(--accent);
  font: 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}

.control-description {
  display: block;
  margin-top: 5px;
  color: var(--faint);
  font-size: 9px;
  line-height: 1.4;
}

input[type="range"] {
  width: 100%;
  height: 18px;
  margin: 9px 0 0;
  appearance: none;
  background: transparent;
  cursor: ew-resize;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 2px;
  border-radius: 999px;
  background:
    linear-gradient(var(--accent), var(--accent)) 0 0 / var(--range-progress) 100% no-repeat,
    rgba(255, 255, 255, 0.13);
}

input[type="range"]::-webkit-slider-thumb {
  width: 11px;
  height: 11px;
  margin-top: -4.5px;
  appearance: none;
  border: 2px solid var(--surface);
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 55%, transparent);
}

.control-select select {
  width: 100%;
  height: 32px;
  margin-top: 8px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  background: var(--surface-2);
  font-size: 11px;
}

.control-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  cursor: pointer;
}

.control-toggle input {
  position: absolute;
  opacity: 0;
}

.toggle-track {
  position: relative;
  flex: 0 0 auto;
  width: 30px;
  height: 17px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  transition: background 160ms ease;
}

.toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--muted);
  transition:
    translate 160ms ease,
    background 160ms ease;
}

.control-toggle input:checked + .toggle-track {
  background: color-mix(in srgb, var(--accent) 24%, transparent);
}

.control-toggle input:checked + .toggle-track .toggle-thumb {
  translate: 13px 0;
  background: var(--accent);
}

.control-divider {
  margin: 18px 0 4px;
  color: var(--faint);
  font: 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.inspector-action {
  width: 100%;
  height: 34px;
  margin-top: 8px;
  border: 1px solid color-mix(in srgb, var(--accent) 40%, var(--line));
  border-radius: 6px;
  color: var(--text);
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
  font-size: 10px;
  cursor: pointer;
}

.inspector-action.quiet {
  border-color: var(--line);
  background: transparent;
}

.metrics-root {
  padding: 4px 17px 22px;
}

.metric-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.055);
}

.metric-label {
  color: var(--muted);
  font-size: 10px;
}

.metric-value {
  color: var(--text);
  font: 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}

.metric-value[data-tone="accent"] {
  color: var(--accent);
}

.metric-value[data-tone="warn"] {
  color: #f2bf62;
}

.metric-value[data-tone="warning"] {
  color: #f2bf62;
}

.metric-value[data-tone="good"] {
  color: #70edb1;
}

.toast {
  position: fixed;
  z-index: 100;
  left: 50%;
  bottom: 22px;
  padding: 9px 13px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  color: var(--text);
  background: rgba(13, 17, 23, 0.94);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  font-size: 11px;
  opacity: 0;
  translate: -50% 8px;
  pointer-events: none;
  transition:
    opacity 180ms ease,
    translate 180ms ease;
}

.toast.visible {
  opacity: 1;
  translate: -50% 0;
}

.universe-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(3, 5, 8, 0.6);
  opacity: 0;
  backdrop-filter: blur(4px);
  transition: opacity 220ms ease;
}

.universe-drawer {
  position: fixed;
  z-index: 70;
  top: 0;
  right: 0;
  width: min(430px, 94vw);
  height: 100svh;
  overflow: auto;
  padding: 28px 24px;
  border-left: 1px solid var(--line-strong);
  background:
    radial-gradient(circle at 100% 0, color-mix(in srgb, var(--accent) 10%, transparent), transparent 38%),
    #0b0f15;
  box-shadow: -24px 0 80px rgba(0, 0, 0, 0.45);
  translate: 100% 0;
  transition: translate 240ms cubic-bezier(0.2, 0.7, 0.2, 1);
}

.universe-open .universe-backdrop {
  opacity: 1;
}

.universe-open .universe-drawer {
  translate: 0 0;
}

.universe-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}

.universe-head h2 {
  font-size: 31px;
}

.universe-head button {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--text);
  background: transparent;
  font-size: 20px;
  cursor: pointer;
}

.universe-intro {
  max-width: 340px;
  margin: 16px 0 23px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.55;
}

.universe-list {
  position: relative;
  display: grid;
}

.universe-list::before {
  content: "";
  position: absolute;
  top: 20px;
  bottom: 20px;
  left: 7px;
  width: 1px;
  background: linear-gradient(var(--accent), var(--line) 28%, var(--line) 72%, var(--accent));
}

.universe-link {
  --entry-accent: var(--accent);
  position: relative;
  display: grid;
  grid-template-columns: 16px 1fr auto;
  align-items: center;
  gap: 12px;
  min-height: 50px;
  padding: 7px 5px;
  color: inherit;
  text-decoration: none;
}

.universe-node {
  position: relative;
  z-index: 1;
  width: 7px;
  height: 7px;
  border: 1px solid var(--entry-accent);
  border-radius: 50%;
  background: #0b0f15;
  transition:
    background 160ms ease,
    box-shadow 160ms ease,
    scale 160ms ease;
}

.universe-link:hover .universe-node,
.universe-link.current .universe-node {
  scale: 1.35;
  background: var(--entry-accent);
  box-shadow: 0 0 12px var(--entry-accent);
}

.universe-link-copy strong,
.universe-link-copy small {
  display: block;
}

.universe-link-copy strong {
  font-size: 12px;
  transition: color 160ms ease;
}

.universe-link-copy small {
  margin-top: 2px;
  color: var(--faint);
  font: 9px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.universe-link:hover strong,
.universe-link.current strong {
  color: var(--entry-accent);
}

.universe-arrow {
  color: var(--faint);
  font: 8px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.08em;
}

.universe-foot {
  margin: 24px 0 0;
  color: var(--faint);
  font: 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.mobile-actions {
  display: none;
}

@keyframes live-pulse {
  0%,
  100% {
    opacity: 0.7;
    scale: 0.85;
  }
  50% {
    opacity: 1;
    scale: 1;
  }
}

@media (max-width: 1040px) {
  .topbar {
    grid-template-columns: 210px 1fr auto;
  }

  .studio {
    grid-template-columns: 220px minmax(320px, 1fr) 250px;
  }

  .universe-trigger > span:first-child {
    display: none;
  }
}

@media (max-width: 760px) {
  :root {
    --topbar: 52px;
  }

  .topbar {
    grid-template-columns: 1fr auto auto;
    gap: 7px;
    padding: 0 8px;
  }

  .instrument-brand small,
  .scenario-picker span,
  .tool-button .play-label {
    display: none;
  }

  .scenario-picker {
    min-width: 0;
    width: 122px;
    height: 32px;
  }

  .tool-button.primary {
    width: 34px;
    justify-content: center;
    padding: 0;
  }

  #resetButton,
  #shareButton {
    display: none;
  }

  .universe-trigger {
    width: 34px;
    justify-content: center;
    padding: 0;
  }

  .studio {
    position: relative;
    display: block;
  }

  .experiment-rail {
    position: fixed;
    z-index: 35;
    left: 8px;
    bottom: calc(59px + env(safe-area-inset-bottom));
    width: min(360px, calc(100vw - 16px));
    max-height: min(74svh, 640px);
    border: 1px solid var(--line-strong);
    border-radius: 10px;
    box-shadow: 0 22px 70px rgba(0, 0, 0, 0.5);
    translate: 0 calc(100% + 90px);
    transition: translate 220ms cubic-bezier(0.2, 0.7, 0.2, 1);
  }

  .mobile-guide-open .experiment-rail {
    translate: 0 0;
  }

  .workspace {
    width: 100%;
    height: 100%;
  }

  .inspector {
    position: fixed;
    z-index: 35;
    right: 8px;
    bottom: calc(59px + env(safe-area-inset-bottom));
    width: min(320px, calc(100vw - 16px));
    max-height: min(68svh, 580px);
    border: 1px solid var(--line-strong);
    border-radius: 10px;
    box-shadow: 0 22px 70px rgba(0, 0, 0, 0.5);
    translate: 0 calc(100% + 80px);
    transition: translate 220ms cubic-bezier(0.2, 0.7, 0.2, 1);
  }

  .mobile-inspector-open .inspector {
    translate: 0 0;
  }

  .mobile-actions {
    position: fixed;
    z-index: 40;
    left: 50%;
    bottom: calc(10px + env(safe-area-inset-bottom));
    display: flex;
    align-items: center;
    gap: 6px;
    translate: -50% 0;
    padding: 4px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: rgba(7, 10, 15, 0.82);
    box-shadow: 0 10px 32px rgba(0, 0, 0, 0.36);
    backdrop-filter: blur(14px);
  }

  .mobile-actions button {
    height: 35px;
    padding: 0 11px;
    border: 1px solid var(--line-strong);
    border-radius: 999px;
    color: var(--text);
    background: rgba(12, 17, 24, 0.92);
    font-size: 10px;
  }

  .mobile-panel-toggle,
  .mobile-guide {
    border-color: color-mix(in srgb, var(--accent) 44%, var(--line)) !important;
    background: color-mix(in srgb, var(--accent) 12%, #0c1118) !important;
  }

  .workspace-hud.bottom-left {
    bottom: 58px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
