/* Namma Space viewer. One accent colour, calm dark surfaces; every colour, space and size comes from the tokens. */
:root {
  color-scheme: dark;

  /* colour */
  --c-bg: #0e1116;
  --c-surface: rgba(16, 20, 27, .92);
  --c-raised: rgba(255, 255, 255, .07);
  --c-hover: rgba(255, 255, 255, .12);
  --c-line: rgba(255, 255, 255, .13);
  --c-ink: #eef1f5;
  --c-ink-2: #aeb7c4;
  --c-accent: #ff7a3d;
  --c-accent-hover: #ff9261;
  --c-accent-soft: rgba(255, 122, 61, .18);
  --c-on-accent: #1c0f07;

  /* map (hex, read by the canvas) */
  --map-floor: #657491;   /* floor you can walk on is the brightest thing on the map */
  --map-edge: #414b5f;    /* free floor too close to something to stand on */
  --map-wall: #2c333f;    /* walls and furniture */

  /* type */
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
  --fs-xs: 12px;
  --fs-s: 13px;
  --fs-m: 14px;
  --fs-l: 18px;
  --fs-xl: 28px;

  /* space, shape, motion */
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --r-s: 6px;
  --r-m: 10px;
  --r-l: 14px;
  --tap: 38px;
  --shadow: 0 8px 28px rgba(0, 0, 0, .35);
  --ease: cubic-bezier(.2, .7, .2, 1);
  --dur: .2s;

  --edge-x: max(var(--s4), env(safe-area-inset-left), env(safe-area-inset-right));
  --edge-top: max(var(--s4), env(safe-area-inset-top));
  --edge-bottom: max(var(--s4), env(safe-area-inset-bottom));
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--c-bg); color: var(--c-ink); font: var(--fs-m)/1.45 var(--font); }
h1, h2, p { margin: 0; }
h1, h2 { text-wrap: balance; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid var(--c-accent); outline-offset: 2px; }
[hidden] { display: none !important; }
#view { display: block; touch-action: none; }

kbd { display: inline-block; min-width: 20px; margin-right: 2px; padding: 0 5px; border: 1px solid var(--c-line); border-bottom-width: 2px; border-radius: var(--r-s); background: var(--c-raised); color: var(--c-ink); font: 600 11px/18px var(--font); text-align: center; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 18; stroke-linecap: round; stroke-linejoin: round; }
.small { font-size: var(--fs-xs); color: var(--c-ink-2); }
.eyebrow { color: var(--c-ink-2); font-size: var(--fs-xs); font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }

.panel { position: fixed; background: var(--c-surface); border: 1px solid var(--c-line); border-radius: var(--r-l); box-shadow: var(--shadow); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--s2); min-height: var(--tap); padding: 0 var(--s4); border: 1px solid var(--c-line); border-radius: var(--r-m); background: var(--c-raised); font-weight: 600; transition: background-color var(--dur) var(--ease); }
.btn:hover { background: var(--c-hover); }
.btn.primary { border-color: var(--c-accent); background: var(--c-accent); color: var(--c-on-accent); }
.btn.primary:hover { background: var(--c-accent-hover); }
.btn:disabled { opacity: .45; }
.btn.large { min-height: 44px; padding: 0 var(--s5); font-size: 15px; }
.icon-btn { display: grid; place-items: center; width: 32px; height: 32px; padding: 0; border: 0; border-radius: var(--r-s); background: transparent; color: var(--c-ink-2); }
.icon-btn:hover { color: var(--c-ink); background: var(--c-raised); }
.actions { display: flex; flex-wrap: wrap; gap: var(--s2); margin-top: var(--s3); }

/* loading screen */
.splash { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: var(--s5); background: var(--c-bg); text-align: center; overflow: auto; }
.splash-card { display: flex; flex-direction: column; align-items: center; gap: var(--s3); width: min(440px, 100%); }
.splash h1 { font-size: var(--fs-xl); font-weight: 650; }
.splash .lead { color: var(--c-ink-2); font-size: 15px; }
#msg { margin-top: var(--s3); overflow-wrap: anywhere; }
.bar { width: min(280px, 100%); height: 4px; border-radius: 2px; background: var(--c-hover); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--c-accent); transform: scaleX(0); transform-origin: left; transition: transform var(--dur) linear; }
.bar.unknown i { width: 35%; transform: none; animation: slide 1.2s ease-in-out infinite; }
@keyframes slide { from { translate: -110% 0; } to { translate: 300% 0; } }
.splash.ready .bar, .splash.failed .bar, .splash.failed .lead { display: none; }
#load-detail { min-height: 1.45em; font-variant-numeric: tabular-nums; }
.splash-warning { display: none; width: 40px; height: 40px; color: var(--c-accent); }
.splash.failed .splash-warning { display: block; }

