:root {
  --page: #f9f9f7; --surface: #fcfcfb; --ink: #0b0b0b; --ink2: #52514e; --muted: #898781;
  --line: #e1e0d9; --axis: #c3c2b7;
  --b0: #2a78d6; --b1: #eb6834; --b2: #1baf7a; --b3: #eda100; --b4: #e87ba4; --b5: #6250d6;
  --bad: #d03b3b; --good: #0ca30c;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --page: #0d0d0d; --surface: #1a1a19; --ink: #f0efec; --ink2: #c3c2b7; --muted: #898781;
    --line: #2c2c2a; --axis: #383835;
    --b0: #3987e5; --b1: #d95926; --b2: #199e70; --b3: #c98500; --b4: #d55181; --b5: #9085e9;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--page); color: var(--ink); font: 13px/1.4 system-ui, sans-serif; display: flex; flex-direction: column; }
header { display: flex; align-items: center; gap: 16px; padding: 8px 16px; border-bottom: 1px solid var(--line); background: var(--surface); flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 15px; }
.clock { color: var(--ink2); font-variant-numeric: tabular-nums; }
.controls { margin-left: auto; display: flex; gap: 12px; align-items: center; }
.controls a { color: var(--ink2); }
button, select { font: inherit; background: var(--surface); color: var(--ink); border: 1px solid var(--axis); border-radius: 6px; padding: 3px 8px; cursor: pointer; }
main { flex: 1; display: grid; grid-template-columns: 1fr 380px; min-height: 0; }
.mapwrap { position: relative; min-height: 0; overflow: hidden; background: #6d8a4e; }
canvas { display: block; width: 100%; height: 100%; cursor: grab; }
canvas.dragging { cursor: grabbing; }
.hover { position: absolute; pointer-events: none; background: var(--surface); color: var(--ink); border: 1px solid var(--axis); border-radius: 6px; padding: 6px 8px; font-size: 12px; box-shadow: 0 2px 8px rgb(0 0 0 / .2); max-width: 260px; }
.legend { position: absolute; left: 8px; bottom: 8px; background: color-mix(in srgb, var(--surface) 88%, transparent); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; font-size: 11px; color: var(--ink2); display: flex; flex-wrap: wrap; gap: 4px 10px; max-width: 70%; }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }
aside { border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; padding: 10px; gap: 10px; overflow: hidden; }
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; }
.tile b { display: block; font-size: 16px; font-variant-numeric: tabular-nums; }
.tile span { color: var(--ink2); font-size: 11px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 10px; }
.card h2 { font-size: 13px; margin: 0; }
.feed { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.feedhead { display: flex; flex-direction: column; gap: 6px; }
.filters { display: flex; flex-wrap: wrap; gap: 4px; }
.filters label { font-size: 11px; color: var(--ink2); border: 1px solid var(--line); border-radius: 10px; padding: 1px 7px; cursor: pointer; user-select: none; }
.filters input { display: none; }
.filters label.on { color: var(--ink); border-color: var(--axis); background: color-mix(in srgb, var(--ink) 6%, transparent); }
#events { list-style: none; margin: 8px 0 0; padding: 0; overflow-y: auto; flex: 1; }
#events li { padding: 4px 2px; border-bottom: 1px solid var(--line); cursor: pointer; }
#events li:hover { background: color-mix(in srgb, var(--ink) 5%, transparent); }
#events time { color: var(--muted); font-variant-numeric: tabular-nums; margin-right: 6px; font-size: 11px; }
#events .who { font-weight: 600; }
#events .k-death { color: var(--bad); }
#events .k-born { color: var(--good); }
#events .k-chronicle { display: block; background: color-mix(in srgb, var(--b3) 12%, transparent); border-radius: 6px; padding: 6px 8px; margin-top: 2px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; vertical-align: 0; }
#inspect h2 { display: flex; align-items: center; gap: 6px; font-size: 15px; }
#inspect .close { margin-left: auto; border: 0; background: none; color: var(--muted); font-size: 16px; }
#inspect .sub { color: var(--ink2); margin: 2px 0 8px; }
#inspect dl { display: grid; grid-template-columns: 110px 1fr; gap: 2px 8px; margin: 0; }
#inspect dt { color: var(--muted); }
#inspect dd { margin: 0; }
.bar { display: inline-block; height: 6px; border-radius: 3px; background: var(--axis); width: 80px; position: relative; overflow: hidden; vertical-align: 1px; margin-right: 4px; }
.bar > i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--b0); border-radius: 3px; }
.bar.hot > i { background: var(--bad); }
@media (max-width: 800px) {
  /* On a phone the page scrolls: the map on top, the tiles and the event feed below it. */
  html, body { height: auto; }
  body { display: block; }
  header { padding: 8px 16px; gap: 8px; }
  .controls { margin-left: 0; }
  main { display: block; }
  .mapwrap { height: 55vh; }
  aside { border-left: 0; border-top: 1px solid var(--line); overflow: visible; min-height: auto; }
  .feed { flex: none; min-height: auto; }
  #events { flex: none; max-height: 70vh; }
}

