/* IluMap UI — one look, dark only ("Fun", shared with IluBoard): a patterned
   FigJam-like canvas, floating panels with square corners, marker colours,
   sticker badges that tilt, hand-written section labels. The chrome is
   independent of the map's style preset: the preset only colours map content
   (ocean inside the bounds, land, …). See docs/DESIGN.md. */

/* ---------- tokens ---------- */
:root {
  color-scheme: dark;

  /* surfaces */
  --canvas: #18181b;
  --dot: #2c2c33; /* one ink: the ISOM area patterns and point symbols */
  --topo: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='320' height='320' viewBox='0 0 320 320'%3E%3Cg fill='none' stroke='%232c2c33' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cg transform='translate(34 40) rotate(0)'%3E%3Ccircle r='4.5'/%3E%3C/g%3E%3Cg transform='translate(52 58) rotate(0)'%3E%3Ccircle r='4.5'/%3E%3C/g%3E%3Cg transform='translate(30 70) rotate(0)'%3E%3Ccircle r='4.5'/%3E%3C/g%3E%3Cg transform='translate(150 30) rotate(0)'%3E%3Ccircle r='3.2' fill='%232c2c33' stroke='none'/%3E%3C/g%3E%3Cg transform='translate(164 40) rotate(0)'%3E%3Ccircle r='2.2' fill='%232c2c33' stroke='none'/%3E%3C/g%3E%3Cg transform='translate(262 54) rotate(0)'%3E%3Cpath d='M-3.5-3 0 3.5 3.5-3'/%3E%3C/g%3E%3Cg transform='translate(110 118) rotate(0)'%3E%3Cpath d='M-4-2a4 4 0 0 0 8 0'/%3E%3C/g%3E%3Cg transform='translate(220 132) rotate(10)'%3E%3Cpath d='M-3-3 3 3M3-3-3 3'/%3E%3C/g%3E%3Cg transform='translate(48 168) rotate(0)'%3E%3Ccircle r='2.2' fill='%232c2c33' stroke='none'/%3E%3C/g%3E%3Cg transform='translate(292 186) rotate(0)'%3E%3Ccircle r='4.5'/%3E%3C/g%3E%3Cg transform='translate(170 206) rotate(0)'%3E%3Cpath d='M-3.5-3 0 3.5 3.5-3'/%3E%3C/g%3E%3Cg transform='translate(82 252) rotate(0)'%3E%3Cpath d='M-4-2a4 4 0 0 0 8 0'/%3E%3C/g%3E%3Cg transform='translate(240 262) rotate(0)'%3E%3Ccircle r='3.2' fill='%232c2c33' stroke='none'/%3E%3C/g%3E%3Cg transform='translate(252 274) rotate(0)'%3E%3Ccircle r='2.2' fill='%232c2c33' stroke='none'/%3E%3C/g%3E%3Cg transform='translate(130 298) rotate(0)'%3E%3Cpath d='M-3-3 3 3M3-3-3 3'/%3E%3C/g%3E%3Cg transform='translate(30 300) rotate(0)'%3E%3Ccircle r='4.5'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E"); /* ISOM point symbols: large tree, boulders, pit, depression, special feature */
  --panel: #232328; /* sidebars, pills, cards, floating panels */
  --dialog: #25252b;
  --menu: #2d2d34;
  --input: #1b1b1f;
  --surface: var(--panel);
  --surface-2: #1d1d21; /* inset areas: segmented controls, read-out tiles */
  --seg-on: #3b3b43;
  --border: rgba(255, 255, 255, 0.1);
  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-hover: rgba(255, 255, 255, 0.16);
  --row-hover: rgba(255, 255, 255, 0.06);
  --row-active: rgba(255, 255, 255, 0.1);

  /* text */
  --text: #f4f4f6;
  --text-muted: #b9b9c3;
  --text-faint: #85858f;
  --ink: #1c1917; /* dark text on bright fills */

  /* the box of markers */
  --brand: #ffd23f; /* primary buttons, the active tool, the logo */
  --brand-hover: #ffdd6b;
  --violet: #b18cff;
  --blue: #4fb3ff;
  --orange: #ff9b50;
  --yellow: #ffd23f;
  --green: #3ddc97;
  --red: #ff6b5e;
  --pink: #ff85d3;
  --amber: #ffb547;
  --grey: #9b9ba5;
  --select: #0d99ff; /* Figma's selection blue: focus rings, selection on the map */
  --sticky-1: #ffe27a;
  --sticky-2: #9fd6ff;
  --sticky-3: #95eac0;
  --sticky-4: #ffb3e1;

  /* derived */
  --select-ring: color-mix(in srgb, var(--select) 28%, transparent);
  --select-soft: color-mix(in srgb, var(--select) 16%, transparent);
  --blue-soft: color-mix(in srgb, var(--blue) 15%, transparent);
  --green-soft: color-mix(in srgb, var(--green) 16%, transparent);
  --red-soft: color-mix(in srgb, var(--red) 15%, transparent);
  --amber-soft: color-mix(in srgb, var(--amber) 14%, transparent);

  /* character */
  --wiggle: 1; /* how much things tilt: 0 keeps everything straight */
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --font: "Rubik", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  --hand: "Caveat", "Segoe Print", "Comic Sans MS", cursive;
  --hand-w: 600;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Consolas, Menlo, monospace;

  --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 2px 8px rgba(0, 0, 0, 0.16);
  --shadow-lift: 0 12px 26px rgba(0, 0, 0, 0.42), 0 3px 8px rgba(0, 0, 0, 0.3);
  --shadow-float: 0 8px 28px rgba(0, 0, 0, 0.38), 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 20px 56px rgba(0, 0, 0, 0.6), 0 2px 8px rgba(0, 0, 0, 0.3);
  --key: inset 0 -2px 0 rgba(0, 0, 0, 0.2); /* the bottom edge of a chunky key / sticker */
  --backdrop: rgba(10, 10, 12, 0.6);

  --sidebar-w: 232px;
  --rightbar-w: 332px;
  --gap: 10px; /* the canvas between the side panels and the window edge */
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--canvas);
  color: var(--text);
  font: 13px/1.45 var(--font);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
.mono, code, kbd { font-family: var(--mono); }
.muted { color: var(--text-muted); }
.small { font-size: 11.5px; }
.grow { flex: 1; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--select); outline-offset: 1px; }
* { scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, 0.14) transparent; }
::selection { background: color-mix(in srgb, var(--select) 40%, transparent); }

kbd {
  display: inline-block;
  padding: 0 5px;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  font-size: 10.5px;
  line-height: 17px;
  color: var(--text-faint);
  white-space: nowrap;
}

.ico { display: inline-flex; flex: 0 0 auto; }
.ico svg { display: block; }

/* the logo: a yellow sticker, slightly tilted */
.brand-logo {
  width: 26px; height: 26px; flex: 0 0 26px;
  display: inline-grid; place-items: center;
  background: var(--brand); color: var(--ink);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.35);
  transform: rotate(calc(-6deg * var(--wiggle)));
  transition: transform 0.35s var(--spring);
}
.brand-logo .ico svg { width: 16px; height: 16px; stroke-width: 2; }

/* ---------- layout ---------- */
#app {
  --sb: var(--sidebar-w);
  --rb: var(--rightbar-w);
  display: grid;
  grid-template-columns: var(--sb) minmax(0, 1fr) var(--rb);
  height: 100vh;
}
#app.sidebar-closed { --sb: 0px; }
#app.sidebar-closed #sidebar { display: none; }
#app.rightbar-closed { --rb: 0px; }
#app.rightbar-closed #rightbar { display: none; }
#sidebar { grid-column: 1; grid-row: 1; }
#stage { grid-column: 2; grid-row: 1; container-type: size; container-name: stage; }
#rightbar { grid-column: 3; grid-row: 1; }

/* the canvas, like the empty part of an orienteering map: patches of ISOM area patterns from
   ui/backdrop.js (--terrain, a 960px tile) under ISOM point symbols (--topo, 320px); both follow
   the pan (canvas.js sets --pan-*) and keep their size when zooming, so nothing jumps */
