:root {
  --bg: #0f1317;
  --panel: rgba(22, 28, 35, 0.92);
  --panel2: #1f2731;
  --line: #34404e;
  --accent: #f39c32;
  --accent2: #ffb85c;
  --text: #ebe4d3;
  --muted: #9ea6b0;
  --good: #63d463;
  --bad: #ff5a45;
  --blue: #3fa9f5;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent;
}
canvas#view { position: fixed; inset: 0; display: block; touch-action: none; cursor: crosshair; }
button {
  font: inherit; color: var(--text); background: linear-gradient(#3a4654, #27313c); border: 1px solid #4d5b6b;
  border-radius: 6px; padding: 8px 14px; cursor: pointer; touch-action: manipulation;
}
button:hover { border-color: var(--accent); }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.45; cursor: default; }
.hidden { display: none !important; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; }
#hud > * { pointer-events: auto; }
#topLeft { position: absolute; left: 10px; top: 10px; display: flex; flex-direction: column; gap: 6px; }
.chip {
  display: flex; align-items: center; gap: 8px; background: var(--panel); border: 1px solid var(--line);
  border-left: 3px solid var(--accent); border-radius: 6px; padding: 5px 12px; min-width: 130px;
  font-weight: 700; font-size: 20px; font-variant-numeric: tabular-nums; letter-spacing: 1px;
}
.chip .ico { color: var(--accent); font-size: 16px; }
.chip.timer { font-size: 16px; min-width: 100px; border-left-color: var(--blue); }
.chip.timer .ico { color: var(--blue); }
#objective {
  position: absolute; left: 50%; top: 10px; transform: translateX(-50%); max-width: 46vw;
  background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 6px 14px;
  font-size: 13px; font-weight: 600; text-align: center; pointer-events: none;
}
#topRight { position: absolute; right: 10px; top: 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 4px; }
#minimap { display: block; width: 240px; height: 132px; cursor: pointer; touch-action: none; }
#sideBtns { position: absolute; right: 10px; top: 158px; display: flex; flex-direction: column; gap: 6px; }
#sideBtns button { width: 42px; height: 42px; padding: 0; font-size: 17px; }
#sideBtns button.active { border-color: var(--accent); background: #5a3d12; }

