/* ui.css — one small design system for the whole interface.
   Tokens (:root) are the only colours, sizes and spacings used below; tools/vtest/ui-audit.mjs checks the rendered page
   against them (control heights, font sizes, font families, colours).
   - Type: one UI font (--font), three sizes: 12 (meta), 13 (body, controls), 15 (section titles, semibold).
     The game's bitmap font is used only for the wordmark (and the F3 overlay), drawn at a whole number of device pixels.
   - Spacing: 4 / 8 / 12 / 16 / 24.
   - Controls: one height (--h: 28 px, 40 px on coarse pointers) for buttons, fields, selects, segmented controls, list
     rows and checkbox rows; map zoom buttons --h-zoom (32 / 44). One radius (2 px). One border width (1 px).
   - Pixel art (item icons, wordmark) is drawn at an integer number of device pixels per source pixel: ui.js sets --icon
     (16 source px × round(devicePixelRatio) device px, in CSS px) and redraws the wordmark when the ratio changes. */
:root {
  /* colour */
  --bg: #0d1117;
  --surface: rgba(17, 19, 23, 0.86);
  --surface-raised: #262a30;
  --surface-hover: #30353d;
  --sunken: #0b0d11;
  --border: #3a4049;
  --border-strong: #5c6470;
  --text: #e6e8eb;
  --text-strong: #ffffff;
  --text-muted: #9aa2ad;
  --accent: #3b8a3e;
  --accent-hover: #46a049;
  --focus: #a5e07c;
  --warn: #ffd75e;
  --danger: #ff8f85;
  --tt-bg: rgba(16, 0, 16, 0.94);
  --tt-edge-top: #5000ff;
  --tt-edge-bottom: #28007f;
  --highlight: rgba(255, 255, 255, 0.06);
  --shade: rgba(0, 0, 0, 0.35);
  /* type */
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --pixel: "GuiGame", "GuiFallback", ui-monospace, monospace;
  --fs-meta: 12px; --lh-meta: 16px;
  --fs-body: 13px; --lh-body: 20px;
  --fs-title: 15px; --lh-title: 20px;
  /* space */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s6: 24px;
  /* size */
  --h: 28px;
  --h-zoom: 32px;
  --bar-h: 44px;
  --panel-w: 280px;
  --radius: 2px;
  --icon: 16px;            /* ui.js: 16 × round(dpr) / dpr */
  --edge: var(--s3);       /* overlays' distance from the window edges */
  color-scheme: dark;
}
@media (pointer: coarse) {
  :root { --h: 40px; --h-zoom: 44px; --bar-h: 56px; }
}

/* ---- base ---- */
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); }
body { color: var(--text); font: 400 var(--fs-body) / var(--lh-body) var(--font); -webkit-tap-highlight-color: transparent; }
button, input, select { font: inherit; color: inherit; margin: 0; }
[hidden] { display: none !important; }
a { color: var(--focus); }
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
img.icon, .icon { width: var(--icon); height: var(--icon); flex: none; image-rendering: pixelated; }
kbd { display: inline-block; font: 600 var(--fs-meta) / var(--lh-meta) var(--font); padding: 0 var(--s1); color: var(--text);
  background: var(--surface-raised); border: 1px solid var(--border); border-radius: var(--radius); }
.muted { color: var(--text-muted); }
.grow { flex: 1; }

/* ---- the world ---- */
#view { position: fixed; inset: 0; touch-action: none; cursor: grab; }
#view:active { cursor: grabbing; }
#view canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#map { pointer-events: none; image-rendering: pixelated; }
body.dropping #view { outline: 2px dashed var(--warn); outline-offset: -8px; }
#fatal { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); padding: var(--s6); text-align: center; z-index: 50; }
body.hide-gui .chrome { display: none !important; }

/* ---- surfaces ---- */
.surface { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  backdrop-filter: blur(12px) saturate(1.1); -webkit-backdrop-filter: blur(12px) saturate(1.1); }

