:root {
  --bg: #070b18;
  --bg-2: #0d1428;
  --panel: rgba(18, 27, 52, 0.86);
  --panel-solid: #121b34;
  --line: #24335c;
  --line-2: #33467a;
  --text: #e8eeff;
  --muted: #8f9cc3;
  --cyan: #38d6ff;
  --blue: #5b8cff;
  --orange: #ff9f43;
  --green: #3ddc97;
  --yellow: #ffd166;
  --red: #ff4d5e;
  --violet: #a78bfa;
  --radius: 18px;
  --font: "Segoe UI", "Inter", system-ui, -apple-system, Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
button { font-family: inherit; color: inherit; cursor: pointer; }

#app { position: fixed; inset: 0; }
.screen {
  position: absolute; inset: 0;
  display: none;
  flex-direction: column;
}
.screen.active { display: flex; animation: fadeIn .35s ease; }
@keyframes fadeIn { from { opacity: 0; transform: scale(.99); } to { opacity: 1; transform: none; } }

/* ---------- главный экран ---------- */
#home {
  align-items: center; justify-content: center;
  background:
    radial-gradient(1200px 600px at 20% 110%, rgba(56, 214, 255, .16), transparent 60%),
    radial-gradient(900px 500px at 90% -10%, rgba(255, 159, 67, .14), transparent 60%),
    var(--bg);
}
#home canvas.stars { position: absolute; inset: 0; width: 100%; height: 100%; }
.home-inner { position: relative; text-align: center; padding: 24px; max-width: 1400px; width: 100%; }
.home-kicker {
  display: inline-block; padding: 8px 18px; border-radius: 999px;
  border: 1px solid var(--line-2); color: var(--cyan);
  font-size: 18px; letter-spacing: .08em; text-transform: uppercase;
  background: rgba(56, 214, 255, .06);
}
.home-title {
  font-size: clamp(36px, 5.2vw, 78px); font-weight: 800; line-height: 1.04;
  margin: 22px 0 10px;
  background: linear-gradient(90deg, #fff, #bfe9ff 45%, #ffd2a6);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.home-sub { font-size: clamp(16px, 1.6vw, 24px); color: var(--muted); margin: 0 auto 40px; max-width: 900px; }
.home-cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 32px; }
.home-card {
  position: relative; overflow: hidden;
  border: 1px solid var(--line-2); border-radius: 28px;
  background: linear-gradient(160deg, rgba(30, 44, 86, .9), rgba(12, 18, 38, .95));
  padding: 28px 28px 32px; text-align: left;
  transition: transform .2s ease, border-color .2s ease, box-shadow .2s ease;
  min-height: 360px;
  display: flex; flex-direction: column;
}
.home-card:hover, .home-card:focus-visible { transform: translateY(-4px); border-color: var(--cyan); box-shadow: 0 20px 60px rgba(56, 214, 255, .18); outline: none; }
.home-card.rocket:hover { border-color: var(--orange); box-shadow: 0 20px 60px rgba(255, 159, 67, .18); }
.home-card:active { transform: scale(.98); }
.home-card svg { width: 100%; height: 190px; display: block; margin-bottom: 14px; }
.home-card h2 { margin: 0 0 8px; font-size: 34px; }
.home-card p { margin: 0; color: var(--muted); font-size: 19px; line-height: 1.4; }
.home-card .go {
  margin-top: auto; padding-top: 18px; font-weight: 700; font-size: 20px; color: var(--cyan);
}
.home-card.rocket .go { color: var(--orange); }
.home-foot { margin-top: 28px; color: var(--muted); font-size: 15px; display: flex; gap: 16px; justify-content: center; align-items: center; flex-wrap: wrap; }
.chip-btn {
  border: 1px solid var(--line-2); background: rgba(255, 255, 255, .04);
  border-radius: 999px; padding: 10px 18px; font-size: 15px;
}
.chip-btn:hover { border-color: var(--cyan); }

/* ---------- общая шапка двойника ---------- */
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(7, 11, 24, .9);
  flex: 0 0 auto;
}
.back-btn, .icon-btn {
  border: 1px solid var(--line-2); background: var(--panel-solid);
  border-radius: 14px; padding: 10px 18px; font-size: 18px; font-weight: 600;
}
.back-btn:hover, .icon-btn:hover { border-color: var(--cyan); }
.topbar h1 { margin: 0; font-size: 26px; font-weight: 800; }
.topbar .sub { color: var(--muted); font-size: 16px; }
.topbar .spacer { flex: 1; }
.live-dot {
  display: inline-flex; align-items: center; gap: 8px;
  color: var(--green); font-weight: 700; font-size: 15px; letter-spacing: .06em;
}
.live-dot::before {
  content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--green);
  box-shadow: 0 0 0 0 rgba(61, 220, 151, .6); animation: pulse 1.6s infinite;
}
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(61, 220, 151, .6); } 100% { box-shadow: 0 0 0 12px rgba(61, 220, 151, 0); } }

