:root {
  color-scheme: dark;
  --bg: #090d18;
  --surface: rgba(17, 23, 39, 0.9);
  --solid: #111727;
  --line: #2d3854;
  --line-strong: #465575;
  --text: #eef2fa;
  --muted: #98a3bb;
  --quiet: #66718c;
  --blue: #6d91ff;
  --cyan: #4bc1bd;
  --yellow: #f2c15c;
  --red: #e66d62;
  --danger: #ff8a80;
  --input: #090e1b;
  --subtle: #0c1220;
  --menu: #0b1120;
  --map-bg: #0b101d;
  --error-bg: #2a171c;
  --success-bg: #102827;
  --track: #20283b;
  --toast-bg: #182138;
  --accent-soft: color-mix(in srgb, var(--blue) 11%, transparent);
  --accent-strong: color-mix(in srgb, var(--blue) 18%, transparent);
  --primary: #3455b7;
  --primary-line: #5878da;
  --primary-hover: #29499f;
  --primary-hover-line: #4668cb;
  --primary-active: #203d8c;
  --font-caption: 10px;
  --font-small: 12px;
  --font-body: 13px;
  --font-control: 12px;
  --sans: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Consolas, monospace;
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #eef2f8;
  --surface: rgba(255, 255, 255, .9);
  --solid: #ffffff;
  --line: #c7d0df;
  --line-strong: #99a9c1;
  --text: #172033;
  --muted: #5f6c82;
  --quiet: #68758a;
  --blue: #315fcf;
  --cyan: #168c8a;
  --yellow: #bd7b00;
  --red: #c94b47;
  --danger: #b52f35;
  --input: #f7f9fc;
  --subtle: #f4f7fb;
  --menu: #ffffff;
  --map-bg: #edf2f8;
  --error-bg: #fff0f0;
  --success-bg: #edf9f7;
  --track: #d8e0ec;
  --toast-bg: #ffffff;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body { background: var(--bg); color: var(--text); font-family: var(--sans); }
button, input, select { color: inherit; font: inherit; }
button { cursor: pointer; transition: background-color .15s, border-color .15s, color .15s; }
button:disabled { cursor: default; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
[hidden] { display: none !important; }

#cube-view { position: fixed; z-index: 0; inset: 0; }
#scene { display: block; width: 100%; height: 100%; touch-action: none; }
#scene.is-interactive { cursor: pointer; }
#map.is-interactive { cursor: pointer; }
.scene-tooltip { position: fixed; z-index: 8; max-width: 220px; padding: 8px 10px; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--solid); box-shadow: 0 8px 24px rgba(0,0,0,.2); color: var(--text); font-size: 11px; line-height: 1.45; pointer-events: none; }
.scene-tooltip strong { display: block; margin-bottom: 2px; font-size: 12px; }
.scene-tooltip span { color: var(--muted); font-family: var(--mono); }
.surface {
  position: fixed;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.34);
  backdrop-filter: blur(14px);
}
.visualization-head { align-items: center; }
.cube-view .visualization-head { display: none; }
.promote-view { width: 26px; height: 26px; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: transparent; color: var(--muted); font: 15px/1 var(--mono); }