#stage {
  position: relative;
  overflow: hidden;
  min-width: 0;
  background-color: var(--canvas);
  background-image: var(--topo), var(--terrain, none);
  background-size: 320px 320px, 960px 960px;
  background-position: var(--pan-x, 0) var(--pan-y, 0);
}
#canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; outline: none; touch-action: none; user-select: none; }
#canvas text { user-select: none; }

/* ---------- side panels: float on the canvas ---------- */
#sidebar, #rightbar {
  position: relative; z-index: 20; /* their shadow falls on the stage */
  display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-float);
}
#sidebar { margin: var(--gap) 0 var(--gap) var(--gap); }
#rightbar { margin: var(--gap) var(--gap) var(--gap) 0; }

/* ---------- sidebar ---------- */
#sidebar { padding: 0 0 2px; }
.sb-head { display: flex; align-items: center; justify-content: space-between; height: 56px; padding: 0 8px 0 10px; flex: 0 0 auto; }
.sb-brand { display: flex; align-items: center; gap: 10px; height: 38px; padding: 0 8px 0 4px; font-size: 17px; font-weight: 700; letter-spacing: -0.01em; }
.sb-brand:hover .brand-logo { transform: rotate(calc(5deg * var(--wiggle))) scale(1.08); }
.sb-actions { display: flex; flex-direction: column; gap: 2px; padding: 2px 8px 4px; flex: 0 0 auto; }
.sb-item {
  display: flex; align-items: center; gap: 10px; width: 100%; height: 36px; padding: 0 10px;
  background: none; border: 0; color: var(--text); text-align: left;
  transition: background 0.12s;
}
.sb-item:hover { background: var(--row-hover); }
.sb-item .ico { color: var(--text-muted); transition: transform 0.25s var(--spring), color 0.12s; }
.sb-item:hover .ico { color: var(--text); transform: rotate(calc(-8deg * var(--wiggle))) scale(1.08); }
.sb-search {
  display: flex; align-items: center; gap: 8px; margin: 2px 0 4px; padding: 0 10px; height: 34px;
  background: var(--input); border: 1px solid var(--border); color: var(--text-faint);
  transition: border-color 0.12s, box-shadow 0.12s;
}
.sb-search:focus-within { border-color: var(--select); box-shadow: 0 0 0 3px var(--select-ring); }
.sb-search-input { flex: 1; min-width: 0; background: none; border: 0; outline: none; padding: 0; color: var(--text); }
.sb-search-input::placeholder { color: var(--text-faint); }
.sb-label { padding: 14px 18px 4px; font-family: var(--hand); font-size: 18px; font-weight: var(--hand-w); line-height: 1.1; color: var(--text-faint); flex: 0 0 auto; }
.sb-list { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 0 8px 8px; display: flex; flex-direction: column; gap: 3px; }
.sb-row {
  display: flex; align-items: center; gap: 4px; min-height: 36px; padding: 0 4px 0 10px;
  cursor: pointer; outline-offset: -2px; transition: background 0.12s;
}
.sb-row:hover { background: var(--row-hover); }
.sb-row.active { background: var(--row-active); box-shadow: inset 2px 0 0 var(--brand); }
.sb-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-linked { color: var(--text-faint); display: inline-flex; }
.sb-linked svg { width: 13px; height: 13px; }
.sb-more { width: 28px; height: 28px; opacity: 0; color: var(--text-muted); }
.sb-row:hover .sb-more, .sb-row.active .sb-more, .sb-more.menu-open, .sb-more:focus-visible { opacity: 1; }
.sb-row.renaming { padding: 0 4px; }
.sb-rename {
  width: 100%; height: 30px; padding: 0 8px; background: var(--input); color: var(--text);
  border: 1px solid var(--select); outline: none; box-shadow: 0 0 0 3px var(--select-ring);
}
.sb-empty { font-family: var(--hand); font-size: 17px; line-height: 1.2; color: var(--text-faint); padding: 2px 10px; margin: 0; }
.sb-foot { flex: 0 0 auto; display: flex; align-items: center; gap: 4px; margin: 0 8px; padding: 6px 0 6px; border-top: 1px dashed var(--border); }
.sb-foot .sb-item { flex: 1 1 auto; min-width: 0; }
.sb-item-label { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* language switcher: compact chip next to Settings */
.sb-lang {
  display: inline-flex; align-items: center; gap: 5px; flex: 0 0 auto; height: 28px; padding: 0 9px 0 7px;
  background: none; border: 1px solid var(--border); color: var(--text-muted);
  font-size: 11.5px; font-weight: 600; letter-spacing: 0.3px;
  transition: background 0.12s, color 0.12s;
}
.sb-lang:hover, .sb-lang.menu-open { background: var(--row-hover); color: var(--text); }
.sb-lang .ico svg { width: 14px; height: 14px; }
.menu-item.checked .ico { color: var(--green); }
/* undo history: scrolls, steps after the current one are dimmed (they are the redo steps) */
.menu-pop.history-menu { max-height: min(460px, calc(100vh - 80px)); overflow-y: auto; overscroll-behavior: contain; }
.history-menu .menu-label { overflow: hidden; text-overflow: ellipsis; }
.history-menu .menu-item.future { color: var(--text-muted); }
.history-menu .menu-item.future:hover { color: var(--text); }
.icon-btn.icon-btn-narrow { width: 20px; margin-left: -4px; }
.icon-btn.icon-btn-narrow .ico svg { width: 13px; height: 13px; }

/* ---------- buttons ---------- */
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto;
  width: 32px; height: 32px; padding: 0;
  background: none; border: 0; color: var(--text-muted);
  position: relative;
  transition: background 0.12s, color 0.12s;
}
.icon-btn:hover:not(:disabled) { background: var(--row-hover); color: var(--text); }
.icon-btn:disabled { opacity: 0.3; cursor: default; }
.icon-btn.off, .icon-btn.dim { color: var(--text-faint); }
.icon-btn.on { color: var(--yellow); }
.icon-btn.accent { color: var(--ink); background: var(--brand); box-shadow: var(--key); }
.icon-btn.accent:hover:not(:disabled) { color: var(--ink); background: var(--brand-hover); }
.icon-btn.danger:hover { color: var(--red); }
.icon-btn.toggle.on { color: var(--blue); background: var(--blue-soft); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 32px; padding: 0 14px;
  background: none; border: 1px solid var(--border); color: var(--text);
  font-weight: 500; white-space: nowrap;
  transition: background 0.12s, transform 0.1s, box-shadow 0.12s;
}
.btn:hover:not(:disabled) { background: var(--row-hover); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn .ico svg { width: 15px; height: 15px; }
.btn-small { height: 28px; padding: 0 10px; font-size: 12px; }
.btn-small .ico svg { width: 14px; height: 14px; }
/* the primary button is a chunky key in the brand colour */
.btn-primary {
  background: var(--brand); border-color: transparent; color: var(--ink); font-weight: 600;
  box-shadow: var(--key), 0 2px 10px color-mix(in srgb, var(--brand) 18%, transparent);
}
.btn-primary:hover:not(:disabled) { background: var(--brand-hover); }
.btn-primary:active:not(:disabled) { transform: translateY(1px); box-shadow: none; }
.btn-primary:disabled { background: var(--row-active); color: var(--text-faint); box-shadow: none; opacity: 1; }
.btn-danger { color: var(--red); }
.btn-danger:hover:not(:disabled) { background: var(--red-soft); }
.dialog .dialog-actions .btn-danger.btn, .btn-danger.btn-primary {
  background: var(--red); border-color: transparent; color: var(--ink); font-weight: 600; box-shadow: var(--key);
}
.dialog .dialog-actions .btn-danger:hover { filter: brightness(1.08); background: var(--red); }
.dialog .dialog-actions .btn-danger:active { transform: translateY(1px); box-shadow: none; }

/* ---------- floating chrome ---------- */
.chrome { z-index: 10; }
.pill {
  display: flex; align-items: center; gap: 2px; padding: 4px;
  background: var(--panel); border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-float);
}
.pill-sep { width: 0; height: 18px; border-left: 1px dashed var(--border); margin: 0 4px; flex: 0 0 auto; }
.pill-btn {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 10px;
  background: none; border: 0; color: var(--text-muted); font-size: 13px; white-space: nowrap;
  transition: background 0.12s, color 0.12s;
}
.pill-btn:hover { background: var(--row-hover); color: var(--text); }
.pill-btn.on { background: var(--blue-soft); color: var(--blue); }
.pill-btn.menu-open { background: var(--row-active); color: var(--text); }
.pill-btn .ico:last-child:not(:first-child) { opacity: 0.6; margin-left: -2px; }
.pill-btn > .ico:first-child, .icon-btn > .ico { transition: transform 0.25s var(--spring); }
.pill-btn:hover > .ico:first-child, .pill .icon-btn:hover:not(:disabled) > .ico { transform: rotate(calc(-8deg * var(--wiggle))) scale(1.08); }

