:root {
  color-scheme: dark;
  --ink: #d8d3b0;
  --muted: #8e8a72;
  --line: rgba(232, 223, 158, 0.24);
  --accent: #d8d17d;
  --cell: 560px;
  --half-cell: 280px;
  --room-height: 330px;
  --eye-height: 188px;
  --step-time: 720ms;
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background: #050604;
}

body {
  color: var(--ink);
  font-family: "Courier New", Courier, monospace;
}

button,
a { font: inherit; }

button:focus-visible,
a:focus-visible {
  outline: 2px solid #fffbc7;
  outline-offset: 3px;
}

.complex {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  isolation: isolate;
  overflow: hidden;
  background: #080a07;
}

.complex-bar {
  position: absolute;
  z-index: 30;
  top: 0;
  right: 0;
  left: 0;
  display: flex;
  min-height: 54px;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: max(11px, env(safe-area-inset-top)) 18px 10px;
  border-bottom: 1px solid rgba(222, 216, 157, 0.16);
  background: linear-gradient(to bottom, rgba(5, 6, 4, 0.92), rgba(5, 6, 4, 0.5), transparent);
  text-transform: uppercase;
}

.complex-mark {
  display: flex;
  align-items: baseline;
  gap: 9px;
  color: rgba(237, 231, 184, 0.88);
  font-size: 0.72rem;
  letter-spacing: 0.22em;
}

.complex-mark small {
  color: rgba(205, 199, 158, 0.5);
  font-size: 0.54rem;
  letter-spacing: 0.14em;
}

.complex-mark__pulse {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #e8df85;
  box-shadow: 0 0 8px #d6ca5a;
  animation: pulse 3.8s steps(1, end) infinite;
}

.complex-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.complex-actions button,
.complex-actions a {
  padding: 6px 9px;
  border: 1px solid rgba(220, 214, 166, 0.25);
  background: rgba(15, 16, 11, 0.62);
  color: rgba(225, 220, 180, 0.72);
  font-size: 0.58rem;
  letter-spacing: 0.08em;
  text-decoration: none;
  text-transform: uppercase;
  cursor: pointer;
}

.complex-actions button:hover,
.complex-actions a:hover {
  border-color: rgba(242, 234, 173, 0.55);
  color: #fffbd2;
}

.viewport {
  position: absolute;
  inset: 0;
  overflow: hidden;
  perspective: 760px;
  perspective-origin: 50% 48%;
  background: #15160e;
}

.camera,
.camera-turn,
.world,
.cell {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  transform-style: preserve-3d;
}

.camera {
  transform: translateY(var(--eye-height));
}

.camera-turn {
  transition: transform var(--step-time) cubic-bezier(0.2, 0.72, 0.2, 1);
}

.world {
  transition: transform var(--step-time) cubic-bezier(0.18, 0.7, 0.18, 1);
}

.cell {
  transform: translate3d(calc(var(--x) * var(--cell)), 0, calc(var(--z) * var(--cell)));
}

.surface {
  position: absolute;
  display: block;
  backface-visibility: hidden;
}

.floor,
.ceiling {
  left: calc(var(--half-cell) * -1);
  top: calc(var(--half-cell) * -1);
  width: var(--cell);
  height: var(--cell);
}

.floor {
  transform: rotateX(90deg);
  background:
    repeating-linear-gradient(88deg, rgba(18, 14, 8, 0.11) 0 2px, transparent 2px 10px),
    repeating-linear-gradient(2deg, transparent 0 67px, rgba(35, 28, 13, 0.1) 68px 70px),
    #5b4b2c;
}

.ceiling {
  transform: translateY(calc(var(--room-height) * -1)) rotateX(-90deg);
  background:
    linear-gradient(rgba(61, 57, 31, 0.28) 2px, transparent 2px) 0 0 / 140px 140px,
    linear-gradient(90deg, rgba(61, 57, 31, 0.28) 2px, transparent 2px) 0 0 / 140px 140px,
    #b9b17a;
}