#panel {
  position: absolute; left: 10px; top: 118px; width: 284px; max-height: calc(100vh - 200px); overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); border-top: 3px solid var(--accent); border-radius: 8px; padding: 10px;
}
.pHead { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.pHead img { width: 42px; height: 42px; background: #2a333e; border-radius: 6px; border: 1px solid var(--line); }
.pName { font-weight: 700; font-size: 15px; }
.pTeam { font-size: 12px; }
.pTypes { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
.ptype { position: relative; }
.ptype img { width: 34px; height: 34px; background: #2a333e; border-radius: 5px; border: 1px solid var(--line); }
.ptype b { position: absolute; right: 2px; bottom: 0; font-size: 12px; text-shadow: 0 0 3px #000; }
.hpbar { height: 7px; background: #0b0e11; border-radius: 4px; overflow: hidden; margin-bottom: 8px; }
.hpbar i { display: block; height: 100%; width: 100%; background: var(--good); }
.hpbar i.mid { background: #f0c43a; }
.hpbar i.low { background: var(--bad); }
.hpbar.build i { background: #f0c43a; width: 0; }
.desc { font-size: 12px; color: var(--muted); margin-bottom: 6px; line-height: 1.35; }
.stats { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
.stats span { font-size: 11px; background: #2a333e; border-radius: 4px; padding: 2px 6px; }
.sub { font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: var(--accent2); margin: 8px 0 6px; font-weight: 700; }
.sub small { text-transform: none; letter-spacing: 0; color: var(--muted); font-weight: 400; margin-left: 4px; }
.actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; margin-top: 6px; }
.actions button { padding: 6px 4px; font-size: 12px; display: flex; flex-direction: column; align-items: center; gap: 1px;
  background: linear-gradient(#f2b545, #c98419); color: #1d1406; border-color: #ffd27a; font-weight: 700; }
.actions button span { font-size: 15px; }
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 5px; }
.grid .item { position: relative; display: flex; flex-direction: column; align-items: center; padding: 4px 4px 6px; overflow: hidden; }
.grid .item img { width: 44px; height: 44px; }
.grid .item .nm { font-size: 11px; line-height: 1.15; text-align: center; }
.grid .item .cost { font-size: 12px; color: var(--accent2); font-weight: 700; }
.grid .item.poor { opacity: 0.55; }
.grid .item.poor .cost { color: var(--bad); }
.grid .item .q { position: absolute; top: 3px; right: 5px; font-size: 14px; color: #fff; text-shadow: 0 0 3px #000; }
.grid .item .pr { position: absolute; left: 0; bottom: 0; height: 4px; width: 0; background: var(--blue); }

/* keyboard hint badges */
kbd {
  position: absolute; top: 2px; left: 3px; font: 700 9px/1 "Segoe UI", sans-serif; color: #fff1d6;
  background: rgba(10, 12, 16, 0.75); border: 1px solid rgba(255, 255, 255, 0.25); border-radius: 3px; padding: 2px 3px; pointer-events: none;
}
.actions button { position: relative; }
.actions button kbd { top: 2px; left: auto; right: 3px; color: #2a1a05; background: rgba(255, 255, 255, 0.45); border-color: rgba(0, 0, 0, 0.2); }

/* production: 3-column available grid + queue slots */
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
.grid3 .item { position: relative; display: flex; flex-direction: column; align-items: center; padding: 3px 2px 4px; overflow: hidden;
  background: linear-gradient(#2f6fa8, #1d4a75); border-color: #6fb6ee; }
.grid3 .item:hover { background: linear-gradient(#3a82c2, #22588a); }
.grid3 .item img { width: 38px; height: 38px; margin-top: 2px; }
.grid3 .item .nm { font-size: 10px; line-height: 1.1; text-align: center; color: #dcecf8; min-height: 22px; display: flex; align-items: center; }
.grid3 .item .cost { font-size: 12px; color: #ffd27a; font-weight: 800; }
.grid3 .item.poor { filter: grayscale(0.7); opacity: 0.6; }
.grid3 .item.poor .cost { color: var(--bad); }
.grid3 .item .q { position: absolute; top: 2px; right: 4px; font-size: 13px; color: #fff; background: var(--accent); color: #1d1406; border-radius: 8px; padding: 0 5px; line-height: 16px; }
.grid3 .item .q:empty { display: none; }
.queue { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin-bottom: 4px; }
.qslot { position: relative; height: 52px; padding: 0; border-radius: 6px; overflow: hidden;
  background: linear-gradient(#cfd6dc, #8d979f); border: 1px solid #e8eef2; }
.qslot.empty { background: #0d1014; border: 1px solid #2a323c; box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.6); }
.qslot img { width: 100%; height: 100%; object-fit: contain; }
.qslot .qpr { position: absolute; left: 0; top: 0; width: 100%; height: 100%; background: rgba(10, 14, 20, 0.55); pointer-events: none; }
.qslot:not(.active) .qpr { height: 100%; background: rgba(10, 14, 20, 0.35); }
.qslot .qx { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 22px; font-weight: 900;
  color: #ff5a45; text-shadow: 0 0 4px #000; opacity: 0; transition: opacity .12s; }
.qslot:hover .qx { opacity: 1; }
.qslot:hover { border-color: var(--bad); }
.qslot .qpct { position: absolute; left: 0; right: 0; bottom: 1px; font: 700 10px/1 sans-serif; font-style: normal; color: #fff; text-shadow: 0 0 3px #000; text-align: center; }
.qslot.active { border-color: #8cff6a; box-shadow: 0 0 6px rgba(140, 255, 106, 0.5); }

#squadbar { position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); display: flex; gap: 6px; }
#squadbar button { position: relative; width: 50px; height: 50px; padding: 0; border-radius: 8px; background: linear-gradient(#56606b, #363e47); }
#squadbar button.full { background: linear-gradient(#3fae55, #217434); border-color: #8be39b; }
#squadbar i { position: absolute; left: 4px; top: 2px; font-size: 11px; font-style: normal; color: #dfe6ec; }
#squadbar b { font-size: 18px; }
#squadbar b.plus { font-size: 26px; color: #e9eef2; }

#modeHint {
  position: absolute; left: 50%; bottom: 72px; transform: translateX(-50%); background: rgba(243, 156, 50, 0.95);
  color: #1d1406; padding: 5px 6px 5px 14px; border-radius: 6px; font-weight: 700; font-size: 13px;
  display: flex; align-items: center; gap: 8px; white-space: nowrap; max-width: 96vw;
}
#modeHint span { pointer-events: none; overflow: hidden; text-overflow: ellipsis; }
#modeHint button { padding: 4px 10px; font-size: 12px; font-weight: 800; background: #1d1406; color: #ffd9a0; border-color: #5a3a10; }
#modeHint button[data-mh="go"] { background: #2f8f3a; color: #fff; border-color: #8be39b; }
#modeHint button:disabled { opacity: .45; }
.actions button.auto-on { background: linear-gradient(#6fd36f, #2f8f3a); border-color: #b8f5b8; color: #08240c; }
.actions button.auto-off { background: linear-gradient(#ff8a78, #c0392b); border-color: #ffc2b8; color: #2a0804; }
.actions button.auto-mixed { background: linear-gradient(#d9d0b0, #9a9070); }
.actions button em { font-style: normal; }
#toasts { position: absolute; left: 50%; top: 50px; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 4px; pointer-events: none; }
.toast { background: rgba(20, 26, 32, 0.92); border: 1px solid var(--line); border-left: 3px solid var(--good); padding: 5px 12px; border-radius: 5px; font-size: 13px; transition: opacity .5s; }
.toast.warn { border-left-color: var(--bad); }
.toast.fade { opacity: 0; }

/* ---------- screens ---------- */
#screens { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; background: rgba(8, 10, 13, 0.6); z-index: 10; padding: 16px; }
#screens.on { display: flex; }
.screen { display: none; width: 100%; justify-content: center; }
.screen.on { display: flex; }
#menu.on { position: fixed; inset: 0; align-items: center; }
.box {
  background: var(--panel2); border: 1px solid var(--line); border-top: 4px solid var(--accent); border-radius: 10px;
  padding: 20px 22px; width: min(420px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; box-shadow: 0 20px 60px rgba(0, 0, 0, .55);
  display: flex; flex-direction: column; gap: 10px;
}
.box.wide { width: min(760px, 100%); }
.box h1, .box h2 { margin: 0 0 4px; letter-spacing: 1px; }
.box h3 { margin: 6px 0 4px; color: var(--accent2); font-size: 14px; text-transform: uppercase; letter-spacing: 1px; }
.box p { margin: 0; color: var(--muted); line-height: 1.45; }
button.big { font-size: 17px; padding: 12px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase;
  background: linear-gradient(#f2b545, #c98419); color: #1d1406; border-color: #ffd27a; }
button.big.ghost, button.ghost { background: linear-gradient(#3a4654, #27313c); color: var(--text); border-color: #4d5b6b; }
button.small { padding: 4px 10px; }
#skStart, #resNext { background: linear-gradient(#f2b545, #c98419); color: #1d1406; border-color: #ffd27a; font-weight: 700; }
.menuBox { align-items: stretch; background: rgba(20, 24, 30, 0.88); }
.logo { text-align: center; line-height: 1; margin: 6px 0 2px; }
.logo .l1 { font-size: 44px; font-weight: 900; letter-spacing: 6px; color: var(--accent);
  text-shadow: 0 3px 0 #7a4410, 0 6px 18px rgba(0, 0, 0, .6); }
.logo .l2 { font-size: 22px; font-weight: 800; letter-spacing: 12px; color: #e9e2cf; margin-top: 4px; }
.tagline { text-align: center; color: var(--muted); margin-bottom: 8px; font-size: 13px; letter-spacing: 2px; text-transform: uppercase; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
select, input { font: inherit; color: var(--text); background: #12171d; border: 1px solid var(--line); border-radius: 6px; padding: 8px; }
.row { display: flex; gap: 8px; align-items: center; }
.row input { flex: 1; }
.row.end { justify-content: flex-end; margin-top: 6px; flex-wrap: wrap; }

#missionList { display: flex; flex-direction: column; gap: 6px; }
.mission { display: flex; align-items: center; gap: 12px; text-align: left; padding: 10px 12px; }
.mission .num { width: 34px; height: 34px; border-radius: 50%; background: var(--accent); color: #1d1406; font-weight: 900; display: flex; align-items: center; justify-content: center; flex: none; }
.mission.locked .num { background: #555; color: #aaa; }
.mission .mt { flex: 1; display: flex; flex-direction: column; }
.mission small { color: var(--muted); }
.mission .tag { font-size: 12px; color: var(--muted); }

.brief { text-align: center; width: min(520px, 100%); }
.brHead { font-weight: 900; letter-spacing: 3px; color: var(--accent); font-size: 18px; }
.vs { display: flex; align-items: center; justify-content: center; gap: 14px; }
.vs .side { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); width: 140px; }
.vs svg { width: 72px; height: 72px; filter: drop-shadow(0 4px 6px rgba(0,0,0,.5)); }
.vsText { font-size: 42px; font-weight: 900; font-style: italic; color: var(--accent); text-shadow: 0 3px 0 #7a4410; }
.objective { background: #12171d; border: 1px solid var(--line); border-radius: 6px; padding: 10px; font-weight: 700; }
#resTitle { font-size: 40px; text-align: center; letter-spacing: 4px; }
#resTitle.win { color: var(--good); }
#resTitle.lose { color: var(--bad); }
#resReason { text-align: center; }
#resStats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
#resStats div { background: #12171d; border-radius: 6px; padding: 8px; text-align: center; display: flex; flex-direction: column; }
#resStats b { font-size: 20px; }
#resStats span { font-size: 11px; color: var(--muted); }
.help .cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.help ul { margin: 0; padding-left: 18px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.help b { color: var(--text); }

/* ---------- small screens ---------- */
@media (max-width: 760px) {
  .chip { font-size: 15px; min-width: 96px; padding: 4px 8px; }
  .chip.timer { font-size: 13px; min-width: 80px; }
  #objective { top: 84px; left: 10px; transform: none; max-width: 56vw; font-size: 11px; padding: 4px 8px; text-align: left; }
  #minimap { width: 150px; height: 84px; }
  #sideBtns { top: 104px; }
  #sideBtns button { width: 38px; height: 38px; }
  #panel { top: auto; bottom: 66px; left: 6px; width: min(250px, 62vw); max-height: 48vh; padding: 8px; }
  .grid .item img { width: 40px; height: 40px; }
  .grid3 .item img { width: 36px; height: 36px; }
  .grid3 .item .nm { display: none; }
  .qslot { height: 40px; }
  kbd { display: none; }
  #squadbar { gap: 3px; bottom: 6px; }
  #squadbar button { width: 34px; height: 44px; }
  #squadbar b.plus { font-size: 20px; }
  .help .cols { grid-template-columns: 1fr; }
  #resStats { grid-template-columns: repeat(2, 1fr); }
  .logo .l1 { font-size: 34px; }
}

/* ================= HOME / SETTINGS / ARMORY ================= */
#menuBg { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 5; display: none; background: radial-gradient(ellipse at 50% 40%, #232c37, #0e1217); }
body.bgOn.noDemo #menuBg { display: block; }
body.bgOn #screens { background: radial-gradient(ellipse at 50% 50%, rgba(10,8,14,.32) 0%, rgba(10,8,14,.42) 55%, rgba(6,5,10,.82) 100%); }
body.bgOn.noDemo #screens { background: radial-gradient(ellipse at 50% 55%, rgba(8,6,12,0) 40%, rgba(8,6,12,.55) 100%); }
#fps { position: fixed; right: 8px; bottom: 6px; z-index: 40; font: 700 12px/1 "Segoe UI", sans-serif; color: #ffd9a0; background: rgba(10,12,16,.7);
  padding: 4px 8px; border-radius: 5px; pointer-events: none; font-variant-numeric: tabular-nums; }
.iconBtn { width: 46px; height: 46px; padding: 0; display: inline-flex; align-items: center; justify-content: center; border-radius: 12px;
  background: rgba(18, 20, 28, .55); border: 1px solid rgba(255, 220, 160, .28); backdrop-filter: blur(6px); transition: transform .15s, background .15s, border-color .15s; }
.iconBtn svg { width: 24px; height: 24px; }
.iconBtn:hover { background: rgba(243, 156, 50, .22); border-color: var(--accent); transform: translateY(-1px); }
.iconBtn:hover svg.gear { transform: rotate(60deg); }
svg.gear { transition: transform .5s cubic-bezier(.3,1.4,.5,1); }
.menuTop { position: fixed; top: 14px; right: 14px; display: flex; gap: 10px; z-index: 12; }
.menuWrap { display: flex; flex-direction: column; align-items: center; gap: 18px; width: min(430px, 100%); animation: menuIn .8s cubic-bezier(.2,.8,.2,1) both; }
@keyframes menuIn { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: none; } }
.logoBlock { text-align: center; display: flex; flex-direction: column; align-items: center; }
.emblem svg { width: 84px; height: 84px; filter: drop-shadow(0 6px 14px rgba(0,0,0,.55)); animation: float 5s ease-in-out infinite; }
@keyframes float { 50% { transform: translateY(-5px); } }
#menu .logo .l1 { font-size: 54px; letter-spacing: 7px; background: linear-gradient(#fff0c8, #ffb040 55%, #d9741c); -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 3px 0 #6b3a0c) drop-shadow(0 8px 16px rgba(0,0,0,.6)); text-shadow: none; }
#menu .logo .l2 { font-size: 22px; letter-spacing: 14px; color: #f4ead2; text-shadow: 0 2px 10px rgba(0,0,0,.7); padding-left: 14px; }
#menu .tagline { color: #e8c99a; margin-top: 6px; text-shadow: 0 1px 6px rgba(0,0,0,.8); }
.menuList { display: flex; flex-direction: column; gap: 9px; width: 100%; }
.mrow { display: flex; gap: 9px; }
.mbtn { display: flex; align-items: center; gap: 14px; width: 100%; text-align: left; padding: 11px 16px; border-radius: 12px; position: relative; overflow: hidden;
  background: linear-gradient(rgba(34, 38, 50, .78), rgba(18, 20, 28, .82)); border: 1px solid rgba(255, 220, 160, .22); backdrop-filter: blur(8px);
  box-shadow: 0 6px 18px rgba(0,0,0,.35), inset 0 1px 0 rgba(255,255,255,.08); transition: transform .15s, border-color .15s, background .2s, box-shadow .2s; }
.mbtn::after { content: ""; position: absolute; inset: 0; background: linear-gradient(100deg, transparent 30%, rgba(255,230,180,.16) 50%, transparent 70%); transform: translateX(-120%); transition: transform .6s; }
.mbtn:hover { transform: translateY(-2px) scale(1.01); border-color: var(--accent); box-shadow: 0 10px 26px rgba(0,0,0,.45), 0 0 0 1px rgba(243,156,50,.35); }
.mbtn:hover::after { transform: translateX(120%); }
.mbtn.primary { background: linear-gradient(#f6bd55, #cf8a1c); border-color: #ffdc94; color: #1d1406; }
.mbtn.primary .mt small { color: rgba(40, 24, 4, .9); font-weight: 600; }
.mbtn.primary .mi { background: rgba(40, 24, 4, .18); }
.mbtn.half { flex: 1; justify-content: center; gap: 10px; padding: 11px 10px; }
.mbtn .mi { width: 40px; height: 40px; border-radius: 10px; flex: none; display: flex; align-items: center; justify-content: center; background: rgba(243, 156, 50, .16); }
.mbtn .mi svg { width: 24px; height: 24px; }
.mbtn .mt { flex: 1; display: flex; flex-direction: column; line-height: 1.2; }
.mbtn .mt b { font-size: 16px; letter-spacing: 1px; text-transform: uppercase; }
.mbtn .mt small { color: #aeb3bd; font-size: 12px; margin-top: 1px; }
.mbtn .arr { font-size: 26px; opacity: .55; line-height: 1; }
.mbtn.half .mt { flex: none; }
.menuFoot { color: rgba(236, 214, 176, .7); font-size: 12px; letter-spacing: 3px; text-transform: uppercase; text-shadow: 0 1px 6px #000; }
.menuFoot i { color: var(--accent); font-style: normal; margin: 0 6px; }

.boxHead { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; }
.boxHead h2 { margin: 0; flex: 1; font-size: 24px; }
.boxHead .hi { width: 38px; height: 38px; border-radius: 10px; background: rgba(243, 156, 50, .18); display: flex; align-items: center; justify-content: center; }
.boxHead .hi svg { width: 22px; height: 22px; }
.settingsBox, .armoryBox { background: linear-gradient(rgba(30, 36, 46, .93), rgba(18, 22, 30, .95)); backdrop-filter: blur(10px); border-color: rgba(255,220,160,.2); }
.settingsBox { width: min(900px, 100%); }
.setGrid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 12px; }
.setGrid .setGroup { display: flex; flex-direction: column; }
.closeBtn { width: 38px; height: 38px; padding: 0; flex: none; display: inline-flex; align-items: center; justify-content: center; border-radius: 10px;
  background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.14); color: #e9dfc8; transition: background .15s, border-color .15s, transform .15s; }
.closeBtn svg { width: 18px; height: 18px; }
.closeBtn:hover { background: rgba(229, 83, 61, .28); border-color: #ff7a66; color: #fff; transform: rotate(90deg); }
@media (max-width: 760px) { .setGrid { grid-template-columns: 1fr; } }
.setGroup { background: rgba(10, 12, 18, .45); border: 1px solid rgba(255,255,255,.07); border-radius: 10px; padding: 10px 14px 6px; }
.setGroup h3 { margin: 0 0 4px; }
.setRow { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 9px 0; border-top: 1px solid rgba(255,255,255,.06); }
.setRow:first-of-type { border-top: 0; }
.setRow .sl { display: flex; flex-direction: column; min-width: 0; }
.setRow .sl b { font-size: 14px; }
.setRow .sl small { color: var(--muted); font-size: 12px; }
.switch { position: relative; width: 48px; height: 26px; flex: none; display: block; }
.switch input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 2; }
.switch i { position: absolute; inset: 0; border-radius: 13px; background: #2b333d; border: 1px solid #4a5666; transition: background .2s, border-color .2s; }
.switch i::after { content: ""; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%; background: #c8cfd8; transition: transform .2s, background .2s; box-shadow: 0 2px 4px rgba(0,0,0,.4); }
.switch input:checked + i { background: linear-gradient(#f2b545, #c98419); border-color: #ffd27a; }
.switch input:checked + i::after { transform: translateX(22px); background: #fff; }
input[type=range] { -webkit-appearance: none; appearance: none; width: 180px; height: 6px; padding: 0; border-radius: 3px; background: linear-gradient(90deg, var(--accent) var(--p, 45%), #2b333d var(--p, 45%)); border: 0; outline: 0; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; border-radius: 50%; background: #fff; border: 3px solid var(--accent); box-shadow: 0 2px 6px rgba(0,0,0,.5); cursor: pointer; }
input[type=range]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 3px solid var(--accent); cursor: pointer; }
.seg { display: inline-flex; background: #12171d; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; flex: none; }
.seg button { border: 0; border-radius: 0; background: transparent; padding: 6px 11px; font-size: 13px; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: linear-gradient(#f2b545, #c98419); color: #1d1406; font-weight: 700; }
button.danger { background: linear-gradient(#a94438, #7c2a21); border-color: #e0786b; }
button.danger.confirm { background: linear-gradient(#ff6a55, #c8321f); }

.armoryBox { width: min(920px, 100%); }
.armoryBox .tabs { margin-left: auto; }
.armGrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; overflow-y: auto; max-height: calc(100vh - 220px); padding: 8px 6px 6px 2px; margin: -4px 0 0; }
.armCard { cursor: pointer; display: flex; gap: 12px; background: rgba(10, 12, 18, .5); border: 1px solid rgba(255,255,255,.08); border-radius: 10px; padding: 10px; transition: border-color .15s, transform .15s; }
.armCard:hover { border-color: var(--accent); transform: translateY(-2px); }
.armCard img { width: 84px; height: 84px; flex: none; background: radial-gradient(circle at 50% 70%, #4a3a26, #1f1812); border-radius: 8px; border: 1px solid rgba(255,220,160,.2); }
.armCard .ai { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.armCard .an { font-weight: 800; font-size: 15px; }
.armCard .ad { font-size: 11.5px; color: var(--muted); line-height: 1.35; }
.armCard .as { display: flex; flex-wrap: wrap; gap: 4px; margin-top: auto; }
.armCard .as span { font-size: 11px; background: #232b35; border-radius: 4px; padding: 2px 6px; color: #d7dde4; }
.armCard .as span.cost { color: #ffd27a; font-weight: 700; }
.armCard .as span.ac { color: #8fd3ff; }

@media (max-width: 760px) {
  #menu .logo .l1 { font-size: 38px; letter-spacing: 4px; }
  .emblem svg { width: 62px; height: 62px; }
  .mbtn .mt small { display: none; }
  .mrow { flex-direction: row; }
  input[type=range] { width: 120px; }
  .seg button { padding: 6px 7px; font-size: 12px; }
}
@media (max-height: 640px) { .emblem { display: none; } .menuWrap { gap: 10px; } .mbtn { padding: 8px 14px; } .mbtn .mt small { display: none; } }
@media (prefers-reduced-motion: reduce) { .menuWrap, .emblem svg { animation: none; } }
#sideBtns button svg, .iconBtn svg { color: #ffcf7a; }
#sideBtns button svg { width: 22px; height: 22px; display: block; margin: auto; }
#sideBtns button { display: flex; align-items: center; justify-content: center; border-radius: 10px; }
#sideBtns button:hover svg.gear { transform: rotate(60deg); }
#sideBtns button.active svg { color: #fff; }

/* ---------- Arabic / Kurdish Sorani (right-to-left) ---------- */
/* Zain is loaded from Google Fonts when an RTL language is picked; drop Zain-*.ttf into /fonts for offline play. */
@font-face { font-family: 'Zain'; font-weight: 300; src: local('Zain Light'), url('../fonts/Zain-Light.ttf') format('truetype'); font-display: swap; }
@font-face { font-family: 'Zain'; font-weight: 400; src: local('Zain'), local('Zain Regular'), url('../fonts/Zain-Regular.ttf') format('truetype'); font-display: swap; }
@font-face { font-family: 'Zain'; font-weight: 700; src: local('Zain Bold'), url('../fonts/Zain-Bold.ttf') format('truetype'); font-display: swap; }
@font-face { font-family: 'Zain'; font-weight: 800; src: local('Zain ExtraBold'), url('../fonts/Zain-ExtraBold.ttf') format('truetype'); font-display: swap; }
@font-face { font-family: 'Zain'; font-weight: 900; src: local('Zain Black'), url('../fonts/Zain-Black.ttf') format('truetype'); font-display: swap; }

/* one typeface for every language */
html, body, button, select, input, textarea {
  font-family: "Zain", "Segoe UI", Tahoma, "Noto Naskh Arabic", Arial, sans-serif;
}
/* Arabic letters join: no letter-spacing, no forced capitals, a touch larger because Zain runs small */
html[dir="rtl"] * { letter-spacing: 0 !important; text-transform: none !important; }
body { font-size: 1.08em; }
html[dir="rtl"] .logo, html[dir="rtl"] .logo * { font-family: "Segoe UI", system-ui, sans-serif; letter-spacing: 6px !important; text-transform: uppercase !important; } /* brand name stays Latin */
html[dir="rtl"] .mission, html[dir="rtl"] .mbtn { text-align: start; }
html[dir="rtl"] .help ul { padding-left: 0; padding-right: 18px; }
html[dir="rtl"] .mbtn .arr { transform: scaleX(-1); }
html[dir="rtl"] #objective, html[dir="rtl"] .toast { direction: rtl; }
/* keep the playfield HUD where it is; only text direction flips */
html[dir="rtl"] #hud, html[dir="rtl"] #sideBtns, html[dir="rtl"] #squadbar { direction: ltr; }
html[dir="rtl"] #panel, html[dir="rtl"] #modeHint, html[dir="rtl"] #objective, html[dir="rtl"] #toasts { direction: rtl; }

/* ---------- thin custom scrollbars (every window, panel and list) ---------- */
* { scrollbar-gutter: auto; }
*::-webkit-scrollbar { width: 6px; height: 6px; }
*::-webkit-scrollbar-track { background: transparent; margin: 6px 0; }
*::-webkit-scrollbar-thumb {
  background: rgba(243, 156, 50, .45); border-radius: 6px; border: 0; background-clip: padding-box;
  transition: background .15s;
}
*::-webkit-scrollbar-thumb:hover { background: var(--accent); }
*::-webkit-scrollbar-thumb:active { background: var(--accent2); }
*::-webkit-scrollbar-corner { background: transparent; }
*::-webkit-scrollbar-button { display: none; width: 0; height: 0; }
@supports not selector(::-webkit-scrollbar) {
  * { scrollbar-width: thin; scrollbar-color: rgba(243, 156, 50, .55) transparent; }
}
/* give boxes a little breathing room so the thin bar doesn't hug the text */
.box, #panel, .armGrid { scrollbar-gutter: stable; }
html[dir="rtl"] .box, html[dir="rtl"] #panel, html[dir="rtl"] .armGrid { direction: rtl; }

/* language selector in Settings */
.langSel { min-width: 170px; padding: 8px 12px; cursor: pointer; font-weight: 600; flex: none;
  background: #12171d; border: 1px solid var(--line); border-radius: 8px; }
.langSel:hover, .langSel:focus { border-color: var(--accent); outline: none; }
.langSel option { background: #1b222b; color: var(--text); }

.armCard:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.armCard:active { transform: translateY(0); }
.armDetail { overflow-y: auto; max-height: calc(100vh - 220px); padding: 4px 6px 4px 2px; display: flex; flex-direction: column; gap: 14px; }
.dhead { display: flex; gap: 18px; align-items: center; }
.dpic { width: 220px; height: 220px; flex: none; border-radius: 14px; border: 1px solid rgba(255,220,160,.25); background: radial-gradient(circle at 50% 75%, #5a4630, #1d1610); display: flex; align-items: center; justify-content: center; }
.dpic img { width: 220px; height: 220px; }
.dmain { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.dname { font-size: 30px; font-weight: 900; letter-spacing: 1px; }
.dtags { display: flex; gap: 6px; flex-wrap: wrap; }
.dtags span { font-size: 12px; background: #232b35; border-radius: 5px; padding: 3px 9px; color: #d7dde4; text-transform: uppercase; letter-spacing: 1px; }
.dtags span.t1 { background: rgba(63,169,245,.18); color: #8fd3ff; }
.ddesc { margin: 0; color: #b8c0ca; line-height: 1.5; font-size: 14px; }
.dgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; }
.dgrid.small { grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); }
.dstat { background: rgba(10,12,18,.5); border: 1px solid rgba(255,255,255,.07); border-radius: 8px; padding: 8px 10px; display: flex; flex-direction: column; }
.dstat small { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 1px; }
.dstat b { font-size: 17px; color: #ffe1a8; }
.dcols { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.dcol { background: rgba(10,12,18,.4); border: 1px solid rgba(255,255,255,.07); border-radius: 10px; padding: 12px 14px; }
.dcol h4 { margin: 0 0 8px; color: var(--accent2); font-size: 13px; text-transform: uppercase; letter-spacing: 1px; }
.dcol h4 small { text-transform: none; letter-spacing: 0; color: var(--muted); font-weight: 400; }
.dcol h4.mt { margin-top: 14px; }
.dbar { display: grid; grid-template-columns: 112px 1fr 54px; gap: 8px; align-items: center; margin: 5px 0; font-size: 12.5px; }
.dbar .dl { color: #c9d0d8; }
.dbar .dt { height: 8px; background: #11161c; border-radius: 4px; overflow: hidden; }
.dbar .dt i { display: block; height: 100%; border-radius: 4px; background: #8a96a3; }
.dbar .dt i.g { background: linear-gradient(90deg, #3f9f4a, #63d463); }
.dbar .dt i.b { background: linear-gradient(90deg, #2f7fc0, #5cb6f5); }
.dbar .dt i.o { background: linear-gradient(90deg, #c98419, #f2b545); }
.dbar .dt i.r { background: linear-gradient(90deg, #b8362a, #ff6a55); }
.dbar .dv { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.dchips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip2 { display: inline-flex; align-items: center; gap: 6px; background: #1e2630; border: 1px solid rgba(255,255,255,.1); border-radius: 8px; padding: 3px 10px 3px 4px; font-size: 12.5px; cursor: pointer; transition: border-color .15s; }
.chip2:hover { border-color: var(--accent); }
.chip2 img { width: 32px; height: 32px; border-radius: 6px; background: #2a2218; }
.dnav { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 13px; }
@media (max-width: 760px) { .dhead { flex-direction: column; align-items: flex-start; } .dpic, .dpic img { width: 160px; height: 160px; } .dcols { grid-template-columns: 1fr; } }

/* ---------- interactive tutorial ---------- */
.mbtn.learn { border-color: rgba(140,255,106,.55); background: linear-gradient(rgba(60,110,50,.55), rgba(24,48,24,.65)); }
.mbtn.learn .mi { background: rgba(140,255,106,.2); color: #b9ff9c; }
#tutCard { position: absolute; left: 50%; top: 56px; transform: translateX(-50%); width: min(520px, 92vw); z-index: 30;
  background: rgba(14,18,24,.94); border: 1px solid rgba(140,255,106,.5); border-top: 3px solid #8cff6a; border-radius: 10px; padding: 10px 14px 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,.5); pointer-events: auto; }
#tutCard.ok { border-color: #8cff6a; box-shadow: 0 0 22px rgba(140,255,106,.55); }
#tutCard .tHead { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
#tutCard .tStep { font-size: 11px; font-weight: 800; letter-spacing: .5px; color: #8cff6a; white-space: nowrap; }
#tutCard .tBar { flex: 1; height: 5px; background: rgba(255,255,255,.1); border-radius: 3px; overflow: hidden; }
#tutCard .tBar i { display: block; height: 100%; width: 0; background: #8cff6a; transition: width .4s; }
#tutCard h3 { margin: 0 0 4px; font-size: 17px; color: #ffe2a8; }
#tutCard p { margin: 0 0 5px; font-size: 13.5px; line-height: 1.45; color: #e8edf2; }
#tutCard p.tHint { font-size: 12px; color: #9fb0bf; }
#tutCard.ok p.tHint { color: #8cff6a; font-weight: 700; }
#tutCard .tBtns { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; }
#tutArrow { position: absolute; transform: translate(-50%, 0); font-size: 30px; color: #8cff6a; text-shadow: 0 0 10px #000, 0 0 14px rgba(140,255,106,.9);
  pointer-events: none; z-index: 29; animation: tutBob .8s ease-in-out infinite alternate; }
@keyframes tutBob { from { margin-top: -6px; } to { margin-top: 8px; } }
@media (max-width: 760px) { #tutCard { top: 96px; padding: 8px 10px; } #tutCard p { font-size: 12.5px; } #tutCard h3 { font-size: 15px; } }
.help .row.end { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; margin-top: 12px; }

.qslot.empty.incoming { border: 1px dashed #6fb6ee; background: rgba(63,169,245,.12); animation: incPulse 1s ease-in-out infinite alternate; }
@keyframes incPulse { from { opacity: .5; } to { opacity: 1; } }
.cargoGrid .qslot.cargo { cursor: pointer; }
/* a chosen vehicle in the cargo grid: blue ring + tick that stays visible */
.cargoGrid .qslot.cargo.picked { border-color: #6ad7ff; box-shadow: 0 0 0 2px #6ad7ff, 0 0 10px rgba(106, 215, 255, .45); background: rgba(63, 169, 245, .2); }
.cargoGrid .qslot.cargo.picked .qx { opacity: 1; background: rgba(10, 40, 70, .35); color: #bff0ff; font-size: 18px; align-items: flex-start; justify-content: flex-end; padding: 2px 5px; }

/* performance: blurring a canvas that redraws every frame is very expensive, so the menu glass is solid-ish instead */
.iconBtn, .mbtn, .settingsBox, .armoryBox, .box { -webkit-backdrop-filter: none !important; backdrop-filter: none !important; }
.iconBtn { background: rgba(18, 20, 28, .8); }

/* settings: two balanced columns instead of rows, so short cards (Language) don't stretch to match tall ones */
.setGrid { display: block; column-count: 2; column-gap: 12px; }
.setGrid .setGroup { display: block; break-inside: avoid; -webkit-column-break-inside: avoid; margin: 0 0 10px; }
@media (max-width: 760px) { .setGrid { column-count: 1; } }

/* settings: header stays fixed, only the settings list scrolls; Done button hidden (close X in header) */
#settings .settingsBox { display: flex; flex-direction: column; overflow: hidden; height: auto; max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); padding-bottom: 14px; }
#settings .settingsBox > .boxHead { flex: none; position: relative; z-index: 1; margin: 0 -22px; padding: 0 22px 12px; border-bottom: 1px solid rgba(255,220,160,.14); }
#settings .setScroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-gutter: stable; margin: 0 -14px 0 0; padding: 4px 10px 0 0; }
html[dir="rtl"] #settings .setScroll { margin: 0 0 0 -14px; padding: 4px 0 0 10px; }

/* RTL languages: sliders keep their normal left-to-right direction so the thumb sits where the orange fill ends */
html[dir="rtl"] input[type="range"] { direction: ltr; }

/* skirmish: horizontal modal - live map preview on the left, options in two columns on the right */
.skirmishBox { width: min(980px, 100%); background: linear-gradient(rgba(30, 36, 46, .93), rgba(18, 22, 30, .95)); border-color: rgba(255,220,160,.2); }
.skBody { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.skPreview { display: flex; flex-direction: column; gap: 8px; }
.skMapWrap { position: relative; border-radius: 10px; border: 1px solid var(--line); background: radial-gradient(ellipse at center, #1c2430 0%, #0d1117 75%); padding: 8px; }
#skMap { display: block; width: 100%; height: auto; aspect-ratio: 11 / 6; }
.skMapInfo { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.skMapInfo b { color: var(--accent2); font-size: 15px; letter-spacing: .5px; }
.skMapInfo small { color: var(--muted); font-size: 12px; }
.skLegend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; color: var(--muted); }
.skLegend span { display: inline-flex; align-items: center; gap: 5px; }
.skLegend i { width: 9px; height: 9px; border-radius: 2px; display: inline-block; }
.skLegend i.oil { background: #111; box-shadow: 0 0 0 1.5px #f3c04a; border-radius: 50%; }
.skOpts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 12px; }
.skOpts select, .skOpts input { width: 100%; min-width: 0; }
.skOpts .row { display: flex; gap: 6px; }
@media (max-width: 760px) { .skBody { grid-template-columns: 1fr; } }
@media (max-width: 420px) { .skOpts { grid-template-columns: 1fr; } }
