:root {
  --bg: #f4f5f7;
  --card: #fff;
  --text: #1c222b;
  --muted: #5b6573;
  --border: #d5dae1;
  --accent: #1d5fb8;
  --danger: #b3261e;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #15181d; --card: #1f242b; --text: #e8ebef; --muted: #9aa5b4; --border: #353d48; --accent: #6ea8f7; --danger: #ff8a80; }
}
* { box-sizing: border-box; }
body { margin: 0; font: 16px/1.45 system-ui, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
header { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--border); }
header:empty { display: none; }
header .brand { font-weight: 700; margin-right: auto; }
main { max-width: 760px; margin: 0 auto; padding: 16px; }
a { color: var(--accent); }
h1 { font-size: 1.4rem; overflow-wrap: anywhere; }
h2 { font-size: 1.1rem; margin-top: 0; }
section { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 16px; margin-bottom: 16px; }
form { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
label { display: flex; flex-direction: column; gap: 4px; font-size: .9rem; color: var(--muted); flex: 1 1 160px; }
input, select, button { font: inherit; min-height: 44px; border-radius: 6px; border: 1px solid var(--border); padding: 8px 12px; background: var(--card); color: var(--text); }
button { cursor: pointer; }
button[type="submit"] { background: var(--accent); border-color: var(--accent); color: var(--card); font-weight: 600; }
button.danger { color: var(--danger); }
button:disabled { opacity: .6; cursor: default; }
ul.list { list-style: none; margin: 0 0 12px; padding: 0; }
ul.list li { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); }
ul.list li > :first-child { margin-right: auto; overflow-wrap: anywhere; }
.muted { color: var(--muted); font-size: .9rem; }
.error { color: var(--danger); flex-basis: 100%; margin: 0; }
.error:empty { display: none; }

/* ----- map editor: fills the whole screen ----- */
body.editing { overflow: hidden; }
body.editing main { max-width: none; padding: 0; }
.editor { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
.topbar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; padding: 6px 10px; background: var(--card); border-bottom: 1px solid var(--border); }
.topbar strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.save-status { margin-left: auto; color: var(--muted); font-size: .85rem; text-align: right; }
.topbar a, .topbar button { white-space: nowrap; }
.topbar .actions { display: flex; align-items: center; gap: 4px; overflow-x: auto; max-width: 100%; }
.topbar .actions button { flex: none; min-height: 38px; padding: 4px 6px; font-size: .9rem; }
.topbar .actions button.arrow { font-size: 1.25rem; min-width: 38px; }
.topbar .actions a { font-size: .9rem; }
.stage { position: relative; flex: 1; min-height: 0; overflow: hidden; }
.map-canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: crosshair; user-select: none; -webkit-user-select: none; }
.readout { position: absolute; left: 8px; bottom: 8px; padding: 2px 8px; border-radius: 4px; background: var(--card); font-size: .8rem; pointer-events: none; }
.readout:empty, .line-bar:empty { display: none; }
.line-bar { position: absolute; top: 28px; left: 50%; transform: translateX(-50%); display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; align-items: center; width: max-content; max-width: calc(100% - 16px); padding: 8px 10px; background: var(--card); border: 1px solid var(--border); border-radius: 8px; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--card); }
.toolbar { background: var(--card); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom); }
.tools, .chips { display: flex; gap: 6px; overflow-x: auto; padding: 6px 10px; }
.tools button, .chips button { flex: none; white-space: nowrap; display: flex; align-items: center; gap: 6px; }
.toolbar button[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 2px var(--accent); font-weight: 600; }
.swatch { width: 18px; height: 18px; border-radius: 4px; border: 1px solid rgba(0, 0, 0, .4); }
.size { flex-direction: row; align-items: center; gap: 10px; padding: 4px 12px 0; max-width: 460px; }
.size input { flex: 1; min-width: 0; padding: 0; }
.size-label { min-width: 4.5em; color: var(--text); }
.hint { margin: 0; padding: 8px 12px 0; color: var(--muted); font-size: .85rem; }
dialog { width: min(420px, 92vw); border: 1px solid var(--border); border-radius: 10px; background: var(--card); color: var(--text); }
dialog::backdrop { background: rgba(0, 0, 0, .5); }
input[type="color"] { width: 100%; padding: 4px; }
.dialog-buttons { display: flex; gap: 8px; justify-content: space-between; }
.selection-title { font-weight: 600; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.selection-note { flex-basis: 100%; max-width: 420px; max-height: 4.4em; overflow: hidden; white-space: pre-wrap; overflow-wrap: anywhere; font-size: .9rem; color: var(--muted); text-align: center; }
.note-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.marker { width: 26px; height: 26px; }
textarea { font: inherit; padding: 8px 12px; border-radius: 6px; border: 1px solid var(--border); background: var(--card); color: var(--text); resize: vertical; }
label.wide { flex-basis: 100%; }
label.check { flex-direction: row; align-items: center; gap: 10px; min-height: 40px; flex: 0 0 auto; color: var(--text); font-size: 1rem; }
label.check input { width: 20px; min-height: 20px; }
.versions { max-height: 45vh; overflow-y: auto; }
@media (min-width: 800px) {
  .chips { flex-wrap: wrap; max-height: 30vh; overflow-y: auto; }
}
.presence { font-size: .85rem; color: var(--accent); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.presence:empty { display: none; }
.presence:not(:empty) + .save-status { margin-left: auto; }