.twin-body {
  flex: 1 1 auto; min-height: 0;
  display: grid; gap: 14px; padding: 14px;
}
.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px;
  backdrop-filter: blur(8px);
}
.panel h3 {
  margin: 0 0 10px; font-size: 14px; font-weight: 700; letter-spacing: .1em;
  text-transform: uppercase; color: var(--muted);
}
.scene-wrap {
  position: relative; min-height: 0; min-width: 0;
  border-radius: var(--radius); overflow: hidden;
  border: 1px solid var(--line);
  background: #050914;
}
.scene-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* лента событий поверх сцены */
.ticker {
  position: absolute; left: 14px; top: 14px; z-index: 2;
  display: flex; flex-direction: column; gap: 8px; max-width: min(560px, 70%);
  pointer-events: none;
}
.ticker .msg {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 10px 14px; border-radius: 12px; font-size: 17px; line-height: 1.3;
  background: rgba(7, 11, 24, .82); border: 1px solid var(--line-2);
  animation: slideIn .3s ease;
  transition: opacity .6s ease;
}
.ticker .msg::before {
  content: ""; flex: 0 0 10px; height: 10px; margin-top: 6px; border-radius: 50%; background: var(--cyan);
}
.ticker .msg.warn { border-color: rgba(255, 209, 102, .6); }
.ticker .msg.warn::before { background: var(--yellow); }
.ticker .msg.alarm { border-color: var(--red); background: rgba(70, 10, 20, .88); }
.ticker .msg.alarm::before { background: var(--red); }
.ticker .msg.good { border-color: rgba(61, 220, 151, .7); }
.ticker .msg.good::before { background: var(--green); }
.ticker .msg.old { opacity: .45; }
@keyframes slideIn { from { opacity: 0; transform: translateX(-10px); } to { opacity: 1; transform: none; } }

/* подсказка «что происходит» */
.explain {
  position: absolute; left: 14px; right: 14px; bottom: 14px; z-index: 2;
  display: flex; gap: 14px; align-items: center;
  padding: 12px 16px; border-radius: 14px;
  background: rgba(7, 11, 24, .78); border: 1px solid var(--line-2);
  font-size: 18px; line-height: 1.35; pointer-events: none;
}
.explain .ico {
  flex: 0 0 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 800; font-size: 18px;
  background: rgba(56, 214, 255, .16); color: var(--cyan);
}