.wall {
  left: calc(var(--half-cell) * -1);
  top: calc(var(--room-height) * -1);
  width: var(--cell);
  height: var(--room-height);
  background:
    repeating-linear-gradient(90deg, transparent 0 138px, rgba(60, 55, 27, 0.2) 139px 141px),
    repeating-linear-gradient(0deg, transparent 0 108px, rgba(69, 62, 29, 0.2) 109px 111px),
    linear-gradient(#aaa263, #7e753f);
  box-shadow: inset 0 0 70px rgba(26, 25, 13, 0.26);
}

.wall--north { transform: translateZ(calc(var(--half-cell) * -1)); }
.wall--south { transform: translateZ(var(--half-cell)) rotateY(180deg); }
.wall--west { transform: translateX(calc(var(--half-cell) * -1)) rotateY(90deg); }
.wall--east { transform: translateX(var(--half-cell)) rotateY(-90deg); }

.light-panel {
  left: -94px;
  top: -27px;
  width: 188px;
  height: 54px;
  transform: translateY(calc(var(--room-height) * -1 + 3px)) rotateX(-90deg);
  border: 4px solid rgba(91, 87, 50, 0.6);
  background: #fffbc7;
  box-shadow: 0 0 42px 13px rgba(255, 246, 169, 0.28);
  animation: fluorescent 8.3s steps(1, end) infinite;
}

.zone-service .floor {
  background:
    repeating-linear-gradient(90deg, #3c3e38 0 58px, #242722 59px 62px),
    #343832;
}

.zone-service .ceiling,
.zone-service .wall {
  background:
    repeating-linear-gradient(0deg, transparent 0 81px, rgba(16, 20, 18, 0.38) 82px 85px),
    linear-gradient(#777b70, #484d46);
}

.zone-service .light-panel {
  background: #d7e0ce;
  box-shadow: 0 0 34px 9px rgba(204, 226, 202, 0.18);
}

.zone-pool .floor {
  background:
    radial-gradient(ellipse at 30% 30%, transparent 0 22%, rgba(186, 255, 247, 0.22) 23% 25%, transparent 27%),
    repeating-linear-gradient(90deg, transparent 0 69px, rgba(9, 80, 83, 0.35) 70px 72px),
    repeating-linear-gradient(0deg, transparent 0 69px, rgba(9, 80, 83, 0.35) 70px 72px),
    rgba(20, 142, 151, 0.88);
  box-shadow: inset 0 0 90px rgba(0, 67, 75, 0.58);
  animation: water-shift 7s ease-in-out infinite alternate;
}

.zone-pool .ceiling,
.zone-pool .wall {
  background:
    repeating-linear-gradient(90deg, transparent 0 45px, rgba(19, 91, 91, 0.25) 46px 48px),
    repeating-linear-gradient(0deg, transparent 0 45px, rgba(19, 91, 91, 0.25) 46px 48px),
    linear-gradient(#acd3cb, #729d98);
}

.zone-pool .light-panel {
  background: #e8fff5;
  box-shadow: 0 0 48px 15px rgba(178, 255, 240, 0.3);
}

.door-frame {
  left: -95px;
  top: -245px;
  width: 190px;
  height: 245px;
  border: 18px solid rgba(49, 47, 27, 0.9);
  border-bottom: 0;
  transform: translateZ(calc(var(--half-cell) * -1 + 2px));
  box-shadow: inset 0 0 30px #000, 0 0 12px rgba(0, 0, 0, 0.7);
}

.zone-pool .door-frame {
  border-color: rgba(220, 244, 233, 0.84);
  border-radius: 95px 95px 0 0;
}

.watcher {
  left: -17px;
  top: -154px;
  width: 34px;
  height: 154px;
  border-radius: 48% 48% 12% 12%;
  transform: translateZ(-262px);
  background: #010201;
  box-shadow: 0 0 18px 8px rgba(0, 0, 0, 0.72);
  opacity: 0;
  filter: blur(2px);
  transition: opacity 900ms ease;
}

body.presence-visible .watcher { opacity: 0.75; }

.interference,
.vignette {
  position: absolute;
  z-index: 10;
  inset: 0;
  pointer-events: none;
}

.interference {
  background:
    repeating-linear-gradient(to bottom, transparent 0 3px, rgba(20, 19, 11, 0.05) 3px 4px),
    radial-gradient(circle at 50% 46%, rgba(189, 177, 92, 0.08), transparent 58%);
  opacity: 0.64;
}

.vignette {
  background: radial-gradient(ellipse at center, transparent 28%, rgba(0, 0, 0, 0.16) 59%, rgba(0, 0, 0, 0.9) 112%);
}

.observation {
  position: absolute;
  z-index: 15;
  bottom: 112px;
  left: 50%;
  width: min(620px, calc(100% - 32px));
  transform: translateX(-50%);
  color: rgba(239, 233, 190, 0.84);
  font-size: clamp(0.68rem, 1.3vw, 0.83rem);
  letter-spacing: 0.08em;
  line-height: 1.5;
  text-align: center;
  text-shadow: 0 2px 5px #000;
  transition: opacity 180ms ease;
}

.observation.is-changing { opacity: 0; }

.movement {
  position: absolute;
  z-index: 16;
  bottom: max(16px, env(safe-area-inset-bottom));
  left: 50%;
  display: grid;
  grid-template-columns: repeat(4, minmax(72px, 92px));
  gap: 8px;
  transform: translateX(-50%);
}

.movement button {
  min-height: 56px;
  border: 1px solid rgba(230, 221, 158, 0.34);
  background: rgba(8, 10, 7, 0.76);
  color: rgba(222, 217, 177, 0.74);
  cursor: pointer;
  text-transform: uppercase;
}

.movement button:hover,
.movement button:active {
  border-color: rgba(255, 246, 177, 0.72);
  background: rgba(31, 32, 20, 0.88);
  color: #fffbd0;
}

.movement button:disabled { opacity: 0.32; }
.movement span { display: block; font-size: 1rem; }
.movement small { font-size: 0.46rem; letter-spacing: 0.09em; }

.entry {
  position: fixed;
  z-index: 50;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(circle at 50% 45%, rgba(55, 54, 31, 0.38), rgba(3, 4, 3, 0.98) 70%);
  transition: opacity 900ms ease, visibility 900ms;
}

.entry.is-gone {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

.entry__panel {
  width: min(520px, 100%);
  padding: clamp(24px, 5vw, 48px);
  border: 1px solid rgba(226, 218, 154, 0.24);
  background: rgba(9, 10, 7, 0.86);
  box-shadow: 0 24px 90px #000;
}

.entry__code,
.entry__warning {
  color: var(--muted);
  font-size: 0.66rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.entry h1 {
  margin: 18px 0;
  color: #e8e1a7;
  font-size: clamp(2rem, 7vw, 4.6rem);
  font-weight: 400;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.entry p { line-height: 1.7; }

.entry button,
.entry a {
  display: inline-block;
  margin: 18px 8px 0 0;
  padding: 11px 14px;
  border: 1px solid rgba(232, 223, 157, 0.4);
  background: rgba(43, 43, 25, 0.7);
  color: #e5dfad;
  text-decoration: none;
  cursor: pointer;
}

.no-script {
  position: fixed;
  z-index: 100;
  right: 0;
  bottom: 0;
  left: 0;
  padding: 12px;
  background: #111;
  color: #fff;
  text-align: center;
}

body.is-walking .camera { animation: walk-bob var(--step-time) ease-in-out; }
body.is-turning .camera { animation: turn-sway var(--step-time) ease-in-out; }

@keyframes fluorescent {
  0%, 3%, 7%, 100% { opacity: 1; }
  4%, 6% { opacity: 0.64; }
  5% { opacity: 0.92; }
}

@keyframes water-shift {
  from { filter: brightness(0.86); background-position: 0 0; }
  to { filter: brightness(1.08); background-position: 24px 12px; }
}

@keyframes pulse {
  0%, 94%, 100% { opacity: 1; }
  95%, 97% { opacity: 0.15; }
}

@keyframes walk-bob {
  0%, 100% { margin-top: 0; }
  42% { margin-top: 8px; }
  72% { margin-top: -3px; }
}

@keyframes turn-sway {
  0%, 100% { margin-left: 0; }
  50% { margin-left: 7px; }
}

@media (max-width: 620px) {
  :root {
    --cell: 480px;
    --half-cell: 240px;
    --room-height: 300px;
    --eye-height: 168px;
  }

  .complex-bar { padding-inline: 10px; }
  .complex-mark { font-size: 0.62rem; }
  .complex-mark small { display: none; }
  .complex-actions button,
  .complex-actions a { padding: 6px; font-size: 0.52rem; }
  .movement { grid-template-columns: repeat(4, minmax(58px, 74px)); gap: 5px; }
  .movement button { min-height: 52px; }
  .observation { bottom: 92px; }
}

@media (prefers-reduced-motion: reduce) {
  .camera-turn,
  .world,
  .observation,
  .entry { transition-duration: 1ms; }
  .light-panel,
  .zone-pool .floor,
  body.is-walking .camera,
  body.is-turning .camera { animation: none; }
}
