/* ============================================================
   SPACE MAZE v2 — styles for index.html only.
   theme.css is shared with the sub-pages, so everything the
   maze needs lives here and nothing in theme.css is touched.
   ============================================================ */

/* Registered so the accent colour can cross-fade between sectors */
@property --accent {
  syntax: '<color>';
  inherits: true;
  initial-value: #7a6aee;
}

:root {
  transition: --accent 700ms ease;
  --card: 200px;
  --pan: 650ms;
  --mono: 'Merchant', 'Courier New', monospace;
}

body.maze-page {
  overflow: hidden;
  background: #02020a;
  font-family: 'Pixel', sans-serif;
  -webkit-user-select: none;
  user-select: none;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---------- Background layers ---------- */
#space {
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  z-index: 0;
}

.nebula {
  position: fixed; inset: -8%;
  z-index: 0;
  pointer-events: none;
  will-change: transform;
  background:
    radial-gradient(55% 48% at 28% 34%, color-mix(in srgb, var(--accent) 20%, transparent), transparent 72%),
    radial-gradient(48% 42% at 76% 70%, color-mix(in srgb, var(--accent) 13%, transparent), transparent 72%),
    radial-gradient(circle at 50% 50%, #0a0a1a 0%, #02020a 100%);
}

.crt {
  position: fixed; inset: 0;
  z-index: 50;
  pointer-events: none;
  background:
    radial-gradient(ellipse at center, transparent 55%, rgba(0, 0, 0, 0.6) 100%),
    repeating-linear-gradient(to bottom, rgba(255, 255, 255, 0.022) 0 1px, transparent 1px 3px);
}

/* ---------- Stage / world ---------- */
#stage {
  position: fixed; inset: 0;
  z-index: 5;
  overflow: hidden;
  touch-action: none;
}

#parallax, #world, #labels {
  position: absolute;
  left: 0; top: 0;
  width: 0; height: 0;
}
#parallax { left: 50%; top: 50%; will-change: transform; }

#world {
  transition: transform var(--pan) cubic-bezier(0.65, 0, 0.25, 1);
  will-change: transform;
}

.cell {
  position: absolute;
  left: var(--cx); top: var(--cy);
  width: 0; height: 0;
  pointer-events: none;
}

.shell {
  position: absolute; left: 0; top: 0;
  width: var(--card); height: var(--card);
  margin: calc(var(--card) / -2) 0 0 calc(var(--card) / -2);
  transform: scale(var(--s, 1));
  opacity: var(--o, 1);
  transition: transform var(--pan) cubic-bezier(0.65, 0, 0.25, 1),
              opacity var(--pan) ease;
  pointer-events: auto;
}
.cell.neighbor .shell { cursor: pointer; animation: pop 0.45s 0.12s backwards ease-out; }
.cell.neighbor.keep .shell { animation: none; }
.cell.current.is-room .shell { cursor: pointer; }
.cell.gone .shell { --o: 0; }

@keyframes pop {
  from { opacity: 0; transform: scale(calc(var(--s, 1) * 0.6)); }
}

/* ---------- Cards ---------- */
.card {
  position: relative;
  isolation: isolate;
  width: 100%; height: 100%;
  background: linear-gradient(160deg, rgba(22, 22, 48, 0.97), rgba(8, 8, 20, 0.97));
  border: 2px solid var(--ca, var(--accent));
  box-shadow:
    10px 10px 0 color-mix(in srgb, var(--ca, var(--accent)) 24%, transparent),
    0 0 36px color-mix(in srgb, var(--ca, var(--accent)) 22%, transparent);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 12px;
  text-align: center;
  transition: filter 0.2s;
}
.card::before {            /* inner frame */
  content: '';
  position: absolute; inset: 6px;
  border: 1px solid color-mix(in srgb, var(--ca, var(--accent)) 28%, transparent);
  pointer-events: none;
}
.card::after {             /* breathing aura */
  content: '';
  position: absolute; inset: -46px;
  z-index: -1;
  background: radial-gradient(closest-side, color-mix(in srgb, var(--ca, var(--accent)) 34%, transparent), transparent);
  opacity: 0;
  pointer-events: none;
}
.cell.current .card::after { animation: breathe 3.4s ease-in-out infinite; }
@keyframes breathe { 0%, 100% { opacity: 0.35; } 50% { opacity: 0.95; } }