.fab {
  position: absolute; top: 12px; left: 12px;
  display: inline-flex; align-items: center; justify-content: center;
  width: 42px; height: 42px;
  background: var(--panel); border: 1px solid var(--border-subtle); color: var(--text-muted); box-shadow: var(--shadow-float);
  transition: background 0.12s, color 0.12s, transform 0.25s var(--spring);
}
.fab:hover { color: var(--text); background: var(--seg-on); transform: rotate(calc(-4deg * var(--wiggle))); }

#title-pill { position: absolute; top: 12px; left: 12px; max-width: min(360px, calc(50% - 250px)); padding-left: 8px; min-width: 160px; }
#app.sidebar-closed #title-pill { left: 62px; }
#title-pill > .brand-logo { margin-right: 6px; }
#title-pill:hover > .brand-logo { transform: rotate(calc(5deg * var(--wiggle))) scale(1.06); }
.tp-name {
  flex: 1 1 auto; min-width: 0; height: 32px; padding: 0 6px; background: none; border: 0;
  font-size: 15px; font-weight: 700; letter-spacing: -0.01em; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text);
}
.tp-name:hover { background: var(--row-hover); }
.tp-input {
  flex: 1 1 auto; min-width: 0; height: 30px; padding: 0 8px; font-size: 15px; font-weight: 700;
  background: var(--input); border: 1px solid var(--select); outline: none; box-shadow: 0 0 0 3px var(--select-ring);
}
.tp-save { position: relative; }
.tp-dot {
  position: absolute; top: 6px; right: 6px; width: 8px; height: 8px;
  background: var(--amber); box-shadow: 0 0 0 2px var(--panel); opacity: 0; transition: opacity 0.15s;
}
.tp-dot.on { opacity: 1; animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.35); opacity: 0.6; } }

#panel-toggles { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); }
#history-pill { position: absolute; top: 12px; right: 12px; }

/* vertical tool stacks */
.tb-stack {
  position: absolute; top: 50%; transform: translateY(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
#toolbar { left: 12px; }
.tb-group {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px;
  background: var(--panel); border: 1px solid var(--border-subtle); box-shadow: var(--shadow-float);
}
.tb-btn {
  position: relative; display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; padding: 0; border: 0;
  background: none; color: var(--text-muted);
  transition: background 0.12s, color 0.12s, transform 0.25s var(--spring);
}
.tb-btn .ico { transition: transform 0.25s var(--spring); }
.tb-btn:hover:not(:disabled) { background: var(--row-hover); color: var(--text); }
.tb-btn:hover:not(:disabled):not(.active) .ico { transform: rotate(calc(-8deg * var(--wiggle))) scale(1.08); }
.tb-btn:disabled { opacity: 0.3; cursor: default; }
.tb-btn.on, .tb-btn.menu-open { color: var(--blue); background: var(--blue-soft); }
/* Settings in the zoom pill only while the sidebar (which holds it) is collapsed */
#app:not(.sidebar-closed) .zp-settings { display: none; }
/* the active tool is a yellow sticker */
.tb-btn.active { background: var(--brand); color: var(--ink); box-shadow: var(--key); transform: rotate(calc(-4deg * var(--wiggle))); }
.tb-btn.active:hover { background: var(--brand-hover); color: var(--ink); }
.tb-underline {
  position: absolute; left: 9px; right: 9px; bottom: 4px; height: 3px;
  pointer-events: none;
}
.tb-btn.active .tb-underline { box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35); }

/* bottom: layer dock */
/* centred in the free space between the minimap (left) and the zoom pill (right) */
#dock {
  position: absolute; bottom: 12px; left: var(--dock-l, 204px); right: var(--dock-r, 316px);
  width: max-content; margin-inline: auto;
  gap: 8px; padding: 4px 8px 4px 4px; max-width: calc(100% - var(--dock-l, 204px) - var(--dock-r, 316px));
}
.dock-power {
  display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto;
  width: 32px; height: 32px; border: 0; background: var(--surface-2); color: var(--text-faint);
  transition: background 0.12s, color 0.12s;
}
.dock-power.on { color: var(--green); background: var(--green-soft); }
.dock-power:hover { filter: brightness(1.15); }
.dock-label { display: flex; flex-direction: column; min-width: 92px; max-width: 150px; line-height: 1.2; }
.dock-name { font-weight: 600; font-size: 13px; }
.dock-sub { font-size: 11px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dock-sep { width: 0; height: 22px; border-left: 1px dashed var(--border); flex: 0 0 auto; }
.dock-chips { display: flex; align-items: center; gap: 5px; }
/* one sticker per layer: an outline in the layer colour, filled (and tilted) when active */
.chip {
  display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto;
  width: 28px; height: 28px; padding: 0;
  border: 2px solid var(--chip, var(--text-muted)); background: transparent; color: var(--text);
  font-size: 10.5px; font-weight: 700; letter-spacing: 0.2px;
  transition: background 0.12s, transform 0.25s var(--spring);
}
.chip:hover { background: color-mix(in srgb, var(--chip) 22%, transparent); transform: translateY(-1px) rotate(calc(-3deg * var(--wiggle))); }
.chip.active { background: var(--chip); color: var(--chip-text, var(--ink)); box-shadow: var(--key); transform: rotate(calc(-4deg * var(--wiggle))); }
.chip.off { opacity: 0.4; border-style: dashed; }
.dock-typewrap { display: flex; align-items: center; gap: 6px; }
.dock-type {
  height: 28px; max-width: 140px; padding: 0 8px; font-size: 12px;
  background: var(--input); border: 1px solid var(--border); color: var(--text); outline: none;
}
.dock-type:focus { border-color: var(--select); }
.dock-swatch, input[type="color"].swatch {
  -webkit-appearance: none; appearance: none;
  width: 22px; height: 22px; padding: 0; border: 1px solid var(--border); background: none; cursor: pointer; flex: 0 0 auto;
}
.dock-swatch::-webkit-color-swatch-wrapper, input[type="color"].swatch::-webkit-color-swatch-wrapper { padding: 0; }
.dock-swatch::-webkit-color-swatch, input[type="color"].swatch::-webkit-color-swatch { border: 0; }
.dock-swatch::-moz-color-swatch, input[type="color"].swatch::-moz-color-swatch { border: 0; }
.dock-swatch { transform: rotate(calc(-6deg * var(--wiggle))); transition: transform 0.25s var(--spring); }
.dock-swatch:hover { transform: rotate(calc(6deg * var(--wiggle))) scale(1.1); }

/* bottom-left: scale bar + minimap */
#nav-corner { position: absolute; left: 12px; bottom: 12px; display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
#scalebar { padding: 0 2px; font-size: 11px; color: var(--text-muted); pointer-events: none; }
#scalebar .bar { height: 5px; border: 1.5px solid var(--text-muted); border-top: 0; min-width: 10px; }
#scalebar .lbl { text-align: center; font-variant-numeric: tabular-nums; margin-top: 1px; }
.card { background: var(--panel); border: 1px solid var(--border-subtle); box-shadow: var(--shadow-float); }
#minimap { position: relative; width: 180px; height: 120px; overflow: hidden; cursor: crosshair; flex: 0 0 auto; }
#minimap img { position: absolute; left: 0; top: 0; width: 180px; height: 120px; pointer-events: none; }
.mm-ocean { position: absolute; }
.mm-view {
  position: absolute; border: 1.5px solid var(--select); background: color-mix(in srgb, var(--select) 8%, transparent);
  pointer-events: none; box-sizing: border-box;
}

/* bottom-right: toggles + zoom, read-out above */
#zoom-pill { position: absolute; right: 12px; bottom: 12px; }
.zoom-pct {
  min-width: 52px; height: 32px; padding: 0 4px; background: none; border: 0;
  color: var(--text); font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums;
}
.zoom-pct:hover { background: var(--row-hover); }
#coords {
  position: absolute; right: 16px; bottom: 60px; display: flex; gap: 12px; align-items: center;
  font-size: 11px; color: var(--text-muted); white-space: nowrap; pointer-events: none; font-variant-numeric: tabular-nums;
}
#coords .rd-pos { color: var(--text); opacity: 0.8; }
#coords .rd-sel { color: var(--select); font-family: var(--font); font-weight: 600; }

