:root {
  color-scheme: dark;
  --black: #050707;
  --ink: #0b1010;
  --panel: #151b1b;
  --panel-2: #222929;
  --steel: #9da3a0;
  --steel-dark: #4e5553;
  --white: #eef4ee;
  --red: #e02724;
  --red-dark: #76120f;
  --cyan: #7be5e0;
  --green: #50e34d;
  --yellow: #f3dc47;
  --shadow: rgba(0, 0, 0, .62);
  font-family: "Courier New", ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--black);
}

* { box-sizing: border-box; }

html {
  min-height: 100%;
  background:
    radial-gradient(circle at 50% -20%, #27312f 0, #101515 37%, #050707 75%);
  overscroll-behavior: none;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--white);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
}

button, input { font: inherit; }

button {
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

button:focus-visible, input:focus-visible, a:focus-visible {
  outline: 3px solid var(--cyan);
  outline-offset: 3px;
}

.app-shell {
  width: min(1220px, 100%);
  min-height: 100vh;
  margin: auto;
  padding: max(14px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
}

.topbar, .game-layout, footer { width: 100%; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--white);
  text-decoration: none;
  letter-spacing: .08em;
}

.brand-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  color: var(--white);
  font-size: 1.15rem;
  font-weight: 900;
  font-style: italic;
  background: linear-gradient(145deg, #ee3c38, var(--red-dark));
  border: 2px solid #ff6a65;
  box-shadow: 0 0 0 4px #252b2a, 0 5px 14px var(--shadow);
  clip-path: polygon(10% 0, 100% 0, 90% 100%, 0 100%);
}

.brand strong, .brand small { display: block; }
.brand strong { color: var(--red); font-size: clamp(1.1rem, 3vw, 1.45rem); line-height: 1; text-shadow: 1px 1px #000; }
.brand small { margin-top: 4px; color: var(--steel); font-size: .62rem; letter-spacing: .04em; }

.top-actions { display: flex; gap: 9px; }
.icon-button, .text-button {
  width: 42px;
  height: 38px;
  border: 1px solid #59615e;
  border-bottom-color: #202423;
  border-radius: 3px;
  background: linear-gradient(#313836, #171d1c);
  box-shadow: inset 0 1px #737a77, 0 3px 8px var(--shadow);
  font-weight: 800;
}
.icon-button:hover, .text-button:hover { background: linear-gradient(#414a47, #202725); }
.icon-button.muted { color: #777; text-decoration: line-through; }
.top-actions .editor-link {
  width: auto;
  min-width: 78px;
  padding: 0 10px;
  display: grid;
  place-items: center;
  color: var(--white);
  text-decoration: none;
  font-size: .58rem;
  letter-spacing: .035em;
  text-transform: uppercase;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 2.05fr) minmax(320px, .95fr);
  gap: 18px;
  align-items: start;
}

.cabinet, .control-console {
  background: linear-gradient(145deg, #3c4341 0, #171c1b 16%, #111615 84%, #313836 100%);
  border: 1px solid #6d7471;
  box-shadow: inset 0 0 0 3px #222826, inset 0 0 28px #000, 0 14px 38px var(--shadow);
}

.cabinet { padding: clamp(9px, 2vw, 17px); }
.cabinet-labels {
  display: flex;
  justify-content: space-between;
  padding: 1px 5px 9px;
  color: #bdc3bf;
  font-size: clamp(.48rem, 1.25vw, .65rem);
  letter-spacing: .12em;
}
.pulse-label::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 7px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 8px var(--green);
}

.screen-bezel {
  padding: clamp(7px, 1.7vw, 14px);
  background: linear-gradient(135deg, #1b201f, #565d5a 48%, #191e1d 50%);
  border: 2px solid #737a77;
  box-shadow: inset 0 0 0 3px #090b0b, inset 0 0 18px #000;
}

.screen {
  position: relative;
  overflow: hidden;
  aspect-ratio: 16 / 10;
  width: 100%;
  background: #000;
  border: 2px solid #020303;
  box-shadow: 0 0 24px #000, inset 0 0 22px rgba(123, 229, 224, .08);
  touch-action: none;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.scanlines {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: .09;
  background: repeating-linear-gradient(0deg, rgba(0,0,0,.7) 0 1px, transparent 1px 3px);
  mix-blend-mode: multiply;
}

.screen-ui {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.screen-ui > * { pointer-events: auto; }
.title-controls, .ending-controls {
  align-self: end;
  width: 100%;
  padding: 11px 14px 13px;
  display: flex;
  justify-content: center;
  gap: 8px;
  background: linear-gradient(transparent, rgba(0,0,0,.9) 42%);
}

.screen-action {
  min-height: 34px;
  padding: 7px 16px;
  color: #fff;
  border: 1px solid #ff6a65;
  background: linear-gradient(#df302c, #76120f);
  box-shadow: inset 0 1px rgba(255,255,255,.35), 0 3px 10px #000;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .07em;
  transition: transform .12s ease, filter .12s ease, border-color .12s ease;
}
.screen-action:hover { filter: brightness(1.13); transform: translateY(-1px); }
.screen-action:active { transform: translateY(1px); }
.screen-action.secondary { border-color: #777f7c; background: linear-gradient(#454d4a, #1d2321); }

.death-panel {
  position: absolute;
  top: 5%;
  left: 3.5%;
  width: 43%;
  padding: 2.5% 2.5% 3%;
  color: #fff;
  background: linear-gradient(135deg, rgba(0, 0, 0, .98), rgba(0, 0, 0, .72));
  border-left: 3px solid var(--red);
  box-shadow: 9px 0 20px rgba(0, 0, 0, .48);
}
.death-panel strong {
  display: block;
  color: var(--red);
  font-size: clamp(.75rem, 2.5vw, 1.45rem);
  line-height: 1;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.death-panel p {
  min-height: 2.5em;
  margin: 7px 0 10px;
  color: #e8ecea;
  font-size: clamp(.48rem, 1.25vw, .75rem);
  line-height: 1.25;
}
.death-panel > div { display: flex; flex-wrap: wrap; gap: 6px; }
.death-panel .screen-action {
  min-height: 27px;
  padding: 5px 9px;
  font-size: clamp(.45rem, 1.15vw, .68rem);
}

.intro-skip {
  position: absolute;
  right: 9px;
  bottom: 8px;
  padding: 5px 8px;
  border: 0;
  color: #bbb;
  background: rgba(0,0,0,.62);
  font-size: .58rem;
}

.message-box {
  position: absolute;
  left: 3%;
  right: 3%;
  bottom: 7%;
  z-index: 3;
  padding: 9px 12px;
  color: #fff;
  background: rgba(0, 0, 0, .94);
  border: 1px solid #f3f5f4;
  box-shadow: 0 0 0 2px #1b1f1e, 0 5px 14px #000;
  animation: message-in .16s ease-out;
}
.message-box p { margin: 0; font-size: clamp(.65rem, 2.2vw, .95rem); line-height: 1.3; }
.message-box span { display: block; margin-top: 5px; color: var(--steel); font-size: clamp(.48rem, 1.4vw, .65rem); text-align: right; }

.status-strip {
  display: grid;
  grid-template-columns: repeat(5, auto);
  gap: 5px 10px;
  align-items: center;
  justify-content: space-between;
  padding: 11px 5px 0;
  font-size: clamp(.52rem, 1.35vw, .73rem);
}
.status-strip b { color: var(--steel); font-size: .85em; letter-spacing: .07em; }
.status-strip output { color: var(--cyan); font-weight: 800; }
.status-strip output.danger { color: #ff4c47; text-shadow: 0 0 8px rgba(255, 76, 71, .85); }
.tool-status { display: flex; align-items: center; gap: 5px; }
.tool-status i { width: 8px; height: 8px; border-radius: 50%; background: #3f4744; box-shadow: inset 0 1px 2px #000; }
.tool-status i.on { background: var(--green); box-shadow: 0 0 7px var(--green); }
.walk-hint {
  margin: 7px 4px 0;
  color: var(--cyan);
  font-size: clamp(.5rem, 1.2vw, .64rem);
  letter-spacing: .08em;
  text-align: center;
  opacity: .82;
}

.control-console { padding: 14px; }
.console-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 10px;
  color: var(--red);
  font-weight: 900;
  letter-spacing: .11em;
  border-bottom: 1px solid #4e5553;
}
.console-heading i { width: 42px; height: 7px; background: repeating-linear-gradient(90deg, var(--red) 0 5px, transparent 5px 9px); }

.controls-grid { padding: 14px 0; display: grid; gap: 16px; }
.dpad {
  display: grid;
  grid-template-columns: repeat(3, 56px);
  grid-template-rows: repeat(3, 50px);
  justify-content: center;
  filter: drop-shadow(0 5px 5px #000);
}
.dpad button {
  border: 1px solid #68706d;
  background: linear-gradient(#3c4441, #1b211f);
  color: #d7dcda;
  font-size: 1.15rem;
}
.dpad button:active, .dpad button.pressed { color: var(--cyan); background: #0c1110; transform: translateY(1px); }
.dpad [data-move="up"] { grid-column: 2; grid-row: 1; border-radius: 8px 8px 0 0; }
.dpad [data-move="left"] { grid-column: 1; grid-row: 2; border-radius: 8px 0 0 8px; }
.dpad-core { grid-column: 2; grid-row: 2; background: radial-gradient(circle, #111 18%, #303735 20% 62%, #151a18 64%); }
.dpad [data-move="right"] { grid-column: 3; grid-row: 2; border-radius: 0 8px 8px 0; }
.dpad [data-move="down"] { grid-column: 2; grid-row: 3; border-radius: 0 0 8px 8px; }

.action-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.action-grid button {
  min-height: 52px;
  padding: 7px 5px;
  border: 1px solid #5d6562;
  border-bottom-color: #0a0c0b;
  background: linear-gradient(#343b39, #151a19);
  box-shadow: inset 0 1px #767d7a, 0 2px 4px #000;
  transition: transform .1s ease, filter .1s ease;
}
.action-grid button:hover { background: linear-gradient(#424b48, #202624); }
.action-grid button:active { transform: translateY(1px); }
.action-grid span { display: block; color: var(--red); font-size: .55rem; text-align: left; }
.action-grid b { font-size: clamp(.64rem, 1.8vw, .78rem); letter-spacing: .04em; }

.command-line {
  padding: 10px;
  background: #080b0a;
  border: 1px solid #4f5855;
  box-shadow: inset 0 0 9px #000;
}
.command-line label { display: block; margin-bottom: 7px; color: var(--green); font-size: .65rem; letter-spacing: .1em; }
.command-line div { display: flex; align-items: center; gap: 7px; color: var(--green); }
.command-line input { min-width: 0; flex: 1; border: 0; outline: 0; color: #c6ffc5; background: transparent; user-select: text; text-transform: none; }
.command-line input::placeholder { color: #466346; }
.command-line button { width: 34px; border: 1px solid #3f5d3e; background: #172217; color: var(--green); }

.quick-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 9px; }
.quick-actions button { padding: 8px 3px; border: 1px solid #4c5552; background: #1b211f; color: #bdc5c2; font-size: .66rem; }
.keyboard-hint { margin: 10px 2px 0; color: #7e8784; font-size: .58rem; line-height: 1.35; }

footer {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: auto;
  padding-top: 16px;
  color: #555f5b;
  font-size: .55rem;
  letter-spacing: .08em;
}

.modal { position: fixed; z-index: 20; inset: 0; display: grid; place-items: center; padding: 18px; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.8); backdrop-filter: blur(3px); }
.modal-panel {
  position: relative;
  width: min(620px, 100%);
  max-height: min(85vh, 720px);
  overflow: auto;
  padding: 22px;
  color: var(--white);
  background: linear-gradient(145deg, #29302e, #101414 50%);
  border: 1px solid #89918e;
  box-shadow: inset 0 0 0 4px #1b211f, 0 18px 50px #000;
  animation: modal-in .18s cubic-bezier(.2,.8,.2,1);
}
.modal-backdrop { animation: backdrop-in .16s ease-out; }
.modal-panel h2 { margin: 0 34px 16px 0; color: var(--red); font-size: 1.05rem; letter-spacing: .08em; }
.modal-close { position: absolute; top: 10px; right: 11px; width: 34px; height: 34px; border: 1px solid #5b6360; background: #181d1c; font-size: 1.35rem; }
.modal p, .modal li { color: #c8cfcc; font-size: .78rem; line-height: 1.55; }
.modal ul { padding-left: 20px; }
.modal-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 17px; }
.modal-actions button, .floor-grid button {
  padding: 9px 12px;
  border: 1px solid #69716e;
  background: linear-gradient(#3c4441, #191f1d);
}
.modal-actions .primary { border-color: #ff6863; background: linear-gradient(#d92d29, #72110f); }
.inventory-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.inventory-list div { padding: 12px; background: #080b0a; border: 1px solid #39413e; text-align: center; }
.inventory-list b { display: block; margin-top: 5px; color: var(--cyan); }

.elevator-display, .computer-shell, .surgery-shell {
  position: relative;
  overflow: hidden;
  min-height: 280px;
  background: #000 center / cover no-repeat;
  border: 2px solid #727a77;
}
.elevator-display { background-image: linear-gradient(rgba(0,0,0,.24), rgba(0,0,0,.48)), url("assets/images/lyfta2.png"); }
.floor-readout { padding: 12px; color: #fff; font-weight: 900; text-shadow: 2px 2px #000; }
.floor-grid { position: absolute; right: 12px; bottom: 12px; width: min(190px, 56%); display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
.floor-grid button { padding: 8px 4px; background: rgba(24,29,28,.94); }
.floor-grid button.active { color: #fff; border-color: var(--red); box-shadow: inset 0 0 0 1px var(--red); }
.floor-grid button:hover { color: var(--cyan); border-color: #8a9490; }
.elevator-tools { position: absolute; left: 10px; bottom: 10px; display: grid; gap: 6px; }
.elevator-tools button { padding: 8px; color: #fff; border: 1px solid #ddd; background: rgba(0,0,0,.78); }

.computer-shell { min-height: 340px; padding: 36px 40px; background-image: url("assets/images/monitor.png"); background-size: 100% 100%; }
.terminal-output { height: 190px; overflow: auto; white-space: pre-wrap; color: #78f37a; font-size: .7rem; line-height: 1.35; text-shadow: 0 0 5px #27a62a; }
.terminal-form { display: flex; gap: 5px; color: #78f37a; }
.terminal-form input { flex: 1; min-width: 0; border: 0; border-bottom: 1px solid #276c2a; outline: 0; color: #adffae; background: transparent; user-select: text; }
.terminal-form button { border: 1px solid #276c2a; color: #78f37a; background: #071007; }

.surgery-shell { min-height: 0; aspect-ratio: 16 / 10; padding: 12px; background-image: linear-gradient(rgba(0,0,0,.04), rgba(0,0,0,.12)), url("assets/images/surgery.png"); background-size: 100% 100%; }
.surgery-code { display: inline-block; padding: 6px 9px; color: #fff; background: #000; border: 1px solid #ddd; font-weight: 900; }
.surgery-reference-toggle {
  position: absolute;
  z-index: 3;
  top: 50px;
  left: 12px;
  padding: 5px 8px;
  color: var(--cyan);
  background: rgba(0,0,0,.9);
  border: 1px solid var(--cyan);
  font-size: clamp(.5rem, 1.2vw, .65rem);
  text-transform: uppercase;
}
.surgery-reference {
  position: absolute;
  z-index: 5;
  inset: 8px;
  overflow: auto;
  padding: 10px;
  color: #e8eee9;
  background: rgba(5,8,7,.98);
  border: 2px solid #aab2ae;
  box-shadow: inset 0 0 0 2px #242b29;
}
.surgery-reference[hidden] { display: none; }
.surgery-reference h3 { margin: 0 28px 5px 0; color: var(--cyan); font-size: clamp(.65rem, 1.7vw, .9rem); }
.surgery-reference p { margin: 0 0 7px; color: #c8cfcc; font-size: clamp(.48rem, 1.2vw, .65rem); line-height: 1.3; }
.surgery-reference-close { position: absolute; top: 5px; right: 5px; width: 26px; height: 24px; padding: 0; color: #fff; border: 1px solid #606966; background: #171c1b; }
.surgery-reference-grid { display: grid; gap: 2px; }
.surgery-reference-grid > div {
  display: grid;
  grid-template-columns: 45px 58px 1fr;
  gap: 7px;
  align-items: center;
  min-height: 23px;
  padding: 3px 6px;
  background: #101615;
  border-left: 2px solid #3e4946;
  font-size: clamp(.48rem, 1.15vw, .64rem);
}
.surgery-reference-grid b { color: #fff; }
.surgery-reference-grid code { color: var(--yellow); font: inherit; font-weight: 900; }
.surgery-reference-grid span { color: #aeb8b4; }
.surgery-status {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 56%;
  min-height: 31px;
  padding: 7px 9px;
  color: var(--green);
  background: rgba(0,0,0,.88);
  border-left: 2px solid var(--green);
  font-size: clamp(.52rem, 1.35vw, .72rem);
  line-height: 1.25;
}
.surgery-hotspot {
  position: absolute;
  z-index: 2;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 2px;
  background: transparent;
}
.surgery-hotspot span {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.surgery-hotspot:hover,
.surgery-hotspot:focus-visible {
  border-color: rgba(255,255,255,.9);
  outline: 0;
  box-shadow: 0 0 0 2px rgba(0,0,0,.75), 0 0 12px rgba(123,229,224,.85);
}
.surgery-hotspot.selected {
  border-color: var(--green);
  background: rgba(80,227,77,.13);
  box-shadow: 0 0 12px rgba(80,227,77,.95);
}
.hotspot-s { left: 10.3%; top: 75.2%; width: 7.4%; height: 23%; }
.hotspot-e { left: 17.3%; top: 75.2%; width: 7.4%; height: 23%; }
.hotspot-b { left: 24.2%; top: 75.2%; width: 7.4%; height: 23%; }
.hotspot-t { left: 48.1%; top: 79.2%; width: 9.5%; height: 15%; }
.hotspot-u { left: 47.3%; top: 42%; width: 10%; height: 16%; }

.screen[data-mode="play"] #gameCanvas { cursor: crosshair; }

@keyframes modal-in {
  from { opacity: 0; transform: translateY(8px) scale(.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes backdrop-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes message-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 880px) {
  .app-shell { max-width: 720px; }
  .game-layout { grid-template-columns: 1fr; }
  .control-console { padding: 12px; }
  .controls-grid { grid-template-columns: minmax(160px, .8fr) minmax(250px, 1.2fr); align-items: center; }
  .keyboard-hint { display: none; }
  footer { margin-top: 14px; }
}

@media (max-width: 570px) {
  .app-shell { padding-left: 7px; padding-right: 7px; }
  .topbar { margin: 2px 4px 9px; width: auto; }
  .brand-mark { width: 39px; height: 39px; font-size: .95rem; }
  .brand small { max-width: 190px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .icon-button, .text-button { width: 36px; height: 34px; }
  .top-actions { gap: 5px; }
  .top-actions .editor-link { width: auto; min-width: 62px; padding-inline: 7px; font-size: .5rem; }
  .cabinet { padding: 7px; }
  .cabinet-labels { padding-bottom: 6px; }
  .screen-bezel { padding: 5px; }
  .status-strip { grid-template-columns: repeat(4, 1fr); }
  .tool-status { grid-column: 1 / -1; justify-content: center; }
  .controls-grid { grid-template-columns: 1fr; gap: 10px; }
  .dpad { grid-template-columns: repeat(3, 54px); grid-template-rows: repeat(3, 45px); }
  .action-grid button { min-height: 47px; }
  .modal { padding: 8px; }
  .modal-panel { padding: 17px 13px; }
  .computer-shell { min-height: 300px; padding: 31px 27px; }
  footer { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
  .scanlines { display: none; }
}
