:root {
  color-scheme: dark;
  --bg: #080a0c;
  --panel: #0d1013;
  --panel-2: #111519;
  --line: #272d32;
  --line-soft: #1a1f23;
  --text: #f2f3ee;
  --muted: #818a90;
  --accent: #d9ff43;
  --accent-dark: #151c00;
  --danger: #ff6b5f;
  --sidebar: 330px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

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

body {
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

button, input { font: inherit; }
button { color: inherit; }

.app-shell {
  width: 100vw;
  height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
  grid-template-rows: 64px minmax(0, 1fr);
  background: var(--bg);
}

.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  padding: 0 18px 0 20px;
  z-index: 10;
  background: rgba(8, 10, 12, .92);
  backdrop-filter: blur(16px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  color: var(--text);
  text-decoration: none;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .16em;
}

.brand-mark { position: relative; display: block; width: 25px; height: 18px; }
.brand-mark i { position: absolute; top: 2px; width: 14px; height: 14px; border: 2px solid var(--text); border-radius: 50%; }
.brand-mark i:first-child { left: 0; }
.brand-mark i:last-child { right: 0; border-color: var(--accent); mix-blend-mode: screen; }

.topbar-actions { display: flex; align-items: center; gap: 8px; }
.scenario-nav-button {
  width: 34px;
  height: 34px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: transparent;
  color: #aeb4b2;
  cursor: pointer;
  transition: .18s ease;
}
.scenario-nav-button:hover { border-color: var(--accent); color: var(--text); }
.scenario-nav-button svg { width: 14px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.status-pill {
  height: 34px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 99px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.status-pill b { color: var(--text); }
#statusDot { width: 6px; height: 6px; margin-right: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 12px var(--accent); }
#statusDot.paused { background: var(--muted); box-shadow: none; }

.icon-button {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 50%;
  cursor: pointer;
  transition: .18s ease;
}
.icon-button:hover { border-color: var(--accent); color: var(--accent); transform: translateY(-1px); }
.icon-button svg { width: 15px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.sidebar {
  min-height: 0;
  overflow-y: auto;
  border-right: 1px solid var(--line);
  background: var(--panel);
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

.intro { padding: 30px 24px 26px; border-bottom: 1px solid var(--line); }
.eyebrow { margin: 0 0 16px; color: var(--accent); font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .16em; }
h1 { margin: 0; font-size: clamp(31px, 3vw, 42px); line-height: .91; letter-spacing: -.06em; font-weight: 780; }
.lede { max-width: 265px; margin: 18px 0 0; color: var(--muted); font-size: 12px; line-height: 1.55; }

.panel { padding: 20px 24px 22px; border-bottom: 1px solid var(--line); }
.section-heading { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; color: var(--muted); font-size: 9px; font-weight: 800; letter-spacing: .16em; }
.section-heading b { color: var(--text); font-weight: 800; }
.section-index { color: #4d565c; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.control-row { display: flex; justify-content: space-between; align-items: center; margin: 16px 0 10px; color: #c6cbca; font-size: 11px; }
.control-row output { min-width: 57px; padding: 4px 7px; border: 1px solid var(--line); border-radius: 4px; color: var(--text); background: #090c0e; text-align: right; font: 10px ui-monospace, SFMono-Regular, Menlo, monospace; }
.value-field {
  min-width: 68px;
  height: 25px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 3px;
  padding: 0 7px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #090c0e;
  transition: .18s ease;
}
.value-field:focus-within { border-color: var(--accent); }
.value-field input {
  width: 38px;
  min-width: 0;
  padding: 0;
  border: 0;
  outline: 0;
  appearance: textfield;
  background: transparent;
  color: var(--text);
  text-align: right;
  font: 10px ui-monospace, SFMono-Regular, Menlo, monospace;
}
.value-field input::-webkit-inner-spin-button,
.value-field input::-webkit-outer-spin-button { margin: 0; appearance: none; }
.value-field small { color: #727a80; font: 8px ui-monospace, SFMono-Regular, Menlo, monospace; }
.measurement-field { min-width: 104px; }
.measurement-field input { width: 72px; }
.name-field { min-width: 144px; }
.name-field input { width: 122px; text-align: left; }
.name-field input::placeholder { color: #505960; }

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(90deg, var(--accent) var(--fill, 30%), #32383d var(--fill, 30%)); }
input[type="range"]::-moz-range-track { height: 2px; background: #32383d; }
input[type="range"]::-moz-range-progress { height: 2px; background: var(--accent); }
input[type="range"]::-webkit-slider-thumb { width: 10px; height: 10px; margin-top: -4px; appearance: none; border: 2px solid var(--bg); border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
input[type="range"]::-moz-range-thumb { width: 8px; height: 8px; border: 2px solid var(--bg); border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 1px var(--accent); }

.primary-button {
  width: 100%;
  height: 44px;
  margin-top: 20px;
  padding: 0 14px 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 0;
  border-radius: 4px;
  background: var(--accent);
  color: #0d1104;
  cursor: pointer;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: .11em;
  transition: .18s ease;
}
.primary-button:hover { background: #e5ff78; transform: translateY(-1px); box-shadow: 0 10px 30px rgba(217,255,67,.10); }
.primary-button.active { background: var(--text); }
.primary-button svg { width: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.hint { margin: 10px 0 0; color: #687178; font-size: 9px; line-height: 1.4; }

.text-button { padding: 0; background: none; border: 0; color: #656d73; font-size: 8px; font-weight: 800; letter-spacing: .12em; cursor: pointer; }
.text-button:hover { color: var(--danger); }
.object-inspector {
  position: absolute;
  top: 18px;
  right: 18px;
  z-index: 6;
  width: 286px;
  padding: 18px 20px 20px;
  border: 1px solid #30373c;
  border-radius: 7px;
  background: rgba(13, 16, 19, .94);
  box-shadow: 0 18px 60px rgba(0, 0, 0, .34);
  backdrop-filter: blur(14px);
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  transition: opacity .18s ease, transform .18s ease, visibility .18s ease;
}
.object-inspector .section-heading { margin-bottom: 16px; }
.object-inspector.empty {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(-8px);
}
.coordinates-heading { margin: 18px 0 9px; color: #656d73; font-size: 8px; font-weight: 800; letter-spacing: .14em; }
.color-heading { margin-bottom: 10px; }
.color-picker {
  display: grid;
  grid-template-columns: repeat(6, 24px);
  justify-content: space-between;
  gap: 10px 8px;
}
.color-swatch {
  position: relative;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 3px solid transparent;
  border-radius: 50%;
  background: var(--swatch);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .1);
  cursor: pointer;
  transition: transform .14s ease, box-shadow .14s ease, border-color .14s ease;
}
.color-swatch:hover { transform: scale(1.1); }
.color-swatch.active {
  border-color: #0d1013;
  box-shadow: 0 0 0 2px #f3f4ef;
}
.color-swatch:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.coordinate-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.coordinate-field { min-width: 0; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 7px 8px; border: 1px solid var(--line-soft); border-radius: 4px; background: #090c0e; color: #8b9397; font: 800 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace; }
.coordinate-field .value-field { min-width: 0; }
.coordinate-field .value-field input { width: 50px; }
.inspector-velocity-button {
  width: 100%;
  height: 36px;
  margin-top: 14px;
  border: 1px solid #59681b;
  border-radius: 4px;
  background: var(--accent-dark);
  color: var(--accent);
  cursor: pointer;
  font: 850 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: .11em;
  transition: border-color .16s ease, background .16s ease, color .16s ease;
}
.inspector-velocity-button:hover { border-color: var(--accent); background: #1a2108; color: #e5ff78; }
.inspector-velocity-button:focus-visible { outline: 1px solid var(--text); outline-offset: 2px; }
.inspector-velocity-button.empty { display: none; }
.velocity-controls.empty { display: none; }
.velocity-section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 18px 0 9px;
}
.velocity-section-heading .coordinates-heading { margin: 0; }
.remove-velocity-button {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 50%;
  background: transparent;
  color: #687178;
  cursor: pointer;
  transition: border-color .16s ease, background .16s ease, color .16s ease;
}
.remove-velocity-button:hover { border-color: #6d302c; background: #251413; color: #ff8a80; }
.remove-velocity-button:focus-visible { outline: 1px solid var(--text); outline-offset: 2px; }
.remove-velocity-button svg { width: 11px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.velocity-control-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; color: #c6cbca; font-size: 11px; }
.velocity-control-row + .velocity-control-row { margin-top: 8px; }
.velocity-value-field { min-width: 94px; }
.velocity-value-field input { width: 54px; }

.mode-list {
  display: grid;
  gap: 6px;
  margin-bottom: 20px;
}
.force-subheading { margin: 0 0 10px; color: #656d73; font-size: 8px; font-weight: 800; letter-spacing: .16em; }
.force-section-block + .force-section-block { margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--line); }
.force-parameters-block .formula { margin-top: 2px; }
.force-mode-list { margin-bottom: 14px; }
.collision-settings { margin-bottom: 20px; }
.collision-settings.hidden { display: none; }
.collision-heading { margin: 0 0 8px; color: #656d73; font-size: 8px; font-weight: 800; letter-spacing: .14em; }
.collision-mode-list { margin-bottom: 0; }
.mode-option {
  min-height: 38px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #090c0e;
  color: #858d91;
  cursor: pointer;
  font-size: 10px;
  transition: border-color .18s ease, color .18s ease, background .18s ease;
}
.mode-option:hover { border-color: #41494f; color: var(--text); }
.mode-option:has(input:checked) { border-color: #59681b; background: var(--accent-dark); color: var(--text); }
.mode-option input { width: 13px; height: 13px; margin: 0; accent-color: var(--accent); cursor: pointer; }
.mode-option input:focus-visible { outline: 1px solid var(--text); outline-offset: 3px; }
.mode-option span { font-weight: 700; letter-spacing: .04em; }

.time-scale-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 10px; }
.time-scale-actions button {
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #090c0e;
  color: #aeb4b2;
  cursor: pointer;
  font: 800 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  transition: border-color .18s ease, color .18s ease, background .18s ease;
}
.time-scale-actions button:hover { border-color: var(--accent); background: var(--accent-dark); color: var(--accent); }
.time-scale-actions button:active { transform: translateY(1px); }
.time-scale-actions button:focus-visible { outline: 1px solid var(--text); outline-offset: 2px; }

.scenario-compose { display: grid; grid-template-columns: minmax(0, 1fr) 38px; gap: 6px; }
.scenario-compose input {
  width: 100%;
  min-width: 0;
  height: 38px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 4px;
  outline: none;
  background: #090c0e;
  color: var(--text);
  font-size: 10px;
  transition: .18s ease;
}
.scenario-compose input::placeholder { color: #596168; }
.scenario-compose input:focus { border-color: var(--accent); }
.scenario-compose button {
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 4px;
  background: var(--accent);
  color: #0d1104;
  cursor: pointer;
}
.scenario-compose button:hover { background: #e5ff78; }
.scenario-compose svg { width: 15px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.scenario-list { display: grid; gap: 6px; margin-top: 12px; }
.scenario-empty { margin: 4px 0 0; color: #687178; font-size: 9px; line-height: 1.45; }
.scenario-card { padding: 10px; border: 1px solid var(--line-soft); border-radius: 4px; background: #0a0d0f; }
.scenario-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.scenario-card-name { overflow: hidden; color: #dfe2de; font-size: 10px; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.scenario-card-meta { margin-top: 4px; color: #60686e; font: 8px/1.35 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .04em; }
.scenario-card-actions { display: grid; grid-template-columns: 1fr auto; gap: 5px; margin-top: 9px; }
.scenario-run,
.scenario-delete { height: 28px; border-radius: 3px; cursor: pointer; font-size: 8px; font-weight: 850; letter-spacing: .1em; transition: .16s ease; }
.scenario-run { border: 1px solid #485113; background: var(--accent-dark); color: var(--accent); }
.scenario-run:hover { border-color: var(--accent); }
.scenario-delete { padding: 0 8px; border: 1px solid var(--line); background: transparent; color: #626a70; }
.scenario-delete:hover { border-color: var(--danger); color: var(--danger); }

.scenario-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 22px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
}
.scenario-modal.visible { opacity: 1; pointer-events: auto; }
.scenario-modal-backdrop { position: absolute; inset: 0; border: 0; background: rgba(2, 4, 5, .78); backdrop-filter: blur(8px); cursor: default; }
.scenario-dialog {
  position: relative;
  width: min(620px, 100%);
  max-height: min(720px, calc(100vh - 44px));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid #30373c;
  border-radius: 8px;
  background: #0d1013;
  box-shadow: 0 30px 100px rgba(0, 0, 0, .55);
  transform: translateY(10px) scale(.985);
  transition: transform .2s ease;
}
.scenario-modal.visible .scenario-dialog { transform: translateY(0) scale(1); }
.scenario-dialog-header { min-height: 92px; padding: 22px 22px 18px; display: flex; align-items: flex-start; justify-content: space-between; border-bottom: 1px solid var(--line); }
.scenario-dialog-header .eyebrow { margin-bottom: 10px; }
.scenario-dialog-header h2 { margin: 0; color: var(--text); font-size: 25px; line-height: 1; letter-spacing: -.04em; }
.scenario-dialog-header h2 span { margin-left: 8px; color: #596168; font: 700 10px ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .1em; vertical-align: middle; }
.scenario-close-button { width: 32px; height: 32px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 50%; background: transparent; color: #7c858a; cursor: pointer; }
.scenario-close-button:hover { border-color: var(--text); color: var(--text); }
.scenario-close-button svg { width: 14px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.scenario-dialog-body { min-height: 0; padding: 18px 22px 22px; overflow-y: auto; }
.scenario-dialog .scenario-compose { grid-template-columns: minmax(0, 1fr) 42px; }
.scenario-dialog .scenario-compose input,
.scenario-dialog .scenario-compose button { height: 42px; }
.scenario-dialog .scenario-list { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 16px; }
.scenario-dialog .scenario-empty { grid-column: 1 / -1; padding: 26px 0; text-align: center; }
body.modal-open { overflow: hidden; }

.formula { margin: 0 0 20px; color: var(--text); font: 500 18px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: -.04em; }
.formula span { color: var(--accent); }

.stage { position: relative; min-width: 0; min-height: 0; overflow: hidden; background: #090b0d; cursor: default; }
.stage::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 20;
  pointer-events: none;
  box-shadow: inset 0 0 0 1px transparent, inset 0 0 24px transparent;
  transition: box-shadow .22s ease;
}
.stage.running::after {
  box-shadow: inset 0 0 0 1px rgba(217, 255, 67, .42), inset 0 0 24px rgba(217, 255, 67, .055);
}
.stage.placing { cursor: crosshair; }
#simulation { display: block; width: 100%; height: 100%; touch-action: none; }
.origin-marker,
.live-coordinates { position: absolute; bottom: 17px; z-index: 4; pointer-events: none; font: 800 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .08em; }
.origin-marker {
  left: 0;
  min-width: 34px;
  padding: 3px 5px;
  color: #697177;
  background: #090b0d;
  text-align: center;
}
.origin-marker.offscreen { display: none; }
.live-coordinates { right: 18px; padding: 7px 9px; border: 1px solid #30373c; border-radius: 4px; background: rgba(13, 16, 19, .88); color: var(--accent); backdrop-filter: blur(10px); }
.live-coordinates.empty { display: none; }
.selection-toolbar {
  position: absolute;
  left: 50%;
  bottom: 18px;
  z-index: 7;
  height: 36px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 5px 0 12px;
  border: 1px solid #394147;
  border-radius: 5px;
  background: rgba(13, 16, 19, .94);
  box-shadow: 0 12px 34px rgba(0, 0, 0, .36);
  color: #b9c0be;
  font: 800 8px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: .11em;
  opacity: 0;
  visibility: hidden;
  transform: translate(-50%, 8px);
  transition: .16s ease;
}
.selection-toolbar.visible { opacity: 1; visibility: visible; transform: translate(-50%, 0); }
.selection-toolbar b { color: var(--accent); }
.selection-toolbar button {
  height: 26px;
  padding: 0 9px;
  border: 0;
  border-radius: 3px;
  background: #251413;
  color: #ff8a80;
  cursor: pointer;
  font: inherit;
  letter-spacing: inherit;
}
.selection-toolbar button:hover { background: #361817; color: #ffb0a9; }
.velocity-context-menu {
  position: absolute;
  z-index: 12;
  width: 148px;
  padding: 4px;
  border: 1px solid #343b40;
  border-radius: 5px;
  background: rgba(13, 16, 19, .98);
  box-shadow: 0 14px 42px rgba(0, 0, 0, .48);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(-4px);
  transition: opacity .12s ease, transform .12s ease, visibility .12s ease;
}
.velocity-context-menu.visible { opacity: 1; visibility: visible; pointer-events: auto; transform: translateY(0); }
.velocity-context-menu button { width: 100%; height: 32px; padding: 0 9px; border: 0; border-radius: 3px; background: transparent; color: #c6cbca; cursor: pointer; text-align: left; font: 800 8px/1 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .1em; }
.velocity-context-menu button:hover,
.velocity-context-menu button:focus-visible { outline: none; background: var(--accent-dark); color: var(--accent); }
.placement-badge { position: absolute; top: 18px; left: 50%; transform: translate(-50%, -10px); padding: 9px 12px; border: 1px solid var(--accent); border-radius: 3px; background: rgba(15, 20, 4, .9); color: var(--accent); font: 800 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .1em; opacity: 0; pointer-events: none; transition: .2s ease; }
.placement-badge.visible { opacity: 1; transform: translate(-50%, 0); }
kbd { margin-left: 8px; padding: 2px 4px; border: 1px solid #5d681d; border-radius: 2px; font: inherit; }

@media (max-width: 760px) {
  body { overflow: auto; }
  .app-shell { height: auto; min-height: 100vh; grid-template-columns: 1fr; grid-template-rows: 56px minmax(52vh, 480px) auto; }
  .topbar { grid-column: 1; grid-row: 1; }
  .stage { grid-row: 2; border-bottom: 1px solid var(--line); }
  .sidebar { grid-row: 3; border-right: 0; overflow: visible; }
  .intro { display: none; }
  .sidebar { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .panel { border-right: 1px solid var(--line); }
  .formula-panel { grid-column: 1 / -1; }
}

@media (max-width: 520px) {
  .app-shell { grid-template-rows: 56px minmax(58vh, 430px) auto; }
  .sidebar { display: block; }
  .panel { border-right: 0; }
  .status-pill { display: none; }
  .scenario-dialog .scenario-list { grid-template-columns: 1fr; }
  .object-inspector { top: 12px; right: 12px; width: min(286px, calc(100% - 24px)); max-height: calc(100% - 24px); overflow-y: auto; }
  .live-coordinates { right: 12px; bottom: 12px; }
  .origin-marker { left: 12px; bottom: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
