:root {
  color-scheme: dark;
  --ink: #f6f3ec;
  --muted: #c3bec8;
  --panel: #1a1b24e8;
  --line: #ffffff25;
  --mono: ui-monospace, "IBM Plex Mono", monospace;
  font: 15px system-ui, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: #1b1c23; color: var(--ink); overflow: hidden; }
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible { outline: 2px solid #a5f4e0; outline-offset: 3px; }
#scene {
  position: relative; isolation: isolate; width: 100%; height: 100vh; height: 100dvh;
  overflow: hidden; touch-action: none; outline: none;
  background: linear-gradient(#9faab5, #e7d7c0);
}
#view, .shade { position: absolute; inset: 0; width: 100%; height: 100%; }
.shade {
  pointer-events: none;
  background: linear-gradient(#14152283, transparent 21%, transparent 78%, #1415229c);
}
.hud {
  position: absolute; inset: max(16px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) auto max(20px, env(safe-area-inset-left));
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: start; gap: 10px;
  pointer-events: none;
}
.identity { text-shadow: 0 1px 8px #12131b; }
h1 { font-size: 23px; line-height: 1; margin: 0 0 8px; letter-spacing: -.04em; font-weight: 650; }
#timer { font: 12px var(--mono); font-variant-numeric: tabular-nums; }
.maze-summary { margin: 0 0 7px; font: 12px var(--mono); white-space: nowrap; }
#maze-difficulty { text-transform: capitalize; }
#maze-difficulty::before { content: " · "; }
.layerTitle { display: flex; align-items: center; gap: 7px; }
#layergrid { display: grid; grid-template-columns: repeat(3, 4px); gap: 1.5px; }
#layergrid i { width: 4px; height: 4px; border-radius: 1px; background: currentColor; opacity: .25; }
#layergrid i.on { opacity: 1; }
#timer, nav, .atlas, #status, #touch button {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 3px 16px #16152129;
}
#timer { padding: 10px 16px; font-size: 17px; }
nav { display: flex; padding: 3px; justify-self: end; pointer-events: auto; }
nav button, #map-toggle, .close {
  border: 0; background: none; border-radius: 5px;
}
nav button { width: 36px; height: 34px; font-size: 21px; line-height: 1; }
button:hover { background: #ffffff19; }
.atlas[hidden] { display: none; }
.atlas { position: absolute; top: calc(max(16px, env(safe-area-inset-top)) + 51px); right: max(20px, env(safe-area-inset-right)); padding: 7px 10px 9px; }
#map-toggle {
  display: flex; justify-content: space-between; align-items: center;
  gap: 18px; width: 100%; min-height: 25px; padding: 2px 4px;
  font: 600 12px var(--mono);
}
#floorplans { display: block; width: clamp(106px, 17vw, 172px); margin: 6px auto; }
.floor { fill: #2e303a; }
.plan-wall { fill: none; stroke: #aba7b5; stroke-width: 1.2; stroke-linecap: square; }
.active-plan .floor { fill: #554665; }
.active-plan .plan-wall { stroke: #f1e8fc; }
.portal-arrow { fill: #cea7ff; }
.exit-marker { fill: #ffd172; }
.player-marker { fill: #83ffe4; stroke: #183d38; stroke-width: 1; stroke-linejoin: round; }
.current-cell { fill: #7cffe5; opacity: .18; }
.cross {
  position: absolute; left: 50%; top: 50%; width: 4px; height: 4px; translate: -50% -50%;
  border-radius: 50%; background: #ffffffe0; box-shadow: 0 0 3px #141527;
  pointer-events: none;
}
#status {
  position: absolute; bottom: calc(64px + env(safe-area-inset-bottom)); left: 50%;
  translate: -50% 0; padding: 9px 13px; white-space: nowrap; font-size: 13px; pointer-events: none;
}
#status:empty { display: none; }
.controls {
  position: absolute; bottom: max(16px, env(safe-area-inset-bottom)); left: 50%; translate: -50% 0;
  display: flex; gap: 17px; white-space: nowrap; font-size: 12px; text-shadow: 0 1px 6px #11121a;
  pointer-events: none;
}
kbd { border: 1px solid #ffffff55; border-radius: 4px; padding: 3px 5px; background: #191923a8; margin-right: 2px; font: 11px var(--mono); }
#touch { display: none; position: absolute; bottom: max(16px, env(safe-area-inset-bottom)); left: 50%; translate: -50% 0; gap: 6px; }
#touch, #touch button {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
#touch button { width: 49px; height: 44px; font-size: 22px; }
dialog { width: min(440px, calc(100vw - 24px)); padding: 24px; background: #1c1d28; color: var(--ink); border: 1px solid var(--line); border-radius: 12px; }
dialog::backdrop { background: #11131a99; }
h2 { margin: 0 32px 12px 0; font-size: 24px; }
.close { float: right; width: 32px; height: 32px; font-size: 22px; }
#body { color: var(--muted); line-height: 1.55; white-space: pre-line; }
#ok { margin-top: 18px; border: 0; border-radius: 6px; background: #dfcaff; color: #20182c; padding: 9px 14px; font-weight: 600; }
@media (pointer: coarse) { .controls { display: none; } #touch { display: flex; } }
@media (max-width: 560px) {
  .hud { left: 12px; right: 12px; }
  h1 { font-size: 19px; }
  #maze-difficulty { display: none; }
  nav button { width: 31px; }
  .atlas { right: 12px; }
  .controls { gap: 9px; }
  .controls span:last-child { display: none; }
}

#maze-settings { display: grid; gap: 12px; }
#maze-settings label { display: grid; grid-template-columns: 1fr 1.4fr; align-items: center; gap: 8px; }
#maze-settings select {
  min-width: 0; width: 100%; font: inherit; color: var(--ink); padding: 8px;
  border: 1px solid var(--line); border-radius: 6px; background: #292a38;
}
#challenge-info { margin: 0; color: var(--muted); font-size: 13px; }
#challenge-info:empty { display: none; }
#maze-settings .primary {
  justify-self: start; margin-top: 6px; border: 0; border-radius: 6px;
  background: #dfcaff; color: #20182c; padding: 9px 14px; font-weight: 600;
}
