:root {
  --bg: #0b0e13;
  --panel: #12161d;
  --card: #171c25;
  --line: #262d3a;
  --text: #e6ebf3;
  --muted: #8b95a7;
  --accent: #ff6a3d;
  --accent-2: #ffb35c;
  --good: #4cc38a;
  --bad: #ff4d4d;
  --warn: #ffb020;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 13px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: 0.45; }

#app { display: grid; grid-template-columns: 330px 1fr; height: 100vh; }

/* ---------- Панель ---------- */
#panel { background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto; padding: 14px 14px 24px;
  display: flex; flex-direction: column; gap: 12px; }
.brand { display: flex; gap: 10px; align-items: center; }
.logo { width: 38px; height: 38px; border-radius: 9px; display: grid; place-items: center; font-weight: 800;
  background: linear-gradient(135deg, var(--accent), #b3261e); letter-spacing: -0.5px; }
h1 { margin: 0; font-size: 17px; letter-spacing: 0.2px; }
.sub { color: var(--muted); font-size: 12px; }
h2 { margin: 0; font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); font-weight: 600; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
.card-h { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.card-h select { max-width: 60%; }
.hint { color: var(--muted); font-size: 11.5px; margin: 8px 0 0; }
.warn { color: var(--warn); }

select, input[type=number] { background: #0f131a; border: 1px solid var(--line); border-radius: 6px; padding: 5px 7px; min-width: 0; }
select:focus, input:focus { outline: 1px solid var(--accent); outline-offset: 0; }
input[type=number] { width: 100%; }

.layer { border: 1px solid var(--line); border-radius: 8px; padding: 7px; margin-bottom: 6px; background: #131820; }
.layer-top { display: flex; gap: 6px; align-items: center; }
.layer-top select { flex: 1; }
.lnum { width: 22px; height: 22px; border-radius: 5px; background: var(--c); color: #111; font-weight: 700;
  display: grid; place-items: center; flex: none; font-size: 12px; }
.layer-nums { display: flex; gap: 10px; margin-top: 6px; color: var(--muted); font-size: 12px; }
.layer-nums label { display: flex; align-items: center; gap: 5px; }
.layer-nums input { width: 62px; }
.icon { background: none; border: 1px solid var(--line); border-radius: 6px; width: 28px; height: 28px; color: var(--muted); }
.icon:hover:not(:disabled) { color: var(--bad); border-color: var(--bad); }
.ghost { background: none; border: 1px dashed var(--line); border-radius: 8px; padding: 6px; width: 100%; color: var(--muted); }
.ghost:hover { color: var(--text); border-color: var(--muted); }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid2 label { display: flex; flex-direction: column; gap: 3px; color: var(--muted); font-size: 11.5px; }
.grid2 label:first-child { grid-column: 1 / -1; }

.actions { display: flex; flex-direction: column; gap: 8px; }
.primary { background: linear-gradient(180deg, #ff7a45, #e0442a); border: none; border-radius: 10px; padding: 12px;
  font-weight: 800; letter-spacing: 3px; font-size: 16px; box-shadow: 0 4px 18px rgba(255, 90, 50, 0.25); }
.primary:hover:not(:disabled) { filter: brightness(1.08); }
#again { background: #1b2230; border: 1px solid var(--line); border-radius: 8px; padding: 8px; }
#again:hover:not(:disabled) { border-color: var(--accent-2); }

#result table { width: 100%; border-collapse: collapse; margin-top: 8px; }
#result td { padding: 4px 0; border-top: 1px solid var(--line); vertical-align: top; }
#result td:first-child { color: var(--muted); padding-right: 8px; }
#result td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.verdict { margin-top: 8px; font-weight: 800; letter-spacing: 1.5px; font-size: 15px; padding: 8px; border-radius: 7px; text-align: center; }
.verdict.bad { background: rgba(255, 77, 77, 0.14); color: var(--bad); }
.verdict.good { background: rgba(76, 195, 138, 0.14); color: var(--good); }
.verdict.warn { background: rgba(255, 176, 32, 0.14); color: var(--warn); }

.about summary { cursor: pointer; color: var(--muted); font-weight: 600; }
.about ul { padding-left: 18px; margin: 8px 0 0; color: #c4ccd8; font-size: 12px; }
.about li { margin-bottom: 5px; }

/* ---------- Основная область ---------- */
#main { display: grid; grid-template-rows: auto 1fr auto 110px; min-width: 0; min-height: 0; }
#modes { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-bottom: 1px solid var(--line); background: var(--panel); flex-wrap: wrap; }
#modeBtns { display: flex; gap: 4px; flex-wrap: wrap; }
#modeBtns button { background: #161b24; border: 1px solid var(--line); border-radius: 7px; padding: 5px 9px; color: #c7cfdc; }
#modeBtns button:hover { border-color: var(--muted); }
#modeBtns button.on { background: #2a1a14; border-color: var(--accent); color: #fff; }
#modeBtns kbd { font: 10px ui-monospace, monospace; color: var(--muted); margin-right: 5px; }
#modes .bot { margin-left: auto; color: var(--muted); display: flex; gap: 6px; align-items: center; }

#viewport { position: relative; min-height: 0; overflow: hidden; background: #0e1116; }
#view { width: 100%; height: 100%; display: block; cursor: crosshair; touch-action: none; }
#legend { position: absolute; left: 12px; top: 12px; display: flex; flex-direction: column; gap: 8px; pointer-events: none; max-width: 300px; }
.lg-block { background: rgba(14, 17, 22, 0.82); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; position: relative; backdrop-filter: blur(4px); }
.lg-block .half { position: absolute; right: 8px; top: 6px; color: var(--muted); font-size: 11px; }
.lg-title { font-weight: 600; margin-bottom: 6px; }
.lg-row { display: flex; align-items: center; gap: 7px; font-size: 12px; color: #c9d1dd; margin: 2px 0; }
.lg-row i { width: 14px; height: 10px; border-radius: 2px; flex: none; }
.lg-bar { height: 10px; border-radius: 3px; width: 240px; }
.lg-ticks { display: flex; justify-content: space-between; width: 240px; font-size: 10.5px; color: var(--muted); margin-top: 2px; font-variant-numeric: tabular-nums; }
.lg-hint { font-size: 11px; color: var(--muted); margin-top: 5px; max-width: 250px; }
#probe { position: absolute; pointer-events: none; background: rgba(10, 12, 16, 0.94); border: 1px solid #36404f; border-radius: 7px;
  padding: 7px 9px; font-size: 12px; line-height: 1.5; white-space: nowrap; font-variant-numeric: tabular-nums; }
#viewBtns { position: absolute; right: 12px; bottom: 12px; display: flex; gap: 6px; }
#viewBtns button { background: rgba(22, 27, 36, 0.9); border: 1px solid var(--line); border-radius: 7px; padding: 5px 9px; color: #c7cfdc; }
#empty { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; color: var(--muted); font-size: 15px; pointer-events: none; }
#empty span { font-size: 12px; }
#empty[hidden], #progress[hidden], #probe[hidden], #resultCard[hidden] { display: none; }
#progress { position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); background: rgba(14, 17, 22, 0.92); border: 1px solid var(--line);
  border-radius: 10px; padding: 9px 12px; display: flex; align-items: center; gap: 12px; font-variant-numeric: tabular-nums; }
#progress .bar { width: 200px; height: 6px; background: #232a36; border-radius: 3px; overflow: hidden; }
#progress .bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }
#progress button { background: none; border: 1px solid var(--line); border-radius: 6px; padding: 3px 8px; color: var(--muted); }

#timeline { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-top: 1px solid var(--line); background: var(--panel); }
#play { width: 36px; height: 30px; border-radius: 7px; border: 1px solid var(--line); background: #1b2230; }
#scrub { flex: 1; accent-color: var(--accent); }
#tlabel { min-width: 90px; text-align: right; font: 12px ui-monospace, Consolas, monospace; color: #c7cfdc; }
#chart { width: 100%; height: 110px; display: block; background: #0f1218; border-top: 1px solid var(--line); }

body.running #panel section, body.running #addLayer { pointer-events: none; opacity: 0.6; }

@media (max-width: 820px) {
  #app { grid-template-columns: 1fr; grid-template-rows: auto 70vh; height: auto; }
  #panel { border-right: none; border-bottom: 1px solid var(--line); }
  #main { height: 90vh; }
  .lg-bar, .lg-ticks { width: 180px; }
}

.grid2 label.angle { grid-column: 1 / -1; }
.grid2 label.angle input { accent-color: var(--accent); width: 100%; }
.grid2 label.angle span { color: var(--text); font-size: 12px; }
#modes .bot.hidden3d { visibility: hidden; }

.about h3 { font-size: 12px; margin: 12px 0 6px; color: var(--text); }
table.calib { width: 100%; border-collapse: collapse; font-size: 11.5px; font-variant-numeric: tabular-nums; }
table.calib th { text-align: left; color: var(--muted); font-weight: 600; padding: 3px 2px; }
table.calib td { padding: 3px 2px; border-top: 1px solid var(--line); color: #c9d1dd; }
table.calib td:nth-child(n+2), table.calib th:nth-child(n+2) { text-align: right; }
table.calib td.ok { color: var(--good); } table.calib td.mid { color: var(--warn); } table.calib td.bad { color: var(--bad); }
table.calib td:nth-child(n+2) { white-space: nowrap; }

.io { display: flex; gap: 8px; }
.io button { flex: 1; background: #161b24; border: 1px solid var(--line); border-radius: 8px; padding: 7px; font-size: 12px; color: #c7cfdc; }
.io button:hover:not(:disabled) { border-color: var(--muted); }
#ioMsg { margin: 0; min-height: 1em; }

.grid2 .comp { grid-column: 1 / -1; font-size: 11.5px; color: #c9d1dd; line-height: 1.5; }
.comp .ok { color: var(--good); } .comp .warn { color: var(--warn); }
select:disabled, input:disabled { opacity: 0.55; }

/* ---------- Игровой слой ---------- */
body.mode-campaign .only-sandbox, body.mode-sandbox .only-campaign { display: none !important; }
#modeTabs { display: flex; gap: 6px; }
#modeTabs button { flex: 1; background: #161b24; border: 1px solid var(--line); border-radius: 8px; padding: 8px; font-weight: 600; color: #c7cfdc; }
#modeTabs button.on { border-color: var(--accent); background: #2a1a14; color: #fff; }
.card label.angle { display: flex; flex-direction: column; gap: 3px; color: var(--muted); font-size: 11.5px; margin-top: 8px; }
.card label.angle input { accent-color: var(--accent); width: 100%; }
.card label.angle span { color: var(--text); font-size: 12px; }
.card label.angle input:disabled + span { color: var(--muted); }
.stats { margin-top: 8px; font-size: 12px; display: flex; flex-direction: column; gap: 5px; }
.meter { display: grid; grid-template-columns: 70px 1fr auto; gap: 8px; align-items: center; }
.meter .bar { height: 7px; background: #232a36; border-radius: 4px; overflow: hidden; position: relative; }
.meter .bar i { display: block; height: 100%; background: var(--good); }
.meter .bar i.warn { background: var(--warn); } .meter .bar i.bad { background: var(--bad); }
.meter .bar b { position: absolute; top: -2px; bottom: -2px; width: 2px; background: rgba(255,255,255,0.5); }
.meter span { color: var(--muted); } .meter em { font-style: normal; font-variant-numeric: tabular-nums; }
#missionCard .mc-top { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
#missionCard .mc-top h2 { flex: 1; color: var(--text); text-transform: none; letter-spacing: 0; font-size: 15px; }
#missionCard .back { background: none; border: 1px solid var(--line); border-radius: 6px; padding: 3px 8px; color: var(--muted); }
#missionCard .brief { font-size: 12.5px; color: #c9d1dd; margin: 0 0 8px; }
.threats { display: flex; flex-direction: column; gap: 4px; margin: 6px 0; }
.threat { display: grid; grid-template-columns: 22px 1fr auto; gap: 6px; align-items: center; background: #131820; border: 1px solid var(--line);
  border-radius: 7px; padding: 6px 8px; font-size: 12px; text-align: left; color: var(--text); }
.threat[data-k] { cursor: pointer; } .threat[data-k]:hover { border-color: var(--muted); }
.threat.cur { border-color: var(--accent); }
.threat .st { font-size: 14px; text-align: center; }
.threat .res { color: var(--muted); font-variant-numeric: tabular-nums; }
.stars { color: #ffcc4d; letter-spacing: 2px; font-size: 16px; }
.stars .off { color: #3a404a; }
.mc-verdict { margin-top: 8px; padding: 8px; border-radius: 7px; text-align: center; font-weight: 700; }
.mc-verdict.good { background: rgba(76,195,138,0.14); color: var(--good); } .mc-verdict.bad { background: rgba(255,77,77,0.14); color: var(--bad); }
.mc-verdict small { display: block; font-weight: 400; color: var(--muted); margin-top: 3px; }
#missionSelect { position: absolute; inset: 0; overflow-y: auto; padding: 24px; background: rgba(11,14,19,0.97); z-index: 5; }
#missionSelect[hidden] { display: none; }
#missionSelect h2 { color: var(--text); font-size: 20px; text-transform: none; letter-spacing: 0; margin: 0 0 4px; }
#missionSelect p.lead { color: var(--muted); margin: 0 0 18px; max-width: 640px; }
.mgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.mcard { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px; text-align: left; color: var(--text); display: flex; flex-direction: column; gap: 6px; min-height: 150px; }
.mcard:hover:not(:disabled) { border-color: var(--accent); transform: translateY(-1px); }
.mcard:disabled { opacity: 0.45; cursor: not-allowed; }
.mcard .ic { font-size: 26px; } .mcard b { font-size: 15px; } .mcard .num { color: var(--muted); font-size: 11px; }
.mcard .ms { color: var(--muted); font-size: 12px; flex: 1; }

#missionCard:empty { display: none; }

/* ---------- Экраны: меню и задания ---------- */
.screen { position: fixed; inset: 0; z-index: 50; overflow-y: auto; overflow-x: hidden; background:
  radial-gradient(1200px 600px at 70% 45%, rgba(255,106,61,0.10), transparent 60%),
  radial-gradient(900px 500px at 20% 80%, rgba(79,195,247,0.06), transparent 60%), var(--bg); }
.screen[hidden] { display: none; }
body.screen-open #app { visibility: hidden; }
.menu-art { position: absolute; right: -4%; top: 50%; transform: translateY(-50%); width: min(62vw, 900px); opacity: 0.55; pointer-events: none; }
.menu-inner { position: relative; max-width: 520px; padding: 9vh 7vw 40px; display: flex; flex-direction: column; gap: 14px; }
.menu-logo { width: 64px; height: 64px; border-radius: 16px; display: grid; place-items: center; font-weight: 900; font-size: 24px;
  background: linear-gradient(135deg, var(--accent), #b3261e); box-shadow: 0 10px 40px rgba(255,90,50,0.35); }
.menu-title { margin: 6px 0 0; font-size: clamp(32px, 6vw, 56px); letter-spacing: 4px; font-weight: 900;
  background: linear-gradient(180deg, #fff, #c9d1dd); -webkit-background-clip: text; background-clip: text; color: transparent; }
.menu-tag { margin: 0 0 10px; color: #aab4c4; font-size: 15px; line-height: 1.5; }
.menu-btns { display: flex; flex-direction: column; gap: 10px; }
.mbtn { display: flex; align-items: center; gap: 14px; text-align: left; padding: 14px 16px; border-radius: 12px;
  background: rgba(23,28,37,0.85); border: 1px solid var(--line); color: var(--text); backdrop-filter: blur(4px); transition: transform .12s, border-color .12s; }
.mbtn:hover:not(:disabled) { border-color: var(--accent); transform: translateX(4px); }
.mbtn .mi { font-size: 22px; width: 30px; text-align: center; }
.mbtn b { display: block; font-size: 16px; } .mbtn small { display: block; color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.mbtn.hero { background: linear-gradient(180deg, #ff7a45, #e0442a); border-color: transparent; box-shadow: 0 6px 24px rgba(255,90,50,0.3); }
.mbtn.hero small { color: rgba(255,255,255,0.8); }
.mbtn.ghost { background: transparent; }
.menu-foot { color: var(--muted); font-size: 12px; margin-top: 10px; }
.about-box { position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(640px, 92vw); max-height: 86vh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 22px 24px; z-index: 60; box-shadow: 0 0 0 100vmax rgba(5,7,10,0.72), 0 20px 80px rgba(0,0,0,0.6); }
.about-box[hidden] { display: none; }
.about-box h2 { color: var(--text); font-size: 18px; text-transform: none; letter-spacing: 0; margin: 0 0 10px; }
.about-box p { color: #c9d1dd; line-height: 1.55; font-size: 13.5px; }
.about-close { position: absolute; right: 12px; top: 12px; background: none; border: 1px solid var(--line); border-radius: 8px; width: 30px; height: 30px; color: var(--muted); }
#missions .ms-inner { max-width: 1100px; margin: 0 auto; padding: 28px 24px 40px; }
#missions .ms-head { display: flex; align-items: center; gap: 14px; margin-bottom: 6px; }
#missions .ms-head h2 { flex: 1; color: var(--text); font-size: 24px; text-transform: none; letter-spacing: 0; margin: 0; }
#missions .ms-total { color: #ffcc4d; font-size: 15px; }
#missions p.lead { color: var(--muted); margin: 0 0 20px; max-width: 760px; line-height: 1.5; }
.back-btn { background: #161b24; border: 1px solid var(--line); border-radius: 8px; padding: 7px 12px; color: #c7cfdc; }
.back-btn:hover { border-color: var(--muted); }
.topbar { display: flex; align-items: center; gap: 10px; }
.topbar button { background: #161b24; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; color: #c7cfdc; font-weight: 600; }
.topbar button:hover { border-color: var(--muted); }
#modeLabel { color: var(--muted); font-size: 12px; }
@media (max-width: 820px) { .menu-art { opacity: 0.25; width: 110vw; } .menu-inner { padding-top: 6vh; } }

/* ---------- Простой / подробный интерфейс ---------- */
body.ui-simple .only-detailed { display: none !important; }
body.ui-simple #main { grid-template-rows: auto 1fr auto; }
.lg-ends { display: flex; justify-content: space-between; width: 240px; font-size: 11px; color: var(--muted); margin-top: 2px; }
body.ui-simple #modeBtns kbd { display: none; }
.ui-switch { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 6px; color: var(--muted); font-size: 13px; }
.ui-switch small { flex-basis: 100%; font-size: 12px; }
.seg { display: inline-flex; background: #12161d; border: 1px solid var(--line); border-radius: 9px; padding: 3px; gap: 3px; }
.seg button { background: none; border: none; border-radius: 6px; padding: 6px 14px; color: #c7cfdc; font-weight: 600; }
.seg button.on { background: #2a1a14; color: #fff; box-shadow: inset 0 0 0 1px var(--accent); }
#uiToggle { margin-left: auto; font-weight: 500 !important; font-size: 12px; }
.verdict.big { font-size: 20px; padding: 12px; }
.simple-res { font-size: 13.5px; color: #c9d1dd; margin: 8px 0 0; line-height: 1.5; }

/* ---------- Подсказки за рекламу ---------- */
.hints { margin-top: 10px; border: 1px dashed #4a3a22; border-radius: 9px; padding: 8px 10px; background: rgba(255,179,92,0.05); }
.hints .hint-h { display: flex; justify-content: space-between; align-items: center; font-weight: 600; font-size: 12.5px; color: var(--accent-2); }
.hints .hint-h span { color: var(--muted); font-weight: 400; }
.hints ol { margin: 6px 0 0; padding-left: 20px; font-size: 12.5px; color: #e6ebf3; }
.hints li { margin: 3px 0; }
.hints li.ok { color: var(--good); list-style: none; margin-left: -20px; }
.hints .hint-btn { width: 100%; margin-top: 7px; background: #2a2114; border: 1px solid #6b5230; border-radius: 7px; padding: 7px; color: #ffd9a8; font-weight: 600; }
.hints .hint-btn:hover:not(:disabled) { border-color: var(--accent-2); }
.hints .hint-apply { width: 100%; margin-top: 6px; background: none; border: 1px solid var(--line); border-radius: 7px; padding: 6px; color: #c7cfdc; font-size: 12px; }
.hints .hint-msg { font-size: 11.5px; color: var(--muted); margin-top: 5px; }
.ad-stub { position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,0.85); display: grid; place-items: center; }
.ad-card { width: min(420px, 90vw); background: #11151c; border: 1px solid var(--line); border-radius: 14px; padding: 26px; text-align: center; }
.ad-label { color: var(--muted); letter-spacing: 3px; text-transform: uppercase; font-size: 12px; }
.ad-count { font-size: 64px; font-weight: 800; margin: 10px 0; color: var(--accent-2); }
.ad-note { color: var(--muted); font-size: 12.5px; margin-bottom: 14px; }
.ad-close { background: none; border: 1px solid var(--line); border-radius: 8px; padding: 7px 12px; color: var(--muted); }

/* ---------- Полигон: закрытое ---------- */
.unlock-info { margin: 0; font-size: 12px; color: var(--muted); background: rgba(255,179,92,0.06); border: 1px dashed #4a3a22; border-radius: 9px; padding: 7px 10px; }
button.link { background: none; border: none; padding: 0 2px; color: var(--accent-2); text-decoration: underline; font-size: inherit; }
.unlock-box h3 { margin: 8px 0 4px; font-size: 20px; }
.unlock-box .primary { display: block; width: 100%; margin: 6px 0 10px; }
.mcard .reward { font-size: 11.5px; color: var(--accent-2); }
.mc-verdict small.new-unlocks { color: var(--accent-2); }

/* ---------- Язык ---------- */
.lang-switch { display: flex; align-items: center; gap: 10px; margin-top: 10px; font-size: 12px; color: var(--muted); }
.lang-switch select { min-height: 34px; padding: 4px 8px; border: 1px solid var(--line); border-radius: 5px; background: #10191e; }