/* ---- buttons: one family. default · primary · ghost · icon · segmented. All --h tall, 1 px border, 2 px radius ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--s2); flex: none;
  height: var(--h); min-width: var(--h); padding: 0 var(--s3); white-space: nowrap; user-select: none; cursor: pointer;
  font-size: var(--fs-body); line-height: var(--lh-body); color: var(--text);
  background: var(--surface-raised); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: inset 0 1px 0 var(--highlight), inset 0 -1px 0 var(--shade); }
.btn:hover { background: var(--surface-hover); border-color: var(--border-strong); }
.btn:active { box-shadow: inset 0 1px 0 var(--shade); }
.btn:disabled { color: var(--text-muted); background: var(--surface-raised); border-color: var(--border); box-shadow: none; cursor: default; }
.btn.primary { color: var(--text-strong); background: var(--accent); border-color: var(--accent); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.primary:disabled { color: var(--text-muted); background: var(--surface-raised); border-color: var(--border); }
.btn.ghost { background: transparent; border-color: transparent; box-shadow: none; }
.btn.ghost:hover { background: var(--surface-hover); border-color: var(--border); }
.btn.ghost:disabled { background: transparent; border-color: transparent; }
.btn.square { width: var(--h); padding: 0; }
a.btn { text-decoration: none; }
.btn.gh svg { width: 16px; height: 16px; display: block; }
.btn.wide { width: 100%; }
.btn .label { overflow: hidden; text-overflow: ellipsis; }
.btn.warn { color: var(--warn); }
/* segmented: buttons joined into one control; the selected one is the accent */
.seg { display: inline-flex; flex: none; border-radius: var(--radius); }
.seg .btn { border-radius: 0; }
.seg .btn + .btn { margin-left: -1px; }
.seg .btn:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.seg .btn:last-child { border-radius: 0 var(--radius) var(--radius) 0; }
.seg .btn.on { position: relative; z-index: 1; color: var(--text-strong); background: var(--accent); border-color: var(--accent); }
.seg .btn:focus-visible { position: relative; z-index: 2; }
.seg.fill { display: flex; }
.seg.fill .btn { flex: 1; min-width: 0; padding: 0 var(--s2); }
.burger { width: 14px; height: 10px; flex: none; background: linear-gradient(currentColor 0 2px, transparent 2px 4px, currentColor 4px 6px, transparent 6px 8px, currentColor 8px 10px); }
.arrow { width: 8px; height: 8px; flex: none; border: solid currentColor; border-width: 2px 2px 0 0; transform: translateX(-2px) rotate(45deg); }

/* ---- text fields: a box with an optional inline label; the box is the control ---- */
.field { display: flex; align-items: center; gap: var(--s2); height: var(--h); padding: 0 var(--s2); min-width: 0; cursor: text; margin: 0;
  background: var(--sunken); border: 1px solid var(--border); border-radius: var(--radius); }
.field:hover { border-color: var(--border-strong); }
.field:focus-within { border-color: var(--focus); }
.field > label, .field > .lbl { flex: none; color: var(--text-muted); cursor: inherit; }
.field input { flex: 1; min-width: 0; height: 100%; padding: 0; background: transparent; border: 0; color: var(--text-strong); caret-color: var(--text-strong);
  font-variant-numeric: tabular-nums; }
.field input:focus-visible { outline: none; }
.field input::placeholder { color: var(--text-muted); }
.field input[type=search]::-webkit-search-cancel-button { filter: grayscale(1) brightness(1.5); }

/* ---- selects: label on the left, the box on the right ---- */
.sel { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); height: var(--h); }
.sel > span { color: var(--text); }
.sel select { -webkit-appearance: none; appearance: none; height: var(--h); width: 148px; min-width: 0; padding: 0 var(--s6) 0 var(--s2); cursor: pointer;
  color: var(--text-strong); background-color: var(--sunken); border: 1px solid var(--border); border-radius: var(--radius);
  background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%), linear-gradient(-45deg, transparent 50%, var(--text-muted) 50%);
  background-repeat: no-repeat; background-size: 4px 4px, 4px 4px; background-position: right 12px center, right 8px center; }
