/* MapFun — base: reset, layout grid, shared tokens. Theme colours live in theme-*.css */

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background-color var(--t-theme), color var(--t-theme);
}
button, input, select, textarea { font: inherit; color: inherit; }
button, .tab, .chip, .peek, #topbar, .kbd { user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
input, textarea { user-select: text; -webkit-user-select: text; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
button:disabled { cursor: not-allowed; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img, svg, canvas { display: block; max-width: 100%; }
[hidden] { display: none !important; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0; }
::selection { background: color-mix(in srgb, var(--accent) 35%, transparent); }

:root {
  /* geometry & motion — theme independent */
  --topbar-h: 52px;
  /* The left column: one width for the skin rail and the tool box below it, one floor they both stop at
     (clear of #coords). css/skins.css, css/extras.css and css/nav.css all measure from these two. */
  --rail-w: 116px;
  --rail-floor: calc(50px + var(--safe-b));
  --radius: 10px;
  --radius-sm: 6px;
  --t-fast: 120ms cubic-bezier(.2,.7,.2,1);
  --t-med: 200ms cubic-bezier(.2,.7,.2,1);
  --t-theme: 200ms ease;
  --font-ui: 'Inter', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-display: var(--font-ui);
  --font-mono: ui-monospace, 'JetBrains Mono', SFMono-Regular, Menlo, Consolas, monospace;
  --shadow: 0 8px 30px rgba(0,0,0,.35), 0 1px 0 rgba(255,255,255,.04) inset;
  --focus: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

/* ---------- App layout ------------------------------------------------- */
#app {
  position: fixed; inset: 0;
  display: grid;
  grid-template-rows: auto 1fr; /* the top bar sizes itself; app.js mirrors its height into --topbar-h */
  grid-template-columns: 1fr;
}
#topbar { grid-row: 1; z-index: 20; }
#stage {
  grid-row: 2;
  position: relative;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: grab;
  background: var(--bg);
  transition: background-color var(--t-theme);
}
#stage.dragging { cursor: grabbing; }
#stage.rolling { cursor: crosshair; }
#stage.pointing { cursor: pointer; }
#stage canvas, #stage .overlay {
  position: absolute; inset: 0; width: 100%; height: 100%;
}
#stage canvas { pointer-events: none; }
#stage .overlay { pointer-events: none; z-index: 4; }   /* HTML overlays sit above the paper texture (z 3) */
#stage canvas.gl { z-index: 1; }
#stage canvas.vec { z-index: 2; }

/* Floating chrome above the stage */
#skinbar { position: absolute; left: 12px; top: calc(var(--topbar-h) + 12px); z-index: 12; }
#infocard { position: absolute; right: 12px; top: calc(var(--topbar-h) + 12px); z-index: 14; }
#coords { position: absolute; left: 12px; bottom: calc(12px + var(--safe-b)); z-index: 12; }
#attribution { position: absolute; right: 12px; bottom: calc(10px + var(--safe-b)); z-index: 12; }
/* Toasts clear the timeline instrument: both are centred on the bottom edge, and a skin credit landing on
   top of "Travel through time" was the first thing you saw after every skin change. --tl-h is published by
   src/time/timeline.js; the fallback is the collapsed bar's height. */
#toasts { position: absolute; left: 50%; bottom: calc(var(--tl-h, 56px) + 26px + var(--safe-b)); transform: translateX(-50%); z-index: 30; }
#timeline { position: absolute; left: 50%; bottom: calc(16px + var(--safe-b)); transform: translateX(-50%); z-index: 12; }

/* Accessibility */
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#stage:focus-visible { outline: none; box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--accent) 55%, transparent); }

/* Scrollbars in panels */
.scroll { scrollbar-width: thin; scrollbar-color: color-mix(in srgb, var(--ink) 25%, transparent) transparent; }
.scroll::-webkit-scrollbar { width: 8px; height: 8px; }
.scroll::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--ink) 22%, transparent); border-radius: 8px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
  .wordmark .mark .spin { animation: none !important; } /* an infinite spin at 0.001 ms is not "reduced" */
}

@media (max-width: 720px) {
  :root { --topbar-h: 92px; } /* fallback until app.js measures the wrapped bar */
}