/* centre dot, only while the mouse is captured */
#cross { position: fixed; left: 50%; top: 50%; z-index: 2; display: none; width: 6px; height: 6px; margin: -3px 0 0 -3px; border-radius: 50%; background: rgba(255, 255, 255, .8); box-shadow: 0 0 0 1px rgba(0, 0, 0, .4); pointer-events: none; }
body.locked #cross { display: block; }
#fade { position: fixed; inset: 0; z-index: 8; background: var(--c-bg); opacity: 0; pointer-events: none; }

/* search */
.search { left: var(--edge-x); top: var(--edge-top); z-index: 12; width: min(400px, calc(100vw - 2 * var(--edge-x) - 52px)); }
.field { display: flex; align-items: center; gap: var(--s2); height: 46px; padding: 0 var(--s2) 0 var(--s3); color: var(--c-ink-2); }
.field:focus-within { outline: 2px solid var(--c-accent); outline-offset: -1px; border-radius: var(--r-l); }
#q { flex: 1; min-width: 0; height: 100%; padding: 0; border: 0; outline: 0; background: transparent; color: var(--c-ink); font-size: 15px; text-overflow: ellipsis; }
#q::placeholder { color: var(--c-ink-2); }
.field-key { margin-right: var(--s1); }
.search:focus-within .field-key, .field:has(#qclear:not([hidden])) .field-key { display: none; }
.results-panel { border-top: 1px solid var(--c-line); padding: var(--s2) var(--s2) 0; }
#results-head { padding: var(--s1) var(--s2) var(--s2); }
#results { list-style: none; margin: 0; padding: 0; max-height: min(52vh, 420px); overflow: auto; overscroll-behavior: contain; }
#results li { display: flex; align-items: center; gap: var(--s3); min-height: 48px; padding: var(--s2) var(--s3) var(--s2) var(--s2); border-radius: var(--r-m); cursor: pointer; }
#results li .icon { color: var(--c-ink-2); }
#results li[aria-selected="true"] { background: var(--c-accent-soft); }
#results li[aria-selected="true"] .icon { color: var(--c-accent); }
.r-text { display: flex; flex: 1; flex-direction: column; min-width: 0; }
.r-name, .r-sub { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.r-sub { color: var(--c-ink-2); font-size: var(--fs-xs); }
.r-dist { font-size: var(--fs-s); font-variant-numeric: tabular-nums; white-space: nowrap; }
.r-dist.none { color: var(--c-ink-2); font-size: var(--fs-xs); }
#results mark { background: none; color: var(--c-accent); font-weight: 650; }
#results li.empty { cursor: default; color: var(--c-ink-2); }
.results-keys { display: flex; gap: var(--s3); margin: var(--s2) calc(-1 * var(--s2)) 0; padding: var(--s2) var(--s4); border-top: 1px solid var(--c-line); color: var(--c-ink-2); font-size: var(--fs-xs); }

/* top right */
.toolbar { position: fixed; right: var(--edge-x); top: var(--edge-top); z-index: 9; display: flex; gap: var(--s2); }
.toolbar .panel { position: static; width: 46px; height: 46px; }
.toolbar .panel:hover { background: var(--c-bg); }
.stats { right: calc(var(--edge-x) + 54px); top: var(--edge-top); z-index: 9; padding: var(--s2) var(--s3); color: var(--c-ink-2); font-size: var(--fs-xs); font-variant-numeric: tabular-nums; }

/* route panel and place card */
.sheet { z-index: 11; width: min(344px, calc(100vw - 2 * var(--edge-x))); padding: var(--s4); }
.sheet h2 { font-size: var(--fs-l); font-weight: 650; overflow-wrap: anywhere; }
#card-desc::first-letter, .r-sub::first-letter { text-transform: uppercase; }
.sheet-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s3); }
.sheet-title { min-width: 0; }
.route { left: var(--edge-x); bottom: calc(var(--edge-bottom) + 52px); display: flex; flex-direction: column; max-height: calc(100vh - var(--edge-top) - var(--edge-bottom) - 120px); overflow: hidden; }
.route-progress { position: absolute; inset: 0 0 auto; height: 3px; }
.route-progress i { display: block; height: 100%; background: var(--c-accent); transform: scaleX(0); transform-origin: left; }
.route-stats { margin-top: var(--s2); color: var(--c-ink-2); font-size: var(--fs-s); font-variant-numeric: tabular-nums; }
.route-stats b { margin-right: var(--s2); color: var(--c-ink); font-size: var(--fs-xl); font-weight: 650; }
.route-steps { list-style: none; flex: 0 1 auto; min-height: 0; max-height: 148px; margin: var(--s3) 0 0; padding: var(--s2) 0 0; border-top: 1px solid var(--c-line); overflow: auto; }
.route-steps li { display: flex; align-items: center; gap: var(--s3); padding: 3px var(--s1); border-radius: var(--r-s); color: var(--c-ink-2); font-size: var(--fs-s); }
.route-steps li[aria-current] { color: var(--c-ink); font-weight: 600; }
.route-steps li[aria-current] .icon { color: var(--c-accent); }
.route-steps li.done { opacity: .5; }
.route .actions { flex: none; }
.route .actions .btn { flex: 1; }
.route-tip { flex: none; margin-top: var(--s2); }
.route.guiding .route-tip { visibility: hidden; }
.card { left: 50%; bottom: calc(var(--edge-bottom) + 52px); translate: -50% 0; }
.card h2 { margin-top: 2px; }
.card p { color: var(--c-ink-2); font-size: var(--fs-s); }
.card.arrived { border-color: var(--c-accent); }
.card.arrived .eyebrow { color: var(--c-accent); }

