:root {
  --night: #241d4a;
  --purple: #4b3f8c;
  --cream: #f2e6c9;
  --cream-dark: #c4b28a;
  --gold: #f5c542;
  --orange: #e8722a;
  --teal: #2e8b8b;
  --ink: #1d1a2e;
  --label: "Silkscreen", "Courier New", ui-monospace, monospace;
  --text: "Chivo", system-ui, -apple-system, "Segoe UI", sans-serif;
  --num: "VT323", ui-monospace, "SF Mono", Menlo, monospace;
  --ui: var(--ink);
  --gutter: 16px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { background: var(--cream); }
body {
  background: var(--cream);
  color: var(--ink);
  font-family: var(--text);
  font-size: 15px;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}
body.walking { overflow: hidden; }
body.night { background: var(--night); }

#scene {
  position: fixed; inset: 0;
  width: 100vw; height: 100vh; height: 100dvh;
  display: block;
  touch-action: pan-y;
  z-index: 0;
}
body.walking #scene { touch-action: none; cursor: grab; }
body.walking #scene:active { cursor: grabbing; }

#scroller { height: 900vh; width: 1px; }

/* --- the drawing sheet overlay (plan state) --- */
#sheet {
  position: fixed; inset: 0; pointer-events: none; z-index: 1;
  transition: opacity .2s linear;
}
#sheet::before {
  content: ""; position: absolute;
  inset: 10px;
  border: 1.5px solid var(--ink);
  outline: 1px solid var(--ink); outline-offset: -6px;
}
#drawing { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
#drawing text { font-family: var(--num); fill: var(--ink); }
#drawing .dim { stroke: var(--ink); stroke-width: 1; fill: none; }
#drawing .tick { stroke: var(--ink); stroke-width: 1.5; }
#drawing .north path { fill: var(--ink); }
#drawing .north circle { fill: none; stroke: var(--ink); stroke-width: 1.2; }
#drawing .north text { font-family: var(--label); font-size: 12px; }
#drawing .scalebar rect.f { fill: var(--ink); }
#drawing .scalebar rect.o { fill: var(--cream); stroke: var(--ink); stroke-width: 1; }

#labels { position: absolute; inset: 0; }
.room-label {
  position: absolute; left: 0; top: 0;
  transform: translate(-50%, -50%);
  text-align: center; white-space: nowrap;
  line-height: 1;
  color: var(--ink);
  will-change: transform;
}
.room-label .rn {
  font-family: var(--label);
  font-size: var(--ls, 13px);
  letter-spacing: .02em;
  text-transform: uppercase;
  display: block;
}
.room-label .ra {
  font-family: var(--num);
  font-size: calc(var(--ls, 13px) * 1.45);
  display: block; margin-top: 2px;
  color: var(--ink);
}
.room-label.outdoor .rn, .room-label.outdoor .ra { color: var(--purple); }

#titleblock {
  position: absolute; right: 26px; bottom: 44px;
  min-width: 210px;
  border: 1.5px solid var(--ink);
  background: var(--cream);
  font-family: var(--label);
  font-size: 12px; text-transform: uppercase;
}
.tb-row { display: flex; justify-content: space-between; gap: 16px; padding: 5px 9px; border-top: 1px solid var(--ink); }
.tb-row:first-child { border-top: 0; }
.tb-head { font-size: 13px; background: var(--ink); color: var(--cream); }
.tb-row .num { font-family: var(--num); font-size: 19px; line-height: 12px; text-transform: none; }
.tb-foot { color: var(--purple); }

