:root {
  font-family: system-ui, sans-serif;
  color-scheme: light dark;
  --bg: #f6f5f1;
  --surface: #fbfaf7;
  --field: #ffffff;
  --ink: #1d1d1f;
  --muted: #6b6b70;
  --line: #1d1d1f1f;
  --line-strong: #1d1d1f40;
  --hover: #1d1d1f0f;
  --danger: #c0392b;
  --focus: #2f7fc1;
  --edge: #1d1d1f;
  --grid: #1d1d1f;
  --plane: #4f9dde;
  --line-1: #d9622b;
  --line-2: #2f7fc1;
  --line-3: #2f9b6a;
  --line-4: #8e5bc8;
  --line-5: #c8a12a;
  --line-6: #c84b7a;
  /* Front-page map (static/assets/map.js builds its MapLibre style from these). */
  --map-land: #f1efe9;
  --map-water: #cddfec;
  --map-green: #dde6d2;
  --map-road: #ffffff;
  --map-border: #b9b3a8;
  --map-label: #6b6b70;
  --map-building: #e4e0d6;
  --map-plane-border: #8fc1e6;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #151821;
    --field: #1b1f29;
    --ink: #ecebe6;
    --muted: #9a9aa2;
    --line: #ecebe61f;
    --line-strong: #ecebe640;
    --hover: #ecebe614;
    --danger: #f07167;
    --focus: #6fb4ee;
    --edge: #ecebe6;
    --grid: #ecebe6;
    --plane: #6fb4ee;
    --line-1: #f08a4b;
    --line-2: #5fa8e8;
    --line-3: #4fc28c;
    --line-4: #b48ae8;
    --line-5: #e2c25a;
    --line-6: #ec7aa5;
    --map-land: #161a22;
    --map-water: #0b1119;
    --map-green: #18211c;
    --map-road: #272c37;
    --map-border: #3d4350;
    --map-label: #8c8c95;
    --map-building: #1f232d;
    --map-plane-border: #c3dcf2;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { background: var(--bg); }
body {
  margin: 0; min-height: 100vh; background: var(--bg); color: var(--ink);
  display: flex; flex-direction: column; line-height: 1.5;
}
body.home { height: 100vh; height: 100dvh; overflow: hidden; }
code, .code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.bar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 1rem clamp(1rem, 4vw, 2.5rem);
}
.bar h1 { margin: 0; font-size: clamp(1.1rem, 3.5vw, 1.5rem); font-weight: 650; letter-spacing: -.03em; }
.bar h1 a { color: inherit; text-decoration: none; }
.bar-links { display: flex; align-items: center; gap: 1.25rem; }
.quiet { color: var(--muted); font-weight: 600; font-size: .95rem; text-decoration: none; white-space: nowrap; }
.quiet:hover { color: var(--ink); text-decoration: underline; text-underline-offset: .2em; }
@media (max-width: 34rem) {
  .bar { flex-wrap: wrap; }
  .bar-links { width: 100%; justify-content: space-between; }
}

.button {
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
  padding: .5rem 1rem; border: 1.5px solid currentColor; border-radius: 999px;
  background: none; color: inherit; font: inherit; font-weight: 600; font-size: .95rem;
  text-decoration: none; white-space: nowrap; cursor: pointer;
}
.button:hover, .button.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.button.primary:hover { opacity: .88; }
.button:disabled { opacity: .5; cursor: default; }
.link {
  background: none; border: 0; padding: 0; font: inherit; font-size: .85rem; color: var(--muted);
  text-decoration: underline; text-underline-offset: .2em; cursor: pointer; white-space: nowrap;
}
.button:focus-visible, .link:focus-visible, .bar h1 a:focus-visible, a:focus-visible {
  outline: 2px solid var(--focus); outline-offset: 3px;
}

/* Front page */
.stage { position: relative; flex: 1; min-height: 0; }
.stage canvas, .preview-stage canvas {
  position: absolute; inset: 0; width: 100%; height: 100%;
  display: block; cursor: grab; touch-action: none; outline: none;
}
.stage canvas:active, .preview-stage canvas:active { cursor: grabbing; }
#map { position: absolute; inset: 0; background: var(--map-land); }
#map .maplibregl-canvas { cursor: grab; }
#map .maplibregl-ctrl-attrib { background: color-mix(in srgb, var(--bg) 85%, transparent); color: var(--muted); }
#map .maplibregl-ctrl-attrib a { color: inherit; }
@media (prefers-color-scheme: dark) {
  #map .maplibregl-ctrl-attrib-button { filter: invert(1); }
}

/* Shared page text */
.page-title { font-size: clamp(1.6rem, 4vw, 2.2rem); letter-spacing: -.03em; line-height: 1.2; margin: .5rem 0; }
.page-title:focus { outline: none; }
.lead { color: var(--muted); max-width: 36rem; margin: 0 0 2rem; }
.hint { color: var(--muted); font-size: .92rem; margin: -.35rem 0 1rem; }
.fine { color: var(--muted); font-size: .85rem; margin: 0; }
.fine a { color: inherit; }
.form-error { color: var(--danger); font-weight: 600; margin: 0 0 1rem; }
.tag {
  flex-shrink: 0; font-size: .7rem; letter-spacing: .04em; text-transform: uppercase; line-height: 1.6;
  color: var(--muted); border: 1px solid var(--line-strong); border-radius: 999px; padding: 0 .45rem;
}

