:root {
  --bg: rgba(12, 20, 32, 0.88);
  --bg-solid: #0d1622;
  --line: rgba(255, 255, 255, 0.09);
  --text: #eef2f7;
  --muted: #8c9bb0;
  --accent: #f5a524;
  --accent-2: #ffcf6b;
  --red: #eb4034;
  --green: #4cd07d;
  --radius: 14px;
  --font: 'Rubik', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --display: 'Black Ops One', 'Rubik', sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #1c4a72; color: var(--text); font-family: var(--font); -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
input { font: inherit; }
.hidden { display: none !important; }
svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

#game { position: fixed; inset: 0; display: block; touch-action: none; cursor: crosshair; }

/* ---------- screens ---------- */
.screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 20; padding: 16px; background: radial-gradient(ellipse at center, rgba(8, 14, 24, 0.35), rgba(8, 14, 24, 0.75)); backdrop-filter: blur(3px); overflow: auto; }
#modal, #help { z-index: 40; }
#loading { z-index: 60; flex-direction: column; gap: 16px; background: #0d1622; font-weight: 500; color: var(--muted); }
.spinner { width: 44px; height: 44px; border-radius: 50%; border: 4px solid rgba(255,255,255,0.1); border-top-color: var(--accent); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.menu-card { width: min(460px, 100%); background: var(--bg); border: 1px solid var(--line); border-radius: 22px; padding: 28px 26px 22px; box-shadow: 0 30px 80px rgba(0,0,0,0.45); margin: auto; }
.logo { font-family: var(--display); font-weight: 400; font-size: 52px; line-height: 0.92; margin: 0; letter-spacing: 1px; color: #fff; text-shadow: 0 4px 0 #0a1420, 0 0 30px rgba(245,165,36,0.25); }
.logo span { display: block; color: var(--accent); font-size: 40px; letter-spacing: 3px; }
.tagline { color: var(--muted); margin: 10px 0 20px; font-size: 14px; }
.field { display: block; margin-bottom: 18px; }
.field span, .opt-label { display: block; font-size: 11px; font-weight: 700; letter-spacing: 1.4px; text-transform: uppercase; color: var(--muted); margin-bottom: 7px; }
.field input, .join-row input { width: 100%; padding: 12px 14px; border-radius: 12px; background: rgba(255,255,255,0.06); border: 1px solid var(--line); color: var(--text); outline: none; font-weight: 500; }
.field input:focus, .join-row input:focus { border-color: var(--accent); }

.tabs { display: grid; grid-template-columns: 1fr 1fr; background: rgba(255,255,255,0.05); border-radius: 12px; padding: 4px; margin-bottom: 18px; }
.tab { padding: 10px; border-radius: 9px; font-weight: 700; color: var(--muted); }
.tab.active { background: var(--accent); color: #1b1203; }
.opt-group { margin-bottom: 14px; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button { flex: 1; padding: 9px 6px; border-radius: 10px; background: rgba(255,255,255,0.06); border: 1px solid transparent; font-weight: 600; font-size: 14px; min-width: 54px; }
.seg button.on { border-color: var(--accent); color: var(--accent-2); background: rgba(245,165,36,0.12); }
.seg.locked button { pointer-events: none; opacity: 0.75; }
.big-btn { width: 100%; margin-top: 8px; padding: 15px; border-radius: 14px; background: linear-gradient(180deg, #ffb83d, #e8900f); color: #221400; font-weight: 800; font-size: 18px; letter-spacing: 0.5px; box-shadow: 0 5px 0 #9c5d05, 0 10px 24px rgba(245,165,36,0.25); transition: transform 0.08s; }
.big-btn small { display: block; font-size: 12px; font-weight: 500; opacity: 0.75; }
.big-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 #9c5d05; }
.big-btn:disabled { filter: grayscale(1) brightness(0.6); cursor: default; }
.mid-btn { width: 100%; padding: 12px; border-radius: 12px; background: rgba(255,255,255,0.08); font-weight: 700; border: 1px solid var(--line); }
.mid-btn:hover { background: rgba(255,255,255,0.13); }
.row { margin-top: 12px; }
.join-row { display: flex; gap: 8px; }
.join-row input { text-transform: uppercase; letter-spacing: 3px; font-weight: 700; }
.join-row .mid-btn { width: auto; padding: 12px 22px; }
.foot { color: var(--muted); font-size: 12px; text-align: center; margin: 18px 0 0; }
.link-btn { display: block; margin: 12px auto 0; color: var(--muted); font-size: 14px; text-decoration: underline; }

.lobby-title { margin: 0; font-family: var(--display); font-weight: 400; font-size: 30px; }
.lobby-title span { color: var(--accent); letter-spacing: 3px; }
#lobbyPlayers { list-style: none; padding: 0; margin: 16px 0; display: flex; flex-direction: column; gap: 6px; max-height: 210px; overflow: auto; }
#lobbyPlayers li { padding: 10px 12px; border-radius: 10px; background: rgba(255,255,255,0.05); display: flex; justify-content: space-between; font-weight: 600; }
#lobbyPlayers li em { color: var(--accent); font-style: normal; font-size: 12px; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#hud > * { pointer-events: auto; }
#topLeft { position: absolute; left: 12px; top: 12px; display: flex; flex-direction: column; gap: 10px; pointer-events: none; }
.btn-row { display: flex; gap: 8px; pointer-events: auto; }
.round-btn { width: 44px; height: 44px; border-radius: 50%; background: var(--bg-solid); display: grid; place-items: center; box-shadow: 0 4px 14px rgba(0,0,0,0.35); border: 1px solid var(--line); }
.round-btn svg { width: 22px; height: 22px; }
.round-btn span { font-weight: 800; font-size: 14px; }
.round-btn:hover { background: #18263a; }
#feed { display: flex; flex-direction: column; gap: 6px; max-width: 340px; pointer-events: none; }
.feed-item { background: var(--bg); padding: 7px 12px; border-radius: 10px; font-size: 13px; font-weight: 500; border-left: 3px solid #4aa3ff; animation: slideIn 0.25s ease-out; transition: opacity 0.6s; }
.feed-item.bad { border-left-color: var(--red); }
.feed-item.good { border-left-color: var(--green); }
.feed-item.nuke { border-left-color: #ff4fd8; }
@keyframes slideIn { from { transform: translateX(-20px); opacity: 0; } }

#topCenter { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); width: min(360px, 40vw); background: var(--bg); border-radius: var(--radius); padding: 9px 14px 10px; border: 1px solid var(--line); }
.ctrl-head { display: flex; justify-content: space-between; font-size: 11px; font-weight: 800; letter-spacing: 1.2px; color: var(--muted); }
#goalTxt { color: var(--accent); }
.ctrl-bar { position: relative; height: 8px; border-radius: 4px; background: rgba(255,255,255,0.1); margin: 7px 0 6px; overflow: hidden; }
#ctrlMe { position: absolute; left: 0; top: 0; bottom: 0; background: var(--red); border-radius: 4px; z-index: 2; transition: width 0.3s; }
#ctrlLeader { position: absolute; left: 0; top: 0; bottom: 0; background: rgba(255,207,107,0.45); border-radius: 4px; transition: width 0.3s; }
.goal-mark { position: absolute; left: 80%; top: -2px; bottom: -2px; width: 2px; background: var(--accent); z-index: 3; }
.ctrl-sub { font-size: 12px; color: var(--text); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

#topRight { position: absolute; right: 12px; top: 12px; display: flex; gap: 8px; }
.pill { background: var(--bg-solid); border-radius: 999px; padding: 9px 14px; font-weight: 700; font-size: 14px; display: flex; align-items: center; gap: 7px; border: 1px solid var(--line); box-shadow: 0 4px 14px rgba(0,0,0,0.3); }
.pill svg { width: 16px; height: 16px; color: var(--green); }
.timer { color: var(--green); }

.panel { position: absolute; right: 12px; top: 66px; background: var(--bg); border-radius: var(--radius); border: 1px solid var(--line); padding: 10px 6px 6px; width: min(380px, 92vw); max-height: 60vh; overflow: auto; }
.panel-head { font-weight: 800; letter-spacing: 1.2px; font-size: 12px; text-transform: uppercase; color: var(--muted); padding: 0 8px 6px; }
.panel table { width: 100%; border-collapse: collapse; font-size: 13px; }
.panel th { text-align: left; font-size: 11px; color: var(--muted); font-weight: 600; padding: 4px 8px; }
.panel td { padding: 5px 8px; border-top: 1px solid var(--line); white-space: nowrap; }
.panel td:nth-child(2) { max-width: 130px; overflow: hidden; text-overflow: ellipsis; }
.panel tr.me td { color: var(--accent-2); font-weight: 700; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

#centerMsg { position: absolute; left: 50%; top: 22%; transform: translateX(-50%); text-align: center; pointer-events: none; transition: opacity 0.6s; }
#centerMsg .big { font-family: var(--display); font-size: clamp(30px, 6vw, 62px); color: #ffd27a; letter-spacing: 3px; text-shadow: 0 4px 0 rgba(0,0,0,0.45), 0 0 40px rgba(0,0,0,0.4); }
#centerMsg .small { font-size: clamp(14px, 2vw, 18px); color: #fff; font-weight: 500; margin-top: 6px; text-shadow: 0 2px 6px rgba(0,0,0,0.8); }

#tooltip, #nukeInfo { position: absolute; pointer-events: none; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 9px 12px; font-size: 13px; min-width: 150px; box-shadow: 0 10px 30px rgba(0,0,0,0.4); }
#tooltip b { font-size: 14px; }
#tooltip .row2, #nukeInfo .row2 { display: flex; justify-content: space-between; gap: 14px; color: var(--muted); margin-top: 3px; }
#tooltip .row2 span:last-child, #nukeInfo .row2 span:last-child { color: var(--text); font-weight: 600; }
#nukeInfo { min-width: 220px; border-color: rgba(255,80,60,0.5); }
#nukeInfo .title { font-weight: 800; color: #ff8a70; margin-bottom: 4px; }
#nukeInfo .hint { color: var(--green); margin-top: 6px; font-size: 12px; }
#nukeInfo .warn { color: #ff6b5a !important; }

#toast { position: absolute; left: 50%; bottom: 200px; transform: translateX(-50%); background: rgba(150, 30, 30, 0.92); padding: 8px 16px; border-radius: 10px; font-weight: 600; font-size: 14px; opacity: 0; transition: opacity 0.3s; pointer-events: none; }
#toast.show { opacity: 1; }

#dock { position: absolute; left: 50%; bottom: max(10px, env(safe-area-inset-bottom)); transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 8px; width: max-content; max-width: calc(100vw - 16px); }
#buildBar { display: flex; gap: 4px; background: var(--bg); border-radius: var(--radius); padding: 6px; border: 1px solid var(--line); overflow-x: auto; max-width: 100%; }
.bitem { position: relative; width: 62px; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 5px 2px 4px; border-radius: 10px; border: 1px solid transparent; }
.bitem img { width: 34px; height: 34px; }
.bitem .cost { font-size: 11px; font-weight: 700; color: var(--accent-2); }
.bitem .key { position: absolute; top: 2px; left: 5px; font-size: 10px; color: var(--muted); font-weight: 700; }
.bitem .cnt { position: absolute; top: 2px; right: 5px; font-size: 10px; color: var(--text); font-weight: 700; }
.bitem:hover { background: rgba(255,255,255,0.07); }
.bitem.sel { border-color: var(--accent); background: rgba(245,165,36,0.14); }
.bitem.poor { opacity: 0.45; }
.bitem.poor .cost { color: #ff7b6b; }
#statBar { display: flex; align-items: center; gap: 14px; background: var(--bg-solid); border-radius: 18px; padding: 8px 10px 8px 14px; border: 1px solid var(--line); box-shadow: 0 8px 24px rgba(0,0,0,0.4); max-width: 100%; }
.stat { display: flex; align-items: center; gap: 8px; min-width: 120px; }
.stat .ic { width: 22px; height: 22px; color: #c7d3e3; flex-shrink: 0; }
.stat .ic.gold { color: var(--accent); }
.stat b { font-size: 18px; font-weight: 800; }
.rate { font-size: 12px; color: var(--green); font-weight: 700; }
.meter { height: 4px; width: 100px; background: rgba(255,255,255,0.1); border-radius: 2px; margin-top: 3px; overflow: hidden; }
#troopMeter { height: 100%; background: linear-gradient(90deg, #4aa3ff, #8fd0ff); width: 0; }
.ratios { display: flex; gap: 4px; background: rgba(255,255,255,0.04); padding: 4px; border-radius: 12px; }
.ratios button { padding: 7px 9px; border-radius: 9px; font-weight: 700; font-size: 13px; color: #b9c5d6; }
.ratios button.on { background: var(--accent); color: #1b1203; }
.sends { display: flex; flex-direction: column; align-items: center; font-size: 11px; color: var(--muted); min-width: 52px; }
.sends b { color: var(--text); font-size: 15px; }

.help-card { width: min(560px, 100%); }
.help-card h2 { font-family: var(--display); font-weight: 400; margin: 0 0 10px; color: var(--accent); }
.help-card ul { padding-left: 18px; line-height: 1.5; font-size: 14px; }
.help-card li { margin-bottom: 5px; }
.keys { font-size: 13px; color: var(--muted); }
kbd { background: rgba(255,255,255,0.1); border-radius: 5px; padding: 1px 6px; font-family: inherit; font-weight: 700; color: var(--text); }

.result-title { font-family: var(--display); font-size: 44px; margin: 0; text-align: center; }
.result-title.win { color: var(--accent); }
.result-title.lose { color: var(--red); }
.result-sub { text-align: center; color: var(--muted); margin: 6px 0 16px; }
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.stats-grid div { background: rgba(255,255,255,0.05); border-radius: 10px; padding: 10px; text-align: center; }
.stats-grid b { display: block; font-size: 20px; }
.stats-grid span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }

@media (max-width: 760px) {
  .logo { font-size: 40px; } .logo span { font-size: 30px; }
  #topCenter { top: 58px; left: 8px; transform: none; width: min(250px, 62vw); padding: 5px 10px 6px; }
  .ctrl-head { font-size: 10px; }
  .ctrl-sub { font-size: 11px; }
  .round-btn { width: 38px; height: 38px; }
  .round-btn svg { width: 19px; height: 19px; }
  #topLeft { top: 10px; left: 8px; }
  #topRight { top: 10px; right: 8px; flex-direction: column; align-items: flex-end; gap: 6px; }
  .pill { padding: 6px 10px; font-size: 12px; }
  #feed { max-width: 70vw; margin-top: 66px; }
  #centerMsg { top: 28%; }
  .feed-item { font-size: 11px; padding: 5px 9px; }
  #statBar { flex-wrap: wrap; justify-content: center; gap: 8px; padding: 7px 8px; }
  .stat { min-width: 0; }
  .stat b { font-size: 15px; }
  .meter { width: 70px; }
  .ratios button { padding: 6px 7px; font-size: 12px; }
  .bitem { width: 50px; }
  .bitem img { width: 28px; height: 28px; }
  .bitem .cost { font-size: 10px; }
  .panel { top: 110px; }
  #toast { bottom: 250px; }
}

#attacks { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.atk { display: flex; align-items: center; gap: 8px; background: var(--bg); border: 1px solid rgba(235,64,52,0.5); border-radius: 10px; padding: 4px 6px 4px 10px; font-size: 12px; font-weight: 600; }
.atk b { color: #ff8a70; }
.atk.def { border-color: rgba(74,163,255,0.6); }
.atk.def b { color: #8fd0ff; }
.atk button { width: 20px; height: 20px; border-radius: 6px; background: rgba(255,255,255,0.08); font-size: 12px; line-height: 1; }

#reinforceBtn { position: relative; overflow: hidden; display: flex; align-items: center; gap: 6px; padding: 6px 10px 6px 8px; border-radius: 12px; background: rgba(74,163,255,0.12); border: 1px solid rgba(74,163,255,0.35); color: #b9dcff; --cd: 0%; }
#reinforceBtn::after { content: ''; position: absolute; left: 0; bottom: 0; height: 3px; width: var(--cd); background: #4aa3ff; transition: width 0.1s linear; }
#reinforceBtn svg { width: 18px; height: 18px; stroke-width: 3; }
#reinforceBtn .rf-col { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.1; }
#reinforceBtn .rf-main { font-size: 12px; font-weight: 800; }
#reinforceBtn .rf-sub { font-size: 11px; font-weight: 700; color: var(--accent-2); }
#reinforceBtn:not(.ready) { opacity: 0.55; }
#reinforceBtn.ready { background: rgba(74,163,255,0.22); box-shadow: 0 0 0 1px rgba(74,163,255,0.5), 0 0 14px rgba(74,163,255,0.25); }
#reinforceBtn.poor .rf-sub { color: #ff7b6b; }
@media (max-width: 760px) { #reinforceBtn { padding: 5px 8px; } #reinforceBtn .rf-main { font-size: 11px; } }