.sel select:hover { border-color: var(--border-strong); }
.sel option { background: var(--surface-raised); color: var(--text); }

/* ---- sliders: a label row, then a --h tall control: 4 px track, 12 px thumb ---- */
.slider { display: flex; flex-direction: column; }
.slider .srow { display: flex; justify-content: space-between; color: var(--text); }
.slider .val { color: var(--text-muted); font-variant-numeric: tabular-nums; }
.slider input { -webkit-appearance: none; appearance: none; display: block; width: 100%; height: var(--h); background: transparent; cursor: pointer; }
.slider input::-webkit-slider-runnable-track { height: 4px; background: var(--sunken); border: 1px solid var(--border); border-radius: var(--radius); }
.slider input::-moz-range-track { height: 4px; background: var(--sunken); border: 1px solid var(--border); border-radius: var(--radius); }
.slider input::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 12px; height: 12px; margin-top: -5px; border-radius: var(--radius);
  background: var(--text); border: 1px solid var(--sunken); box-shadow: inset 0 -2px 0 var(--text-muted); }
.slider input::-moz-range-thumb { width: 12px; height: 12px; border-radius: var(--radius); background: var(--text); border: 1px solid var(--sunken); }
.slider input:hover::-webkit-slider-thumb { background: var(--text-strong); }
.slider input:focus-visible { outline: none; }
.slider input:focus-visible::-webkit-slider-thumb { outline: 2px solid var(--focus); outline-offset: 1px; }

/* ---- checkboxes: a --h tall row; a 14 px box centred on the text's line ---- */
.check { display: flex; align-items: center; gap: var(--s2); height: var(--h); position: relative; cursor: pointer; color: var(--text); user-select: none; }
.check input { position: absolute; left: 0; top: 50%; width: 14px; height: 14px; margin: -7px 0 0; opacity: 0; cursor: pointer; }
.check .box { flex: none; width: 14px; height: 14px; position: relative; background: var(--sunken); border: 1px solid var(--border-strong); border-radius: var(--radius); }
.check:hover .box { border-color: var(--text-muted); }
.check input:checked + .box { background: var(--accent); border-color: var(--accent); }
.check input:checked + .box::after { content: ""; position: absolute; left: 4px; top: 1px; width: 4px; height: 7px; border: solid var(--text-strong); border-width: 0 2px 2px 0; transform: rotate(45deg); }
.check input:focus-visible + .box { outline: 2px solid var(--focus); outline-offset: 1px; }
.checks { display: flex; flex-direction: column; }

/* ---- tooltip (the game's: dark, with a purple-gradient 1 px frame) ---- */
.tip { font-size: var(--fs-meta); line-height: var(--lh-meta); padding: var(--s1) var(--s2); color: var(--text); border: 1px solid transparent; border-radius: var(--radius);
  background: linear-gradient(var(--tt-bg), var(--tt-bg)) padding-box, linear-gradient(var(--tt-edge-top), var(--tt-edge-bottom)) border-box; }
#tooltip { position: fixed; left: 0; top: 0; z-index: 40; pointer-events: none; max-width: min(280px, calc(100vw - 16px)); }
.tip .t-title { color: var(--text-strong); }
.tip .t-sub { color: var(--text-muted); }

/* ---- top bar: 44 px, --h controls centred ---- */
#topbar { position: fixed; top: 0; left: 0; right: 0; height: var(--bar-h); z-index: 12; display: flex; align-items: center; gap: var(--s2); padding: 0 var(--s2);
  border-width: 0 0 1px; border-radius: 0; }
