:root {
  --bg: #111317; --panel: #181b20; --panel2: #1f232a; --panel3: #262b33; --line: #2c323b; --text: #e7eaef; --muted: #9aa3b0;
  --accent: #ff5707; --accent2: #ff7a3d; --good: #6fd38a; --bad: #ff6a5a; --warn: #ffb547; --ag: #4a86e8; --cr: #e8414b;
  font: 14px/1.4 "Segoe UI", system-ui, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent2); }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.good { color: var(--good); } .bad { color: var(--bad); } .mid { color: var(--warn); }
b.ag, .ag-t { color: var(--ag); } b.cr, .cr-t { color: var(--cr); }

#boot { position: fixed; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 16px; letter-spacing: .1em; }
.screen { position: fixed; inset: 0; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 5px; padding: 6px 12px; border: 1px solid #383e48; border-radius: 6px;
  background: var(--panel2); color: var(--text); text-decoration: none; cursor: pointer; white-space: nowrap; }
.btn:hover:not(:disabled) { border-color: #4a525e; background: #252a32; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.accent:hover:not(:disabled) { background: var(--accent2); }
.btn.danger { border-color: #7a2f2a; color: #ffb0a6; }
.btn.on { border-color: var(--accent); color: var(--accent2); }
.btn.small { padding: 3px 8px; font-size: 12.5px; }
input[type=number], select { background: var(--bg); border: 1px solid #383e48; border-radius: 5px; padding: 4px 6px; }

.bar { position: relative; z-index: 5; display: flex; align-items: center; gap: 8px; height: 48px; padding: 0 10px; background: var(--panel);
  border-bottom: 1px solid var(--line); white-space: nowrap; }
.bar h1 { margin: 0 8px 0 4px; font-size: 16px; font-weight: 600; }
.bar .spacer { flex: 1; }
.legal { display: flex; gap: 12px; margin: 0 4px; font-size: 12.5px; }
.legal a { color: var(--muted); text-decoration: none; }
.legal a:hover { color: var(--accent2); text-decoration: underline; }

/* ---------- start screen */
#startBg { position: absolute; inset: 0; width: 100%; height: 100%; }
.start-shade { position: absolute; inset: 0; background: linear-gradient(90deg, rgba(10,11,14,.96) 0%, rgba(10,11,14,.85) 36%, rgba(10,11,14,.25) 75%, rgba(10,11,14,.55) 100%); }
.start-panel { position: absolute; left: 0; top: 0; bottom: 0; width: min(520px, 100%); padding: 28px 44px; display: flex; flex-direction: column; justify-content: center; gap: 10px; }
.start-panel .exit { position: absolute; top: 16px; left: 16px; }
.kicker { color: var(--accent); font-weight: 700; letter-spacing: .18em; text-transform: uppercase; font-size: 13px; }
.kicker::before { content: ''; display: block; width: 92px; height: 6px; background: var(--accent); margin-bottom: 14px; }
.logo { margin: 0; font-size: 54px; line-height: 1; letter-spacing: .08em; font-weight: 800; }
.logo span { color: var(--accent); }
.tagline { color: #c4cad3; margin: 6px 0 14px; max-width: 420px; }
.menu { display: flex; flex-direction: column; gap: 8px; max-width: 320px; }
.menu .btn { justify-content: flex-start; padding: 10px 16px; font-size: 15px; }
.start-legal { margin-top: 24px; }

/* ---------- setup */
.setup-body { position: absolute; top: 48px; bottom: 0; left: 0; right: 0; overflow: auto; padding: 16px; }
.setup-cols { display: grid; grid-template-columns: minmax(240px, 1fr) minmax(240px, 1fr) minmax(320px, 1.3fr); gap: 16px; max-width: 1400px; margin: 0 auto; }
.side-col h2 { font-size: 15px; letter-spacing: .1em; margin: 4px 0 10px; display: flex; align-items: center; gap: 8px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot.ag { background: var(--ag); } .dot.cr { background: var(--cr); }
.fac-list { display: flex; flex-direction: column; gap: 8px; }
.fac-card { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); cursor: pointer; text-align: left; }
.fac-card:hover { border-color: #4a525e; }
.fac-card.sel { border-color: var(--accent); background: #22201e; }
.fac-card .sw { width: 14px; height: 38px; border-radius: 3px; flex: none; }
.fac-card b { display: block; }
.fac-card .meta { font-size: 12px; color: var(--muted); }
.setup-detail { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px; position: sticky; top: 0; align-self: start; }
.setup-detail h2 { margin: 0 0 4px; }
.setup-detail canvas { width: 100%; border-radius: 8px; display: block; margin: 10px 0; background: #0d0f12; }
.opt-row { display: flex; gap: 12px; flex-wrap: wrap; margin: 10px 0; }
.opt-row label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); }
.seg { display: inline-flex; border: 1px solid #383e48; border-radius: 6px; overflow: hidden; }
.seg button { border: 0; background: var(--panel2); padding: 5px 10px; cursor: pointer; }
.seg button.on { background: var(--accent); color: #fff; }

/* ---------- campaign */
.fac-badge { display: flex; align-items: center; gap: 8px; font-weight: 600; padding: 0 6px; }
.fac-badge .sw { width: 12px; height: 26px; border-radius: 2px; }
.fac-badge small { display: block; font-weight: 400; color: var(--muted); font-size: 11px; line-height: 1; }
.res { padding: 4px 10px; border-radius: 6px; background: var(--panel2); border: 1px solid var(--line); font-variant-numeric: tabular-nums; cursor: default; }
.res small { color: var(--muted); }
.camp-main { position: absolute; top: 48px; left: 0; right: 0; bottom: 0; display: flex; }
#mapWrap { position: relative; flex: 1; min-width: 0; overflow: hidden; }
#map { position: absolute; inset: 0; cursor: default; }
#mapHint { position: absolute; left: 10px; top: 8px; font-size: 12px; color: var(--muted); text-shadow: 0 1px 2px #000; pointer-events: none; }
#logPanel { width: 290px; flex: none; background: rgba(20,22,26,.96); border-left: 1px solid var(--line); display: flex; flex-direction: column; padding-bottom: 210px; }
#logPanel h3 { margin: 0; padding: 10px 12px 6px; font-size: 13px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
#log { list-style: none; margin: 0; padding: 0 8px 8px; overflow: auto; flex: 1; font-size: 12.5px; }
#log li { padding: 6px 8px; border-left: 3px solid #3a414c; margin-bottom: 4px; background: var(--panel); border-radius: 0 5px 5px 0; cursor: default; }
#log li.has-prov { cursor: pointer; }
#log li.has-prov:hover { background: var(--panel2); }
#log li.good { border-color: var(--good); } #log li.bad { border-color: var(--bad); } #log li.warn { border-color: var(--warn); }
#log li.event { border-color: var(--accent); background: #221c18; }
#log li .t { color: var(--muted); font-size: 11px; display: block; }
#tip { position: absolute; z-index: 4; pointer-events: none; background: rgba(16,18,22,.96); border: 1px solid #3a414c; border-radius: 7px; padding: 8px 10px; font-size: 12.5px; max-width: 300px; box-shadow: 0 6px 20px rgba(0,0,0,.5); }
#tip h4 { margin: 0 0 4px; font-size: 13.5px; }
#aiBanner { position: absolute; left: 50%; top: 14px; transform: translateX(-50%); background: rgba(16,18,22,.94); border: 1px solid var(--line); border-radius: 20px; padding: 7px 18px; font-weight: 600; z-index: 4; display: flex; align-items: center; gap: 8px; }
#aiBanner .sw { width: 10px; height: 10px; border-radius: 50%; }

#panel { position: absolute; left: 0; right: 290px; bottom: 0; height: 210px; background: rgba(22,24,29,.97); border-top: 1px solid var(--line); display: flex; z-index: 3; }
#panel.empty { height: 0; border: 0; }
#panel .col { padding: 10px 12px; overflow: auto; border-right: 1px solid var(--line); }
#panel .col:last-child { border-right: 0; flex: 1; }
#panel h2 { margin: 0; font-size: 17px; display: flex; align-items: center; gap: 8px; }
#panel h3 { margin: 0 0 6px; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
#endTurn { position: absolute; right: 12px; bottom: 12px; z-index: 6; padding: 12px 20px; font-size: 16px; font-weight: 700; box-shadow: 0 4px 18px rgba(255,87,7,.25); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; font-size: 12.5px; }
.kv span:nth-child(odd) { color: var(--muted); }
.lean { position: relative; height: 8px; border-radius: 4px; background: linear-gradient(90deg, var(--ag), #555 50%, var(--cr)); margin: 4px 0 2px; }
.lean i { position: absolute; top: -3px; width: 4px; height: 14px; background: #fff; border-radius: 2px; transform: translateX(-2px); box-shadow: 0 0 3px #000; }
.slots { display: grid; grid-template-columns: repeat(4, 118px); gap: 6px; }
.slot { height: 64px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); padding: 5px 7px; font-size: 12px; cursor: pointer; position: relative; overflow: hidden; text-align: left; }
.slot:hover { border-color: #4f5763; }
.slot.empty { border-style: dashed; color: var(--muted); display: grid; place-items: center; text-align: center; }
.slot.res { border-color: #6b5a2b; background: #1f1c15; }
.slot.hub { border-color: #3d4a63; background: #171c26; }
.slot.busy { border-color: var(--warn); }
.slot b { display: block; font-size: 12px; line-height: 1.2; }
.slot .lv { position: absolute; right: 6px; bottom: 4px; color: var(--accent2); font-weight: 700; }
.slot .cl { color: var(--muted); font-size: 11px; }
.units { display: flex; flex-wrap: wrap; gap: 5px; }
.ucard { width: 76px; height: 92px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); padding: 4px; font-size: 10.5px; line-height: 1.15; position: relative; cursor: pointer; display: flex; flex-direction: column; text-align: left; }
.ucard:hover { border-color: #4f5763; }
.ucard.sel { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.ucard.off { opacity: .45; }
.ucard canvas { width: 66px; height: 38px; display: block; margin: 0 auto 3px; }
.ucard .nm { flex: 1; overflow: hidden; }
.ucard .hp { height: 4px; background: #2c323b; border-radius: 2px; overflow: hidden; margin-top: 2px; }
.ucard .hp i { display: block; height: 100%; background: var(--good); }
.ucard .rk { position: absolute; right: 4px; top: 3px; color: #ffd34d; font-size: 9px; letter-spacing: -1px; }
.ucard .cost { color: var(--warn); font-weight: 600; }
.ucard .q { position: absolute; left: 3px; top: 3px; background: var(--accent); color: #fff; border-radius: 3px; font-size: 9px; padding: 0 3px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { font-size: 11.5px; padding: 1px 7px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel2); cursor: default; }
.chip.good { border-color: #2f5e3b; color: #9be3ae; } .chip.bad { border-color: #6a2e2a; color: #ffaca2; }
.stars { color: #ffd34d; letter-spacing: 1px; }
.mpbar { height: 6px; background: #2c323b; border-radius: 3px; overflow: hidden; margin: 4px 0; }
.mpbar i { display: block; height: 100%; background: #6fb6ff; }
.row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; }
.acts { display: flex; flex-direction: column; gap: 4px; }
.acts .btn { justify-content: space-between; }

/* ---------- modal */
#modalRoot .back { position: fixed; inset: 0; background: rgba(5,6,8,.62); z-index: 50; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--panel); border: 1px solid #383e48; border-radius: 12px; width: min(560px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.6); }
.modal.wide { width: min(980px, 100%); }
.modal.mid { width: min(760px, 100%); }
.modal > h2 { margin: 0; padding: 14px 18px 10px; font-size: 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.modal .body { padding: 12px 18px; overflow: auto; }
.modal .foot { padding: 10px 18px 14px; display: flex; gap: 8px; justify-content: flex-end; border-top: 1px solid var(--line); flex-wrap: wrap; }
.modal p { margin: 6px 0; }
.modal table { border-collapse: collapse; width: 100%; font-size: 13px; }
.modal th, .modal td { padding: 5px 8px; border-bottom: 1px solid var(--line); text-align: left; }
.modal th { color: var(--muted); font-weight: 600; font-size: 12px; }
.modal td.n, .modal th.n { text-align: right; font-variant-numeric: tabular-nums; }
.banner-img { height: 6px; margin: -12px -18px 10px; }

.bp { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.bp .side h3 { margin: 0 0 6px; display: flex; gap: 6px; align-items: center; font-size: 14px; }
.bp .uchips { display: flex; flex-wrap: wrap; gap: 3px; }
.bp .uchips span { font-size: 11px; padding: 1px 5px; background: var(--panel2); border: 1px solid var(--line); border-radius: 4px; }
.pow { height: 10px; border-radius: 5px; overflow: hidden; background: var(--cr); display: flex; }
.pow > div { height: 100%; background: var(--ag); transition: width .4s; }
.powbig { height: 14px; border-radius: 7px; overflow: hidden; display: flex; margin: 10px 0 4px; }
.powbig > div { height: 100%; }

.dip { display: grid; grid-template-columns: 270px 1fr; gap: 14px; min-height: 440px; }
.dip-list { display: flex; flex-direction: column; gap: 4px; max-height: 60vh; overflow: auto; }
.dip-item { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel2); cursor: pointer; text-align: left; }
.dip-item.sel { border-color: var(--accent); }
.dip-item .sw { width: 8px; height: 30px; border-radius: 2px; flex: none; }
.dip-item .nm { flex: 1; font-size: 12.5px; line-height: 1.2; }
.dip-item .nm small { display: block; color: var(--muted); }
.ticons { display: flex; gap: 3px; }
.ticons span { font-size: 10px; padding: 0 4px; border-radius: 3px; background: #2c323b; }
.ticons .w { background: #6a2420; color: #ffc0b8; }
.deal { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.deal fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.deal legend { color: var(--muted); font-size: 12px; padding: 0 4px; }
.deal label { display: flex; align-items: center; gap: 6px; font-size: 13px; padding: 2px 0; }
.deal input[type=number] { width: 90px; }
.verdict { margin: 8px 0; padding: 8px 10px; border-radius: 6px; background: var(--panel2); font-size: 13px; }
.skill-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.skill { border: 1px solid var(--line); border-radius: 8px; padding: 8px; background: var(--panel2); font-size: 12.5px; }
.skill.have { border-color: var(--good); background: #18241c; }
.skill.can { border-color: var(--accent); cursor: pointer; }

#toast { position: fixed; left: 50%; bottom: 230px; transform: translateX(-50%); background: rgba(16,18,22,.96); border: 1px solid #4a525e; border-radius: 8px; padding: 8px 16px; z-index: 60; }

/* ---------- battle */
#battle { background: #0b0d10; }
#bgl, #bov { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#bov { pointer-events: none; }
#bTop { position: absolute; top: 8px; left: 50%; transform: translateX(-50%); display: flex; gap: 12px; align-items: center; background: rgba(14,16,20,.88);
  border: 1px solid var(--line); border-radius: 10px; padding: 6px 12px; z-index: 3; width: min(600px, calc(100vw - 480px)); min-width: 300px; }
@media (max-width: 860px) { #bTop { left: 10px; transform: none; width: calc(100vw - 20px); top: 52px; } }
.b-side { flex: 1; font-size: 12.5px; line-height: 1.2; }
.b-side b { display: block; font-size: 13px; }
.b-right { text-align: right; }
.b-mid { width: 240px; text-align: center; }
.b-title { font-weight: 700; font-size: 13px; margin-bottom: 4px; }
.b-time { font-size: 12px; color: var(--muted); margin-top: 3px; font-variant-numeric: tabular-nums; }
#bTop .pow > div { background: var(--l); }
#bTop .pow { background: var(--r); }
#bCtrl { position: absolute; top: 10px; right: 10px; display: flex; gap: 4px; z-index: 3; }
#bDeploy { position: absolute; top: 74px; left: 50%; transform: translateX(-50%); z-index: 3; background: rgba(14,16,20,.92); border: 1px solid var(--accent);
  border-radius: 10px; padding: 8px 14px; display: flex; gap: 14px; align-items: center; max-width: 92vw; font-size: 13px; }
#bMini { position: absolute; left: 10px; bottom: 10px; width: 180px; height: 180px; border: 1px solid var(--line); border-radius: 8px; background: #0d0f12; z-index: 3; cursor: pointer; }
#bCards { position: absolute; left: 200px; right: 10px; bottom: 10px; display: flex; flex-wrap: wrap-reverse; gap: 4px; justify-content: center; z-index: 3; pointer-events: none; }
.bcard { pointer-events: auto; width: 62px; height: 78px; border: 1px solid #3a414c; border-radius: 6px; background: rgba(22,24,29,.92); padding: 3px; font-size: 9.5px; line-height: 1.1; position: relative; cursor: pointer; display: flex; flex-direction: column; overflow: hidden; }
.bcard canvas { width: 54px; height: 30px; display: block; margin: 0 auto 2px; }
.bcard.sel { border-color: #fff; box-shadow: 0 0 0 1px #fff, 0 0 10px rgba(255,255,255,.3); }
.bcard.rout { border-color: var(--bad); }
.bcard.dead { opacity: .35; }
.bcard .bars i { display: block; height: 3px; margin-top: 2px; border-radius: 1px; }
.bcard .n { font-weight: 700; font-size: 10px; }
.bcard .st { position: absolute; right: 3px; top: 2px; font-size: 9px; font-weight: 700; }
#bInfo { position: absolute; left: 200px; bottom: 100px; width: 300px; background: rgba(14,16,20,.92); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; z-index: 3; font-size: 12px; }
#bInfo h4 { margin: 0 0 4px; font-size: 13.5px; }
#bInfo .row { margin-top: 6px; }
#bMsg { position: absolute; top: 34%; left: 50%; transform: translate(-50%, -50%); z-index: 4; background: rgba(12,14,18,.9); border: 1px solid var(--accent); border-radius: 12px; padding: 18px 28px; text-align: center; font-size: 22px; font-weight: 700; letter-spacing: .06em; }

.map-legal { position: absolute; right: 10px; top: 8px; z-index: 2; background: rgba(14,16,20,.75); padding: 3px 8px; border-radius: 6px; display: none; }
@media (max-width: 1400px) {
  #campaign .bar > .legal { display: none; }
  .map-legal { display: flex; }
  #campaign .bar { gap: 6px; }
  #campaign .bar .btn { padding: 5px 9px; }
  .res { padding: 3px 7px; }
}
@media (max-width: 1280px) {
  #logPanel { width: 240px; }
  #panel { right: 240px; }
  .slots { grid-template-columns: repeat(auto-fill, 112px); }
  #resDate small, .fac-badge small { display: none; }
  #mapHint { display: none; }
}
@media (max-width: 1080px) {
  #exitBtn { font-size: 0; padding: 5px 8px; }
  #exitBtn::before { content: '← Store'; font-size: 13px; }
  #campaign .bar { overflow-x: auto; scrollbar-width: thin; }
}
@media (max-width: 900px) {
  #logPanel { display: none; }
  #panel { right: 0; height: 230px; }
  .setup-cols { grid-template-columns: 1fr; }
  .bar .legal, #btnTax { display: none; }
  .dip { grid-template-columns: 1fr; }
  .logo { font-size: 40px; }
}