/* Add my worldline */
.add {
  display: grid; grid-template-columns: minmax(0, 40rem) minmax(16rem, 1fr); gap: 2.5rem; align-items: start;
  padding: 0 clamp(1rem, 4vw, 2.5rem) 3rem;
}
.step { margin-bottom: 2.25rem; }
.step h3 { font-size: 1.1rem; margin: 0 0 .75rem; }
.fields { display: grid; grid-template-columns: minmax(0, 17rem) minmax(0, 1fr); gap: 1rem; }
.field { display: flex; flex-direction: column; gap: .35rem; min-width: 0; }
.field > label:first-child { font-weight: 600; font-size: .9rem; }
input[type=text], input[type=date], input[type=password] {
  font: inherit; color: inherit; background: var(--field); width: 100%; min-width: 0;
  border: 1px solid var(--line-strong); border-radius: 8px; padding: .55rem .7rem;
}
input:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
input[aria-invalid=true] { border-color: var(--danger); }
input:disabled { opacity: .45; }
.date { display: flex; align-items: center; gap: .6rem; }
.date .year { width: 6.5rem; }
.date .exact { width: auto; flex: 0 1 11rem; }
.check { display: flex; align-items: center; gap: .4rem; font-size: .9rem; }

.place { position: relative; }
.place input { padding-right: 5.5rem; }
.place .badge { position: absolute; right: .55rem; top: 50%; transform: translateY(-50%); pointer-events: none; }
.suggestions {
  position: absolute; z-index: 10; left: 0; right: 0; top: calc(100% + 4px);
  margin: 0; padding: .3rem; list-style: none; max-height: 18rem; overflow-y: auto;
  background: var(--field); border: 1px solid var(--line-strong); border-radius: 8px; box-shadow: 0 8px 24px #0003;
}
.suggestions li {
  display: flex; justify-content: space-between; align-items: baseline; gap: .75rem;
  padding: .45rem .55rem; border-radius: 6px; cursor: pointer;
}
.suggestions li[aria-selected=true], .suggestions li[role=option]:hover { background: var(--hover); }
.suggestions .message { color: var(--muted); cursor: default; }

.chapters { list-style: none; padding: 0; margin: 0 0 1rem; display: grid; gap: 1rem; }
.chapter {
  display: grid; gap: .9rem; padding: 1rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
}
.chapter-head { display: flex; justify-content: space-between; align-items: baseline; }
.chapter h4 { margin: 0; font-size: .95rem; }
.dates { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.trap { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
.submit-row { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem 1rem; margin-bottom: 1.5rem; }

.preview { position: sticky; top: 1rem; }
.preview-label { font-weight: 600; font-size: .9rem; margin: 0 0 .5rem; }
.preview-stage {
  position: relative; height: min(28rem, 60vh);
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
}
.preview-empty { margin-top: .5rem; }

@media (max-width: 52rem) {
  .add { grid-template-columns: 1fr; gap: 1.5rem; }
  .preview { position: static; }
  .preview-stage { height: 15rem; }
}
@media (max-width: 36rem) {
  .fields, .dates { grid-template-columns: 1fr; }
}

/* Saved worldline */
.done, .login, .admin { width: 100%; padding: 0 clamp(1rem, 4vw, 2.5rem) 3rem; }
.done { max-width: 44rem; }
.done a { color: inherit; }
.ids { display: flex; gap: .75rem; align-items: baseline; margin: 0; }
.ids dt { font-weight: 600; }
.ids dd { margin: 0; }
.claim {
  margin: 1.5rem 0; padding: 1.25rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
}
.claim h3 { margin: 0 0 .5rem; }
.claim p { margin: 0 0 .75rem; }
.code {
  font-size: clamp(1rem, 4.2vw, 1.35rem); letter-spacing: .03em; overflow-wrap: anywhere; user-select: all;
  background: var(--field); border: 1px dashed var(--line-strong); border-radius: 8px; padding: .75rem 1rem;
}
.actions { display: flex; flex-wrap: wrap; gap: .6rem; margin-bottom: .75rem; }

/* Admin */
.login form { max-width: 22rem; display: grid; gap: 1rem; }
.admin { max-width: 52rem; }
.tabs { display: flex; flex-wrap: wrap; gap: .4rem; margin: 1rem 0 1.25rem; }
.tabs button {
  font: inherit; font-weight: 600; padding: .4rem .9rem; cursor: pointer;
  background: none; color: var(--muted); border: 1px solid var(--line-strong); border-radius: 999px;
}
.tabs button[aria-selected=true] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.count { font-variant-numeric: tabular-nums; opacity: .75; margin-left: .2rem; }
.items { display: grid; gap: 1rem; }
.item { padding: 1rem 1.1rem; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.item header { display: flex; justify-content: space-between; gap: 1rem; color: var(--muted); font-size: .85rem; margin-bottom: .5rem; }
.item p { margin: 0 0 .5rem; }
.item a { color: inherit; }
.timeline { margin: 0 0 1rem; padding-left: 1.2rem; display: grid; gap: .25rem; }
.timeline .when { font-variant-numeric: tabular-nums; color: var(--muted); margin-right: .5rem; }
.timeline .tag { margin-left: .4rem; }