/* tool hint / status above the dock */
.hud {
  position: absolute; left: 50%; bottom: 64px; transform: translateX(-50%);
  width: max-content; max-width: max(min(720px, calc(100% - 460px)), min(360px, calc(100% - 96px))); padding: 6px 12px;
  background: var(--panel); border: 1px solid var(--border-subtle); box-shadow: var(--shadow-float);
  pointer-events: none; text-align: center; font-size: 12px;
}
.hud-status { font-weight: 600; font-variant-numeric: tabular-nums; }
.hud-hint { font-family: var(--hand); font-size: 16px; line-height: 1.15; color: var(--text-muted); }

#drop-hint {
  display: none; position: absolute; inset: 16px; z-index: 40;
  border: 2px dashed var(--brand);
  align-items: center; justify-content: center; text-align: center; padding: 20px;
  font-family: var(--hand); font-size: 28px; font-weight: var(--hand-w); line-height: 1.2;
  background: color-mix(in srgb, var(--canvas) 72%, transparent);
  pointer-events: none;
}
#drop-hint b { color: var(--brand); }
#stage.drop-target.drop-files #drop-hint { display: flex; }
#stage.drop-target:not(.drop-files) #canvas { outline: 2px dashed var(--brand); outline-offset: -6px; }

/* ---------- floating panels ---------- */
.dock-col { position: absolute; display: flex; flex-direction: column; gap: 10px; pointer-events: none; z-index: 5; }
#dock-left { left: 64px; top: 64px; bottom: 180px; align-items: flex-start; }
#float-layer { position: absolute; inset: 0; pointer-events: none; z-index: 6; }
.fpanel {
  pointer-events: auto;
  display: flex; flex-direction: column; flex: 0 1 auto; min-height: 168px; max-height: min(70vh, 100%); max-width: calc(100vw - 32px);
  background: var(--panel); border: 1px solid var(--border-subtle); box-shadow: var(--shadow-float);
  overflow: hidden;
}
.fpanel.floating { position: absolute; max-height: 70vh; }
.fpanel.dragging { box-shadow: var(--shadow-lg); opacity: 0.96; transform: rotate(calc(-0.6deg * var(--wiggle))); }
.fp-head {
  display: flex; align-items: center; gap: 8px; flex: 0 0 auto;
  height: 44px; padding: 0 6px 0 12px; margin: 0 8px 0 0; border-bottom: 1px dashed var(--border);
  cursor: grab; user-select: none;
}
.fpanel.dragging .fp-head { cursor: grabbing; }
.fp-head > .ico { color: var(--text-muted); }
.fp-title { flex: 1; min-width: 0; font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fp-actions { display: flex; align-items: center; gap: 2px; }
.fp-count { font-size: 11.5px; color: var(--text-muted); padding: 0 6px; font-variant-numeric: tabular-nums; }
.fp-pin.on { color: var(--blue); }
.fp-close { width: 28px; height: 28px; }
.fp-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 8px 12px 12px; }
.panel-hint { margin: 2px 2px 8px; font-family: var(--hand); font-size: 16px; line-height: 1.15; color: var(--text-faint); }