.icon { vertical-align: -3px; margin-right: 3px; image-rendering: pixelated; }

/* Control panel and catalog */
#control, #catalog { max-height: 60vh; overflow-y: auto; }
#control h3, #catalog h3 { font-size: 12px; margin: 10px 0 4px; color: var(--ink2); text-transform: uppercase; letter-spacing: .04em; }
#control .row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 4px 0; }
#control input[type=text], #control input[type=password], #control input[type=number] { font: inherit; background: var(--surface); color: var(--ink); border: 1px solid var(--axis); border-radius: 6px; padding: 3px 6px; width: 120px; }
#control input[type=number] { width: 60px; }
#control input[type=range] { width: 90px; }
#control label { color: var(--ink2); font-size: 12px; }
#control .note { color: var(--muted); font-size: 11px; }
#control .result { margin-top: 6px; font-size: 12px; }
#control .result.bad { color: var(--bad); }
#control .result.good { color: var(--good); }
.pixed { display: grid; grid-template-columns: repeat(8, 18px); gap: 1px; background: var(--line); width: max-content; border: 1px solid var(--line); }
.pixed div { width: 18px; height: 18px; background: var(--surface); cursor: pointer; }
.props { display: grid; grid-template-columns: 90px 1fr; gap: 2px 8px; font-size: 12px; }
#catalog .item { display: flex; gap: 6px; align-items: baseline; padding: 3px 0; border-bottom: 1px solid var(--line); font-size: 12px; }
#catalog .item b { font-weight: 600; }
#catalog .item span { color: var(--ink2); }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; vertical-align: -1px; margin-right: 4px; border: 1px solid var(--line); }
canvas.aiming { cursor: crosshair; }
#events .k-hand { display: block; background: color-mix(in srgb, var(--b5) 14%, transparent); border-left: 3px solid var(--b5); border-radius: 4px; padding: 4px 8px; }

.multi summary { cursor: pointer; font-size: 12px; color: var(--ink2); border: 1px solid var(--axis); border-radius: 6px; padding: 3px 8px; list-style: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.multi summary::after { content: ' ▾'; }
.multi[open] summary::after { content: ' ▴'; }
.multilist { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 10px; padding: 6px 4px; font-size: 12px; }
.multilist label { display: flex; gap: 6px; align-items: center; cursor: pointer; }
.multilist input { display: inline-block !important; }
.multiall { grid-column: 1 / -1; display: flex; gap: 6px; margin-bottom: 4px; }
.filters .multilist label { border: 0; padding: 0; border-radius: 0; color: var(--ink); }
.multi { min-width: 0; max-width: 100%; }
.multi summary { max-width: 100%; box-sizing: border-box; }
aside, .feed, .feedhead, #filters { min-width: 0; }

#ideas { max-height: 70vh; overflow-y: auto; }
#ideas textarea { width: 100%; box-sizing: border-box; font: inherit; background: var(--surface); color: var(--ink); border: 1px solid var(--axis); border-radius: 6px; padding: 6px; margin: 6px 0; }
#ideas input[type=text] { font: inherit; background: var(--surface); color: var(--ink); border: 1px solid var(--axis); border-radius: 6px; padding: 3px 6px; flex: 1; min-width: 0; }
#ideas .row { display: flex; gap: 6px; }
#ideas h3 { font-size: 12px; margin: 10px 0 4px; color: var(--ink2); text-transform: uppercase; letter-spacing: .04em; }
#ideas .note { color: var(--muted); font-size: 11px; }
#ideas .result { font-size: 12px; margin-top: 4px; }
#ideas .result.bad { color: var(--bad); } #ideas .result.good { color: var(--good); }
ol.ideas { list-style: none; margin: 0; padding: 0; }
ol.ideas li { padding: 6px 2px; border-bottom: 1px solid var(--line); font-size: 12px; border-left: 3px solid var(--axis); padding-left: 8px; margin-bottom: 2px; }
ol.ideas li.st-done { border-left-color: var(--good); } ol.ideas li.st-working { border-left-color: var(--b3); }
ol.ideas li.st-rejected, ol.ideas li.st-failed { border-left-color: var(--bad); }
ol.ideas .st { font-weight: 600; }
ol.ideas pre { white-space: pre-wrap; font-size: 11px; max-height: 240px; overflow: auto; background: color-mix(in srgb, var(--ink) 5%, transparent); padding: 6px; border-radius: 4px; }
