:root {
  color-scheme: light;
  --desktop: #303747;
  --panel: #d4d7df;
  --surface: #e3e5ec;
  --highlight: #f7f8fd;
  --edge: #929bad;
  --shadow: #737d90;
  --ink: #20283a;
  --muted: #46516a;
  --accent: #214f69;
  --focus: #125b87;
  --warning: #8b2934;
  --screen: #141b2a;
  --screen-muted: #bac8db;
  --mint: #94e5ba;
  --mono: "Cascadia Mono", "DejaVu Sans Mono", Consolas, monospace;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  min-height: 100vh;
  padding: 18px clamp(8px, 2.5vw, 28px) 32px;
  color: var(--ink);
  background: repeating-linear-gradient(0deg, #343c4d 0 1px, transparent 1px 4px), var(--desktop);
  line-height: 1.45;
}
main {
  max-width: 1560px;
  margin: auto;
  padding: 10px 12px 15px;
  background: var(--panel);
  border: 1px solid #141c2a;
  box-shadow: inset 1px 1px var(--highlight), inset -1px -1px var(--shadow), 4px 5px #19202e;
}
h1, h2, p, dl, dd { margin: 0; }
h1, h2 { font-family: var(--mono); }
h1 { font-size: clamp(.96rem, 2.4vw, 1.27rem); line-height: 1.25; }
h2 { font-size: .92rem; line-height: 1.3; }
a { color: var(--accent); text-underline-offset: .18em; }
button, input, select { font: inherit; }
button {
  min-height: 36px;
  padding: 6px 11px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid;
  border-color: var(--highlight) var(--shadow) var(--shadow) var(--highlight);
  box-shadow: 1px 1px #596478;
  font: 700 .8rem/1.28 var(--mono);
  cursor: pointer;
}
button:hover:not(:disabled) { background: #f0f2f8; }
button:active:not(:disabled), .segmented button[aria-pressed="true"] {
  border-color: var(--shadow) var(--highlight) var(--highlight) var(--shadow);
  box-shadow: inset 1px 1px #63748a;
}
button:disabled { color: #576277; background: #c5c9d4; cursor: default; }
button:focus-visible, input:focus-visible, select:focus-visible, canvas:focus-visible, summary:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.masthead {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 7px 15px;
  padding: 8px 11px;
  margin-bottom: 9px;
  background: #273952;
  color: #f5f7fc;
  border: 1px solid #1a2c44;
  box-shadow: inset 1px 1px #677b99;
}
.starting-state { display: flex; flex-wrap: wrap; align-items: stretch; gap: 5px 12px; }
.starting-state div { padding-inline-start: 8px; border-inline-start: 1px solid #7688a3; }
.starting-state dt { color: #d3dceb; font-size: .74rem; }
.starting-state dd { color: #a6edc9; font: 700 .95rem/1.25 var(--mono); }

.controls, .settings, .map-panel, .detail-card, .method {
  min-width: 0;
  border: 1px solid var(--edge);
  background: var(--surface);
  box-shadow: inset 1px 1px var(--highlight), inset -1px -1px var(--shadow);
}
.controls { padding: 8px 10px; }
.controls-top, .playback, .timeline, .layers, .segmented, .symbols { display: flex; align-items: center; }
.playback { flex-wrap: wrap; gap: 5px; }
.primary { min-width: 105px; color: #18392d; background: #a0ddbf; }
.primary:hover:not(:disabled) { background: #b6e9cf; }
.timeline { gap: 10px; margin-top: 7px; }
.timeline label {
  min-width: 109px;
  padding: 4px 7px;
  border: 1px solid #283549;
  box-shadow: inset 1px 1px #0d1420, inset -1px -1px #35445d;
  color: var(--mint);
  background: var(--screen);
  white-space: nowrap;
  font: .77rem/1.3 var(--mono);
}
.timeline-total { color: var(--screen-muted); }
.track { flex: 1; min-width: 76px; position: relative; }
.track input { width: 100%; display: block; margin: 0; min-height: 27px; accent-color: var(--accent); }
#attraction-tick {
  position: absolute;
  left: calc(9px + (100% - 18px) * var(--attraction-position));
  width: 2px; top: 19px; height: 5px; background: var(--warning); pointer-events: none;
}
.track-key { color: var(--muted); font-size: .75rem; white-space: nowrap; }
.track-key i { display: inline-block; width: 3px; height: 9px; margin-right: 5px; background: var(--warning); }
.video-export {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px;
  padding: 6px 0 0; color: var(--muted); font-size: .83rem;
}
.video-export progress { width: min(150px, 100%); accent-color: var(--accent); }

.settings, .method { margin-top: 8px; }
.settings summary, .method summary {
  padding: 8px 10px;
  color: #263750;
  background: #c5ccda;
  box-shadow: inset 1px 1px #f4f7ff;
  font: 700 .86rem/1.3 var(--mono);
  cursor: pointer;
}
.settings[open] summary, .method[open] summary { border-bottom: 1px solid var(--edge); }
#settings-form { padding: 9px 10px 11px; }
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(225px, 100%), 1fr)); gap: 8px; align-items: start; }
.settings fieldset {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
  margin: 0;
  padding: 8px;
  border: 1px solid var(--edge);
  box-shadow: inset 1px 1px var(--highlight);
  min-width: 0;
}
.settings legend { padding-inline: 4px; font: 700 .76rem/1.3 var(--mono); color: var(--accent); }
.settings label {
  display: flex; flex-direction: column; justify-content: space-between; gap: 3px;
  min-width: 0; font-size: .78rem; color: var(--muted); line-height: 1.25;
}
.settings input, .settings select {
  width: 100%; min-height: 34px; padding: 5px 6px;
  color: var(--ink); background: #f7f8fc;
  border: 1px solid; border-color: var(--shadow) var(--highlight) var(--highlight) var(--shadow);
  box-shadow: inset 1px 1px #dde1ec;
  font: .82rem/1.25 var(--mono);
}
.wide-field, .field-help { grid-column: 1 / -1; }
.distribution-group {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
  padding-block-end: 8px;
  border-block-end: 1px solid var(--edge);
}
.field-help { font-size: .77rem; color: var(--muted); }
.settings-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.settings-actions span { font-size: .79rem; color: var(--muted); }
.settings-chart-link { font-size: .83rem; font-weight: 650; }
.settings-error { margin-top: 6px; color: var(--warning); font-size: .84rem; font-weight: 650; }
.preset-panel { padding: 9px 10px 11px; }
.preset-panel h2 { margin-bottom: 7px; }
#preset-form, .preset-actions { display: flex; flex-wrap: wrap; align-items: end; gap: 5px; }
#preset-form label { flex: 1 1 200px; max-width: 400px; }
.presets-list { list-style: none; margin: 0 0 8px; padding: 0; }
.presets-list li {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center;
  gap: 5px 10px; padding: 6px 0; border-bottom: 1px solid var(--edge);
}
.presets-list strong { overflow-wrap: anywhere; }
.presets-list li > div:first-child { flex: 1 1 330px; min-width: 0; }
.presets-list .support { margin: 3px 0 0; }
.preset-panel .preset-file { margin-top: 8px; max-width: 400px; }

.layers { justify-content: space-between; gap: 7px 12px; flex-wrap: wrap; margin: 10px 0 8px; }
.segmented { flex-wrap: wrap; gap: 5px; }
.segmented button { min-height: 35px; }
.segmented button[aria-pressed="true"] { background: #344f73; color: #f8fbff; }
.option { display: inline-flex; align-items: center; gap: 6px; font-size: .83rem; color: var(--ink); font-weight: 650; }
.option input { width: 17px; height: 17px; margin: 0; accent-color: var(--accent); }

.simulation-layout {
  display: grid;
  grid-template-areas: "map details" "charts charts";
  grid-template-columns: minmax(0, 1.45fr) minmax(260px, 1fr);
  gap: 10px;
  align-items: start;
}
.map-panel { grid-area: map; padding: 3px; }
.panel-heading {
  min-height: 36px; display: flex; align-items: center; justify-content: space-between; gap: 7px;
  padding: 4px 7px; background: #c6cfdf; border: 1px solid #a4afc2;
}
.panel-state { font: .69rem/1.25 var(--mono); color: var(--muted); text-align: right; }
.panel-state.active { color: #184840; font-weight: 700; }
.map-filter {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 4px 8px;
  min-height: 44px; padding: 4px 7px; color: var(--muted); font-size: .79rem;
}
.map-filter button { min-height: 30px; }
.map-filter-actions { display: flex; flex-wrap: wrap; gap: 5px; }
#select-region { display: none; }
#select-region[aria-pressed="true"] { background: #344f73; color: #f8fbff; }
.map-stage { position: relative; isolation: isolate; overflow: hidden; }
.map-brush {
  position: absolute; pointer-events: none;
  border: 2px solid #a4d9ff;
  box-shadow: 0 0 0 1px #141b2a, 0 0 0 100vmax rgba(10, 16, 28, .46);
}
.map-brush.anchor { box-shadow: 0 0 0 1px #141b2a; }
.map-panel canvas {
  display: block; width: 100%; aspect-ratio: 1; height: auto;
  background: var(--screen); cursor: crosshair; outline-offset: -3px;
}
.map-panel canvas:focus-visible { outline-color: #f4e47c; }
.legend {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 7px 12px;
  padding: 8px 9px; background: var(--screen); color: var(--screen-muted); border-top: 1px solid #546481;
}
.scale { width: 224px; max-width: 100%; }
.gradient { height: 8px; width: 100%; border: 1px solid #6c7b96; }
.scale-values { display: flex; justify-content: space-between; font: .71rem/1.3 var(--mono); margin-top: 3px; }
.symbols { flex-wrap: wrap; gap: 5px 11px; font-size: .74rem; }
.symbols span { white-space: nowrap; }
.symbols i { vertical-align: middle; display: inline-block; width: 13px; height: 8px; margin-right: 4px; }
.permanence-key { width: 100%; }
.income-swatch { display: inline-block; width: .72rem; height: .72rem; margin-inline-end: 4px; vertical-align: baseline; }
.symbols .income-swatch { width: .72rem; height: .72rem; }
.symbols .permanence-symbol, .symbols .replacement-symbol, .symbols .new-occupancy-symbol, .symbols .return-symbol {
  width: 10px; height: 10px; background: #c7d5e9;
}
.symbols .permanence-symbol { border: 1px solid #bac8db; }
.symbols .replacement-symbol, .symbols .new-occupancy-symbol, .symbols .return-symbol {
  position: relative;
}
.replacement-symbol::after, .new-occupancy-symbol::after, .return-symbol::after {
  position: absolute; content: ""; width: 5px; height: 5px; top: 2px; right: 2px; background: var(--screen);
}
.new-occupancy-symbol::after, .return-symbol::after { border-radius: 50%; }
.return-symbol::after { background: transparent; outline: 1px solid var(--screen); }
.price-exit-symbol::after { content: "×"; color: #ff7d98; font: 700 1.2rem/.5 var(--mono); }
.empty-symbol { border: 1px solid #60708b; background: #273247; }
.empty-symbol::after { content: ""; display: block; width: 3px; height: 3px; margin: 1.5px auto; background: #e2edf7; }
.zone-symbol { border: 1px dashed #a4e6d0; }
.flow-symbol { border-top: 2px solid #f2e677; margin-top: 6px; }
.symbols .arrival-symbol, .symbols .exit-symbol { width: 7px; height: 7px; }
.arrival-symbol { background: #eef9ff; }
.exit-symbol { background: #ff7d98; }

.details { grid-area: details; display: grid; min-width: 0; gap: 9px; }
.results-panel { grid-area: charts; display: grid; min-width: 0; gap: 9px; }
.trend-panels, .histogram-panels { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
.detail-card { padding: 9px 10px; }
.map-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; margin-top: 8px; }
.map-stats div { min-width: 0; border: 1px solid #728098; background: var(--screen); padding: 5px 6px; }
.map-stats dt { color: #c5d1e1; font-size: .73rem; line-height: 1.25; }
.map-stats dd { font: 700 1.18rem/1.2 var(--mono); color: var(--mint); margin-top: 3px; }
.support { font-size: .83rem; color: var(--muted); margin: 5px 0; }
#rent-chart, #housing-chart { width: 100%; display: block; background: var(--screen); border: 1px solid #78879d; }
#rent-chart { height: 172px; }
#housing-chart { height: 204px; margin-top: 6px; }
.housing-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.housing-stats .rented-stat dd { color: #80d9ef; }
.housing-stats .cumulative-stat dd { color: #d6adff; }
.housing-stats .vacant-stat dd { color: #ffe086; }
.occupied-stat dt::before, .vacant-stat dt::before {
  content: ""; display: inline-block; width: 12px; margin-inline-end: 5px;
  border-top: 2px solid var(--mint); vertical-align: middle;
}
.vacant-stat dt::before { border-top: 2px dashed #ffe086; }
.nucleus-table { margin-top: 6px; }
.nucleus-badge {
  display: inline-grid; place-items: center; min-width: 1.25rem; height: 1.25rem;
  color: #141c29; font: 700 .74rem/1 var(--mono); border: 1px solid #5d687f;
}
.cell-label { font: 700 .77rem/1.35 var(--mono); color: var(--accent); margin: 7px 0 4px; }
.cell-table { border-collapse: collapse; width: 100%; text-align: right; font-size: .79rem; font-variant-numeric: tabular-nums; }
.cell-table th, .cell-table td { border-top: 1px solid #a7afbf; padding: 4px; }
.cell-table td { font-family: var(--mono); }
.cell-table th:first-child { text-align: left; }

.distribution-results { min-width: 0; scroll-margin-top: 8px; }
.distribution-results h2 { margin-bottom: 6px; }
.histogram-panel { --histogram-fill: var(--mint); margin: 0; }
#rent-histogram { --histogram-fill: #ffe086; }
.histogram-panel figcaption { font: 700 .91rem/1.3 var(--mono); }
.histogram-summary { font-size: .84rem; color: var(--muted); margin: 3px 0 6px; }
.histogram-screen { padding: 9px 10px 8px; border: 1px solid #78879d; background: var(--screen); }
.histogram-unit { margin-bottom: 7px; color: #dbe5f2; font: .76rem/1.25 var(--mono); }
.histogram-chart-heading { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 12px; margin-bottom: 7px; }
.histogram-chart-heading .histogram-unit { margin-bottom: 0; }
.histogram-key { display: flex; flex-wrap: wrap; gap: 4px 10px; color: #dbe5f2; font: .76rem/1.25 var(--mono); }
.histogram-key i { display: inline-block; width: 12px; margin-inline-end: 4px; vertical-align: middle; }
.histogram-key-current { height: 8px; background: var(--histogram-fill); }
.histogram-key-baseline { border-top: 2px dashed #eef9ff; }
.histogram-plot {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-rows: 126px auto;
  gap: 5px 7px;
  color: var(--screen-muted);
  font: .71rem/1.2 var(--mono);
}
.histogram-y { display: flex; flex-direction: column; justify-content: space-between; text-align: right; }
.histogram-bars {
  display: grid;
  grid-template-columns: repeat(var(--bin-count), minmax(0, 1fr));
  min-width: 0;
  margin: 0;
  padding: 0;
  list-style: none;
  border: solid #475570;
  border-width: 1px 0;
  background: linear-gradient(#475570, #475570) center / 100% 1px no-repeat;
}
.histogram-bars li { display: flex; position: relative; align-items: flex-end; padding-inline: 1px; min-width: 0; }
.histogram-bars li::after { content: ""; width: 100%; height: var(--bar-height); background: var(--histogram-fill); }
.histogram-bars .has-baseline::before {
  content: ""; position: absolute; inset-inline: 1px; bottom: calc(var(--baseline-height) - 1px);
  border-top: 2px dashed #eef9ff; filter: drop-shadow(0 1px 0 var(--screen)); pointer-events: none;
}
.histogram-bars li:hover::after { background: #eef9ff; }
.histogram-bars .histogram-overflow { --histogram-fill: #d6adff; border-inline-start: 1px dashed #8696ad; }
.histogram-x {
  grid-column: 2;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: start;
  font-variant-numeric: tabular-nums;
}
.histogram-x span:nth-child(2) { text-align: center; }
.histogram-x span:last-child { text-align: right; }
.histogram-x.single-value { display: block; }
.histogram-x.single-value span { display: block; text-align: center; }
.has-overflow .histogram-x { width: calc(100% - 100% / var(--bin-count)); }
.histogram-note { margin-bottom: 0; }
.histogram-playback button { min-width: 105px; }

.method-content { max-width: 830px; padding: 0 11px 12px; }
.method h3 { margin: 13px 0 7px; font: 700 .92rem/1.35 var(--mono); color: var(--accent); }
.method p { margin-top: 6px; color: var(--muted); }
.method-steps { margin: 0; padding-inline-start: 1.5rem; }
.method-steps li { padding-inline-start: .3rem; margin-bottom: 14px; }
.method-steps li::marker { color: var(--accent); font-weight: 700; }
.method-equation {
  background: #f4f6fa; border: 1px solid var(--edge); box-shadow: inset 1px 1px #c4ccda;
  overflow-x: auto; margin-block: 10px; padding: 8px 12px; color: var(--ink);
}
.method-equation math { font-size: 1.15rem; }

@media (min-width: 1100px) {
  .simulation-layout {
    grid-template-areas: "map charts" "details charts";
    grid-template-columns: minmax(0, .88fr) minmax(0, 1.12fr);
    grid-template-rows: auto 1fr;
  }
}
@media (max-width: 700px) {
  body { padding-top: 8px; }
  main { padding: 7px; }
  .simulation-layout {
    grid-template-areas: "map" "details" "charts";
    grid-template-columns: minmax(0, 1fr);
  }
  .track-key { display: none; }
}
@media (max-width: 560px), (any-pointer: coarse) {
  #select-region { display: inline-block; }
  .map-filter button { min-height: 44px; }
}
@media (max-width: 560px) {
  body { padding-inline: 6px; }
  .masthead { padding-inline: 8px; }
  h1 { font-size: 1.12rem; }
  .starting-state { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); width: 100%; gap: 5px; }
  .starting-state div { padding-inline-start: 5px; }
  button, .settings summary, .method summary { min-height: 44px; }
  .settings summary, .method summary { padding-block: 12px; }
  .settings input, .settings select { min-height: 44px; font-size: 1rem; }

  .playback { display: grid; width: 100%; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; }
  .playback button { grid-column: span 2; min-width: 0; padding-inline: 4px; }
  .playback :is(#reset, #export-video) { grid-column: span 3; }
  .track input { min-height: 40px; }
  #attraction-tick { top: 28px; }
  .segmented { display: grid; width: 100%; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .segmented button { min-height: 44px; padding-inline: 5px; }
  .option { min-height: 40px; }
  .map-panel { padding: 2px; }
  .map-filter { padding-block: 6px; }
  .map-filter p { flex: 1 1 90px; }
  .scale { width: 100%; }
  .scale-values { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; overflow-wrap: anywhere; }
  .scale-values :nth-child(2) { text-align: center; }
  .scale-values :last-child { text-align: right; }

  .inspection-card { order: -1; }
  .map-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .permanence-table { table-layout: fixed; font-size: .75rem; }
  .permanence-table th, .permanence-table td { padding-inline: 2px; overflow-wrap: anywhere; }
  .trend-panels, .histogram-panels { grid-template-columns: minmax(0, 1fr); }
  .histogram-x { overflow-wrap: anywhere; }
  .method-equation { padding-inline: 8px; }
  .method-equation math { font-size: 1rem; }
}
@media (max-width: 360px) {
  .playback { grid-template-columns: repeat(2, minmax(0, 1.3fr)) repeat(4, minmax(0, 1fr)); }
  .panel-heading h2 { font-size: .84rem; }
}
