:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  --ink: #151b1d;
  --muted: #657174;
  --paper: #ffffff;
  --canvas: #edf2f1;
  --line: #cbd4d2;
  --teal: #087d77;
  --teal-bright: #52d6ca;
  --red: #e34c45;
  --amber: #d48a16;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--canvas);
  color: var(--ink);
}

button,
input,
select { font: inherit; }

button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.45; }

.app-header {
  min-height: 82px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 15px clamp(18px, 3.5vw, 48px);
  border-top: 5px solid var(--ink);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
}

.brand-mark {
  position: relative;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  border-radius: 6px;
  background: var(--ink);
}

.brand-mark span {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--teal-bright);
  left: 8px;
  top: 9px;
}

.brand-mark span:last-child {
  width: 12px;
  height: 12px;
  left: 25px;
  top: 24px;
  background: #ff665d;
  box-shadow: -9px -7px 0 -5px #f5ad3d;
}

.eyebrow,
.section-index {
  margin: 0 0 3px;
  color: #07635e;
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

h1,
h2,
p { margin-top: 0; }

h1 {
  margin-bottom: 0;
  font-size: clamp(1.35rem, 2.5vw, 1.85rem);
  line-height: 1.08;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 1.25rem;
  letter-spacing: 0;
}

.run-state {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  color: #2b393c;
  font-size: 0.84rem;
  font-weight: 700;
}

.run-state span {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #279164;
  box-shadow: 0 0 0 4px rgba(39, 145, 100, 0.12);
}

.run-state.paused span { background: var(--amber); box-shadow: none; }
.run-state.complete span { background: #7a8588; box-shadow: none; }

.workspace {
  width: min(1500px, 100%);
  min-height: calc(100vh - 82px);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(310px, 350px) minmax(0, 1fr);
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
  background: var(--paper);
}

.controls {
  padding: 25px 24px 32px;
  border-right: 1px solid var(--line);
  background: #f8faf9;
}

.section-heading,
.simulation-toolbar {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 19px;
}

.text-button {
  border: 0;
  padding: 8px;
  color: #07635e;
  background: transparent;
  font-size: 0.84rem;
  font-weight: 750;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 13px 11px;
}

label {
  display: grid;
  gap: 6px;
  color: #3f4b4e;
  font-size: 0.84rem;
  font-weight: 680;
}

label b {
  color: var(--muted);
  font-style: italic;
  font-weight: 550;
}

.seed-field { grid-column: 1 / -1; }

input,
select {
  min-width: 0;
  height: 41px;
  padding: 0 10px;
  border: 1px solid #aeb9b7;
  border-radius: 4px;
  color: var(--ink);
  background: var(--paper);
  font-variant-numeric: tabular-nums;
}

input:focus,
select:focus {
  outline: 3px solid rgba(8, 125, 119, 0.17);
  border-color: var(--teal);
}

.switch-row {
  position: relative;
  grid-template-columns: 1fr 42px;
  align-items: center;
  gap: 14px;
  margin: 20px 0;
  padding: 14px 0;
  border-top: 1px solid #e0e6e4;
  border-bottom: 1px solid #e0e6e4;
  cursor: pointer;
}

.switch-row strong,
.switch-row small { display: block; }
.switch-row strong { margin-bottom: 3px; color: var(--ink); }
.switch-row small { color: var(--muted); font-size: 0.75rem; line-height: 1.35; }

.switch-row input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch-row i {
  position: relative;
  width: 42px;
  height: 23px;
  border-radius: 12px;
  background: #a9b5b2;
  transition: background 120ms ease;
}

.switch-row i::after {
  content: "";
  position: absolute;
  width: 17px;
  height: 17px;
  left: 3px;
  top: 3px;
  border-radius: 50%;
  background: white;
  transition: transform 120ms ease;
}

.switch-row input:checked + i { background: var(--teal); }
.switch-row input:checked + i::after { transform: translateX(19px); }
.switch-row input:focus-visible + i { outline: 3px solid rgba(8, 125, 119, 0.2); }

.form-error {
  margin: -6px 0 14px;
  padding: 10px 12px;
  border-left: 3px solid var(--red);
  background: #fff0ef;
  color: #8e2f2a;
  font-size: 0.84rem;
  line-height: 1.4;
}

.primary-button {
  width: 100%;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 5px;
  background: var(--teal);
  color: white;
  font-weight: 780;
}

.primary-button:hover { background: #075f5b; }

.simulation {
  min-width: 0;
  padding: 25px clamp(20px, 3vw, 40px) 24px;
  background:
    linear-gradient(rgba(21, 27, 29, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(21, 27, 29, 0.035) 1px, transparent 1px),
    #f3f6f5;
  background-size: 30px 30px;
}

.toolbar-actions {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.speed-control {
  display: grid;
  gap: 3px;
  font-size: 0.72rem;
  color: var(--muted);
}

.speed-control select {
  width: 78px;
  height: 36px;
}

.tool-button {
  height: 36px;
  padding: 0 13px;
  border: 1px solid #aeb9b7;
  border-radius: 4px;
  background: var(--paper);
  color: var(--ink);
  font-size: 0.84rem;
  font-weight: 700;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(105px, 1fr));
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 6px 6px 0 0;
  overflow: hidden;
  background: var(--paper);
}

.metric {
  min-width: 0;
  min-height: 72px;
  padding: 12px 15px;
  border-right: 1px solid #dce3e1;
}

.metric:last-child { border-right: 0; }
.metric span { display: block; color: var(--muted); font-size: 0.75rem; }
.metric strong {
  display: block;
  margin-top: 5px;
  font-size: 1.45rem;
  line-height: 1;
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
}
.hit-metric strong { color: #c43832; }
.near-metric strong { color: #a86608; }

.canvas-shell {
  position: relative;
  min-height: 420px;
  aspect-ratio: 1.45 / 1;
  border: 1px solid var(--ink);
  border-radius: 0 0 6px 6px;
  overflow: hidden;
  background: #111719;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.canvas-legend {
  position: absolute;
  left: 13px;
  bottom: 12px;
  display: flex;
  gap: 15px;
  padding: 7px 9px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 4px;
  background: rgba(11, 16, 18, 0.78);
  color: #dce8e5;
  font-size: 0.72rem;
  backdrop-filter: blur(4px);
}

.canvas-legend span { display: flex; align-items: center; gap: 6px; }
.canvas-legend i { display: inline-block; width: 9px; height: 9px; border-radius: 50%; }
.particle-key { background: var(--teal-bright); }
.near-key { background: #f1a532; }
.hit-key { background: #ff6258; }

.completion-banner {
  position: absolute;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  min-width: min(310px, 82%);
  padding: 17px 20px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  background: rgba(16, 23, 25, 0.92);
  color: white;
  text-align: center;
  backdrop-filter: blur(8px);
}

.completion-banner strong,
.completion-banner span { display: block; }
.completion-banner span { margin-top: 5px; color: #b9c7c4; font-size: 0.82rem; }

.caveat {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.4;
}

.parameter-manual {
  margin-top: 27px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
}

.manual-heading {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  column-gap: 24px;
  margin-bottom: 17px;
}

.manual-heading .section-index {
  grid-column: 1 / -1;
}

.manual-heading > p:last-child {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.parameter-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin: 0;
  border-top: 1px solid var(--line);
  border-left: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
}

.parameter-list > div {
  min-width: 0;
  padding: 14px 16px 15px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.parameter-list dt {
  margin-bottom: 5px;
  color: var(--ink);
  font-size: 0.88rem;
  font-weight: 780;
}

.parameter-list dd {
  margin: 0;
  color: #536063;
  font-size: 0.86rem;
  line-height: 1.48;
}

code {
  padding: 1px 4px;
  border-radius: 3px;
  background: #e5edeb;
  color: #075f5b;
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 0.9em;
  font-weight: 700;
}

.manual-checks {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin-top: 12px;
  border: 1px solid #aebbb8;
  border-radius: 5px;
  background: #fff;
}

.manual-checks div {
  min-width: 0;
  padding: 13px 15px;
  border-right: 1px solid #dce3e1;
}

.manual-checks div:last-child { border-right: 0; }

.manual-checks strong,
.manual-checks span { display: block; }

.manual-checks strong {
  margin-bottom: 4px;
  color: #075f5b;
  font-size: 0.8rem;
}

.manual-checks span {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.42;
}

[hidden] { display: none !important; }

@media (max-width: 980px) {
  .workspace { grid-template-columns: 300px minmax(0, 1fr); }
  .metrics { grid-template-columns: 1fr 1fr; }
  .metric:nth-child(2) { border-right: 0; }
  .metric:nth-child(-n + 2) { border-bottom: 1px solid #dce3e1; }
  .canvas-shell { aspect-ratio: 1 / 1; }
  .manual-checks { grid-template-columns: 1fr; }
  .manual-checks div { border-right: 0; border-bottom: 1px solid #dce3e1; }
  .manual-checks div:last-child { border-bottom: 0; }
}

@media (max-width: 740px) {
  .app-header { min-height: 74px; padding: 12px 17px; }
  .brand-mark { width: 39px; height: 39px; }
  .workspace { display: block; border: 0; }
  .controls { border-right: 0; border-bottom: 1px solid var(--line); padding: 22px 18px 26px; }
  .simulation { padding: 22px 14px 18px; }
  .simulation-toolbar { align-items: flex-end; }
  .canvas-shell { min-height: 340px; }
  .manual-heading { display: block; }
  .manual-heading > p:last-child { margin-top: 7px; }
}

@media (max-width: 500px) {
  .run-state { display: none; }
  .field-grid { grid-template-columns: 1fr; }
  .seed-field { grid-column: auto; }
  .simulation-toolbar { display: block; }
  .toolbar-actions { margin-top: 14px; }
  .speed-control { margin-right: auto; }
  .metric { padding: 11px; }
  .canvas-shell { aspect-ratio: 0.88 / 1; min-height: 430px; }
  .canvas-legend { gap: 9px; }
  .parameter-list { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .switch-row i,
  .switch-row i::after { transition: none; }
}