.brand { display: flex; align-items: center; gap: var(--s2); padding: 0 var(--s2) 0 var(--s1); white-space: nowrap; }
.brand canvas { display: block; flex: none; }
#seedForm { width: 248px; flex: 0 1 auto; }
#gotoForm { width: 160px; flex: 0 1 auto; }
#dataChip { max-width: 240px; }
#dataChip .label { color: var(--text-muted); }
#dataChip.warn .label { color: var(--warn); }

/* ---- side panel: 280 px, 16 px padding, sections divided by 1 px lines ---- */
#panel { position: fixed; top: calc(var(--bar-h) + var(--edge)); left: var(--edge); bottom: var(--edge); width: var(--panel-w); z-index: 11;
  overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent;
  display: flex; flex-direction: column; transform: translateX(calc(-100% - 2 * var(--edge))); visibility: hidden; transition: transform .16s ease-out, visibility .16s; }
body.panel-open #panel { transform: none; visibility: visible; }
.peek { display: none; }
.sec { padding: var(--s3) var(--s4); border-top: 1px solid var(--border); }
.sec:first-of-type { border-top: 0; }
.sec > summary { list-style: none; display: flex; align-items: center; gap: var(--s2); height: var(--h); margin: 0 calc(-1 * var(--s2)); padding: 0 var(--s2);
  border-radius: var(--radius); cursor: pointer; user-select: none; font-size: var(--fs-title); line-height: var(--lh-title); font-weight: 600; color: var(--text-strong); }
.sec > summary::-webkit-details-marker { display: none; }
.sec > summary::after { content: ""; margin-left: auto; width: 6px; height: 6px; border: solid var(--text-muted); border-width: 0 2px 2px 0; transform: translateY(-2px) rotate(45deg); }
.sec[open] > summary::after { transform: translateY(2px) rotate(-135deg); }
.sec > summary:hover { background: var(--surface-hover); }
.sec-body { display: flex; flex-direction: column; gap: var(--s2); padding-top: var(--s2); }
.row { display: flex; gap: var(--s2); }
.row > * { flex: 1; min-width: 0; }
.note { margin: 0; font-size: var(--fs-meta); line-height: var(--lh-meta); color: var(--text-muted); overflow-wrap: anywhere; }
.note.strong { color: var(--text); }
.note:empty { display: none; }
.attach { display: flex; flex-direction: column; gap: var(--s2); padding-top: var(--s3); border-top: 1px solid var(--border); }
.only-narrow { display: none !important; }

/* structures: checkbox · icon · name · go */
.list { list-style: none; margin: 0 calc(-1 * var(--s2)); padding: 0; display: flex; flex-direction: column; }
.list li { display: flex; align-items: center; gap: var(--s2); height: var(--h); padding: 0 0 0 var(--s2); border-radius: var(--radius); }
.list li:hover { background: var(--surface-hover); }
.list .check { flex: none; width: 14px; }
.list .name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list .dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--dot); border: 1px solid var(--sunken); }
.list .btn { color: var(--text-muted); }
.list li:hover .btn { color: var(--text); }

/* ---- map overlays: one surface style, 12 px from the edges, on the --h / --h-zoom grid ---- */
#viewbar { position: fixed; bottom: var(--edge); left: calc(50% + var(--off, 0px) / 2); transform: translateX(-50%); z-index: 10; }
#viewbar .btn { padding: 0 var(--s3); }
#mapctl { position: fixed; right: var(--edge); bottom: var(--edge); z-index: 10; display: flex; flex-direction: column; }
#mapctl .btn { width: var(--h-zoom); height: var(--h-zoom); min-width: 0; padding: 0; border-radius: 0; font-size: var(--fs-title); }
#mapctl .btn:first-child { border-radius: var(--radius) var(--radius) 0 0; }
#mapctl .btn:last-child { border-radius: 0 0 var(--radius) var(--radius); margin-top: -1px; }
#readout { position: fixed; left: calc(var(--off, 0px) + var(--edge)); bottom: var(--edge); z-index: 10; pointer-events: none;
  padding: var(--s1) var(--s2); min-width: 0; max-width: calc((100vw - var(--off, 0px)) / 2 - 140px); }
