:root {
  --bg: #f4f2ee;
  --panel: #ffffff;
  --ink: #16181d;
  --muted: #6b6f78;
  --line: #e3e0da;
  --field: #f7f6f3;
  --accent: #e8463a;
  --accent-ink: #ffffff;
  --stage: #dcd8d0;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121316; --panel: #1b1d22; --ink: #eceef2; --muted: #9399a4;
    --line: #2c2f36; --field: #23262c; --stage: #0b0c0e; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121316; --panel: #1b1d22; --ink: #eceef2; --muted: #9399a4;
  --line: #2c2f36; --field: #23262c; --stage: #0b0c0e; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 800; font-size: 20px; letter-spacing: -0.02em; display: flex; align-items: center; gap: 8px; }
.logo {
  display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 8px;
  background: var(--accent); color: var(--accent-ink); font-size: 16px; transform: rotate(-20deg);
}
.title-input {
  flex: 1; max-width: 420px; border: 1px solid transparent; background: var(--field);
  border-radius: 8px; padding: 7px 10px;
}
.title-input:focus { border-color: var(--accent); outline: none; }
.top-actions { margin-left: auto; display: flex; gap: 6px; }
.ghost {
  background: none; border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; cursor: pointer;
}
.ghost:hover { background: var(--field); }
.file-btn { cursor: pointer; }

.layout { flex: 1; display: flex; min-height: 0; }
.sidebar {
  width: 340px; flex: none; overflow-y: auto; background: var(--panel);
  border-right: 1px solid var(--line); padding: 14px 16px 24px;
}
.sidebar section, .sidebar details { border-bottom: 1px solid var(--line); padding-bottom: 14px; margin-bottom: 14px; }
h2, summary { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 0 0 10px; }
summary { cursor: pointer; }
details[open] summary { margin-bottom: 10px; }

.search { position: relative; }
.search input {
  width: 100%; padding: 9px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--field);
}
.search input:focus { outline: none; border-color: var(--accent); }
.results {
  position: absolute; z-index: 10; left: 0; right: 0; top: calc(100% + 4px); list-style: none; margin: 0; padding: 4px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.15);
}
.results li { padding: 7px 9px; border-radius: 6px; cursor: pointer; display: flex; flex-direction: column; }
.results li:hover, .results li:focus { background: var(--field); outline: none; }
.results small { color: var(--muted); }

.row-between { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin: 8px 0; flex-wrap: wrap; }
.check { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.muted { color: var(--muted); }

.places { list-style: none; margin: 10px 0 0; padding: 0; }
.place { display: flex; align-items: center; gap: 4px; }
.place .num {
  flex: none; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink); font-size: 12px; font-weight: 700; cursor: pointer;
}
.place input {
  flex: 1; min-width: 0; border: 1px solid transparent; background: none; border-radius: 6px; padding: 5px 6px; font-weight: 600;
}
.place input:hover { background: var(--field); }
.place input:focus { border-color: var(--accent); outline: none; background: var(--field); }
.icon-btn { background: none; border: 0; width: 26px; height: 26px; border-radius: 6px; color: var(--muted); }
.icon-btn:hover:not(:disabled) { background: var(--field); color: var(--ink); }
.icon-btn:disabled { opacity: .3; cursor: default; }
.leg {
  margin: 2px 0 2px 11px; padding: 4px 0 4px 20px; border-left: 2px dashed var(--line);
  display: flex; align-items: center; gap: 6px;
}
.leg select { padding: 3px 6px; border-radius: 6px; border: 1px solid var(--line); background: var(--field); font-size: 13px; }
.chip { font-size: 11px; border: 0; border-radius: 999px; padding: 2px 8px; background: var(--field); color: var(--muted); }