/* --- HUD --- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 3; }
#hud > * { pointer-events: auto; }
#hud > #hint { pointer-events: none; }

#lcd {
  position: absolute; left: 26px; top: 26px;
  min-width: 132px;
  padding: 7px 10px 5px;
  background: #c9c39a;
  background: linear-gradient(#cfc8a0, #bdb48a);
  border: 2px solid var(--ink);
  box-shadow: inset 0 0 0 2px rgba(29, 26, 46, .14), 3px 3px 0 var(--ink);
  color: var(--ink);
  border-radius: 3px;
}
.lcd-room { font-family: var(--label); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
.lcd-num { position: relative; font-family: var(--num); font-size: 40px; line-height: 34px; white-space: nowrap; }
.lcd-ghost { position: absolute; left: 0; top: 0; color: rgba(29, 26, 46, .1); }
#lcd-area { position: relative; }
.lcd-unit { font-size: 22px; margin-left: 4px; }

#hint {
  position: absolute; left: 50%; bottom: 112px; transform: translateX(-50%);
  font-family: var(--label); font-size: 14px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--ink); white-space: nowrap;
  transition: opacity .3s;
}
#hint::after { content: " ↓"; }

#controls {
  position: absolute; left: 50%; bottom: 44px; transform: translateX(-50%);
  display: flex; gap: 10px;
}
button {
  font-family: var(--label); font-size: 14px; text-transform: uppercase; letter-spacing: .03em;
  min-height: 48px; min-width: 118px; padding: 0 18px;
  border: 2px solid var(--ink); border-radius: 0;
  background: var(--cream); color: var(--ink);
  box-shadow: 3px 3px 0 var(--ink);
  cursor: pointer;
  touch-action: manipulation;
}
button:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
button:focus-visible { outline: 3px solid var(--orange); outline-offset: 2px; }
#btn-build { background: var(--gold); }
#btn-walk { background: var(--teal); color: var(--cream); }
#btn-exit { position: absolute; right: 26px; top: 26px; min-width: 88px; }
body.night button { border-color: var(--ink); }
body.night #hint { color: var(--cream); }

#joystick {
  position: absolute; left: 26px; bottom: 54px;
  width: 92px; height: 92px; border-radius: 50%;
  border: 2px solid var(--cream);
  background: rgba(29, 26, 46, .18);
  touch-action: none; opacity: .6;
}
#joystick[hidden] { display: none; }
#joy-knob {
  position: absolute; left: 50%; top: 50%; width: 38px; height: 38px; margin: -19px 0 0 -19px;
  border-radius: 50%; background: var(--gold); border: 2px solid var(--ink);
}
#walkhelp {
  position: absolute; left: 50%; bottom: 44px; transform: translateX(-50%);
  font-family: var(--label); font-size: 12px; text-transform: uppercase; color: var(--cream);
  background: var(--ink); padding: 8px 14px; white-space: nowrap; transition: opacity .8s; border: 1.5px solid var(--cream);
}
#walkhelp[hidden] { display: none; }

#footer {
  position: fixed; right: 26px; bottom: 14px; z-index: 3;
  font-family: var(--text); font-size: 12px; color: var(--cream);
  background: var(--ink); padding: 3px 8px; /* readable on paper, walls and night alike */
  white-space: nowrap;
}


/* recording mode: no chrome except the LCD */
body.rec #sheet #titleblock, body.rec #controls, body.rec #hint, body.rec #footer,
body.rec #btn-exit, body.rec #walkhelp, body.rec #joystick { display: none !important; }
body.rec #lcd { left: 48px; top: 64px; transform: scale(1.6); transform-origin: left top; }

/* still image for the Reel: the sheet only, title block kept */
body.still #hud { display: none !important; }
body.still #sheet #titleblock { display: block !important; right: 40px; bottom: 40px; transform: scale(1.35); transform-origin: right bottom; }

/* phone */
@media (max-width: 600px) {
  #lcd { left: 22px; top: 22px; min-width: 112px; padding: 5px 8px 3px; } /* sits inside the sheet border */
  .lcd-num { font-size: 34px; line-height: 28px; }
  #titleblock { right: auto; left: var(--gutter); bottom: auto; top: 18px; display: none; }
  #controls { bottom: 40px; width: calc(100% - 2 * var(--gutter)); justify-content: center; }
  #controls button { flex: 1 1 0; min-width: 0; }
  #hint { bottom: 100px; }
  #footer { right: auto; left: 50%; transform: translateX(-50%); bottom: 10px; }
  #btn-exit { right: var(--gutter); top: var(--gutter); }
  #joystick { left: var(--gutter); bottom: 48px; }
  #walkhelp { display: none !important; }
  #sheet::before { inset: 6px; }
}
@media (max-width: 600px) and (min-height: 700px) {
  #titleblock.phone-show { display: block; }
}

@media (prefers-reduced-motion: reduce) {
  #sheet, #hint { transition: none; }
}
.noscript { position: fixed; inset: 40% 0 auto; text-align: center; font-family: var(--label); }

/* button type test: Chivo instead of the pixel face (?ui=chivo) */
body.ui-chivo button { font-family: var(--text); font-weight: 600; font-size: 15px; text-transform: none; letter-spacing: 0; }
body.ui-chivo #hint { font-family: var(--text); text-transform: none; letter-spacing: 0; }