#readout > div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#roPos { color: var(--text-strong); font-variant-numeric: tabular-nums; }
#roBiome, #readout .scale { font-size: var(--fs-meta); line-height: var(--lh-meta); color: var(--text-muted); }
#readout .scale { display: flex; align-items: center; gap: var(--s2); }
#scaleBar { height: 4px; flex: none; border: 1px solid var(--text-muted); border-top: 0; }
#readout.noscale .scale { display: none; }
#maploading { position: fixed; top: calc(var(--bar-h) + var(--edge)); left: calc(50% + var(--off, 0px) / 2); transform: translateX(-50%); z-index: 10; pointer-events: none;
  display: flex; align-items: center; gap: var(--s2); min-height: var(--h); padding: var(--s1) var(--s3); color: var(--text-muted);
  max-width: calc(100vw - var(--off, 0px) - 4 * var(--edge)); font-variant-numeric: tabular-nums; }
#maploadingTxt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#maploading .spin { width: 12px; height: 12px; border: 2px solid var(--border-strong); border-top-color: var(--focus); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
body.panel-open { --off: calc(var(--panel-w) + var(--edge)); }
#toasts { position: fixed; top: calc(var(--bar-h) + var(--edge)); left: calc(50% + var(--off, 0px) / 2); transform: translateX(-50%); z-index: 13;
  display: flex; flex-direction: column; align-items: center; gap: var(--s2); pointer-events: none; width: max-content; max-width: calc(100vw - 2 * var(--edge)); }
#toasts:not(:empty) ~ #maploading { display: none; }
.toast { font-size: var(--fs-body); line-height: var(--lh-body); padding: var(--s1) var(--s3); transition: opacity .8s; }
.toast.warn { color: var(--danger); }
.toast.fade { opacity: 0; }

/* F3: the game's debug overlay, in its font (size set by ui.js to a whole number of device pixels per font pixel) */
#f3 { position: fixed; top: calc(var(--bar-h) + var(--edge)); left: calc(var(--off, 0px) + var(--edge)); right: calc(var(--h-zoom) + 2 * var(--edge)); z-index: 9;
  display: flex; justify-content: space-between; gap: var(--s3); pointer-events: none; color: var(--text);
  font: var(--f3-fs, 16px) / 1.125 var(--pixel); -webkit-font-smoothing: none; }
.f3col { display: flex; flex-direction: column; max-width: 50%; }
.f3col > div { align-self: flex-start; background: var(--surface); padding: 0 var(--s1); overflow-wrap: anywhere; }
.f3col > div.gap { background: none; height: 1em; }
#stats > div { align-self: flex-end; text-align: right; }
#stats span::after { content: ": "; }
#stats b { font-weight: inherit; }

/* about dialog */
.dialog { width: min(520px, calc(100vw - 2 * var(--s4))); max-height: calc(100vh - 2 * var(--s6)); padding: var(--s4); color: var(--text); overflow: auto; }
.dialog::backdrop { background: var(--shade); }
.dialog h2 { margin: 0 0 var(--s2); font-size: var(--fs-title); line-height: var(--lh-title); font-weight: 600; color: var(--text-strong); }
.dialog form { margin-top: var(--s4); display: flex; justify-content: flex-end; }
.prose p { margin: 0 0 var(--s2); } .prose ul { padding-left: var(--s4); margin: 0; } .prose li { margin: var(--s1) 0; }
.prose h3 { font-size: var(--fs-body); line-height: var(--lh-body); font-weight: 600; color: var(--text-strong); margin: var(--s3) 0 var(--s1); }

