:root { --bg: rgba(20,14,11,.78); --line: rgba(255,225,200,.16); --tx: #f6ece2; --mute: #c9b3a2; --acc: #f0763a; --ok: #58c6ff; --bad: #ff4d3d; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #1a0f0a; color: var(--tx); font: 15px/1.4 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; }
#app { position: fixed; inset: 0; user-select: none; -webkit-user-select: none; }
#scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#visor { position: absolute; inset: 0; pointer-events: none; box-shadow: inset 0 0 14vmin rgba(10,6,4,.75); border-radius: 0; }
#lowO2 { position: absolute; inset: 0; pointer-events: none; box-shadow: inset 0 0 22vmin rgba(255,40,20,.7); opacity: 0; transition: opacity .3s; }
button, input { font: inherit; color: inherit; }
input[type=text], input:not([type]) { background: rgba(0,0,0,.35); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; min-width: 0; flex: 1; outline: none; user-select: text; -webkit-user-select: text; }
input:focus { border-color: var(--acc); }
.btn { background: rgba(255,255,255,.08); border: 1px solid var(--line); border-radius: 10px; padding: 9px 14px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: rgba(255,255,255,.16); }
.btn.pri { background: var(--acc); border-color: transparent; color: #1c0d05; font-weight: 700; }
.btn.pri:hover { filter: brightness(1.1); }
.btn.wide { display: block; width: 100%; margin: 8px 0; text-align: center; }
.link { background: none; border: 0; color: var(--ok); cursor: pointer; padding: 0 0 0 8px; font-size: 13px; }
.note { color: var(--mute); font-size: 13px; margin: 8px 0 0; }
.lbl { color: var(--mute); font-size: 13px; margin: 14px 0 6px; }
.fld { display: flex; flex-direction: column; gap: 6px; color: var(--mute); font-size: 13px; }
.fld input { color: var(--tx); font-size: 15px; }
.chk { display: flex; align-items: center; gap: 8px; margin-top: 12px; cursor: pointer; }
.row { display: flex; gap: 8px; margin-top: 10px; }

.screen { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; padding: 20px 16px; overflow: auto; background: linear-gradient(rgba(20,10,6,.45), rgba(20,10,6,.7)); }
.screen header { text-align: center; }
.screen h1 { margin: 0; font-size: clamp(44px, 9vw, 92px); letter-spacing: .32em; margin-right: -.32em; font-weight: 800; color: #ffe2c9; text-shadow: 0 4px 30px rgba(240,118,58,.6); }
.screen header p { margin: 4px 0 0; color: var(--mute); letter-spacing: .08em; }
.cols { display: flex; gap: 16px; flex-wrap: wrap; justify-content: center; width: 100%; max-width: 860px; }
.card { flex: 1 1 340px; max-width: 420px; background: var(--bg); border: 1px solid var(--line); border-radius: 16px; padding: 18px; backdrop-filter: blur(8px); }
.card h2, .sheet h2 { margin: 0 0 12px; font-size: 18px; }
#chars { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.char { background: rgba(0,0,0,.3); border: 2px solid transparent; border-radius: 12px; padding: 8px 4px 6px; cursor: pointer; text-align: center; font-size: 12px; color: var(--mute); }
.char.on { border-color: var(--acc); color: var(--tx); background: rgba(240,118,58,.14); }
.char svg { display: block; width: 44px; height: 54px; margin: 0 auto 4px; }
#rooms { max-height: 190px; overflow: auto; display: flex; flex-direction: column; gap: 6px; }
.room { display: flex; align-items: center; gap: 10px; background: rgba(0,0,0,.3); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; cursor: pointer; text-align: left; }
.room:hover { border-color: var(--acc); }
.room b { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.room span { color: var(--mute); font-size: 13px; }
.empty { color: var(--mute); font-size: 13px; padding: 8px 2px; }
.screen footer { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; justify-content: center; }
#conn { color: var(--mute); font-size: 13px; margin-left: 8px; }
#conn.ok { color: #7fe08f; } #conn.bad { color: var(--bad); }

#hud { position: absolute; inset: 0; pointer-events: none; }
#hud > * { position: absolute; }
#roomBox { left: 14px; top: 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; min-width: 170px; pointer-events: auto; }
#roomTitle { font-weight: 700; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#roomCode { background: none; border: 0; padding: 0; color: var(--ok); cursor: pointer; font-size: 13px; letter-spacing: .12em; }
#players { margin-top: 6px; display: flex; flex-direction: column; gap: 3px; font-size: 14px; }
.pl { display: flex; align-items: center; gap: 7px; } .pl i { width: 10px; height: 10px; border-radius: 3px; flex: none; } .pl span { color: var(--mute); font-size: 12px; }
#shipPtr { left: 50%; top: 12px; transform: translateX(-50%); background: var(--bg); border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px; display: flex; gap: 8px; align-items: center; font-variant-numeric: tabular-nums; }
#shipArrow { display: inline-block; color: var(--acc); font-size: 16px; line-height: 1; }
#topBtns { right: 14px; top: 12px; display: flex; gap: 8px; pointer-events: auto; }
#topBtns button { width: 44px; height: 44px; border-radius: 12px; background: var(--bg); border: 1px solid var(--line); cursor: pointer; font-size: 18px; }
#topBtns button.off { opacity: .45; } #topBtns button.live { border-color: #7fe08f; }
#hint { left: 50%; bottom: 96px; transform: translateX(-50%); background: var(--bg); border-radius: 10px; padding: 7px 14px; font-size: 13px; color: var(--mute); text-align: center; max-width: 92vw; transition: opacity .4s; }
#mini { right: 14px; top: 66px; width: 160px; height: 160px; border-radius: 50%; background: rgba(20,14,11,.6); box-shadow: 0 2px 12px rgba(0,0,0,.45); }
#bigWrap { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; background: rgba(8,4,3,.55); }
#bigMap { cursor: grab; touch-action: none; } #bigMap.drag { cursor: grabbing; }
#bigBar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: center; } #bigBar .btn { padding: 6px 12px; }
#bigMap { width: min(600px, 84vmin); height: min(600px, 84vmin); border-radius: 16px; border: 1px solid var(--line); box-shadow: 0 10px 40px rgba(0,0,0,.6); }
#bigInfo { display: inline-block; background: var(--bg); border-radius: 10px; padding: 6px 12px; font-size: 13px; color: var(--mute); }
@media (max-width: 600px) { #mini { width: 110px; height: 110px; } #res { top: 52px; font-size: 13px; } .tl { width: 46px; height: 46px; font-size: 18px; } }
#res { left: 50%; top: 56px; transform: translateX(-50%); display: flex; gap: 12px; align-items: center; background: var(--bg); border: 1px solid var(--line); border-radius: 999px; padding: 5px 14px; font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
#res em, #termRes em { font-style: normal; font-weight: 400; color: #7fe08f; font-size: 13px; }
#tools { right: 14px; bottom: 16px; display: flex; gap: 6px; pointer-events: auto; }
.tl { position: relative; width: 58px; height: 58px; border-radius: 12px; background: var(--bg); border: 2px solid var(--line); cursor: pointer; font-size: 24px; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.tl.on { border-color: var(--acc); background: rgba(240,118,58,.2); }
.tl b { position: absolute; left: 5px; top: 2px; font-size: 11px; color: var(--mute); } .tl span { font-size: 9px; color: var(--mute); white-space: nowrap; overflow: hidden; max-width: 54px; }
#use { overflow: hidden; } #use i { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--acc); } #use b { color: #ffc247; }
.gain { left: 50%; top: calc(50% - 40px); transform: translateX(-50%); font-weight: 800; font-size: 20px; text-shadow: 0 2px 6px #000; animation: up 1.1s ease-out forwards; }
@keyframes up { to { opacity: 0; transform: translate(-50%, -50px); } }
.sheet.big { width: min(560px, 100%); max-height: 92vh; overflow: auto; }
.tabs { display: flex; gap: 6px; margin-bottom: 10px; } .tabs .btn.on { background: var(--acc); color: #1c0d05; font-weight: 700; } .tabs [data-close] { margin-left: auto; }
#termRes { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; font-weight: 600; margin-bottom: 10px; font-variant-numeric: tabular-nums; }
.lvls { display: flex; gap: 6px; align-items: center; margin-bottom: 8px; } .lvls .btn { padding: 6px 12px; } .lvls .note { margin: 0 0 0 auto; }
.grid { display: grid; grid-template-columns: repeat(9, 1fr); gap: 3px; max-width: 360px; margin: 0 auto; }
.cell { aspect-ratio: 10.6 / 8.6; border-radius: 6px; border: 1px solid var(--line); background: rgba(0,0,0,.3); font-size: 15px; padding: 0; cursor: pointer; color: var(--mute); }
.cell.can { border-style: dashed; border-color: rgba(127,224,143,.6); color: #7fe08f; font-weight: 700; }
.cell.mod { color: #fff; border-color: rgba(255,255,255,.35); } .cell.lock { background: rgba(240,118,58,.15); cursor: default; } .cell.under { opacity: .35; }
.cell.sel { outline: 2px solid var(--acc); outline-offset: 1px; }
.info { margin-top: 10px; } .info h3 { margin: 6px 0 2px; font-size: 16px; }
.opt { display: flex; gap: 10px; align-items: center; justify-content: space-between; background: rgba(0,0,0,.25); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; margin: 6px 0; }
.opt > div { display: flex; flex-direction: column; gap: 2px; min-width: 0; } .opt span { color: var(--mute); font-size: 13px; } .opt .cost { color: var(--tx); font-weight: 600; } .opt .cost.bad { color: #ff8b7d; }
.opt .btn { flex: none; } .btn:disabled { opacity: .55; cursor: default; }
#cross { left: 50%; top: 50%; width: 4px; height: 4px; margin: -2px 0 0 -2px; border-radius: 50%; background: rgba(255,255,255,.75); box-shadow: 0 0 0 1px rgba(0,0,0,.35); }
#use { left: 50%; top: calc(50% + 28px); transform: translateX(-50%); background: var(--bg); border: 1px solid var(--acc); border-radius: 10px; padding: 6px 12px; font-size: 14px; white-space: nowrap; }
#chat { left: 14px; bottom: 16px; width: min(380px, 60vw); pointer-events: auto; }
#chatLog { display: flex; flex-direction: column; gap: 3px; max-height: 34vh; overflow: hidden; justify-content: flex-end; font-size: 14px; }
#chat.open #chatLog { overflow-y: auto; justify-content: flex-start; background: var(--bg); border-radius: 10px; padding: 6px; }
.msg { background: rgba(14,9,7,.55); border-radius: 8px; padding: 3px 8px; width: fit-content; max-width: 100%; overflow-wrap: anywhere; transition: opacity .6s; user-select: text; -webkit-user-select: text; }
.msg.old { opacity: 0; } #chat.open .msg.old { opacity: 1; }
.msg b { font-weight: 700; } .msg.sys { color: var(--mute); font-style: italic; }
#chatIn { width: 100%; margin-top: 6px; background: var(--bg); }
#o2 { left: 50%; bottom: 22px; transform: translateX(-50%); width: min(340px, 44vw); text-align: center; }
#o2Label { font-size: 13px; margin-bottom: 5px; text-shadow: 0 1px 4px #000; font-variant-numeric: tabular-nums; }
#o2Bar { height: 12px; border-radius: 999px; background: rgba(0,0,0,.5); border: 1px solid var(--line); overflow: hidden; }
#o2Fill { display: block; height: 100%; width: 100%; background: var(--ok); border-radius: 999px; transition: background .3s; }
#dead { position: absolute; inset: 0; background: rgba(8,3,2,.9); display: flex; align-items: center; justify-content: center; text-align: center; pointer-events: none; }
#dead h2 { font-size: 30px; margin: 0 0 6px; color: #ffb7a8; } #dead p { color: var(--mute); margin: 0 0 14px; }
#deadT { font-size: 54px; font-weight: 800; font-variant-numeric: tabular-nums; }
.veil { position: absolute; inset: 0; background: rgba(8,4,3,.6); display: flex; align-items: center; justify-content: center; padding: 16px; }
.sheet { width: min(380px, 100%); background: rgba(26,18,14,.96); border: 1px solid var(--line); border-radius: 16px; padding: 20px; }
.rng { display: grid; grid-template-columns: 1fr 44px; gap: 4px 8px; align-items: center; margin: 12px 0; color: var(--mute); font-size: 13px; }
.rng input { grid-column: 1; width: 100%; accent-color: var(--acc); } .rng b { color: var(--tx); text-align: right; font-weight: 600; } .rng { grid-template-rows: auto auto; } .rng input, .rng b { grid-row: 2; }
select { background: rgba(0,0,0,.35); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; color: var(--tx); font: inherit; }
select option { background: #1a120e; }
#fps { position: absolute; right: 14px; top: 232px; background: var(--bg); border-radius: 8px; padding: 3px 8px; font: 12px ui-monospace, monospace; color: #7fe08f; pointer-events: none; }
#toast { position: absolute; left: 50%; top: 70px; transform: translateX(-50%); background: rgba(20,14,11,.92); border: 1px solid var(--line); border-radius: 10px; padding: 8px 16px; opacity: 0; transition: opacity .3s; pointer-events: none; max-width: 90vw; text-align: center; }
#toast.on { opacity: 1; }
[hidden] { display: none !important; }
body.menu #visor { display: none; }

/* ---------- телефон: сенсорное управление, только альбомная ориентация ---------- */
:root { --sl: env(safe-area-inset-left, 0px); --sr: env(safe-area-inset-right, 0px); --sb: env(safe-area-inset-bottom, 0px); }
html { overscroll-behavior: none; -webkit-text-size-adjust: 100%; }
body { touch-action: manipulation; -webkit-tap-highlight-color: transparent; -webkit-touch-callout: none; }
#pad, #stick, #acts, .tonly, #rotate { display: none; }
body.touch .tonly { display: block; }
body.touch #scene, body.touch #pad { touch-action: none; }
body.touch #pad { display: block; inset: 0; pointer-events: auto; }
body.touch #tools { display: none; }
body.touch input, body.touch select { font-size: 16px; }   /* меньше 16 — айфон приближает страницу при вводе */
/* джойстик */
body.touch #stick { display: block; left: calc(var(--sl) + 104px); top: calc(100% - 100px - var(--sb)); width: 124px; height: 124px; margin: -62px 0 0 -62px; border-radius: 50%; border: 2px solid rgba(255,255,255,.24); background: rgba(20,14,11,.3); opacity: .5; transition: opacity .2s, border-color .15s; }
body.touch #stick.on { opacity: 1; } body.touch #stick.run { border-color: var(--acc); }
#knob { position: absolute; left: 50%; top: 50%; width: 54px; height: 54px; margin: -27px 0 0 -27px; border-radius: 50%; background: rgba(255,255,255,.42); box-shadow: 0 2px 8px rgba(0,0,0,.4); }
#stick.run #knob { background: var(--acc); }
/* кнопки под правым большим пальцем */
body.touch #acts { display: block; right: calc(var(--sr) + 14px); bottom: calc(var(--sb) + 12px); width: 180px; height: 186px; }
#acts button { position: absolute; display: flex; align-items: center; justify-content: center; padding: 0; border-radius: 50%; background: rgba(20,14,11,.5); border: 2px solid rgba(255,255,255,.3); font-size: 28px; line-height: 1; pointer-events: auto; touch-action: none; transition: transform .08s; }
#acts button.on { background: rgba(240,118,58,.5); border-color: var(--acc); transform: scale(.93); }
#bAct { right: 0; bottom: 62px; width: 90px; height: 90px; font-size: 38px !important; } #bAct.hot { border-color: var(--acc); box-shadow: 0 0 16px rgba(240,118,58,.55); }
#bJump { right: 100px; bottom: 0; width: 72px; height: 72px; }
#bSwap { right: 100px; bottom: 128px; width: 56px; height: 56px; font-size: 24px !important; } #bSwap small { position: absolute; right: -2px; bottom: -4px; font-size: 13px; color: var(--mute); }
/* интерфейс: всё мелкое уходит в углы, середина и низ свободны для пальцев */
body.touch #roomBox { left: calc(var(--sl) + 10px); top: 8px; padding: 5px 10px; min-width: 0; z-index: 2; }
body.touch #roomTitle { font-size: 14px; max-width: 170px; } body.touch #roomCode::after { content: ' · 👥 ' attr(data-n); color: var(--mute); letter-spacing: 0; }
body.touch #players { display: none; } body.touch #roomBox.open #players { display: flex; }
body.touch #shipPtr { top: 8px; padding: 4px 12px; font-size: 13px; white-space: nowrap; }
body.touch #res { top: 42px; font-size: 13px; padding: 3px 12px; gap: 10px; }
body.touch #topBtns { right: calc(var(--sr) + 10px); top: 8px; gap: 6px; }
body.touch #mini { right: calc(var(--sr) + 10px); top: 60px; width: 92px; height: 92px; pointer-events: auto; }
body.touch #chat { left: calc(var(--sl) + 10px); top: 62px; bottom: auto; width: min(320px, 38vw); pointer-events: none; } body.touch #chat.open { pointer-events: auto; z-index: 3; }
body.touch #chatLog { max-height: 26vh; font-size: 13px; }
body.touch #o2 { bottom: calc(var(--sb) + 10px); width: min(260px, 30vw); }
body.touch #hint { bottom: 62px; font-size: 12px; max-width: 46vw; }
body.touch #fps { right: auto; top: auto; left: calc(var(--sl) + 10px); bottom: 4px; }
body.touch #toast { top: 78px; max-width: 60vw; font-size: 14px; }
@media (max-width: 760px) { body.touch #res em { display: none; } body.touch #roomTitle { max-width: 120px; } }
@media (max-height: 350px) { body.touch #mini { width: 70px; height: 70px; } }
/* низкий альбомный экран: окна и меню в две колонки, чтобы ничего не обрезалось */
@media (max-height: 520px) and (orientation: landscape) {
  .veil { padding: 8px calc(var(--sr) + 8px) 8px calc(var(--sl) + 8px); }
  .sheet { max-height: 100%; overflow: auto; padding: 14px 16px; -webkit-overflow-scrolling: touch; }
  .sheet.big { width: min(780px, 100%); max-height: 100%; }
  .sheet h2 { margin-bottom: 6px; }
  #pause .sheet { width: min(520px, 100%); display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; } #pause h2, #pause .note { grid-column: 1 / -1; }
  #settings .sheet { width: min(680px, 100%); display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; align-items: center; } #settings h2, #settings .note, #settings .btn { grid-column: 1 / -1; }
  #termBody { display: grid; grid-template-columns: minmax(0, 300px) minmax(0, 1fr); gap: 0 14px; align-items: start; } #termBody .lvls, #termBody > .note { grid-column: 1 / -1; } #termBody .info { margin-top: 0; }
  .screen { justify-content: flex-start; gap: 10px; padding: 10px calc(var(--sr) + 12px) 12px calc(var(--sl) + 12px); }
  .screen h1 { font-size: 34px; } .screen header p, .card .note { display: none; }
  .cols { flex-wrap: nowrap; gap: 10px; max-width: 900px; } .card { flex: 1 1 0; min-width: 0; max-width: none; padding: 12px 14px; }
  .card h2 { margin-bottom: 8px; } .lbl { margin: 8px 0 4px; } .char svg { width: 34px; height: 42px; } #rooms { max-height: 96px; }
  #bigWrap { flex-direction: row; gap: 12px; } #bigMap { width: min(600px, 92vmin); height: min(600px, 92vmin); } #bigBar { flex-direction: column; align-items: stretch; max-width: 190px; } #bigBar .btn { padding: 10px 12px; }
  #dead h2 { font-size: 24px; } #deadT { font-size: 44px; }
}
/* телефон держат вертикально — игру не показываем */
#rotate { position: fixed; inset: 0; z-index: 50; background: #1a0f0a; align-items: center; justify-content: center; text-align: center; padding: 24px; }
#rotate h2 { margin: 14px 0 6px; } #rotate p { color: var(--mute); margin: 0 0 16px; }
#rotate .ph { font-size: 64px; animation: rot 2.4s ease-in-out infinite; }
@keyframes rot { 0%, 20% { transform: rotate(0); } 60%, 100% { transform: rotate(-90deg); } }
@media (orientation: portrait) { body.touch #rotate { display: flex; } }

/* бонусы от занятий в отсеках */
#buffs { left: 50%; bottom: 62px; transform: translateX(-50%); display: flex; gap: 6px; font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; }
#buffs span { background: var(--bg); border: 1px solid rgba(127,224,143,.5); border-radius: 999px; padding: 2px 9px; }
body.touch #buffs { bottom: calc(var(--sb) + 46px); font-size: 12px; }
