:root {
  --bg: #05040a;
  --ink: #9ff3ff;
  --cyan: #2de2e6;
  --mag: #ff2a6d;
  --red: #ff2338;
  --green: #39ff88;
  --violet: #6b4dff;
  --font-ui: 'Silkscreen', monospace;
  --font-term: 'VT323', monospace;
  --font-title: 'Press Start 2P', monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(ellipse at 50% 40%, #150f2b 0%, var(--bg) 70%);
  color: var(--ink);
  font-family: var(--font-ui);
  -webkit-font-smoothing: none;
}

button { font: inherit; color: inherit; cursor: pointer; padding: 0; }
button:disabled { cursor: default; }
svg { display: block; }
.hidden { display: none !important; }

/* 9-slice pixel frames (images generated in sprites.js#installFrames). */
.f {
  border-style: solid;
  border-color: transparent;
  border-image-slice: 3 fill;
  border-image-repeat: stretch;
  background: none;
}

/* ---------- Bezel ---------- */
.bezel {
  position: fixed;
  inset: 12px;
  border-width: 18px;
  border-image-source: var(--fr-bezel);
}

.title-plate {
  position: absolute;
  top: -31px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 12px 3px;
  border-width: 9px;
  border-image-source: var(--fr-plate);
  font-family: var(--font-title);
  font-size: 15px;
  color: #f2efff;
  text-shadow: 2px 2px 0 #000, -1px 0 0 var(--mag), 1px 0 0 var(--cyan);
  white-space: nowrap;
}
.title-plate i {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  margin: -6px 0 -4px;
  background: var(--mag);
  border: 3px solid #000;
  border-radius: 50%;
}

.corner {
  position: absolute;
  z-index: 5;
  width: 72px;
  height: 72px;
  display: grid;
  place-items: center;
  border-width: 12px;
}
.corner-tl { top: -30px; left: -30px; border-image-source: var(--fr-mag); }
.corner-tr { top: -30px; right: -30px; border-image-source: var(--fr-light); }
.corner:hover { filter: brightness(1.2); }
.corner-tr.has-alerts { border-image-source: var(--fr-red); animation: alert-flash 0.6s steps(1) infinite; }

.side-tabs {
  position: absolute;
  z-index: 5;
  top: 70px;
  left: -28px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.tab {
  width: 56px;
  height: 36px;
  border-width: 6px;
  border-image-source: var(--fr-light);
  color: #1a1433;
  font-size: 13px;
}
.tab.active { border-image-source: var(--fr-light-on); color: #000; }
.tab:disabled { opacity: 0.45; }

.mascot {
  position: absolute;
  z-index: 6;
  left: -24px;
  bottom: -18px;
  animation: bob 1.6s steps(2) infinite;
}

.status-bar {
  position: absolute;
  z-index: 5;
  left: 50%;
  bottom: -8px;
  transform: translateX(-50%);
  width: min(58%, 720px);
  height: 48px;
  display: grid;
  place-items: center;
  border-width: 9px;
  border-image-source: var(--fr-screen);
  font-family: var(--font-term);
  font-size: 26px;
  letter-spacing: 3px;
  color: var(--ink);
  text-shadow: 0 0 6px #2de2e688;
  white-space: nowrap;
  overflow: hidden;
}
.status-bar.alert { color: var(--red); text-shadow: 0 0 6px #ff233888; }

.speaker {
  position: absolute;
  z-index: 5;
  bottom: -2px;
  left: calc(50% + min(29%, 360px) + 14px);
  width: 60px;
  height: 38px;
  display: grid;
  place-items: center;
  border-width: 6px;
  border-image-source: var(--fr-btn);
}

/* ---------- Screen ---------- */
.screen {
  position: absolute;
  inset: 30px 30px 52px 30px;
  border-width: 9px;
  border-image-source: var(--fr-screen);
}
.screen-inner {
  position: absolute;
  inset: 0;
  overflow: clip;
  background: radial-gradient(ellipse at 50% 45%, #0f1d26 0%, #06080d 75%);
  animation: flicker 5s infinite;
}
.screen-inner.off { transform: scale(0, 0); }
.screen-inner.power-on { animation: power-on 0.9s ease-out both, flicker 5s 0.9s infinite; }
.screen-inner.glitch { animation: glitch 0.55s steps(2) both; }

.view { position: absolute; inset: 0; }

/* ---------- Welcome ---------- */
#welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-bottom: 3.5%;
}
.bg-logo {
  position: absolute;
  left: 50%;
  top: 46%;
  width: min(62%, 68vh);
  transform: translate(-50%, -50%);
  opacity: 0.11;
  pointer-events: none;
}
.bg-logo svg { width: 100%; height: auto; }
.hang {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  transform-origin: 50% 0;
  animation: swing 3.4s ease-in-out infinite;
}
.hang.retract { animation: retract 0.7s cubic-bezier(.6, -0.3, .8, .4) forwards; }
.thread { flex: 1; width: 3px; background: #f2efff; box-shadow: 0 0 6px #ffffff88; }
.copy { position: relative; text-align: center; margin-top: 14px; }
.copy p { margin: 0 0 18px; font-size: 15px; line-height: 1.6; letter-spacing: 1px; }
.copy p.small { font-size: 12px; margin-bottom: 12px; }
.segbar { display: flex; gap: 4px; justify-content: center; align-items: flex-end; margin-bottom: 20px; }
.seg { width: 12px; height: 9px; background: #1a3640; }
.seg:first-child { height: 14px; }
.seg.on { background: var(--cyan); box-shadow: 0 0 6px var(--cyan); }
.settings { visibility: hidden; }
.settings.show { visibility: visible; animation: blink-in 0.4s steps(4); }
.btn-row { display: flex; gap: 10px; justify-content: center; }

.pxbtn {
  padding: 2px 10px;
  border-width: 6px;
  border-image-source: var(--fr-btn);
  font-size: 12px;
  color: var(--ink);
}
.pxbtn:hover, .pxbtn:focus-visible { border-image-source: var(--fr-btn-hot); outline: none; }
.pxbtn.dim { border-image-source: var(--fr-dim); color: #8a879c; }
.pxbtn.dim:hover { border-image-source: var(--fr-btn); color: var(--ink); }
.pxbtn.red { border-image-source: var(--fr-red); color: #ffd0d6; }
.pxbtn.green { border-image-source: var(--fr-green); color: #c9ffe0; }
.pxbtn.red:hover, .pxbtn.green:hover { filter: brightness(1.35); }
.pxbtn:disabled { opacity: 0.5; filter: none; }

/* ---------- Terminal ---------- */
#terminal {
  padding: 26px 34px;
  font-family: var(--font-term);
  font-size: 22px;
  color: var(--green);
  text-shadow: 0 0 6px #39ff8866;
}
#term-out { margin: 0; font: inherit; white-space: pre-wrap; }
#term-out .warn { color: var(--red); text-shadow: 0 0 6px #ff233888; }
#term-out .dim { color: #1f9b58; }
#term-out .hi { color: #eafff2; }
.cursor { animation: blink 0.8s steps(1) infinite; }
.term-skip { position: absolute; right: 26px; bottom: 18px; font-size: 16px; color: #1f9b58; animation: blink 1.4s steps(1) infinite; }

/* ---------- Map ---------- */
#gl { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; }
#gl.pointing { cursor: pointer; }
#labels { position: absolute; inset: 0; pointer-events: none; z-index: 10; overflow: clip; }
.lbl {
  position: absolute;
  left: 0;
  top: 0;
  font-family: var(--font-term);
  font-size: 18px;
  line-height: 1;
  color: var(--cyan);
  white-space: nowrap;
  text-shadow: 0 0 4px #000, 0 0 8px #2de2e688;
  will-change: transform;
}
.lbl.floor { padding: 2px 6px; background: #000b; border-left: 3px solid var(--cyan); }
.lbl.floor.blank { color: #5f7a86; border-color: #5f7a86; }
.lbl.room { color: #c9bcff; font-size: 16px; }
.lbl.street { color: #ff2a6d99; font-size: 16px; letter-spacing: 6px; }

.hud {
  position: absolute;
  z-index: 20;
  font-family: var(--font-term);
  font-size: 28px;
  line-height: 1;
  color: #fff;
  text-shadow: 2px 0 0 var(--mag), -2px 0 0 var(--cyan), 0 0 8px #0008;
  pointer-events: none;
}
.hud small { display: block; font-size: 17px; margin-top: 4px; color: #bdf9ff; text-shadow: 0 0 4px #000; }
.hud-tl { top: 14px; left: 18px; }
.hud-tr { top: 14px; right: 18px; }
.hud-bl { bottom: 14px; left: 18px; }
.hud-br { bottom: 14px; right: 18px; }
.rec { color: var(--red); text-shadow: none; animation: blink 1s steps(1) infinite; }

.legend {
  position: absolute;
  z-index: 20;
  left: 18px;
  bottom: 50px;
  font-family: var(--font-term);
  font-size: 18px;
  color: #cfd8ff;
  pointer-events: none;
}
.sw { display: inline-block; width: 12px; height: 12px; margin-right: 8px; vertical-align: -1px; }
.sw-clear { background: var(--green); }
.sw-alert { background: var(--red); animation: alert-flash 0.6s steps(1) infinite; }

.hint {
  position: absolute;
  z-index: 20;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  font-family: var(--font-term);
  font-size: 17px;
  color: #6f8a96;
  letter-spacing: 2px;
  pointer-events: none;
  white-space: nowrap;
}

.tip {
  position: absolute;
  z-index: 30;
  left: 0;
  top: 0;
  padding: 1px 8px;
  font-family: var(--font-term);
  font-size: 19px;
  background: #000d;
  border: 2px solid currentColor;
  pointer-events: none;
  white-space: nowrap;
}

/* ---------- Panels ---------- */
.panel {
  position: absolute;
  z-index: 40;
  top: 58px;
  right: 16px;
  width: 320px;
  max-height: calc(100% - 120px);
  overflow-y: auto;
  padding: 8px 12px 12px;
  border-width: 6px;
  border-image-source: var(--fr-panel);
  font-family: var(--font-term);
  font-size: 19px;
  color: #d6ffe9;
  scrollbar-width: thin;
  scrollbar-color: var(--green) transparent;
  text-transform: uppercase;
}
.panel.is-alert { border-image-source: var(--fr-alert); }
.panel h2 { margin: 0; font-family: var(--font-ui); font-size: 15px; font-weight: normal; color: #fff; letter-spacing: 1px; }
.panel h3 { margin: 12px 0 4px; font-family: var(--font-ui); font-size: 11px; font-weight: normal; color: var(--green); letter-spacing: 1px; }
.panel .sub { color: #7fb89a; font-size: 16px; }
.panel .close { position: absolute; top: 4px; right: 8px; font-family: var(--font-ui); font-size: 13px; color: #7fb89a; background: none; border: 0; }
.panel .close:hover { color: #fff; }
.status-big { display: flex; align-items: center; gap: 10px; margin: 10px 0 4px; font-family: var(--font-ui); font-size: 18px; }
.status-big.clear { color: var(--green); }
.status-big.alert { color: var(--red); animation: alert-flash 0.6s steps(1) infinite; }
.stats { color: #b9e8cf; }
.log { list-style: none; margin: 0; padding: 0; }
.log li { display: flex; gap: 8px; padding: 1px 0; border-bottom: 1px dashed #173a28; }
.log li .t { flex: 0 0 42px; color: #5f9b7b; }
.log li.k .what { color: #ff7a88; }
.log li.c .what { color: var(--green); }
.log .empty { color: #5f9b7b; border: 0; }
.note-input {
  width: 100%;
  margin: 4px 0 8px;
  padding: 4px 6px;
  font-family: var(--font-term);
  font-size: 18px;
  color: #eafff2;
  background: #000;
  border: 2px solid #1f6b45;
  outline: none;
  text-transform: uppercase;
}
.note-input:focus { border-color: var(--green); }
.panel .btn-row { justify-content: stretch; }
.panel .btn-row .pxbtn { flex: 1; padding: 4px 6px; font-size: 11px; }
.alert-row { display: flex; align-items: center; gap: 8px; width: 100%; padding: 4px 0; text-align: left; background: none; border: 0; border-bottom: 1px dashed #173a28; font-family: var(--font-term); font-size: 19px; }
.alert-row:hover { color: #fff; }
.alert-row .state { margin-left: auto; }
.alert-row.k .state { color: var(--red); }
.alert-row.c .state { color: var(--green); }

/* ---------- CRT / VCR overlays ---------- */
.fx { position: absolute; inset: 0; pointer-events: none; }
.scanlines { z-index: 60; background: repeating-linear-gradient(to bottom, transparent 0 2px, rgba(0, 0, 0, 0.3) 2px 3px); }
.vignette { z-index: 61; background: radial-gradient(ellipse at center, transparent 55%, rgba(0, 0, 0, 0.7) 100%); }
.tracking {
  z-index: 62;
  inset: auto 0 auto 0;
  top: -90px;
  height: 80px;
  background: linear-gradient(to bottom, transparent, rgba(255, 255, 255, 0.04) 40%, rgba(255, 255, 255, 0.1) 50%, rgba(255, 255, 255, 0.04) 60%, transparent);
  mix-blend-mode: screen;
  animation: tracking 8s linear infinite;
}
.noise {
  z-index: 63;
  inset: -50%;
  opacity: 0.07;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  animation: noise 0.4s steps(4) infinite;
}

/* ---------- Animations ---------- */
@keyframes power-on {
  0% { transform: scale(0, 0.004); filter: brightness(5); }
  35% { transform: scale(1, 0.004); filter: brightness(5); }
  60% { transform: scale(1, 1); filter: brightness(2.2); }
  100% { transform: scale(1, 1); filter: none; }
}
@keyframes flicker {
  0%, 100% { opacity: 1; }
  48% { opacity: 1; }
  50% { opacity: 0.94; }
  52% { opacity: 1; }
}
@keyframes glitch {
  0% { transform: translate(0); filter: none; clip-path: inset(0); }
  20% { transform: translate(-8px, 2px); filter: hue-rotate(90deg) saturate(3); clip-path: inset(10% 0 40% 0); }
  40% { transform: translate(10px, -3px); filter: invert(1); clip-path: inset(50% 0 5% 0); }
  60% { transform: translate(-4px, 0); filter: hue-rotate(-90deg); clip-path: inset(0 0 70% 0); }
  80% { transform: translate(3px, 1px); filter: brightness(2); clip-path: inset(0); }
  100% { transform: translate(0); filter: none; clip-path: inset(0); }
}
@keyframes swing { 0%, 100% { transform: rotate(-1.2deg); } 50% { transform: rotate(1.2deg); } }
@keyframes retract { to { transform: translateY(-110%); } }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }
@keyframes blink { 50% { opacity: 0; } }
@keyframes blink-in { 0% { opacity: 0; } 50% { opacity: 1; } 75% { opacity: 0; } 100% { opacity: 1; } }
@keyframes tracking { 0% { top: -90px; } 100% { top: 110%; } }
@keyframes noise {
  0% { transform: translate(0, 0); }
  25% { transform: translate(-5%, 3%); }
  50% { transform: translate(4%, -6%); }
  75% { transform: translate(-3%, 5%); }
  100% { transform: translate(0, 0); }
}
@keyframes alert-flash { 50% { opacity: 0.25; } }

@media (max-width: 760px) {
  .mascot, .hint, .hud-br, .speaker { display: none; }
  .title-plate { font-size: 10px; }
  .status-bar { width: 78%; font-size: 20px; }
  .panel { width: calc(100% - 32px); }
  .copy p { font-size: 12px; }
}