.icon {
  width: calc(var(--card) * 0.48);
  height: calc(var(--card) * 0.48);
  image-rendering: pixelated;
  object-fit: cover;
  transition: filter 0.4s;
}
.hub { width: calc(var(--card) * 0.4); color: var(--ca, var(--accent)); }
.hub .ring { transform-origin: 32px 32px; animation: spin 14s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.cap, .enter-prompt {
  font-size: 10px;
  letter-spacing: 2px;
  text-transform: uppercase;
}
.cap { color: var(--text-mid); }
.enter-prompt { color: var(--text-hi); animation: blink 1.4s steps(2, jump-none) infinite; }
@keyframes blink { 50% { opacity: 0.25; } }
.cell:not(.current) .cap, .cell:not(.current) .enter-prompt { display: none; }

/* Neighbours: distant silhouettes */
.cell.neighbor .icon { filter: saturate(0.7) brightness(0.8); }
.cell.neighbor.unknown .icon { filter: brightness(0) invert(0.22); }
.cell.neighbor.unknown .card { border-style: dashed; }
.cell.neighbor:hover .card { filter: brightness(1.35); }
.cell.neighbor.unknown:hover .icon { filter: brightness(0) invert(0.45); }

/* Bump when walking into a wall */
.cell.current.bump .shell { animation: bump 0.22s ease-out; }
@keyframes bump {
  40% { transform: translate(var(--bx, 0), var(--by, 0)) scale(1); }
}

/* Docking: zoom into the card */
.cell.docking .card {
  transform: scale(9);
  opacity: 0;
  transition: transform 0.85s cubic-bezier(0.5, 0, 0.9, 0.4), opacity 0.85s cubic-bezier(0.6, 0, 1, 1);
}

/* ---------- Corridors ---------- */
/* The lane box fades in; the moving dashes live on ::before so the two
   animations never share one animation list. */
.lane {
  position: absolute;
  opacity: 0.9;
  transition: opacity 0.25s;
  pointer-events: none;
  animation: fade-in 0.45s 0.12s backwards;
}
.lane.keep { animation: none; }
.lane::before { content: ''; position: absolute; inset: 0; }
.lane.h { height: 2px; margin-top: -1px; mask-image: linear-gradient(90deg, transparent, #000 14%, #000 86%, transparent); }
.lane.v { width: 2px; margin-left: -1px; mask-image: linear-gradient(180deg, transparent, #000 14%, #000 86%, transparent); }
.lane.h::before {
  background: repeating-linear-gradient(90deg, var(--accent) 0 6px, transparent 6px 12px);
  animation: flow-h 0.7s linear infinite;
}
.lane.v::before {
  background: repeating-linear-gradient(180deg, var(--accent) 0 6px, transparent 6px 12px);
  animation: flow-v 0.7s linear infinite;
}
.lane.rev.h::before { animation-name: flow-h-rev; }
.lane.rev.v::before { animation-name: flow-v-rev; }
.lane.gone { opacity: 0; }

@keyframes flow-h     { to { background-position-x: 12px; } }
@keyframes flow-h-rev { to { background-position-x: -12px; } }
@keyframes flow-v     { to { background-position-y: 12px; } }
@keyframes flow-v-rev { to { background-position-y: -12px; } }
@keyframes fade-in    { from { opacity: 0; } }

/* ---------- Labels on neighbours ---------- */
.label {
  position: absolute;
  transform: translateX(-50%);
  white-space: nowrap;
  font: inherit;
  font-size: 12px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #000;
  background: var(--accent);
  border: 0;
  padding: 5px 9px;
  box-shadow: 0 0 18px color-mix(in srgb, var(--accent) 55%, transparent);
  cursor: pointer;
  transition: opacity 0.2s, filter 0.2s;
  animation: fade-in 0.4s 0.2s backwards;
}
.label:hover, .label:focus-visible { filter: brightness(1.25); outline: none; }
.label .key {
  display: inline-block;
  background: #000;
  color: var(--accent);
  padding: 1px 5px;
  margin-right: 7px;
}
.label .new {
  margin-left: 8px;
  font-size: 9px;
  background: #000;
  color: var(--text-hi);
  padding: 1px 4px;
  animation: blink 1s steps(2, jump-none) infinite;
}

body.moving .cell .shell { animation: none; }
body.moving .enter-prompt { opacity: 0; }
body.moving .label, body.jumping .label { opacity: 0; pointer-events: none; animation: none; }
body.jumping #world { opacity: 0; transition: opacity 0.25s; }

/* ---------- HUD ---------- */
#hud {
  position: fixed; inset: 0;
  z-index: 60;
  pointer-events: none;
  transition: opacity 0.4s;
}
#hud > * { pointer-events: auto; }
body.docking #hud { opacity: 0; }

#hud-top {
  position: absolute; left: 24px; top: 22px;
  pointer-events: none;
}
#site-title { color: var(--text-hi); font-size: 14px; letter-spacing: 2px; }
#loc-line { margin-top: 6px; font-size: 10px; color: var(--text-dim); letter-spacing: 1px; }
#loc-name { color: var(--accent); }
#hint { margin-top: 6px; font-size: 11px; color: var(--text-dim); letter-spacing: 1px; line-height: 1.7; }
#hint b { color: var(--text-mid); font-weight: normal; }
.touch-only { display: none; }

/* Minimap */
#map {
  position: absolute; right: 24px; top: 22px;
  width: 190px;
  padding: 8px;
  background: rgba(6, 6, 18, 0.78);
  border: 1px solid var(--border);
  box-shadow: 6px 6px 0 rgba(0, 0, 0, 0.55);
}
.map-head {
  display: flex; justify-content: space-between;
  font-size: 9px; letter-spacing: 1px;
  color: var(--text-dim);
  margin-bottom: 6px;
}
#map-count { color: var(--accent); }
#minimap { display: block; width: 172px; height: 132px; cursor: pointer; }

/* Transmission panel */
#panel {
  position: absolute; left: 24px; bottom: 24px;
  width: min(360px, calc(100vw - 48px));
  transition: opacity 0.3s;
}
.panel-head { display: flex; align-items: stretch; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
#info-name {
  background: var(--text-hi);
  color: #000;
  padding: 6px 12px;
  font-weight: bold;
  text-transform: uppercase;
  font-size: 16px;
  letter-spacing: 1px;
}
#info-name.glitch { animation: glitch 0.4s steps(2, jump-none); }
@keyframes glitch {
  0%   { transform: translate(0); }
  25%  { transform: translate(-3px, 1px); background: var(--accent); }
  50%  { transform: translate(3px, -1px); }
  75%  { transform: translate(-1px, 0); background: var(--accent); }
}
#info-coord { align-self: flex-end; font-size: 9px; color: var(--text-dim); letter-spacing: 1px; }
#info-desc {
  background: rgba(8, 8, 22, 0.88);
  color: var(--text-mid);
  padding: 12px;
  font-size: 13px;
  line-height: 1.6;
  border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--border));
  min-height: 3.2em;
}
.btn {
  font: inherit;
  font-size: 11px;
  letter-spacing: 1px;
  color: var(--text-hi);
  background: rgba(8, 8, 22, 0.88);
  border: 1px solid var(--accent);
  padding: 6px 10px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.btn:hover, .btn:focus-visible { background: var(--accent); color: #000; outline: none; }
#info-enter { margin-top: 6px; display: block; }
#info-enter[hidden] { display: none; }

body.moving #panel { opacity: 0.25; }
body.term-open #panel { opacity: 0.2; }

/* Toolbar */
#toolbar { position: absolute; right: 24px; bottom: 24px; display: flex; gap: 8px; }

/* Toast */
#toast {
  position: fixed; left: 50%; top: 22px;
  transform: translate(-50%, -20px);
  max-width: min(560px, calc(100vw - 32px));
  z-index: 120;
  padding: 10px 16px;
  font-size: 12px; letter-spacing: 1px; text-align: center;
  color: #000; background: var(--accent);
  box-shadow: 0 0 24px color-mix(in srgb, var(--accent) 60%, transparent);
  opacity: 0; pointer-events: none;
  transition: opacity 0.3s, transform 0.3s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Terminal */
#term {
  position: fixed; left: 50%; bottom: 24px;
  width: min(640px, calc(100vw - 32px));
  transform: translate(-50%, 24px);
  opacity: 0; pointer-events: none;
  z-index: 110;
  background: rgba(4, 4, 14, 0.94);
  border: 1px solid var(--accent);
  box-shadow: 8px 8px 0 rgba(0, 0, 0, 0.6), 0 0 30px color-mix(in srgb, var(--accent) 25%, transparent);
  font-family: var(--mono);
  font-size: 15px;
  transition: opacity 0.2s, transform 0.2s;
  -webkit-user-select: text; user-select: text;
}
#term.open { opacity: 1; pointer-events: auto; transform: translate(-50%, 0); }
#term-log { max-height: 34vh; overflow-y: auto; padding: 10px 14px 4px; line-height: 1.45; }
#term-log .line { white-space: pre-wrap; color: var(--text-mid); }
#term-log .line.cmd { color: var(--text-hi); }
#term-log .line.err { color: #ff6b6b; }
#term-log .line.ok  { color: var(--accent); }
#term-row { display: flex; align-items: center; gap: 8px; padding: 6px 14px 10px; }
#term-prompt { color: var(--accent); white-space: nowrap; }
#term-input {
  flex: 1; min-width: 0;
  background: transparent; border: 0; outline: 0;
  color: var(--text-hi);
  font: inherit;
  caret-color: var(--accent);
}