/* ---------- элементы управления ---------- */
.ctrl-group { margin-bottom: 16px; }
.ctrl-group:last-child { margin-bottom: 0; }
.big-value { font-size: 30px; font-weight: 800; font-variant-numeric: tabular-nums; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.muted { color: var(--muted); }
.small { font-size: 14px; }

input[type=range].big {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 56px; background: transparent; margin: 4px 0;
  touch-action: none;
}
input[type=range].big::-webkit-slider-runnable-track {
  height: 18px; border-radius: 999px;
  background: var(--track, linear-gradient(90deg, #24335c, #24335c));
  border: 1px solid var(--line-2);
}
input[type=range].big::-moz-range-track {
  height: 18px; border-radius: 999px;
  background: var(--track, #24335c); border: 1px solid var(--line-2);
}
input[type=range].big::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 44px; height: 44px; margin-top: -14px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff, #cfe6ff 40%, #7aa6ff);
  border: 3px solid #0b1020; box-shadow: 0 4px 16px rgba(0, 0, 0, .5), 0 0 0 4px rgba(91, 140, 255, .35);
}
input[type=range].big::-moz-range-thumb {
  width: 40px; height: 40px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff, #cfe6ff 40%, #7aa6ff);
  border: 3px solid #0b1020; box-shadow: 0 4px 16px rgba(0, 0, 0, .5);
}
.scale-labels { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin-top: -4px; }

.pump-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.pump-btn {
  border: 1px solid var(--line-2); background: var(--panel-solid);
  border-radius: 14px; padding: 10px 4px 8px; font-size: 14px; font-weight: 700;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  transition: border-color .15s, background .15s;
}
.pump-btn svg { width: 40px; height: 40px; }
.pump-btn.on { border-color: rgba(56, 214, 255, .7); background: rgba(56, 214, 255, .1); }
.pump-btn.on svg .imp { animation: spin .8s linear infinite; transform-origin: 20px 20px; }
.pump-btn.off { opacity: .75; }
.pump-btn.off svg .imp { fill: #4a5578; }
@keyframes spin { to { transform: rotate(360deg); } }

.az-btn {
  width: 100%; border: 0; border-radius: 18px;
  padding: 18px 12px; font-size: 24px; font-weight: 900; letter-spacing: .04em;
  color: #fff;
  background: radial-gradient(120% 140% at 50% 0%, #ff6b78, #c81d33 60%, #8e0f22);
  box-shadow: 0 8px 0 #5c0815, 0 14px 30px rgba(255, 77, 94, .35);
  transition: transform .08s ease, box-shadow .08s ease;
}
.az-btn small { display: block; font-size: 14px; font-weight: 600; opacity: .9; letter-spacing: 0; }
.az-btn:active { transform: translateY(6px); box-shadow: 0 2px 0 #5c0815, 0 6px 16px rgba(255, 77, 94, .35); }
.az-btn.restart {
  background: radial-gradient(120% 140% at 50% 0%, #6ff0b8, #1fae74 60%, #0f6c47);
  box-shadow: 0 8px 0 #0a4a30, 0 14px 30px rgba(61, 220, 151, .3);
}
.az-btn:disabled { filter: grayscale(.7) brightness(.7); cursor: default; }

.btn {
  border: 1px solid var(--line-2); background: var(--panel-solid);
  border-radius: 14px; padding: 12px 14px; font-size: 16px; font-weight: 600;
  text-align: left;
}
.btn:hover { border-color: var(--cyan); }
.btn:active { transform: scale(.98); }

.goals { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.goals li {
  display: flex; gap: 10px; align-items: center; font-size: 15px; line-height: 1.25;
  padding: 8px 10px; border-radius: 12px; border: 1px dashed var(--line-2);
}
.goals li .box {
  flex: 0 0 24px; height: 24px; border-radius: 8px; border: 2px solid var(--line-2);
  display: grid; place-items: center; font-size: 15px; font-weight: 900; color: transparent;
}
.goals li.done { border-style: solid; border-color: rgba(61, 220, 151, .6); background: rgba(61, 220, 151, .08); }
.goals li.done .box { background: var(--green); border-color: var(--green); color: #05231a; }

/* ---------- плитки показателей ---------- */
.metrics { display: grid; gap: 12px; }
.tile {
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 12px 14px; min-width: 0; position: relative; overflow: hidden;
}
.tile .label { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .value { font-size: 30px; font-weight: 800; font-variant-numeric: tabular-nums; margin-top: 2px; white-space: nowrap; }
.tile .value .unit { font-size: 16px; color: var(--muted); font-weight: 600; margin-left: 4px; }
.tile .bar { height: 8px; border-radius: 999px; background: #1a2546; margin-top: 8px; overflow: hidden; position: relative; }
.tile .bar > i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 999px; background: var(--cyan); transition: width .2s linear, background .3s; }
.tile .bar > b { position: absolute; top: -3px; bottom: -3px; width: 2px; background: #fff; opacity: .7; }
.tile .hint { font-size: 13px; color: var(--muted); margin-top: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile.warn { border-color: rgba(255, 209, 102, .7); }
.tile.alarm { border-color: var(--red); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { background: rgba(90, 15, 25, .9); } }
.trend-tile { padding: 8px 10px; }
.trend-tile { position: relative; min-height: 104px; }
.trend-tile canvas { position: absolute; inset: 8px 10px; width: calc(100% - 20px); height: calc(100% - 16px); display: block; }

/* ---------- АЭС ---------- */
#npp .twin-body {
  grid-template-columns: minmax(0, 1fr) 380px;
  grid-template-rows: minmax(0, 1fr) auto;
}
#npp .side { grid-row: 1 / span 2; grid-column: 2; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
#npp .metrics { grid-column: 1; grid-template-columns: repeat(5, minmax(0, 1fr)) minmax(0, 2.1fr); }

/* ---------- ракета ---------- */
#rocket .twin-body {
  grid-template-columns: 400px minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) auto;
}
#rocket .side { grid-row: 1 / span 2; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
#rocket .metrics { grid-column: 2; grid-template-columns: repeat(6, minmax(0, 1fr)); }

.fuel-list { display: grid; gap: 8px; }
.fuel-card {
  display: grid; grid-template-columns: 34px 1fr; gap: 12px; align-items: center;
  text-align: left; padding: 10px 12px; border-radius: 14px;
  border: 1px solid var(--line-2); background: var(--panel-solid);
  transition: border-color .15s, background .15s;
}
.fuel-card .sw { width: 34px; height: 34px; border-radius: 10px; }
.fuel-card b { font-size: 17px; display: block; }
.fuel-card span { font-size: 13px; color: var(--muted); }
.fuel-card.sel { border-color: var(--orange); background: rgba(255, 159, 67, .1); box-shadow: inset 0 0 0 1px var(--orange); }
.fuel-fact { font-size: 15px; color: #cbd6f7; margin-top: 10px; line-height: 1.35; min-height: 40px; }

.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.seg button {
  border: 1px solid var(--line-2); background: var(--panel-solid); border-radius: 14px;
  padding: 8px 4px; font-size: 16px; font-weight: 700;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.seg button svg { height: 54px; width: 30px; }
.seg button.sel { border-color: var(--orange); background: rgba(255, 159, 67, .1); }

.dv-bar { position: relative; height: 26px; border-radius: 999px; background: #1a2546; border: 1px solid var(--line-2); overflow: hidden; margin-top: 8px; }
.dv-bar > i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 999px; transition: width .35s ease, background .35s; }
.dv-bar > b { position: absolute; top: 0; bottom: 0; width: 3px; background: #fff; box-shadow: 0 0 8px #fff; }
.dv-bar > em { position: absolute; top: 3px; font-style: normal; font-size: 12px; font-weight: 800; color: #fff; transform: translateX(6px); text-shadow: 0 1px 2px #000; }

.launch-btn {
  width: 100%; border: 0; border-radius: 18px; padding: 18px; font-size: 28px; font-weight: 900; letter-spacing: .08em;
  color: #1d0d00;
  background: radial-gradient(120% 140% at 50% 0%, #ffd18a, #ff9f43 55%, #e46a10);
  box-shadow: 0 8px 0 #8a3d05, 0 14px 30px rgba(255, 159, 67, .35);
  transition: transform .08s ease, box-shadow .08s ease;
}
.launch-btn:active { transform: translateY(6px); box-shadow: 0 2px 0 #8a3d05; }
.launch-btn:disabled { filter: grayscale(.8) brightness(.6); cursor: default; }

.records { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 15px; }
.records li { display: flex; justify-content: space-between; gap: 8px; padding: 6px 10px; border-radius: 10px; background: rgba(255, 255, 255, .03); }
.records li:first-child { background: rgba(255, 209, 102, .12); color: var(--yellow); font-weight: 700; }

.result {
  position: absolute; inset: 0; z-index: 5;
  display: none; align-items: center; justify-content: center;
  background: rgba(3, 6, 14, .55);
}
.result.show { display: flex; animation: fadeIn .4s ease; }
.result .card {
  width: min(620px, 92%); text-align: center; padding: 30px 32px;
  border-radius: 26px; background: var(--panel-solid); border: 2px solid var(--line-2);
  box-shadow: 0 30px 80px rgba(0, 0, 0, .6);
}
.result .card.win { border-color: var(--green); }
.result .card.lose { border-color: var(--orange); }
.result .big { font-size: 44px; font-weight: 900; margin: 6px 0 8px; }
.result .card.win .big { color: var(--green); }
.result .card.lose .big { color: var(--orange); }
.result p { font-size: 19px; color: #cbd6f7; line-height: 1.4; margin: 8px 0; }
.result .stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 18px 0; }
.result .stats div { background: rgba(255, 255, 255, .04); border-radius: 12px; padding: 10px; }
.result .stats b { display: block; font-size: 24px; }
.result .stats span { font-size: 13px; color: var(--muted); }
.result .actions { display: flex; gap: 12px; justify-content: center; margin-top: 14px; }
.result .actions button { font-size: 20px; padding: 14px 22px; border-radius: 14px; font-weight: 800; border: 1px solid var(--line-2); background: var(--panel); }
.result .actions button.primary { background: var(--orange); border-color: var(--orange); color: #1d0d00; }

/* ---------- справка ---------- */
.modal {
  position: fixed; inset: 0; z-index: 50; display: none;
  align-items: center; justify-content: center; background: rgba(3, 6, 14, .7);
}
.modal.show { display: flex; animation: fadeIn .3s ease; }
.modal .card {
  width: min(980px, 94vw); max-height: 88vh; overflow: auto;
  border-radius: 24px; background: var(--panel-solid); border: 1px solid var(--line-2);
  padding: 28px 32px; user-select: text;
}
.modal h2 { margin: 0 0 12px; font-size: 30px; }
.modal h4 { margin: 20px 0 6px; font-size: 18px; color: var(--cyan); }
.modal p, .modal li { font-size: 18px; line-height: 1.5; color: #d5def8; }
.modal .formula {
  font-family: "Cambria Math", "Times New Roman", serif; font-size: 22px;
  background: rgba(255, 255, 255, .04); border-radius: 12px; padding: 10px 14px; margin: 8px 0;
  overflow-x: auto;
}
.modal .close { float: right; }
.modal .cols { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }

/* ---------- узкие экраны ---------- */
@media (max-width: 1280px) {
  #npp .metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  #rocket .metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  #npp .twin-body { grid-template-columns: minmax(0, 1fr) 330px; }
  #rocket .twin-body { grid-template-columns: 340px minmax(0, 1fr); }
  .tile .value { font-size: 24px; }
}
@media (max-width: 900px) {
  html, body { overflow: auto; }
  #app { position: static; }
  .screen { position: static; min-height: 100vh; }
  .home-cards { grid-template-columns: 1fr; }
  #npp .twin-body, #rocket .twin-body { grid-template-columns: 1fr; grid-template-rows: auto; }
  #npp .side, #rocket .side { grid-row: auto; grid-column: auto; overflow: visible; }
  #npp .metrics, #rocket .metrics { grid-column: auto; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .scene-wrap { height: 62vh; }
  .modal .cols { grid-template-columns: 1fr; }
  .topbar .sub { display: none; }
}
.ticker.right { left: auto; right: 14px; align-items: flex-end; }

/* Конструктор ракеты: кнопка пуска всегда на виду */
#rk-launch {
  position: sticky; bottom: 0; z-index: 3;
  background: var(--panel-solid);
  box-shadow: 0 -12px 30px rgba(3, 6, 14, .7);
}
.fuel-list { grid-template-columns: 1fr 1fr; }
.fuel-list .fuel-card:last-child { grid-column: 1 / -1; }
.fuel-card { grid-template-columns: 26px 1fr; gap: 8px; padding: 8px 10px; }
.fuel-card .sw { width: 26px; height: 26px; border-radius: 8px; }
.fuel-card b { font-size: 15px; }
.fuel-card span { font-size: 12px; line-height: 1.2; display: block; }
.seg button svg { height: 42px; }
#rocket .side .panel { padding: 14px; }
#rocket input[type=range].big { height: 48px; }

/* ---------- горение ---------- */
.home-cards { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.home-card.fire:hover { border-color: #ff6a3d; box-shadow: 0 20px 60px rgba(255, 106, 61, .2); }
.home-card.fire .go { color: #ff8a5c; }
#fire .twin-body {
  grid-template-columns: minmax(0, 1fr) 390px;
  grid-template-rows: minmax(0, 1fr) auto;
}
#fire .side { grid-row: 1 / span 2; grid-column: 2; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
#fire .metrics { grid-column: 1; grid-template-columns: repeat(7, minmax(0, 1fr)); }
#fire .side .panel { padding: 14px; }
#fire .fuel-list .fuel-card:last-child { grid-column: auto; }
#fire input[type=range].big { height: 48px; }
.seg.two { grid-template-columns: 1fr 1fr; }
.seg.two button { padding: 10px 6px; }
.az-btn.fire-btn {
  background: radial-gradient(120% 140% at 50% 0%, #ffd18a, #ff7a2f 55%, #d5450e);
  box-shadow: 0 8px 0 #7a2405, 0 14px 30px rgba(255, 122, 47, .35);
  color: #1d0d00;
}
.az-btn.fire-btn.off {
  background: radial-gradient(120% 140% at 50% 0%, #a8b3d6, #5f6a91 60%, #3c4566);
  box-shadow: 0 8px 0 #262c44; color: #fff;
}
.equation { font-family: "Cambria Math", "Segoe UI", serif; font-size: 18px; line-height: 1.45; color: #e8eeff; }
@media (max-width: 1280px) {
  #fire .metrics { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  #fire .twin-body { grid-template-columns: minmax(0, 1fr) 330px; }
}
@media (max-width: 900px) {
  .home-cards { grid-template-columns: 1fr; }
  #fire .twin-body { grid-template-columns: 1fr; grid-template-rows: auto; }
  #fire .side { grid-row: auto; grid-column: auto; overflow: visible; }
  #fire .metrics { grid-column: auto; grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---------- 3D-локация на главном экране ---------- */
.world { display: none; position: absolute; inset: 0; }
#home.world-on .world { display: block; }
#home.world-on .home-inner, #home.world-on canvas.stars { display: none; }
#world-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
#world-canvas:active { cursor: grabbing; }
.world-labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.world-label {
  position: absolute; left: 0; top: 0;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 10px 18px 12px; border-radius: 16px;
  background: rgba(7, 11, 24, .82); border: 2px solid var(--cyan);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .45);
  transition: opacity .25s ease, background .15s, scale .15s;
  white-space: nowrap;
}
.world-label::after {
  content: ""; position: absolute; left: 50%; bottom: -10px; transform: translateX(-50%);
  border: 8px solid transparent; border-top-color: var(--cyan); border-bottom: 0;
}
.world-label b { font-size: 20px; }
.world-label span { font-size: 14px; color: var(--muted); }
.world-label.rocket { border-color: var(--orange); }
.world-label.rocket::after { border-top-color: var(--orange); }
.world-label.fire { border-color: #ff6a3d; }
.world-label.fire::after { border-top-color: #ff6a3d; }
.world-label:hover, .world-label.hot { background: rgba(30, 44, 86, .95); scale: 1.06; }
.world-label { animation: bob 3s ease-in-out infinite; }
@keyframes bob { 50% { margin-top: -6px; } }

.world-top {
  position: absolute; left: 24px; top: 20px; pointer-events: none;
  text-shadow: 0 2px 12px rgba(0, 0, 0, .45);
}
.world-top .home-kicker { background: rgba(7, 11, 24, .6); }
.world-title { margin: 12px 0 4px; font-size: clamp(30px, 3.6vw, 54px); font-weight: 900; color: #fff; }
.world-sub { margin: 0; font-size: 19px; color: #eef3ff; }
.world-status {
  position: absolute; right: 24px; top: 24px;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; border-radius: 999px; font-size: 16px; font-weight: 600;
  background: rgba(7, 11, 24, .78); border: 1px solid var(--line-2);
}
.world-status i { width: 10px; height: 10px; border-radius: 50%; background: var(--green); animation: pulse 1.6s infinite; }
.world-status i.bad { background: var(--red); }
.world-hint {
  position: absolute; left: 50%; top: 22%; transform: translateX(-50%) scale(.95);
  padding: 14px 26px; border-radius: 18px; font-size: 26px; font-weight: 800;
  background: rgba(7, 11, 24, .82); border: 1px solid var(--line-2);
  opacity: 0; transition: opacity .3s, transform .3s; pointer-events: none; text-align: center;
}
.world-hint.show { opacity: 1; transform: translateX(-50%) scale(1); }
.world-bar {
  position: absolute; left: 50%; bottom: 22px; transform: translateX(-50%);
  display: flex; align-items: stretch; gap: 10px;
  padding: 10px; border-radius: 22px;
  background: rgba(7, 11, 24, .8); border: 1px solid var(--line-2);
  backdrop-filter: blur(8px);
  max-width: calc(100% - 32px);
}
.wb {
  display: flex; flex-direction: column; align-items: flex-start; justify-content: center;
  padding: 10px 18px; border-radius: 14px; border: 1px solid var(--line-2);
  background: var(--panel-solid); text-align: left; min-width: 150px;
}
.wb b { font-size: 19px; white-space: nowrap; }
.wb span { font-size: 13px; color: var(--muted); }
.wb:hover { border-color: var(--cyan); }
.wb:active { transform: scale(.97); }
.wb.npp { border-color: rgba(56, 214, 255, .6); }
.wb.rocket { border-color: rgba(255, 159, 67, .6); }
.wb.fire { border-color: rgba(255, 106, 61, .6); }
.wb.action { background: linear-gradient(160deg, #ffb35c, #e46a10); color: #1d0d00; border-color: transparent; }
.wb.action span { color: #3a1a00; }
.wb.icon { min-width: 56px; align-items: center; font-size: 24px; }
.wb-gap { width: 8px; }
@media (max-width: 1100px) {
  .wb { min-width: 0; padding: 8px 12px; }
  .wb span { display: none; }
  .world-sub { display: none; }
}

/* ---------- стенд двигателей ---------- */
.home-cards { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.home-card.nozzle .go { color: #ffb35c; }
#nozzle .twin-body {
  grid-template-columns: minmax(0, 1fr) 400px;
  grid-template-rows: minmax(0, 1fr) auto;
}
#nozzle .side { grid-row: 1 / span 2; grid-column: 2; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
#nozzle .metrics { grid-column: 1; grid-template-columns: repeat(8, minmax(0, 1fr)); }
#nozzle .side .panel { padding: 14px; }
#nozzle input[type=range].big { height: 46px; }
#nozzle .fuel-list .fuel-card:last-child { grid-column: auto; }
#nz-fire-panel {
  position: sticky; bottom: 0; z-index: 3;
  background: var(--panel-solid);
  box-shadow: 0 -12px 30px rgba(3, 6, 14, .7);
}
.wb.nozzle { border-color: rgba(255, 179, 92, .6); }
.world-label.nozzle { border-color: #ffb35c; }
.world-label.nozzle::after { border-top-color: #ffb35c; }
#nozzle .tile .value { font-size: 26px; }
@media (max-width: 1280px) {
  #nozzle .metrics { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  #nozzle .twin-body { grid-template-columns: minmax(0, 1fr) 340px; }
  .home-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  #nozzle .twin-body { grid-template-columns: 1fr; grid-template-rows: auto; }
  #nozzle .side { grid-row: auto; grid-column: auto; overflow: visible; }
  #nozzle .metrics { grid-column: auto; grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---------- посадка ступени и аэродинамическая труба ---------- */
.home-cards { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 22px; }
.home-card { min-height: 0; padding: 20px 22px 22px; }
.home-card svg { height: 130px; }
.home-card h2 { font-size: 26px; }
.home-card p { font-size: 16px; }
.home-card.landing .go { color: #7fd3ff; }
.home-card.aero .go { color: #a78bfa; }
#landing .twin-body, #aero .twin-body {
  grid-template-columns: minmax(0, 1fr) 380px;
  grid-template-rows: minmax(0, 1fr) auto;
}
#landing .side, #aero .side { grid-row: 1 / span 2; grid-column: 2; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
#landing .metrics { grid-column: 1; grid-template-columns: repeat(7, minmax(0, 1fr)); }
#aero .metrics { grid-column: 1; grid-template-columns: repeat(7, minmax(0, 1fr)); }
#aero .tile .value { font-size: 24px; }
#landing .side .panel, #aero .side .panel { padding: 14px; }
#aero .fuel-list .fuel-card:last-child { grid-column: 1 / -1; }
.fuel-card .sw[class*="body-"] { background: #0b1226; border: 1px solid var(--line-2); position: relative; }
.sw.body-cylinder::after, .sw.body-square::after, .sw.body-plate::after, .sw.body-airfoil::after, .sw.body-nose::after, .sw.body-blunt::after, .sw.body-custom::after {
  content: ""; position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); background: #cdd4e4;
}
.sw.body-cylinder::after { width: 14px; height: 14px; border-radius: 50%; }
.sw.body-square::after { width: 12px; height: 12px; }
.sw.body-plate::after { width: 3px; height: 16px; }
.sw.body-airfoil::after { width: 20px; height: 6px; border-radius: 6px 10px 10px 6px / 3px 3px 3px 3px; }
.sw.body-nose::after { width: 20px; height: 8px; border-radius: 10px 0 0 10px; }
.sw.body-blunt::after { width: 20px; height: 8px; }
.sw.body-custom::after { width: 14px; height: 3px; transform: translate(-50%, -50%) rotate(-30deg); background: #ffd166; }
.ld-engine {
  width: 100%; border: 0; border-radius: 16px; padding: 14px 10px; font-size: 20px; font-weight: 900; color: #1d0d00;
  background: radial-gradient(120% 140% at 50% 0%, #ffd18a, #ff9f43 55%, #e46a10);
  box-shadow: 0 6px 0 #8a3d05;
}
.ld-engine small { display: block; font-size: 13px; font-weight: 600; }
.ld-engine.on { background: radial-gradient(120% 140% at 50% 0%, #fff3c4, #ffd166 50%, #ff9f43); box-shadow: 0 0 24px rgba(255, 200, 80, .6), 0 6px 0 #8a3d05; }
.ld-engine:disabled, .ld-arrow:disabled { filter: grayscale(.8) brightness(.6); }
.ld-arrows { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 6px; }
.ld-arrow {
  border: 1px solid var(--line-2); background: var(--panel-solid); border-radius: 16px;
  font-size: 34px; font-weight: 900; padding: 10px 0 8px; touch-action: none;
}
.ld-arrow small { display: block; font-size: 13px; color: var(--muted); font-weight: 600; }
.ld-arrow.pressed { background: rgba(56, 214, 255, .2); border-color: var(--cyan); }
#ld-legs.on { border-color: var(--green); }
#ld-auto.sel { border-color: var(--orange); background: rgba(255, 159, 67, .15); }
.ld-hud {
  position: absolute; left: 50%; top: 18px; transform: translateX(-50%); z-index: 3;
  padding: 12px 22px; border-radius: 16px; font-size: 22px; font-weight: 700;
  background: rgba(7, 11, 24, .8); border: 1px solid var(--line-2); pointer-events: none;
}
.ld-hud .urgent { color: var(--yellow); animation: blink 0.6s steps(2) infinite; }
.wb.landing { border-color: rgba(127, 211, 255, .6); }
.wb.aero { border-color: rgba(167, 139, 250, .6); }
.world-label.landing { border-color: #7fd3ff; }
.world-label.landing::after { border-top-color: #7fd3ff; }
.world-label.aero { border-color: #a78bfa; }
.world-label.aero::after { border-top-color: #a78bfa; }
.wb { min-width: 0; padding: 8px 14px; }
.wb b { font-size: 17px; }
@media (max-width: 1600px) { .wb span { display: none; } }
@media (max-width: 1280px) {
  #landing .metrics, #aero .metrics { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  #landing .twin-body, #aero .twin-body { grid-template-columns: minmax(0, 1fr) 330px; }
}
@media (max-width: 900px) {
  #landing .twin-body, #aero .twin-body { grid-template-columns: 1fr; grid-template-rows: auto; }
  #landing .side, #aero .side { grid-row: auto; grid-column: auto; overflow: visible; }
  #landing .metrics, #aero .metrics { grid-column: auto; grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---------- течение в трубе и сверхзвук ---------- */
#pipe .twin-body, #supersonic .twin-body {
  grid-template-columns: minmax(0, 1fr) 380px;
  grid-template-rows: minmax(0, 1fr) auto;
}
#pipe .side, #supersonic .side { grid-row: 1 / span 2; grid-column: 2; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
#pipe .metrics { grid-column: 1; grid-template-columns: repeat(8, minmax(0, 1fr)); }
#supersonic .metrics { grid-column: 1; grid-template-columns: repeat(7, minmax(0, 1fr)); }
#pipe .tile .value, #supersonic .tile .value { font-size: 24px; }
#pipe .side .panel, #supersonic .side .panel { padding: 14px; }
#pipe .fuel-list .fuel-card:last-child { grid-column: 1 / -1; }
#pipe input[type=range].big, #supersonic input[type=range].big { height: 44px; }
.preset-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.preset-grid .btn { text-align: center; padding: 10px 8px; font-size: 15px; }
.seg.three-rows { grid-template-columns: repeat(3, 1fr); }
.seg.three-rows button { padding: 6px 4px; }
.sw[class*="nose-"] { background: #0c1a3a; border: 1px solid var(--line-2); position: relative; overflow: hidden; }
.sw.nose-cone::after, .sw.nose-ogive::after, .sw.nose-hemi::after, .sw.nose-flat::after {
  content: ""; position: absolute; top: 50%; left: 4px; right: -4px; height: 12px; transform: translateY(-50%); background: #e8eef8;
}
.sw.nose-cone::after { clip-path: polygon(0 50%, 60% 0, 100% 0, 100% 100%, 60% 100%); }
.sw.nose-ogive::after { border-radius: 100% 0 0 100% / 50% 0 0 50%; }
.sw.nose-hemi::after { border-radius: 6px 0 0 6px; }
.home-card.pipe .go { color: #9fd0ff; }
.home-card.supersonic .go { color: #ffd166; }
.wb.pipe { border-color: rgba(159, 208, 255, .6); }
.wb.supersonic { border-color: rgba(255, 209, 102, .6); }
.world-label.pipe { border-color: #9fd0ff; }
.world-label.pipe::after { border-top-color: #9fd0ff; }
.world-label.supersonic { border-color: #ffd166; }
.world-label.supersonic::after { border-top-color: #ffd166; }
.home-cards { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.world-bar { gap: 6px; padding: 8px; }
.wb { padding: 8px 10px; }
.wb b { font-size: 15px; }
@media (max-width: 1900px) { .wb span { display: none; } }
@media (max-width: 1280px) {
  #pipe .metrics, #supersonic .metrics { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  #pipe .twin-body, #supersonic .twin-body { grid-template-columns: minmax(0, 1fr) 330px; }
  .home-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  #pipe .twin-body, #supersonic .twin-body { grid-template-columns: 1fr; grid-template-rows: auto; }
  #pipe .side, #supersonic .side { grid-row: auto; grid-column: auto; overflow: visible; }
  #pipe .metrics, #supersonic .metrics { grid-column: auto; grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ================= Телефон ================= */
@media (max-width: 900px) {
  /* каркас: страница прокручивается, сцена сверху, цифры сразу под ней, настройки ниже */
  html, body { overflow-x: hidden; overflow-y: auto; }
  #app { position: static; }
  .screen { position: static; min-height: 100svh; }
  .screen .twin-body { display: flex; flex-direction: column; gap: 10px; padding: 10px; }
  .screen .scene-wrap { order: -2; height: 56svh; min-height: 300px; flex: 0 0 auto; border-radius: 14px; }
  .screen .metrics { order: -1; grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 8px; }
  .screen .side { order: 0; overflow: visible; }
  .tile { padding: 9px 11px; border-radius: 12px; }
  .tile .value { font-size: 21px !important; }
  .tile .label { font-size: 11px; }
  .tile .hint { font-size: 11px; white-space: normal; }
  .trend-tile { grid-column: 1 / -1; min-height: 120px; }

  /* шапка: компактная и прилипает к верху */
  .topbar { gap: 8px; padding: 8px 10px; position: sticky; top: 0; z-index: 30; }
  .topbar h1 { font-size: 16px; line-height: 1.2; }
  .topbar .sub, .topbar .live-dot { display: none; }
  .back-btn, .icon-btn { padding: 8px 10px; font-size: 14px; border-radius: 10px; white-space: nowrap; }
  .topbar .icon-btn[data-help] { font-size: 0; }
  .topbar .icon-btn[data-help]::before { content: "?"; font-size: 18px; font-weight: 800; padding: 0 4px; }

  /* подсказки поверх сцены: мельче и только последняя */
  .ticker, .ticker.right { left: 8px; right: 8px; top: 50px; max-width: none; gap: 4px; align-items: stretch; }
  .ticker .msg { font-size: 12px; padding: 6px 10px; }
  .ticker .msg.old { display: none; }
  .explain { left: 8px; right: 8px; bottom: 8px; font-size: 12px; padding: 7px 10px; gap: 8px; line-height: 1.3; }
  .explain .ico { flex-basis: 24px; height: 24px; font-size: 13px; }

  .panel { padding: 12px; border-radius: 14px; }
  .big-value { font-size: 22px; }
  input[type=range].big { height: 44px; }
  .result .card { padding: 18px; }
  .result .big { font-size: 28px; }
  .result p { font-size: 15px; }
  .result .stats { gap: 6px; }
  .result .stats b { font-size: 16px; }
  .result .actions button { font-size: 16px; padding: 10px 14px; }
  .modal .card { padding: 18px; width: 96vw; }
  .modal h2 { font-size: 22px; }
  .modal p, .modal li { font-size: 15px; }
  .modal .formula { font-size: 16px; }

  /* главный экран: 3D-остров во весь экран */
  #home { position: relative; }
  #home.world-on { height: 100svh; min-height: 0; overflow: hidden; }
  #home.world-on .world { position: absolute; inset: 0; }
  .home-cards { grid-template-columns: 1fr !important; }
  .world-top { left: 12px; top: 10px; right: 12px; }
  .world-top .home-kicker { font-size: 10px; padding: 5px 10px; }
  .world-title { font-size: 26px; margin: 8px 0 0; }
  .world-sub { display: none; }
  .world-status { left: 12px; right: auto; top: 88px; font-size: 12px; padding: 6px 10px; }
  .world-label { padding: 5px 9px 6px; border-radius: 10px; border-width: 1.5px; }
  .world-label b { font-size: 13px; }
  .world-label span { display: none; }
  .world-label::after { bottom: -7px; border-width: 6px; }
  .world-bar {
    left: 8px; right: 8px; bottom: calc(10px + env(safe-area-inset-bottom)); transform: none; max-width: none;
    overflow-x: auto; justify-content: flex-start; scrollbar-width: none; -webkit-overflow-scrolling: touch;
  }
  .world-bar::-webkit-scrollbar { display: none; }
  .wb { flex: 0 0 auto; }
  .world-hint { font-size: 17px; top: 30%; width: max-content; max-width: 90%; }

  /* посадка ступени: кнопки управления всегда под пальцем, внизу экрана */
  #ld-controls {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
    border-radius: 16px 16px 0 0; padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    display: grid; grid-template-columns: 1fr 1.6fr 1fr;
    grid-template-areas: "left engine right" "thr thr thr" "legs legs auto";
    gap: 6px; background: rgba(13, 20, 40, .97); box-shadow: 0 -10px 30px rgba(3, 6, 14, .7);
  }
  #ld-controls > h3, #ld-controls > .row { display: none; }
  #ld-engine { grid-area: engine; font-size: 15px; padding: 10px 6px; }
  #ld-engine small { display: none; }
  #ld-throttle { grid-area: thr; height: 34px !important; margin: 0; }
  #ld-controls .ld-arrows { display: contents; }
  #ld-left { grid-area: left; }
  #ld-right { grid-area: right; }
  .ld-arrow { font-size: 26px; padding: 6px 0; }
  .ld-arrow small { display: none; }
  #ld-legs { grid-area: legs; margin: 0 !important; padding: 8px; font-size: 14px; }
  #ld-auto { grid-area: auto; margin: 0 !important; padding: 8px; font-size: 14px; }
  #landing .twin-body { padding-bottom: 190px; }
  .ld-hud { top: auto; bottom: 8px; font-size: 14px; padding: 6px 12px; max-width: 92%; white-space: nowrap; }

  /* ракета: «ПУСК» и запас скорости закреплены внизу */
  #rk-launch {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto; z-index: 25;
    border-radius: 16px 16px 0 0; padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
    display: grid; grid-template-columns: 1fr 1.3fr; align-items: center; gap: 10px;
  }
  #rk-launch > h3, #rk-launch .dv-bar, #dv-note { display: none; }
  #rk-launch .row { flex-direction: column; align-items: flex-start; gap: 0; }
  #rk-launch .big-value { font-size: 20px; }
  .launch-btn { font-size: 22px; padding: 12px; }
  #rocket .twin-body { padding-bottom: 96px; }

  /* стенд двигателей: «Зажигание» внизу */
  #nz-fire-panel {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
    border-radius: 16px 16px 0 0; padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  }
  #nz-fire { padding: 10px; font-size: 20px; }
  #nz-fire small { display: none; }
  #nozzle .twin-body { padding-bottom: 90px; }

  /* кнопки-сегменты и карточки — под палец, но компактнее */
  .fuel-card { padding: 8px; }
  .fuel-card b { font-size: 14px; }
  .fuel-card span { font-size: 11px; }
  .seg button { padding: 8px 4px; }
}

/* очень маленькие телефоны */
@media (max-width: 380px) {
  .topbar h1 { font-size: 14px; }
  .world-title { font-size: 22px; }
  .fuel-list { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  /* труба: высота по содержимому (поле, легенда, график); пояснение — в плитке «режим» */
  #aero .scene-wrap { height: auto; aspect-ratio: auto; min-height: 0; }
  #ae-canvas { position: relative; height: calc(100vw * 0.4 + 172px); }
  #ae-scene .explain { display: none; }
}