/* ---------- right sidebar: POIs on top, Inspector / Style tabs below ---------- */
#rightbar { --rb-split: 0.36; }
.rb-points { display: flex; flex-direction: column; min-height: 0; flex: 0 0 calc(var(--rb-split) * (100% - 7px)); }
.rb-tabs { display: flex; flex-direction: column; min-height: 0; flex: 1 1 0; }
.rb-head {
  display: flex; align-items: center; gap: 8px; flex: 0 0 auto;
  height: 48px; padding: 0 12px 0 14px; font-weight: 700; font-size: 14px;
}
.rb-head > .ico { color: var(--text-muted); }
.rb-title { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rb-count { font-size: 11.5px; font-weight: 400; color: var(--text-muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.rb-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 0 12px 12px; }
.rb-body[hidden] { display: none; }
.rb-split {
  flex: 0 0 7px; position: relative; cursor: row-resize; outline: none;
}
.rb-split::before {
  content: ''; position: absolute; left: 12px; right: 12px; top: 3px; height: 0; border-top: 1px dashed var(--border);
}
.rb-split::after {
  content: ''; position: absolute; left: 50%; top: 1px; width: 36px; height: 5px; margin-left: -18px;
  background: var(--text-faint); opacity: 0; transition: opacity 0.15s;
}
.rb-split:hover::after, .rb-split.dragging::after, .rb-split:focus-visible::after { opacity: 1; }
.rb-split.dragging::before, .rb-split:focus-visible::before { border-top: 1px solid var(--select); }
.rb-split.dragging::after, .rb-split:focus-visible::after { background: var(--select); }
.rb-tabbar {
  display: flex; gap: 3px; flex: 0 0 auto; margin: 6px 12px 8px; padding: 3px;
  background: var(--surface-2); border: 1px solid var(--border-subtle);
}
.rb-tab {
  flex: 1 1 0; min-width: 0; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 30px; padding: 0 8px; border: 0; background: none;
  color: var(--text-muted); font-size: 13px; white-space: nowrap;
  transition: background 0.12s, color 0.12s;
}
.rb-tab span { overflow: hidden; text-overflow: ellipsis; }
.rb-tab:hover { color: var(--text); background: var(--row-hover); }
.rb-tab.on { color: var(--text); background: var(--seg-on); box-shadow: var(--shadow), inset 0 0 0 1px var(--border-subtle); font-weight: 600; }
.rb-tabs .rb-body { padding-top: 2px; }
/* sticky tool rows inside the sidebar use its background */
#rightbar .poi-tools { background: var(--panel); top: 0; }

/* ---------- POI icon picker ---------- */
.poi-sym { display: inline-flex; flex: 0 0 auto; }
.poi-sym svg { display: block; }
.icon-pick-btn {
  display: inline-flex; align-items: center; gap: 8px; height: 32px; padding: 0 8px; min-width: 36px;
  background: var(--input); border: 1px solid var(--border); color: var(--text);
}
.icon-pick-btn:hover { border-color: var(--border-hover); }
.icon-pick-btn.with-label { width: 100%; justify-content: flex-start; }
.icon-pick-btn.inherited .icon-pick-label { color: var(--text-muted); }
.icon-pick-label { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 12.5px; }
.style-table .icon-pick-btn.with-label { height: 28px; }
.menu-pop.icon-picker { width: 316px; max-width: calc(100vw - 16px); box-sizing: border-box; }
.icon-pop { width: 100%; min-width: 0; }
.icon-groups { max-height: min(440px, 60vh); overflow-y: auto; overflow-x: hidden; padding-right: 2px; }
.icon-group-title { font-family: var(--hand); font-size: 16px; font-weight: var(--hand-w); color: var(--text-faint); margin: 8px 2px 2px; }
.icon-group-title:first-child { margin-top: 0; }
.icon-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.icon-cell {
  display: inline-flex; align-items: center; justify-content: center; height: 36px; min-width: 0; padding: 0;
  background: var(--surface-2); border: 1px solid transparent;
  transition: background 0.12s, transform 0.25s var(--spring);
}
.icon-cell:hover, .icon-cell:focus-visible { background: var(--row-active); outline: none; border-color: var(--border); transform: rotate(calc(-4deg * var(--wiggle))); }
.icon-cell.on { border-color: var(--select); box-shadow: 0 0 0 2px var(--select-ring); }
.icon-inherit {
  display: flex; align-items: center; gap: 8px; width: 100%; height: 34px; margin-bottom: 8px; padding: 0 8px;
  background: var(--surface-2); border: 1px solid transparent; color: var(--text-muted); font-size: 12.5px;
}
.icon-inherit:hover { background: var(--row-active); color: var(--text); }
.icon-inherit.on { border-color: var(--select); color: var(--text); }

/* ---------- terrain calculator panel ---------- */
/* dropdown under the "Mesh Terrain" button in the top pill */
.menu-pop.terrain-pop { width: 360px; max-width: calc(100vw - 24px); padding: 0; }
.terrain-drop { max-height: min(78vh, calc(100vh - 80px)); overflow-y: auto; padding: 12px 14px 8px; }
.terrain-drop-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-weight: 700; font-size: 14px; }
.terrain-drop-head .ico { color: var(--green); }
.terrain-panel .insp-section { margin-bottom: 4px; }
.tr-note {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 2px 0 10px; padding: 8px 10px;
  border: 1.5px dashed var(--border); font-size: 12px; color: var(--text-muted);
}
.tr-pair { display: flex; align-items: center; gap: 6px; min-width: 0; }
.tr-pair input { flex: 1 1 0; min-width: 0; }
.tr-suffix { flex: 0 0 auto; white-space: nowrap; }
.tr-chips { display: flex; flex-wrap: wrap; gap: 4px; margin: -2px 0 8px; }
.chip-btn {
  height: 26px; padding: 0 9px; font-size: 12px; white-space: nowrap;
  background: var(--panel); border: 1px solid var(--border-subtle); box-shadow: var(--shadow); color: var(--text-muted);
  transition: background 0.12s, color 0.12s, transform 0.25s var(--spring);
}
.chip-btn:hover { color: var(--text); background: var(--seg-on); transform: translateY(-1px) rotate(calc(-2deg * var(--wiggle))); }
.chip-btn.on { color: var(--blue); background: var(--blue-soft); border-color: color-mix(in srgb, var(--blue) 35%, transparent); font-weight: 600; box-shadow: none; }
.seg { display: flex; gap: 3px; padding: 3px; background: var(--surface-2); border: 1px solid var(--border-subtle); }
.seg-btn {
  flex: 1 1 0; height: 28px; border: 0; background: none; color: var(--text-muted); font-size: 12.5px;
  transition: background 0.12s, color 0.12s;
}
.seg-btn:hover { color: var(--text); background: var(--row-hover); }
.seg-btn.on { background: var(--seg-on); color: var(--text); font-weight: 600; box-shadow: var(--shadow), inset 0 0 0 1px var(--border-subtle); }
/* the answer is a sticky note */
.tr-result .tr-quad {
  display: flex; flex-direction: column; gap: 0; padding: 10px 14px 12px; margin: 4px 2px 12px;
  background: var(--sticky-1); color: var(--ink);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.25), 0 10px 24px rgba(0, 0, 0, 0.35);
  transform: rotate(calc(-1deg * var(--wiggle)));
}
.tr-quad-k { font-family: var(--hand); font-size: 17px; font-weight: var(--hand-w); line-height: 1.1; color: rgba(28, 25, 23, 0.72); }
.tr-quad-v { font-size: 22px; font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; }
.tr-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.tr-stat { display: flex; flex-direction: column; gap: 1px; min-width: 0; padding: 7px 9px; background: var(--surface-2); border: 1px solid var(--border-subtle); }
.tr-k { font-size: 11px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tr-v { font-size: 13.5px; font-weight: 600; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.tr-sub { font-size: 11px; color: var(--text-faint); overflow-wrap: anywhere; }
.tr-warn { display: flex; gap: 6px; align-items: flex-start; margin: 8px 0 0; font-size: 12px; color: var(--amber); }
.tr-warn .ico { margin-top: 1px; }
.tr-pre {
  margin: 0 0 8px; padding: 8px 10px; max-height: 220px; overflow: auto; white-space: pre;
  font-size: 11px; line-height: 1.5; background: var(--surface-2); border: 1px solid var(--border-subtle);
}
.tr-options td, .tr-options th { white-space: nowrap; }
.tr-opt { cursor: pointer; }
.tr-opt:hover td, .tr-opt:focus-visible td { background: var(--row-hover); outline: none; }
.tr-opt.on td { background: var(--row-active); color: var(--text); font-weight: 600; }
.tr-opt.heavy td { color: var(--text-faint); }

/* ---------- colour picker (ui/color-picker.js) ---------- */
.menu-pop.cp-pop { width: 332px; max-width: calc(100vw - 16px); box-sizing: border-box; }
.cp { display: flex; flex-direction: column; gap: 10px; }
.cp-top { display: flex; align-items: stretch; gap: 10px; }
.cp-wheel-box { position: relative; width: 176px; height: 176px; flex: 0 0 auto; }
.cp-wheel { display: block; border-radius: 50%; cursor: crosshair; touch-action: none; }
.cp-dot {
  position: absolute; width: 14px; height: 14px; margin: -7px 0 0 -7px; border-radius: 50%;
  border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.6), 0 1px 4px rgba(0, 0, 0, 0.5); pointer-events: none;
}
.cp-vtrack {
  position: relative; width: 16px; flex: 0 0 auto; cursor: ns-resize; touch-action: none; outline: none;
  background: linear-gradient(180deg, var(--cp-top, #fff), #000); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}
.cp-vtrack:focus-visible { box-shadow: 0 0 0 2px var(--select); }
.cp-vthumb {
  position: absolute; left: -3px; right: -3px; height: 6px; margin-top: -3px;
  background: #fff; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.6); pointer-events: none;
}
.cp-swatches { display: flex; flex-direction: column; gap: 8px; flex: 1 1 auto; min-width: 0; }
.cp-sw-col { display: flex; flex-direction: column; gap: 3px; }
.cp-sw-label { font-family: var(--hand); font-size: 15px; font-weight: var(--hand-w); line-height: 1.1; color: var(--text-faint); }
.cp-sw { display: block; width: 100%; height: 34px; border: 1px solid var(--border); padding: 0; }
.cp-old { cursor: pointer; }
.cp-old:hover { border-color: var(--border-hover); }
.cp-sliders { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; }
.cp-rows { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.cp-row { display: grid; grid-template-columns: 12px minmax(0, 1fr) 44px; align-items: center; gap: 6px; }
.cp-key { font-size: 11px; font-weight: 600; color: var(--text-muted); }
.cp-range {
  -webkit-appearance: none; appearance: none; width: 100%; height: 10px; margin: 0;
  background: var(--cp-track, var(--surface-2)); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08); cursor: pointer;
}
.cp-range::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 12px; height: 12px; border-radius: 50%;
  background: #fff; border: 0; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.6), 0 1px 3px rgba(0, 0, 0, 0.5);
}
.cp-range::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: #fff; border: 0; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.6); }
.cp-range:focus-visible { outline: 2px solid var(--select); outline-offset: 2px; }
.cp-num, .cp-hex {
  width: 100%; min-width: 0; height: 26px; padding: 0 5px; font-size: 11.5px; text-align: right;
  background: var(--input); border: 1px solid var(--border); color: var(--text); outline: none;
  -moz-appearance: textfield;
}
.cp-num::-webkit-inner-spin-button, .cp-num::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.cp-num:focus, .cp-hex:focus { border-color: var(--select); box-shadow: 0 0 0 2px var(--select-ring); }
.cp-hexrow { display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; align-items: center; gap: 6px; }
.cp-hex { text-align: left; font-size: 12px; height: 28px; }
.cp-dropper { width: 28px; height: 28px; }
.cp-recent-wrap { display: flex; flex-direction: column; gap: 4px; }
.cp-recent { display: flex; flex-wrap: wrap; gap: 5px; }
.cp-rsw { width: 20px; height: 20px; padding: 0; border: 1px solid var(--border); cursor: pointer; transition: transform 0.25s var(--spring); }
.cp-rsw:hover { transform: rotate(calc(-8deg * var(--wiggle))) scale(1.15); }

/* links: crossings without a bridge on a road link */
.link-warn { color: var(--amber); }

/* ---------- changes on disk (session.js) ---------- */
.disk-diff { margin: 4px 0 10px; }
.disk-diff-pre {
  margin: 4px 0 0; max-height: 44vh; overflow: auto; padding: 10px 12px; white-space: pre-wrap;
  font-size: 11.5px; line-height: 1.55; background: var(--surface-2); border: 1px solid var(--border-subtle);
}

/* ---------- menus & popovers ---------- */
#menus { position: fixed; inset: 0; pointer-events: none; z-index: 300; } /* above dialogs: dropdowns open inside them */
.menu-pop {
  position: fixed; pointer-events: auto; z-index: 150;
  min-width: 210px; max-width: 320px; padding: 6px;
  background: var(--menu); border: 1px solid var(--border); box-shadow: var(--shadow-lg);
  animation: menu-in 0.18s var(--spring);
}
@keyframes menu-in { from { opacity: 0; transform: translateY(-4px) scale(0.98); } }
.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%; height: 34px; padding: 0 10px;
  background: none; border: 0; color: var(--text); text-align: left; white-space: nowrap;
}
.menu-item:hover:not(:disabled), .menu-item:focus-visible { background: rgba(255, 255, 255, 0.08); outline: none; }
.menu-item:disabled { opacity: 0.4; cursor: default; }
.menu-item .ico { color: var(--text-muted); }
.menu-item.danger, .menu-item.danger .ico { color: var(--red); }
.menu-label { flex: 1; }
.menu-item kbd { margin-left: 12px; }
.ico-blank { width: 16px; }
.menu-sep { height: 0; border-top: 1px dashed var(--border); margin: 5px 6px; }
.menu-heading { padding: 4px 10px 2px; font-family: var(--hand); font-size: 17px; font-weight: var(--hand-w); line-height: 1.2; color: var(--text-faint); }
.popover { padding: 12px; width: 280px; }
.pop-title { font-weight: 700; margin-bottom: 6px; }
.popover p { margin: 0 0 10px; }
.pop-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.bg-name { display: flex; flex-direction: column; gap: 1px; margin-bottom: 8px; overflow: hidden; }
.bg-name .mono { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bg-opacity { display: flex; align-items: center; gap: 8px; }
.bg-opacity input { flex: 1; min-width: 0; accent-color: var(--brand); }

/* ---------- form controls ---------- */
/* styled dropdowns (ui/select.js): the <select> stays in the DOM, hidden */
select.sel-native { display: none !important; }
.sel-btn {
  display: flex; align-items: center; gap: 6px; width: 100%; min-width: 0; height: 32px; padding: 0 7px 0 9px;
  background: var(--input); border: 1px solid var(--border);
  color: var(--text); text-align: left; outline: none; cursor: pointer;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.sel-btn:hover:not(:disabled) { border-color: var(--border-hover); }
.sel-btn:focus-visible, .sel-btn.menu-open { border-color: var(--select); box-shadow: 0 0 0 3px var(--select-ring); }
.sel-btn:disabled { opacity: 0.5; cursor: default; }
.sel-btn[hidden] { display: none; }
.sel-label { flex: 1 1 auto; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sel-btn > .ico { flex: 0 0 auto; color: var(--text-muted); }
.sel-btn > .ico svg { width: 14px; height: 14px; }
.filters .sel-btn { height: 28px; padding: 0 4px 0 6px; font-size: 11.5px; gap: 2px; }
.gate-row .sel-btn { height: 28px; padding: 0 4px 0 6px; font-size: 11.5px; }
.style-table .sel-btn { height: 26px; padding: 0 4px 0 6px; font-size: 11.5px; }
.sel-btn.dock-type { width: auto; min-width: 96px; height: 28px; font-size: 12px; }
.menu-pop.sel-menu { max-height: min(360px, 60vh); overflow-y: auto; }
.menu-pop.sel-menu .menu-item.checked { color: var(--text); font-weight: 600; }
.menu-pop.sel-menu .menu-item.checked .ico { color: var(--green); }
.search, .filters select, .field input, .field select, .field textarea, .link-add input, .gate-row input, .gate-row select,
.style-table input:not([type="color"]), .style-table select, .dialog select, .dialog input:not([type="checkbox"]):not([type="color"]), .dialog textarea {
  width: 100%; min-width: 0; height: 32px;
  background: var(--input); border: 1px solid var(--border);
  padding: 0 9px; outline: none; color: var(--text);
  transition: border-color 0.12s, box-shadow 0.12s;
}
.search:hover, .field input:hover, .field textarea:hover, .dialog input:hover, .dialog textarea:hover { border-color: var(--border-hover); }
.search::placeholder, .field input::placeholder, .field textarea::placeholder, .dialog input::placeholder, .dialog textarea::placeholder { color: var(--text-faint); }
.field textarea, .dialog textarea { height: auto; padding: 6px 9px; }
.search:focus, .filters select:focus, .field input:focus, .field select:focus, .field textarea:focus, .link-add input:focus,
.gate-row input:focus, .gate-row select:focus, .style-table input:focus, .style-table select:focus,
.dialog select:focus, .dialog input:focus, .dialog textarea:focus {
  border-color: var(--select); box-shadow: 0 0 0 3px var(--select-ring);
}
input[type="checkbox"], input[type="radio"], input[type="range"] { accent-color: var(--brand); }
input[type="color"] { cursor: pointer; }

/* ---------- layers panel ---------- */
.layer-list { display: flex; flex-direction: column; gap: 2px; }
.layer-row {
  display: flex; align-items: center; gap: 0; height: 32px; padding: 0 4px;
  cursor: pointer; transition: background 0.12s;
}
.layer-row:hover { background: var(--row-hover); }
.layer-row.active { background: var(--row-active); box-shadow: inset 2px 0 0 var(--brand); }
.layer-row.active .layer-name { font-weight: 600; }
.layer-row.hidden-layer .layer-name { opacity: 0.45; }
.layer-row.pseudo { cursor: default; }
.layer-row .icon-btn { width: 26px; height: 26px; }
.layer-row .icon-btn svg { width: 15px; height: 15px; }
.chev .ico { transition: transform 0.12s; }
.chev.open .ico { transform: rotate(90deg); }
.layer-name { flex: 1; min-width: 0; padding-left: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.layer-name .kind { margin-left: 6px; color: var(--text-faint); font-size: 10px; }
.layer-row .count { color: var(--text-muted); font-size: 11px; min-width: 18px; text-align: right; padding-right: 4px; font-variant-numeric: tabular-nums; }
input[type="color"].swatch { width: 16px; height: 16px; margin: 0 5px; }
.swatch-spacer { width: 26px; flex: 0 0 auto; }
.swatch-multi {
  display: inline-block; flex: 0 0 auto; width: 16px; height: 16px; margin: 0 5px; border: 1px solid var(--border);
  background: conic-gradient(#7a736b 0 25%, #3e5b47 0 50%, #607356 0 75%, #9d8b63 0);
}
.layer-extra { padding: 2px 4px 8px 30px; }
.opacity { display: flex; align-items: center; gap: 8px; font-size: 11.5px; color: var(--text-muted); margin: 2px 0 6px; }
.opacity input { flex: 1; min-width: 0; }
.feature-list { list-style: none; margin: 0; padding: 0; max-height: 220px; overflow-y: auto; }
.feature-list li {
  display: flex; justify-content: space-between; gap: 6px;
  padding: 3px 8px; cursor: pointer; font-size: 12px;
}
.feature-list li:hover { background: var(--row-hover); }
.feature-list li.sel { background: var(--select-soft); color: var(--text); }
.feature-list li.is-hidden { opacity: 0.5; font-style: italic; }
.feature-list .fname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.feature-list .fid { color: var(--text-faint); font-size: 10.5px; font-family: var(--mono); white-space: nowrap; }
.feature-list li.empty { cursor: default; }
/* trash on list rows (Layers, Points): shown on hover / keyboard focus, always on touch */
.row-del { width: 24px; height: 24px; margin-left: auto; flex: 0 0 auto; opacity: 0; color: var(--text-muted); }
.row-del svg { width: 14px; height: 14px; }
.feature-list li:hover .row-del, .poi-row:hover .row-del, .row-del:focus-visible { opacity: 1; }
.row-del:hover { color: var(--red); background: var(--red-soft); }
@media (hover: none) { .row-del { opacity: 0.7; } }
.feature-list li { align-items: center; }
.feature-list .fid { margin-left: auto; }
.feature-list .row-del { width: 20px; height: 20px; margin: -2px -4px -2px 0; }
.feature-list .row-del svg { width: 13px; height: 13px; }

/* ---------- points panel ---------- */
.poi-tools { display: flex; flex-direction: column; gap: 6px; margin-bottom: 6px; position: sticky; top: -8px; padding-top: 0; background: var(--panel); z-index: 1; }
.poi-search-row { display: flex; gap: 4px; align-items: center; }
.poi-search-row .icon-btn.accent { transition: background 0.12s, transform 0.25s var(--spring); }
.poi-search-row .icon-btn.accent:hover { transform: translateY(-1px) rotate(calc(-6deg * var(--wiggle))); }
.filters { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 4px; }
.filters select { height: 28px; padding: 0 5px; font-size: 11.5px; }
.poi-list { display: flex; flex-direction: column; gap: 2px; }
.section-title { font-family: var(--hand); font-size: 17px; font-weight: var(--hand-w); line-height: 1.15; color: var(--text-faint); padding: 8px 6px 2px; }
.section-title.warn { color: var(--amber); }
.poi-row {
  display: flex; align-items: center; gap: 7px; min-height: 40px;
  padding: 3px 6px; cursor: pointer; border: 1px solid transparent;
  transition: background 0.12s;
}
.poi-row:hover { background: var(--row-hover); }
.poi-row:hover .grip { opacity: 0.9; }
.poi-row.sel { background: var(--row-active); box-shadow: inset 2px 0 0 var(--select); }
.poi-row.unplaced { border: 1.5px dashed var(--border); }
.poi-row.dragging { opacity: 0.5; }
.poi-row .grip { opacity: 0.3; cursor: grab; display: inline-flex; color: var(--text-muted); }
.poi-row .grip svg { width: 12px; height: 14px; }
.poi-ico { display: inline-flex; flex: 0 0 auto; }
.poi-main { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.25; }
.poi-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.poi-sub { font-size: 11px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* status badges are stickers: solid fill, dark ink, a slight tilt */
.badge {
  display: inline-flex; align-items: center; height: 18px; padding: 0 7px;
  font-size: 10.5px; font-weight: 700; letter-spacing: 0.02em; white-space: nowrap; text-transform: lowercase;
  color: var(--ink); background: var(--badge, var(--grey)); box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.16);
  transform: rotate(calc(-3deg * var(--wiggle)));
}
.badge.status-idea { --badge: var(--yellow); }
.badge.status-approved { --badge: var(--green); }
.badge.status-slice { --badge: var(--blue); }
.badge.status-cut { --badge: var(--grey); text-decoration: line-through; }
.empty { padding: 10px; text-align: center; font-family: var(--hand); font-size: 17px; line-height: 1.2; color: var(--text-faint); }

/* ---------- inspector ---------- */
.insp-head { display: flex; align-items: center; gap: 8px; padding: 4px 0 6px; min-width: 0; }
.insp-kind {
  flex: 0 0 auto; font-size: 10.5px; font-weight: 700; letter-spacing: 0.2px; line-height: 18px;
  padding: 0 8px; background: var(--seg-on); color: var(--text);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.16); transform: rotate(calc(-3deg * var(--wiggle)));
}
.insp-head .insp-kind[style] { color: var(--ink); }
.insp-title { font-weight: 700; font-size: 15px; letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.insp-section { border-top: 1px dashed var(--border); padding: 8px 0 6px; }
.inspector > .insp-section:first-of-type, .map-panel > .insp-section:first-of-type { border-top: 0; padding-top: 4px; }
.insp-section h4 { margin: 0 0 6px; font-family: var(--hand); font-size: 19px; font-weight: var(--hand-w); line-height: 1.1; color: var(--text-faint); }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; min-width: 0; }
.field > span { font-size: 12px; font-weight: 500; color: var(--text-muted); }
.field textarea { resize: vertical; font-size: 12px; }
.field textarea[name="points"] { font-family: var(--mono); font-size: 11.5px; white-space: pre; }
.field .hint, .hint { font-family: var(--hand); font-size: 15px; font-weight: var(--hand-w); line-height: 1.15; color: var(--text-faint); }
.field-check { flex-direction: row; align-items: center; gap: 8px; }
.field-check input[type="checkbox"] { width: auto; flex: 0 0 auto; }
.field-check > span { font-size: 13px; font-weight: 400; color: var(--text); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.row-zone { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: start; }
.row-zone .btn { margin-top: 20px; }
.check { display: flex; align-items: center; gap: 8px; margin: 4px 0 8px; cursor: pointer; font-size: 12.5px; }
.checks { display: flex; flex-wrap: wrap; gap: 0 14px; }
.color-override { display: flex; align-items: center; gap: 8px; }
.color-override input[type="color"] { width: 36px; height: 26px; padding: 0 2px; background: var(--input); border: 1px solid var(--border); }
.color-override input.unset { opacity: 0.55; }
.color-override .icon-btn { width: 26px; height: 26px; }
.insp-actions { display: flex; flex-wrap: wrap; gap: 6px; padding-top: 10px; }
.stats { margin: 2px 0 0; }
.insp-empty { padding: 0 0 6px; }
.insp-empty p { margin: 0 0 6px; }
.map-settings { border-top: 1px dashed var(--border); margin-top: 4px; }
.multi-list { list-style: none; padding: 0; margin: 4px 0; }
.multi-list li { display: flex; align-items: center; gap: 6px; padding: 2px 0; }
.multi-list .icon-btn { width: 24px; height: 24px; }
.tag {
  font-size: 10.5px; font-weight: 500; line-height: 18px; padding: 0 7px;
  color: var(--violet); background: color-mix(in srgb, var(--violet) 15%, transparent);
}
.link-target {
  background: none; border: 0; padding: 0; text-align: left; color: var(--text); min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1;
}
.link-target:hover { color: var(--blue); }
.link-target small { color: var(--text-muted); }
.link-list { display: flex; flex-direction: column; gap: 2px; margin-bottom: 8px; }
.link-row { display: grid; grid-template-columns: auto auto 1fr auto; grid-template-rows: auto auto; align-items: center; column-gap: 6px; padding: 4px 0; border-bottom: 1px dashed var(--border-subtle); }
.link-row .link-meta { grid-column: 3 / 4; grid-row: 2; }
.link-row .icon-btn { grid-row: 1 / 3; grid-column: 4; width: 26px; height: 26px; }
.link-type { font-size: 10.5px; font-weight: 600; line-height: 18px; padding: 0 7px; background: var(--row-active); color: var(--text-muted); }
.link-type.t-road { color: var(--yellow); background: color-mix(in srgb, var(--yellow) 14%, transparent); }
.link-type.t-river { color: var(--blue); background: var(--blue-soft); }
.link-type.t-quest { color: var(--green); background: var(--green-soft); }
.link-arrow { color: var(--text-muted); }
.link-add { display: flex; flex-direction: column; gap: 6px; }
.link-add .row2 { gap: 6px; }
.link-add .btn { align-self: flex-start; }
.gate-row {
  display: grid; grid-template-columns: 1fr 1fr 28px; gap: 4px; align-items: center;
  padding: 6px 0; border-bottom: 1px dashed var(--border-subtle);
}
.gate-row > :nth-child(5) { grid-column: 3; grid-row: 1 / 3; }
.gates-head { display: none; }
.gate-row input, .gate-row select { height: 28px; padding: 0 6px; font-size: 11.5px; }
.gate-row .icon-btn { width: 26px; height: 26px; }
.gates + .btn { margin-top: 6px; }

/* ---------- style panel ---------- */
.style-table { width: 100%; border-collapse: collapse; margin-bottom: 8px; font-size: 12px; }
.style-table th { text-align: left; font-weight: 500; color: var(--text-muted); font-size: 11px; padding: 2px 4px 4px; }
.style-table td { padding: 3px 4px; border-top: 1px dashed var(--border-subtle); }
.style-table input[type="color"] { width: 34px; height: 24px; padding: 0 2px; background: var(--input); border: 1px solid var(--border); }
.style-table input.narrow { width: 72px; height: 26px; padding: 0 6px; }
.style-table select { height: 26px; padding: 0 5px; font-size: 11.5px; }

/* ---------- canvas overlays ---------- */
#cv-content .ilm-feat, #cv-content .ilm-poi { cursor: pointer; }
/* hover highlight only where a click would select the object (tools with picks = objects) */
#canvas[data-picks="objects"] #cv-content .ilm-feat:hover, #canvas[data-picks="objects"] #cv-content .ilm-poi:hover { filter: brightness(1.35); }
#cv-content .ilm-feat.is-selected, #cv-content .ilm-poi.is-selected { filter: brightness(1.2); }
#canvas[data-picks="objects"] #cv-content #layer-zones .ilm-feat:hover { filter: brightness(1.15); }
#canvas[data-picks="objects"] #cv-content .ilm-feat, #canvas[data-picks="objects"] #cv-content .ilm-poi { cursor: pointer; }
/* Hand tool / Space / pan in progress: no hover highlight, the canvas cursor everywhere */
#canvas.panning #cv-content .ilm-feat:hover, #canvas.panning #cv-content .ilm-poi:hover { filter: none; }
#canvas.panning #cv-content .ilm-feat.is-selected, #canvas.panning #cv-content .ilm-poi.is-selected { filter: brightness(1.2); }
#canvas.panning #cv-content *, #canvas.panning #cv-overlay * { cursor: inherit; }
/* selection is Figma blue; anything being drawn or measured is the yellow marker */
.ov-sel { fill: none; stroke: var(--select); pointer-events: none; }
.ov-cage { fill: none; stroke: var(--select); stroke-opacity: 0.45; pointer-events: none; }
.ov-vertex { fill: var(--canvas); stroke: var(--select); cursor: move; }
.ov-vertex.on { fill: var(--select); stroke: #ffffff; }
.ov-vertex:hover { fill: var(--yellow); }
.ov-draft { fill: none; stroke: var(--yellow); pointer-events: none; }
.ov-draft.fill { fill: var(--yellow); fill-opacity: 0.12; }
#cv-tool .ov-vertex { pointer-events: none; stroke: var(--yellow); }
#cv-tool .ov-vertex.first { fill: var(--yellow); pointer-events: none; }
#cv-tool .ov-cage { stroke: var(--yellow); }
.ov-box { fill: var(--select); fill-opacity: 0.08; stroke: var(--select); pointer-events: none; }
.ov-scale-box { fill: none; stroke: var(--select); pointer-events: none; }
/* Edit tool previews: Alt → the point that will be added / the point that will be deleted; Ctrl → the object a click selects */
.ov-add, .ov-del, .ov-pick { pointer-events: none; }
.ov-add circle { fill: var(--green); fill-opacity: 0.3; stroke: var(--green); }
.ov-add path { stroke: #ffffff; stroke-linecap: round; }
.ov-del circle { fill: var(--red); fill-opacity: 0.28; stroke: var(--red); }
.ov-del path { stroke: var(--red); stroke-linecap: round; }
.ov-del.blocked circle { fill: none; stroke: var(--yellow); }
.ov-del.blocked path { stroke: var(--yellow); }
.ov-pick { fill: var(--select); fill-opacity: 0.1; stroke: var(--select); stroke-linejoin: round; }

/* the active tool's shortcuts: top right under the history pill, right-aligned; a line lights up while its modifier is held */
#tool-keys {
  position: absolute; top: 60px; right: 14px; z-index: 5; max-width: 340px;
  display: flex; flex-direction: column; align-items: flex-end; gap: 2px;
  pointer-events: none; text-align: right; font-size: 11px; line-height: 1.45; color: var(--text-muted);
}
#tool-keys .tk-row { display: flex; justify-content: flex-end; align-items: baseline; gap: 8px; padding: 0 3px; }
#tool-keys .tk-text { opacity: 0.85; }
#tool-keys .tk-keys { color: var(--text); font-weight: 600; white-space: nowrap; }
#tool-keys .tk-row.on { color: var(--ink); background: var(--brand); transform: rotate(calc(-1deg * var(--wiggle))); }
#tool-keys .tk-row.on .tk-text { opacity: 1; }
#tool-keys .tk-row.on .tk-keys { color: var(--ink); }
@container stage (max-width: 720px) { #tool-keys { display: none; } }
.ov-scale-handle { fill: #ffffff; stroke: var(--select); }
.ov-scale-handle:hover { fill: var(--select); }
#canvas.panning .ov-scale-handle { cursor: inherit !important; pointer-events: none; }
.ov-measure { fill: none; stroke: var(--yellow); pointer-events: none; }
.ov-measure-pt { fill: var(--yellow); pointer-events: none; }
.ov-measure-label { fill: #fff6d6; stroke: var(--canvas); paint-order: stroke; font-family: var(--font); pointer-events: none; }
.ov-measure-label.strong { font-weight: 700; fill: var(--yellow); }
.ov-calib circle { fill: none; stroke: var(--pink); }
.ov-calib text { fill: var(--pink); stroke: var(--canvas); paint-order: stroke; font-weight: 700; font-family: var(--font); }

/* ---------- dialogs & toasts ---------- */
.backdrop {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  background: var(--backdrop); backdrop-filter: blur(2px);
}
.dialog {
  width: min(460px, calc(100vw - 32px)); max-height: calc(100vh - 40px); overflow-y: auto;
  background: var(--dialog); border: 1px solid var(--border); box-shadow: var(--shadow-lg);
  padding: 16px 22px 18px;
  animation: pop-in 0.32s var(--spring);
}
@keyframes pop-in { from { opacity: 0; transform: translateY(10px) scale(0.96); } }
.dialog-wide { width: min(680px, calc(100vw - 32px)); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: -4px -10px 10px 0; }
.dialog h2 { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: -0.01em; }
.dialog-msg { color: var(--text-muted); margin: 0 0 14px; white-space: pre-line; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; padding-top: 14px; border-top: 1px dashed var(--border); }
.dialog .field-check { margin: 4px 0 8px; }
table.keys { width: 100%; border-collapse: collapse; }
table.keys td { padding: 5px 6px; border-top: 1px dashed var(--border-subtle); vertical-align: top; }
table.keys td:first-child { white-space: nowrap; width: 1%; }
.settings-extra { margin-top: 8px; }
.danger-zone {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px; border: 1.5px dashed color-mix(in srgb, var(--red) 45%, transparent);
}
.danger-zone p { margin: 4px 0 0; }
.about { margin: 12px 0 0; }
.about a { display: inline-flex; align-items: center; gap: 3px; color: var(--text-muted); }
.about a:hover { color: var(--text); }
.about a svg { width: 12px; height: 12px; }

#toasts {
  position: fixed; right: 16px; bottom: 96px; z-index: 250;
  display: flex; flex-direction: column; gap: 8px; align-items: flex-end;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex; align-items: center; gap: 10px;
  max-width: 440px; padding: 8px 6px 8px 14px;
  background: var(--menu); border: 1px solid var(--border); box-shadow: var(--shadow-lg);
  animation: toast-in 0.35s var(--spring);
}
.toast::before { content: ""; flex: 0 0 auto; width: 9px; height: 9px; background: var(--text-faint); transform: rotate(calc(-10deg * var(--wiggle))); }
.toast-ok::before { background: var(--green); }
.toast-warn::before { background: var(--amber); }
.toast-error::before { background: var(--red); }
.toast.out { opacity: 0; transform: translateY(6px); transition: opacity 0.25s, transform 0.25s; }
.toast > span { flex: 1; }
.toast .btn { color: var(--brand); border-color: transparent; font-weight: 600; }
.toast-x { display: inline-flex; background: none; border: 0; color: var(--text-muted); padding: 4px; }
.toast-x:hover { background: var(--row-hover); color: var(--text); }
.toast-x svg { width: 14px; height: 14px; }
@keyframes toast-in { from { transform: translateY(10px) scale(0.96); opacity: 0; } }

/* ---------- smaller screens ----------
   Chrome on the canvas reacts to the width of the stage (container "stage"),
   which shrinks when the side bars are open; the bars react to the window. */
@container stage (max-width: 1000px) {
  .dock-label { display: none; }
}
@container stage (max-width: 860px) {
  .pill-btn > span:not(.ico) { display: none; }
  .pill-btn { padding: 0 8px; }
  #minimap { display: none; }
  #dock-left { bottom: 60px; }
  .dock-typewrap { display: none; }
  #dock { --dock-l: 116px; }
  #coords .rd-where { display: none; }
}
@container stage (max-width: 640px) {
  #title-pill { max-width: calc(100% - 140px); }
  #panel-toggles { top: 60px; }
  #dock-left { top: 110px; }
  #dock .dock-chips { display: none; }
  #dock { --dock-r: 12px; bottom: 60px; }
}
@media (max-width: 1280px) {
  :root { --sidebar-w: 212px; --rightbar-w: 296px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