.topbar { z-index: 10; top: 14px; right: 14px; left: 14px; height: 54px; padding: 0 8px 0 16px; display: flex; align-items: center; justify-content: space-between; }
.brand { min-width: 0; display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 26px; height: 26px; flex: none; }
.brand-mark path { fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.brand-mark .frame { stroke: var(--blue); }
.brand-mark .axis { stroke: var(--yellow); }
.brand span, .eyebrow { display: block; color: var(--quiet); font: 600 var(--font-caption)/1.35 var(--mono); letter-spacing: 0; }
.brand span { color: var(--muted); letter-spacing: .08em; white-space: nowrap; }
.brand h1 { max-width: 45vw; margin: 0; overflow: hidden; font-size: 16px; line-height: 1.2; text-overflow: ellipsis; white-space: nowrap; }
.actions { display: flex; gap: 6px; }
.icon-command, .square-button, .play {
  border: 1px solid var(--line-strong); background: transparent; border-radius: 7px;
}
.icon-command { height: 36px; padding: 0 11px; display: inline-flex; align-items: center; gap: 7px; }
.icon-command span { font: 17px/1 var(--mono); }
.icon-command b { font-size: var(--font-control); }
button.primary, .icon-command.primary { border-color: var(--primary-line); background: var(--primary); color: white; }
button:hover:not(:disabled) { border-color: var(--blue); background-color: var(--accent-soft); }
button:active:not(:disabled) { background-color: var(--accent-strong); }
button.primary:hover, .icon-command.primary:hover { border-color: var(--primary-hover-line); background-color: var(--primary-hover); color: #fff; }
button.primary:active, .icon-command.primary:active { background-color: var(--primary-active); color: #fff; }

.readout { z-index: 5; left: 14px; bottom: 96px; width: 224px; padding: 14px 16px; }
.age { display: flex; align-items: baseline; gap: 5px; margin-top: 6px; }
.age strong { font: 650 38px/1 var(--mono); font-variant-numeric: tabular-nums; }
.age span { color: var(--muted); font-size: 13px; }
.place { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-size: 15px; }
.place i { width: 9px; height: 9px; flex: none; border-radius: 50%; background: var(--quiet); box-shadow: 0 0 12px currentColor; }
.place strong { min-width: 0; overflow-wrap: anywhere; }
.readout p { margin: 5px 0 0; color: var(--muted); font: var(--font-small)/1.45 var(--sans); }
.readout .current-metric { display: flex; align-items: baseline; gap: 7px; margin-top: 8px; color: var(--muted); }
.current-metric span { min-width: 0; overflow-wrap: anywhere; }
.current-metric strong { flex: none; color: var(--text); font: 650 var(--font-body)/1.3 var(--mono); }
#current-coordinate { color: var(--quiet); font: 10.5px/1.4 var(--mono); }

.overview { z-index: 5; top: 80px; right: 14px; width: 190px; padding: 10px; }
.overview-head { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; justify-content: space-between; margin-bottom: 8px; color: var(--muted); font-size: var(--font-small); }
.overview-head span { font: var(--font-caption) var(--mono); }
#map { display: block; width: 168px; height: 168px; border-radius: 5px; background: var(--map-bg); }
.map-navigation { display: none; }
.legend { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 7px; margin-top: 9px; color: var(--quiet); font: var(--font-caption) var(--mono); }
.legend i { height: 6px; border-radius: 3px; background: linear-gradient(90deg, var(--blue), var(--cyan), var(--yellow), var(--red)); }

.controls { z-index: 6; right: 14px; bottom: 14px; left: 14px; min-height: 66px; padding: 10px 12px; display: flex; align-items: center; gap: 14px; }
.play { width: 40px; height: 40px; flex: none; display: grid; place-items: center; font-size: 14px; }
.timeline { position: relative; min-width: 120px; max-width: 640px; height: 42px; flex: 1 1 420px; }
.timeline-segments { position: absolute; top: 8px; right: 0; left: 0; height: 6px; overflow: hidden; border-radius: 3px; background: var(--track); }
.timeline-segments i { position: absolute; height: 100%; }
.timeline-segments i.gap { opacity: .8; background: repeating-linear-gradient(135deg, rgba(152,163,187,.36) 0 3px, transparent 3px 6px); box-shadow: inset 0 0 0 1px rgba(152,163,187,.18); }
.timeline input { position: absolute; top: 0; width: 100%; height: 22px; margin: 0; appearance: none; background: transparent; }
.timeline input::-webkit-slider-runnable-track { height: 22px; background: transparent; }
.timeline input::-webkit-slider-thumb { width: 16px; height: 16px; margin-top: 3px; appearance: none; border: 2px solid var(--bg); border-radius: 50%; background: white; box-shadow: 0 0 0 1px #aab4ca; }
.timeline input::-moz-range-track { background: transparent; }
.timeline input::-moz-range-thumb { width: 13px; height: 13px; border: 2px solid var(--bg); border-radius: 50%; background: white; }
.timeline-labels { position: absolute; top: 27px; right: 0; left: 0; height: 14px; }
.timeline-labels span { position: absolute; max-width: 76px; overflow: hidden; transform: translateX(-50%); color: var(--quiet); font-size: var(--font-caption); text-overflow: ellipsis; white-space: nowrap; }
.stage-picker { width: clamp(186px, calc(18vw + 26px), 266px); display: flex; align-items: center; gap: 6px; flex: none; color: var(--quiet); font-size: var(--font-caption); }
.stage-picker span { flex: none; }
.stage-picker select { flex: 1; min-width: 0; height: 31px; padding: 0 26px 0 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--input); color: var(--text); font-size: var(--font-control); }
.primary-view-options, .view-options { display: flex; gap: 5px; }
.primary-view-options { gap: 0; padding: 2px; border: 1px solid var(--line); border-radius: 7px; background: var(--input); }
.primary-view-options button, .view-options button { height: 31px; padding: 0 9px; border: 1px solid var(--line); border-radius: 6px; background: transparent; color: var(--muted); font-size: var(--font-control); }
.primary-view-options button { height: 27px; border: 0; }
.view-options { margin-left: auto; }
.primary-view-options button[aria-pressed="true"], .view-options button[aria-pressed="true"] { border-color: var(--blue); background: var(--accent-strong); color: var(--text); }

body[data-primary-view="map"] #map-view { z-index: 0; inset: 0; width: auto; padding: 0; border: 0; border-radius: 0; background: transparent; box-shadow: none; backdrop-filter: none; }
body[data-primary-view="map"] #map-view .overview-head { display: none; }
body[data-primary-view="map"] #map { position: fixed; inset: 0; width: 100%; height: 100%; border-radius: 0; }
body[data-primary-view="map"] #map { touch-action: none; }
body[data-primary-view="map"] #map-view .map-navigation { position: fixed; z-index: 6; top: 80px; left: 14px; display: flex; align-items: center; padding: 4px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); box-shadow: 0 10px 28px rgba(0,0,0,.24); backdrop-filter: blur(14px); }
.map-navigation button { width: 32px; height: 32px; padding: 0; border: 0; border-radius: 5px; background: transparent; color: var(--text); font: 17px/1 var(--mono); }
.map-navigation button:disabled { opacity: .35; cursor: default; }
.map-navigation output { width: 44px; color: var(--muted); font: var(--font-caption)/1 var(--mono); text-align: center; }
.map-navigation button + button { border-left: 1px solid var(--line); border-radius: 0 5px 5px 0; }
body[data-primary-view="map"] #map-view .legend { position: fixed; right: 14px; bottom: 96px; width: 190px; margin: 0; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); box-shadow: 0 14px 40px rgba(0,0,0,.28); backdrop-filter: blur(14px); }
body[data-primary-view="map"] #cube-view { z-index: 5; top: 80px; right: 14px; bottom: auto; left: auto; width: 190px; height: auto; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); box-shadow: 0 14px 40px rgba(0,0,0,.34); backdrop-filter: blur(14px); }
body[data-primary-view="map"] #cube-view .visualization-head { display: flex; justify-content: space-between; height: 18px; margin-bottom: 8px; color: var(--muted); font-size: var(--font-small); }
body[data-primary-view="map"] #scene { width: 168px; height: 168px; border-radius: 5px; }

.backdrop { position: fixed; z-index: 20; inset: 0; background: rgba(3, 6, 12, .64); }
.editor { position: fixed; z-index: 30; top: 0; right: 0; width: min(470px, 100%); height: 100%; overflow: hidden; border-left: 1px solid var(--line); background: var(--solid); box-shadow: -20px 0 60px rgba(0,0,0,.5); }
.editor > header { height: 60px; padding: 0 18px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.editor h2 { margin: 0; font-size: 16px; }
.square-button { width: 32px; height: 32px; font-size: 20px; }
.editor form { height: calc(100% - 60px); display: flex; flex-direction: column; }
.form-body { flex: 1; overflow: auto; padding: 18px; }
.form-body > label, .stage-card label, .dialog label { display: grid; gap: 6px; margin-bottom: 14px; color: var(--muted); font-size: var(--font-small); }
input { min-width: 0; height: 38px; padding: 0 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--input); }
input[aria-invalid="true"] { border-color: var(--danger); }
.section-head { margin: 22px 0 9px; display: flex; align-items: baseline; justify-content: space-between; }
.section-head h3 { margin: 0; font-size: var(--font-body); }
.section-head span { color: var(--quiet); font-size: var(--font-caption); }
.stage-list { display: grid; gap: 8px; }
.stage-card { padding: 11px; border: 1px solid var(--line); border-radius: 7px; background: var(--subtle); }
.stage-card { position: relative; }
.stage-card .stage-main { display: grid; grid-template-columns: minmax(100px, 1fr) 62px 14px 62px 32px; gap: 7px; align-items: end; }
.stage-card label { margin: 0; }
.stage-card .dash { padding-bottom: 11px; color: var(--quiet); text-align: center; }
.stage-card .remove-stage { width: 32px; height: 38px; border: 1px solid var(--line); border-radius: 6px; background: transparent; color: var(--danger); }
.stage-card .remove-stage:hover { border-color: var(--danger); background-color: color-mix(in srgb, var(--danger) 11%, transparent); }
.stage-card .remove-stage:active { background-color: color-mix(in srgb, var(--danger) 18%, transparent); }
.stage-extra { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 7px; margin-top: 8px; }
.city-suggestions { position: absolute; z-index: 4; top: 61px; left: 11px; width: min(310px, calc(100% - 22px)); max-height: 240px; overflow: auto; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--menu); box-shadow: 0 12px 28px rgba(0,0,0,.22); }
.city-suggestions button { width: 100%; min-height: 36px; padding: 6px 9px; display: flex; align-items: center; justify-content: space-between; gap: 8px; border: 0; border-bottom: 1px solid rgba(70,85,117,.45); background: transparent; text-align: left; }
.city-suggestions button:last-child { border-bottom: 0; }
.city-suggestions button span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.city-suggestions button small { flex: none; color: var(--quiet); font: var(--font-caption) var(--mono); }
.add-button { width: 100%; height: 40px; margin-top: 10px; border: 1px dashed var(--line-strong); border-radius: 7px; background: transparent; color: var(--muted); }
.data-credit { margin: 10px 0 0; color: var(--quiet); font-size: var(--font-caption); }
.data-credit a { color: var(--muted); }
.form-errors { margin-top: 12px; padding: 10px; border: 1px solid #9d5559; border-radius: 6px; background: var(--error-bg); color: var(--danger); font-size: 12px; line-height: 1.5; }
.form-errors.valid { border-color: #4f8580; background: var(--success-bg); color: var(--cyan); }
.editor footer { min-height: 64px; padding: 12px 18px; display: flex; align-items: center; justify-content: flex-end; gap: 7px; border-top: 1px solid var(--line); }
.editor footer button, .dialog button { height: 36px; padding: 0 13px; border-width: 1px; border-style: solid; border-radius: 6px; }
.editor footer button:not(.primary), .dialog button:not(.primary) { border-color: var(--line-strong); background: transparent; }
.file-actions { display: flex; gap: 6px; margin-right: auto; }

.dialog { position: fixed; z-index: 31; top: 50%; left: 50%; width: min(440px, calc(100% - 28px)); padding: 20px; transform: translate(-50%, -50%); border: 1px solid var(--line); border-radius: 8px; background: var(--solid); box-shadow: 0 24px 70px rgba(0,0,0,.6); }
.dialog h2 { margin: 0 0 6px; font-size: 16px; }
.dialog p { margin: 0 0 15px; color: var(--muted); font-size: 12px; }
.dialog label { margin-bottom: 15px; }
.dialog > div { display: flex; justify-content: flex-end; gap: 7px; }
.export-view-options { margin: 0 0 18px; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 7px; border: 0; }
.export-view-options legend { margin-bottom: 7px; color: var(--muted); font-size: var(--font-small); }
.export-view-options label { position: relative; margin: 0; }
.export-view-options input { position: absolute; opacity: 0; pointer-events: none; }
.export-view-options span { height: 38px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 6px; color: var(--muted); font-size: var(--font-control); cursor: pointer; transition: background-color .15s, border-color .15s, color .15s; }
.export-view-options label:hover span { border-color: var(--blue); background: var(--accent-soft); }
.export-view-options input:checked + span { border-color: var(--blue); background: var(--accent-strong); color: var(--text); }
.export-view-options input:focus-visible + span { outline: 2px solid var(--blue); outline-offset: 2px; }
.toast { position: fixed; z-index: 50; bottom: 100px; left: 50%; max-width: calc(100% - 28px); padding: 9px 14px; opacity: 0; transform: translate(-50%, 8px); border: 1px solid var(--line-strong); border-radius: 6px; background: var(--toast-bg); font-size: 12px; pointer-events: none; transition: .18s; }
.toast.visible { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 760px) {
  .brand { display: grid; grid-template-columns: auto 1fr; align-items: center; column-gap: 9px; }
  .brand-mark { width: 24px; height: 24px; grid-row: 1 / 3; }
  .brand h1 { margin-top: 1px; max-width: 40vw; }
  .icon-command { width: 36px; padding: 0; justify-content: center; }
  .icon-command b { display: none; }
  .overview { top: 76px; right: 10px; width: 142px; padding: 8px; }
  #map { width: 124px; height: 124px; }
  .readout { left: 10px; bottom: 190px; width: 188px; padding: 12px; }
  .age strong { font-size: 31px; }
  .controls { right: 10px; bottom: 10px; left: 10px; flex-wrap: wrap; gap: 8px; }
  .timeline { max-width: none; order: 2; flex-basis: calc(100% - 48px); }
  .stage-picker { order: 3; width: 102px; }
  .stage-picker span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .primary-view-options { order: 3; width: calc(100% - 110px); }
  .primary-view-options button { flex: 1; }
  .view-options { order: 4; width: 100%; margin-left: 0; }
  .view-options button { flex: 1; }
  body[data-primary-view="map"] #cube-view { top: 76px; right: 10px; width: 142px; padding: 8px; }
  body[data-primary-view="map"] #scene { width: 124px; height: 124px; }
  body[data-primary-view="map"] #map-view .map-navigation { top: 76px; left: 10px; }
  body[data-primary-view="map"] #map-view .legend { right: 10px; bottom: 190px; width: 142px; padding: 8px; }
  .editor { top: auto; bottom: 0; width: 100%; height: min(86%, 760px); border-top: 1px solid var(--line); border-left: 0; }
  .stage-card .stage-main { grid-template-columns: 1fr 54px 10px 54px 32px; }
  .stage-extra { grid-template-columns: 1fr 1fr; }
  .editor footer { flex-wrap: wrap; }
  .file-actions { width: 100%; }
}

@media (max-width: 390px) {
  .overview { width: 126px; }
  #map { width: 108px; height: 108px; }
  .readout { width: 174px; }
}

@media (max-width: 350px) {
  .brand { grid-template-columns: auto minmax(0, 1fr); }
  .brand-mark { grid-row: auto; }
  .brand span { display: none; }
  .brand h1 { max-width: none; }
}

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