/* ---- ≤700 px: the panel is a bottom sheet (peek bar · half · full); the top bar keeps the seed and a menu button ---- */
html.narrow .only-wide { display: none !important; }
html.narrow .only-narrow { display: flex !important; }
html.narrow .brand { padding: 0 var(--s1); }
html.narrow .brand canvas { display: none; }
html.narrow #seedForm { flex: 1 1 auto; width: auto; }
html.narrow #panel { top: auto; left: 0; right: 0; bottom: 0; width: auto; height: var(--bar-h); transform: none; visibility: visible; overflow: hidden;
  border-width: 1px 0 0; border-radius: 0; transition: height .2s ease-out; }
html.narrow body[data-sheet="half"] #panel { height: 50vh; overflow-y: auto; }
html.narrow body[data-sheet="full"] #panel { height: calc(100vh - var(--bar-h)); height: calc(100dvh - var(--bar-h)); overflow-y: auto; }
html.narrow .peek { display: flex; align-items: center; gap: var(--s2); position: sticky; top: 0; z-index: 1; flex: none; height: calc(var(--bar-h) - 1px); padding: 0 var(--s2);
  background: var(--surface-raised); border-bottom: 1px solid var(--border); }
html.narrow .sec:first-of-type { border-top: 0; }
.grab { flex: 1; justify-content: flex-start; touch-action: none; cursor: grab; font-size: var(--fs-title); font-weight: 600; color: var(--text-strong); }
.grab .handle { width: 24px; height: 4px; flex: none; border-radius: var(--radius); background: var(--border-strong); }
html.narrow body.panel-open { --off: 0px; }
html.narrow #viewbar { left: var(--edge); transform: none; bottom: calc(var(--bar-h) + var(--edge)); }
html.narrow #mapctl { bottom: calc(var(--bar-h) + var(--edge)); }
html.narrow #readout { top: calc(var(--bar-h) + var(--edge)); bottom: auto; left: var(--edge); max-width: calc(100vw - 2 * var(--edge)); }
html.narrow #maploading { top: auto; bottom: calc(var(--bar-h) + var(--h-zoom) * 2 + 2 * var(--edge)); }
html.narrow #toasts { top: auto; bottom: calc(var(--bar-h) + var(--h-zoom) * 2 + 2 * var(--edge)); }
html.narrow body.panel-open #mapctl, html.narrow body.panel-open #readout, html.narrow body.panel-open #viewbar, html.narrow body.panel-open #maploading { display: none; }
html.narrow #f3 { flex-direction: column; gap: var(--s2); right: var(--edge); top: calc(var(--bar-h) + 80px); }
html.narrow .f3col { max-width: 100%; }
html.narrow #stats > div { align-self: flex-start; text-align: left; }
@media (prefers-reduced-motion: reduce) { #panel { transition: none; } #maploading .spin { animation: none; } }

/* fly pad: touch screens only, while flying. Left: move (D-pad); right: up, down, fast. Drag anywhere else to look. */
#flypad { display: none; }
@media (any-pointer: coarse) {
  body.flying #flypad { display: block; }
  body.flying #mapctl { display: none; }
}
#flypad .btn { width: var(--h-zoom); height: var(--h-zoom); min-width: 0; padding: 0; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
#flypad .btn.held, #flypad .btn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent, #fff); }
#flypad .dpad { position: fixed; z-index: 10; left: var(--edge); bottom: calc(var(--edge) + 80px); display: grid; gap: var(--s1);
  grid-template-areas: ". f ." "l . r" ". b ."; grid-template-columns: repeat(3, var(--h-zoom)); grid-template-rows: repeat(3, var(--h-zoom)); }
#flypad .updown { position: fixed; z-index: 10; right: var(--edge); bottom: calc(2 * var(--edge) + var(--h)); display: flex; flex-direction: column; gap: var(--s1); }
#flypad .updown .btn { width: auto; padding: 0 var(--s3); font-size: var(--fs-meta); }
html.narrow #flypad .dpad, html.narrow #flypad .updown { bottom: calc(var(--bar-h) + 2 * var(--edge) + var(--h)); }
html.narrow body.panel-open #flypad { display: none; }