/* Docking overlay */
#dock {
  position: fixed; inset: 0;
  z-index: 150;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
  font-family: var(--mono);
  font-size: clamp(16px, 2.6vw, 26px);
  letter-spacing: 2px;
  color: var(--text-hi);
  text-shadow: 0 0 14px var(--accent);
  padding: 24px; text-align: center;
}
body.docking #dock { opacity: 1; }
#dock { align-items: flex-end; padding-bottom: 16vh; }
#dock-line {
  background: rgba(0, 0, 0, 0.7);
  border: 1px solid var(--accent);
  padding: 10px 18px;
  max-width: 100%;
}
#dock-line:empty { display: none; }

/* Everything but the room you're entering gets out of the way */
body.docking .label,
body.docking .lane { opacity: 0; }
body.docking .cell.neighbor .shell { --o: 0; }
body.docking #toast { opacity: 0; }

#flash {
  position: fixed; inset: 0;
  z-index: 200;
  background: radial-gradient(circle, #fff 0%, var(--accent) 80%);
  opacity: 0; pointer-events: none;
  transition: opacity 0.28s ease-in;
}
#flash.on { opacity: 1; }

/* ---------- Small screens & touch ---------- */
@media (max-width: 700px) {
  #parallax { top: 42%; }
  #hud-top { left: 14px; top: 14px; max-width: calc(100% - 160px); }
  #site-title { font-size: 12px; }
  #map { right: 12px; top: 12px; width: 134px; padding: 6px; }
  .map-head { font-size: 8px; }
  #minimap { width: 120px; height: 92px; }
  #panel { left: 12px; right: 12px; bottom: 56px; width: auto; }
  #info-name { font-size: 13px; padding: 5px 9px; }
  #info-desc { font-size: 11px; padding: 9px; }
  #toolbar { right: 12px; bottom: 12px; }
  #hint .kb-only { display: none; }
  #hint .touch-only { display: inline; }
  .label { font-size: 10px; padding: 4px 6px; }
  .label .key { display: none; }
}
@media (pointer: coarse) {
  #hint .kb-only { display: none; }
  #hint .touch-only { display: inline; }
  .label .key { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .lane.h::before, .lane.v::before, .hub .ring, .cell.current .card::after, .enter-prompt, .label .new { animation: none !important; }
  .cell.neighbor .shell { animation: none; }
  :root { transition: none; }
  .crt { background: radial-gradient(ellipse at center, transparent 55%, rgba(0, 0, 0, 0.6) 100%); }
}