#toast { left: 50%; top: calc(var(--edge-top) + 58px); z-index: 20; width: max-content; max-width: calc(100vw - 2 * var(--edge-x)); padding: var(--s2) var(--s4); border-radius: var(--r-m); text-align: center; opacity: 0; visibility: hidden; translate: -50% -8px; pointer-events: none; transition: opacity var(--dur) var(--ease), translate var(--dur) var(--ease), visibility 0s var(--dur); }
#toast.show { opacity: 1; visibility: visible; translate: -50% 0; transition-delay: 0s; }

/* map */
.map { --map-size: 240px; right: var(--edge-x); bottom: var(--edge-bottom); z-index: 9; overflow: hidden; }
.map.large { --map-size: min(520px, calc(100vw - 2 * var(--edge-x) - 2px), 58vh); z-index: 13; }
.map-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); width: 0; min-width: 100%; height: 38px; padding: 0 var(--s1) 0 var(--s3); border-bottom: 1px solid var(--c-line); }
.map-here { display: flex; align-items: center; gap: var(--s2); min-width: 0; font-size: var(--fs-s); font-weight: 600; }
.map-here .icon { color: var(--c-accent); width: 16px; height: 16px; }
#room { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
#minimap { display: block; width: var(--map-size); cursor: pointer; }
body.map-off .map { display: none; }
@media (min-width: 1600px) and (min-height: 900px) { .map { --map-size: 288px; } }

/* floating place names */
#labels { position: fixed; inset: 0; z-index: 3; overflow: hidden; pointer-events: none; }
.poi { position: absolute; left: 0; top: 0; max-width: 220px; margin: -8px 0 0; padding: 3px 10px; overflow: hidden; border: 1px solid var(--c-line); border-radius: 999px; background: var(--c-surface); font-size: var(--fs-xs); font-weight: 600; line-height: 1.5; white-space: nowrap; text-overflow: ellipsis; pointer-events: auto; will-change: transform; }
.poi:hover { border-color: var(--c-accent); }
.poi.target { border-color: var(--c-accent); background: var(--c-accent); color: var(--c-on-accent); }

/* key hints */
.hud { left: var(--edge-x); bottom: var(--edge-bottom); z-index: 5; display: flex; flex-wrap: wrap; align-items: center; gap: var(--s1) var(--s4); max-width: calc(100vw - 320px); padding: var(--s2) var(--s3); color: var(--c-ink-2); font-size: var(--fs-xs); }
.when-locked, body.locked .when-free { display: none; }
body.locked .when-locked { display: inline; }