.grid { display: grid; gap: 10px; }
.grid label:not(.check) { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.grid label { position: relative; }
.grid label span[data-out] { position: absolute; right: 0; top: 0; color: var(--ink); font-variant-numeric: tabular-nums; }
.grid select, .grid input[type="file"] {
  padding: 6px 8px; border-radius: 6px; border: 1px solid var(--line); background: var(--field); color: var(--ink);
}
.grid input[type="color"] { width: 100%; height: 32px; padding: 2px; border: 1px solid var(--line); border-radius: 6px; background: var(--field); }
input[type="range"] { accent-color: var(--accent); width: 100%; }
input[type="checkbox"] { accent-color: var(--accent); }

.primary {
  margin-top: 14px; width: 100%; padding: 11px; border: 0; border-radius: 9px;
  background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 15px;
}
.primary:hover { filter: brightness(1.06); }
.progress-wrap { display: grid; gap: 4px; margin-top: 8px; }
progress { width: 100%; accent-color: var(--accent); }
.status { color: var(--muted); font-size: 13px; min-height: 1em; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--stage); }
.stage { flex: 1; min-height: 0; display: grid; place-items: center; padding: 16px; }
.frame { position: relative; overflow: hidden; border-radius: 6px; box-shadow: 0 10px 40px rgba(0,0,0,.25); background: #0b1020; }
#map { position: absolute; inset: 0; }
.overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.transport {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--panel); border-top: 1px solid var(--line);
}
.play {
  width: 38px; height: 38px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink); font-size: 14px; flex: none;
}
.time { font-variant-numeric: tabular-nums; color: var(--muted); min-width: 88px; text-align: right; }

body.locked .sidebar, body.locked .transport, body.locked .topbar { pointer-events: none; }
body.locked .sidebar > :not(details:last-of-type) { opacity: .5; }
body.locked .frame { pointer-events: none; }
body.locked .maplibregl-ctrl { display: none; }

@media (max-width: 800px) {
  .layout { flex-direction: column-reverse; }
  .sidebar { width: 100%; border-right: 0; border-top: 1px solid var(--line); flex: 1; }
  .main { flex: none; height: 52vh; }
  .title-input { display: none; }
  .topbar { padding: 10px 16px; }
}

body { font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
optgroup { font-weight: 700; }
.dialog {
  width: min(520px, calc(100vw - 32px)); border: 1px solid var(--line); border-radius: 14px;
  background: var(--panel); color: var(--ink); padding: 20px 22px; box-shadow: 0 24px 64px rgba(0,0,0,.35);
}
.dialog::backdrop { background: rgba(10, 12, 16, .45); }
.dialog h2 { font-size: 16px; text-transform: none; letter-spacing: 0; color: var(--ink); }
.keys-fields { display: grid; gap: 14px; margin: 16px 0; }
.key-field { display: grid; gap: 4px; }
.key-field span { display: flex; justify-content: space-between; }
.key-field a { color: var(--accent); font-size: 12px; }
.key-field input { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--field); }
.key-field input:focus { outline: none; border-color: var(--accent); }
.key-field small { color: var(--muted); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.primary.small { width: auto; margin: 0; padding: 7px 16px; font-size: 14px; }
#cancel-export { justify-self: start; }
body.locked #cancel-export { pointer-events: auto; }

.export-rig { position: fixed; left: -100000px; top: 0; pointer-events: none; }
.export-rig canvas:not(.maplibregl-canvas) { display: none; }
.primary:disabled { opacity: .55; cursor: progress; filter: none; }

.places { position: relative; }
.place { border-radius: 8px; cursor: grab; touch-action: none; user-select: none; background: var(--panel); }
.place input { cursor: text; user-select: text; }
.grip { color: var(--muted); opacity: .45; font-size: 13px; width: 12px; flex: none; text-align: center; }
.place:hover .grip { opacity: 1; }
.place.dragging { position: relative; z-index: 5; cursor: grabbing; box-shadow: 0 6px 18px rgba(0,0,0,.18); opacity: .95; }
body.sorting, body.sorting * { cursor: grabbing !important; }
.drop-indicator { position: absolute; left: 0; right: 0; height: 3px; border-radius: 2px; background: var(--accent); pointer-events: none; }
