* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: #000; color: #dfe8e4; overflow: hidden; overscroll-behavior: none; }
body { font-family: "Courier New", "Liberation Mono", monospace; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }

/* --- экраны --- */
.screen { position: fixed; inset: 0; z-index: 20; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2.2vmin; padding: 3vmin; text-align: center; }
#loading, #intro, #fatal { background: #000; }
#help, #over { background: rgba(0, 0, 0, .72); }
h1 { margin: 0; font-size: clamp(26px, 9vmin, 84px); letter-spacing: .08em; line-height: 1.05; text-shadow: 0 0 18px rgba(170, 220, 255, .45); }
h2 { margin: 0 0 1.5vmin; font-size: clamp(18px, 5vmin, 34px); }
.sub { margin: 0; opacity: .7; font-size: clamp(11px, 2.6vmin, 18px); letter-spacing: .12em; }
.ver { position: absolute; left: 2vmin; bottom: 1.5vmin; margin: 0; opacity: .4; font-size: 11px; }
.col { display: flex; flex-direction: column; gap: 1.6vmin; align-items: stretch; }
.big { min-width: min(70vw, 300px); padding: 1.9vmin 3vmin; font-size: clamp(14px, 3.4vmin, 22px); font-weight: bold; letter-spacing: .08em; background: rgba(10, 16, 20, .7); border: 2px solid #9fb6b0; border-radius: 4px; }
.big:hover, .big:active { background: #dfe8e4; color: #000; }
#menu { align-items: flex-start; justify-content: center; padding-left: max(6vw, env(safe-area-inset-left)); text-align: left; background: linear-gradient(90deg, rgba(0, 0, 0, .8), rgba(0, 0, 0, .15) 70%); }
#menu .col { margin-top: 2vmin; }
.bar { width: min(70vw, 420px); height: 14px; border: 2px solid #9fb6b0; padding: 2px; }
.bar i { display: block; height: 100%; width: 0; background: #dfe8e4; transition: width .15s; }
#load-text { margin: 0; opacity: .7; font-size: 14px; min-height: 1.2em; }
.panel { max-width: 760px; max-height: 94vh; overflow: auto; padding: 2.5vmin 3.5vmin; background: rgba(6, 10, 12, .92); border: 2px solid #9fb6b0; text-align: left; touch-action: pan-y; }
.panel ul { margin: 0 0 2vmin; padding-left: 1.2em; font-size: clamp(12px, 2.7vmin, 17px); line-height: 1.45; }
.panel .big { display: block; margin: 0 auto; }
#intro div { display: flex; flex-direction: column; gap: 1vmin; font-size: clamp(22px, 7vmin, 56px); }
#intro span { font-size: .6em; opacity: .8; }
#over h1 { color: #e23b2e; text-shadow: 0 0 22px rgba(255, 40, 20, .6); }
#over p, #win p { margin: 0; font-size: clamp(13px, 3vmin, 20px); opacity: .85; }
#win { background: #000; }
.six { font-size: clamp(60px, 26vmin, 220px); font-weight: bold; line-height: 1; }
.six small { font-size: .4em; margin-left: .15em; }
#fatal { z-index: 60; }

/* --- системные кнопки --- */
#sys { position: fixed; z-index: 55; top: max(1.2vmin, env(safe-area-inset-top)); right: max(1.2vmin, env(safe-area-inset-right)); display: flex; gap: 1vmin; }
#sys button { width: clamp(40px, 8.5vmin, 54px); height: clamp(40px, 8.5vmin, 54px); padding: 0; display: grid; place-items: center; background: rgba(0, 0, 0, .5); border: 2px solid rgba(207, 238, 230, .6); border-radius: 6px; }
#sys svg { width: 62%; height: 62%; fill: #dfe8e4; display: block; pointer-events: none; }
#sys .off, #sys .active .on { display: none; }
#sys .active .off { display: inline; }
#sys .unsupported { display: none; }

/* --- HUD --- */
#hud { position: fixed; inset: 0; z-index: 10; pointer-events: none; }
#hud button { pointer-events: auto; }
#clock { position: absolute; top: max(1.5vmin, env(safe-area-inset-top)); left: max(2vmin, env(safe-area-inset-left)); display: flex; flex-direction: column; text-shadow: 0 0 6px #000, 0 0 2px #000; }
#clock b { font-size: clamp(20px, 6.2vmin, 44px); }
#clock span { font-size: clamp(11px, 2.8vmin, 18px); opacity: .85; }
#power { position: absolute; left: max(2vmin, env(safe-area-inset-left)); bottom: max(2vmin, env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: .4vmin; font-size: clamp(12px, 3.1vmin, 20px); text-shadow: 0 0 6px #000, 0 0 2px #000; }
#usage { display: inline-flex; gap: 3px; vertical-align: middle; }
#usage b { width: 1.4vmin; min-width: 7px; height: 2.6vmin; min-height: 12px; background: #4fd66a; }
#usage b:nth-child(3) { background: #e1c93a; }
#usage b:nth-child(n+4) { background: #e2452e; }
.side { position: absolute; top: 50%; transform: translateY(-50%); display: flex; flex-direction: column; gap: 2.4vmin; }
#side-l { left: max(2vmin, env(safe-area-inset-left)); }
#side-r { right: max(2vmin, env(safe-area-inset-right)); }
.act { width: clamp(84px, 21vmin, 150px); height: clamp(52px, 14vmin, 96px); font-size: clamp(13px, 3.4vmin, 22px); font-weight: bold; letter-spacing: .06em; border-radius: 8px; border: 3px solid #1a1a1a; box-shadow: 0 0 0 2px rgba(255, 255, 255, .25), inset 0 -6px 0 rgba(0, 0, 0, .35); }
.act.door { background: #5c1512; color: #f1c9c4; }
.act.door.on { background: #ff3b28; color: #fff; box-shadow: 0 0 18px #ff3b28, inset 0 -3px 0 rgba(0, 0, 0, .3); }
.act.light { background: #4a4d52; color: #dfe8e4; }
.act.light.on { background: #f4f7ff; color: #000; box-shadow: 0 0 18px #cfe0ff, inset 0 -3px 0 rgba(0, 0, 0, .2); }
.act.dead { filter: grayscale(1) brightness(.5); }
#btn-mon { position: absolute; left: 50%; bottom: max(1.5vmin, env(safe-area-inset-bottom)); transform: translateX(-50%); width: min(46vw, 460px); height: clamp(38px, 9vmin, 60px); font-size: clamp(12px, 3vmin, 19px); font-weight: bold; letter-spacing: .15em; background: rgba(10, 16, 20, .45); border: 2px solid rgba(207, 238, 230, .7); border-radius: 6px; }
#btn-mon:active { background: rgba(207, 238, 230, .3); }
#cam-ui { position: absolute; inset: 0; pointer-events: none; }
#cam-ui::before { content: ""; position: absolute; inset: 1.2vmin; border: 2px solid rgba(207, 238, 230, .5); }
#cam-rec { position: absolute; top: max(13vmin, 62px); left: max(4vmin, env(safe-area-inset-left)); font-size: clamp(12px, 3vmin, 20px); font-weight: bold; }
#cam-rec i { display: inline-block; width: 1em; height: 1em; border-radius: 50%; background: #e2301e; vertical-align: -0.12em; animation: blink 1.2s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
#cam-name { position: absolute; top: max(2.5vmin, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); font-size: clamp(13px, 3.4vmin, 24px); font-weight: bold; white-space: nowrap; text-shadow: 0 0 6px #000; }
#cam-off { position: absolute; left: 0; right: 0; top: 36%; text-align: center; font-size: clamp(16px, 4.6vmin, 34px); font-weight: bold; }
#cam-off small { display: block; font-size: .55em; opacity: .7; margin-top: .4em; }
#map { position: absolute; right: max(2vmin, env(safe-area-inset-right)); bottom: max(2vmin, env(safe-area-inset-bottom)); width: min(44vw, 70vh, 460px); aspect-ratio: 1.22; pointer-events: auto; }
#map svg { position: absolute; inset: 0; width: 100%; height: 100%; }
#map button { position: absolute; transform: translateX(-50%); width: 15%; height: 12.5%; padding: 0; font-size: clamp(10px, 2.5vmin, 17px); font-weight: bold; background: rgba(40, 52, 50, .88); border: 2px solid #cfe; border-radius: 3px; }
#map button.on { background: #b6e33a; color: #000; }
#map button::after { content: ""; position: absolute; inset: -22% -12%; }

#rotate { display: none; position: fixed; inset: 0; z-index: 50; background: #000; align-items: center; justify-content: center; text-align: center; font-size: 64px; }
#rotate p { font-size: 16px; margin: 12px 24px 0; }
@media (orientation: portrait) and (max-width: 820px) { #rotate { display: flex; } }