/* help */
.help { width: min(460px, calc(100vw - 2 * var(--s4))); max-height: calc(100vh - 2 * var(--s4)); padding: var(--s5); border: 1px solid var(--c-line); border-radius: var(--r-l); background: var(--c-bg); color: var(--c-ink); overscroll-behavior: contain; }
.help::backdrop { background: rgba(5, 7, 10, .6); }
.help h2 { font-size: var(--fs-l); }
.keys { margin: var(--s4) 0 var(--s5); }
.keys div { display: grid; grid-template-columns: 96px 1fr; gap: var(--s3); align-items: baseline; padding: var(--s2) 0; border-top: 1px solid var(--c-line); }
.keys dt { font-weight: 600; }
.keys dd { margin: 0; color: var(--c-ink-2); }
.help .btn { width: 100%; }
.for-touch { display: none; }
@media (pointer: coarse) {
  .for-mouse, .hud, .results-keys, .field-key { display: none; }
  .for-touch { display: block; }
}

/* edit mode: tagging */
.tagger { right: var(--edge-x); top: calc(var(--edge-top) + 58px); z-index: 12; width: 300px; max-height: calc(100vh - 380px); min-height: 200px; padding: var(--s4); overflow: auto; overscroll-behavior: contain; }
.tag-title { margin-bottom: var(--s1); font-size: 15px; }
.tagger label { display: block; margin-top: var(--s2); color: var(--c-ink-2); font-size: var(--fs-xs); }
.tagger input, .tagger select, .cal input[type=number] { display: block; width: 100%; margin-top: 3px; padding: 7px 9px; border: 1px solid var(--c-line); border-radius: var(--r-s); background-color: var(--c-bg); color: var(--c-ink); }
.tag-list { list-style: none; margin: var(--s3) 0 0; padding: 0; font-size: var(--fs-s); }
.tag-list li { display: flex; justify-content: space-between; gap: var(--s2); padding: var(--s1) 0; border-top: 1px solid var(--c-line); color: var(--c-ink-2); }
.tag-list li > span:first-child { min-width: 0; overflow-wrap: anywhere; }
.tag-list button { padding: 0 var(--s1); border: 0; background: none; color: var(--c-accent); }

/* calibration */
.cal { right: var(--edge-x); bottom: calc(var(--edge-bottom) + 300px); z-index: 14; width: 270px; max-height: calc(100vh - 340px); min-height: 200px; padding: var(--s3) var(--s4); overflow: auto; }
.cal label { display: grid; grid-template-columns: 64px 1fr 44px; gap: var(--s2); align-items: center; margin: var(--s1) 0; color: var(--c-ink-2); font-size: var(--fs-s); }
.cal input[type=range] { width: 100%; accent-color: var(--c-accent); }
.cal .btn { margin-top: var(--s2); }
.cal hr { margin: var(--s3) 0 var(--s2); border: 0; border-top: 1px solid var(--c-line); }

/* plain roaming when there is no walkable map, and the recorder's clean view */
body.no-nav :is(.search, .map, .route, .card, #labels) { display: none !important; }
body.clean :is(.hud, .stats, .toolbar, #cross) { display: none !important; }

/* shorter laptop screens: keep the directions compact */
@media (max-height: 800px) {
  .route-steps { max-height: 96px; }
  .route-tip { display: none; }
}

/* narrow windows and phones: the map moves under the search box, sheets span the bottom */
@media (max-width: 760px) {
  .map.large { z-index: 13; }
  :root { --edge-x: 10px; --edge-top: max(10px, env(safe-area-inset-top)); --edge-bottom: max(10px, env(safe-area-inset-bottom)); }
  .hud, .results-keys, .field-key, .route-steps, .route-tip { display: none; }
  .map { --map-size: 140px; top: calc(var(--edge-top) + 54px); bottom: auto; }
  .map .map-head { height: 32px; padding-left: var(--s2); font-size: var(--fs-xs); }
  .map .map-here .icon { display: none; }
  .map.large { --map-size: min(calc(100vw - 2 * var(--edge-x) - 2px), 50vh); }
  .sheet { left: var(--edge-x); bottom: var(--edge-bottom); width: calc(100vw - 2 * var(--edge-x)); translate: none; padding: var(--s3) var(--s4); }
  .route-stats b { font-size: var(--fs-l); }
  .tagger { top: auto; bottom: var(--edge-bottom); max-height: 46vh; width: min(300px, calc(100vw - 2 * var(--edge-x))); }
  .cal { bottom: var(--edge-bottom); }
  .stats { top: auto; right: var(--edge-x); bottom: calc(var(--edge-bottom) + 190px); }
  #toast { top: auto; bottom: calc(var(--edge-bottom) + 190px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0s !important; transition-delay: 0s !important; animation: none !important; }
  .bar.unknown i { width: 100%; opacity: .35; }
}
