:root {
    --bg: #0f1410;
    --panel: rgba(20, 26, 20, 0.94);
    --line: rgba(170, 200, 150, 0.22);
    --ink: #e8efe2;
    --muted: #a7b49b;
    --gold: #d6b04c;
    --gold-dark: #8f7426;
    --blue: #5d93f0;
    --red: #e0605a;
    --font: 'Barlow', system-ui, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
html { touch-action: manipulation; }
body { background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 17px; overflow: hidden;
    -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
input, select, button { font: inherit; }
input { -webkit-user-select: text; user-select: text; }
.screen { position: fixed; inset: 0; overflow-y: auto; }

.btn { color: var(--ink); background: rgba(255, 240, 210, 0.08); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; font-weight: 700; cursor: pointer; }
.btn:hover { background: rgba(255, 240, 210, 0.14); }
.btn.gold { background: linear-gradient(180deg, #e8b85a, var(--gold-dark)); color: #20160a; border-color: #f0cf87; }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 10px; font-size: 15px; }
.btn.wide { width: 100%; margin: 16px 0 6px; padding: 14px; font-size: 19px; }
.btn.big { padding: 16px 14px; font-size: 20px; text-align: left; }
.btn.big small { display: block; font-size: 14px; font-weight: 500; opacity: .8; margin-top: 2px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.nowrap { flex-wrap: nowrap; }
.row.nowrap input { flex: 1; min-width: 0; }
.row.center { justify-content: center; }
.row label { color: var(--muted); font-size: 15px; display: flex; flex-direction: column; gap: 3px; }
.hint { color: var(--muted); font-size: 15px; }
.msg { color: var(--red); min-height: 1.2em; }
input, select { color: var(--ink); background: rgba(0, 0, 0, 0.35); border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; }
.field { display: block; font-weight: 700; font-size: 15px; color: var(--muted); }
.field input { display: block; width: 100%; margin-top: 4px; }

/* Menu */
.menu-bg { position: fixed; inset: 0; background: url('art/title.webp?v=1') center / cover no-repeat; filter: brightness(.65) saturate(1.1); }
.menu-bg::after { content: ''; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(20, 14, 8, .15), rgba(20, 14, 8, .88) 72%); }
.menu-box { position: relative; max-width: 560px; margin: 0 auto; padding: max(30px, env(safe-area-inset-top)) 16px 24px; }
.logo { font-family: 'Oswald', sans-serif; font-weight: 700; font-size: 72px; letter-spacing: 4px; margin: 10px 0 0; color: #e8efe2; text-shadow: 0 4px 22px rgba(0, 0, 0, .8); }
.tag { margin: 4px 0 18px; font-weight: 700; color: #ecdcb8; }
.menu-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }

.army-pick { display: flex; align-items: center; gap: 10px; width: 100%; margin-top: 12px; padding: 8px 12px; text-align: left; color: var(--ink);
    background: var(--panel); border: 1px solid var(--line); border-radius: 12px; cursor: pointer; overflow: hidden; }
.army-pick .faces { display: flex; }
.army-pick .faces img { width: 30px; height: 40px; object-fit: cover; border-radius: 5px; margin-right: -9px; border: 1px solid rgba(0, 0, 0, .6); }
.army-pick b { display: block; }
.army-pick small { color: var(--muted); }
.army-pick .chg { margin-left: auto; color: var(--gold); font-weight: 800; white-space: nowrap; }

.bar { position: sticky; top: 0; z-index: 2; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px;
    padding: max(10px, env(safe-area-inset-top)) 16px 10px; background: rgba(20, 15, 10, .96); border-bottom: 1px solid var(--line); }
.bar h2 { margin: 0; text-align: center; font-family: 'Oswald', sans-serif; font-size: 22px; }
.panel { max-width: 760px; margin: 16px auto; padding: 16px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; }
.panel h3 { margin: 16px 0 8px; font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: 1.5px; }
.panel h3:first-child { margin-top: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { padding: 7px 13px; border-radius: 999px; border: 1px solid var(--line); background: transparent; color: var(--ink); font-weight: 700; cursor: pointer; }
.chip:hover { border-color: var(--gold); }

/* Army builder */
.army-top { position: sticky; top: 61px; z-index: 1; padding: 12px 16px; background: rgba(27, 22, 16, .97); border-bottom: 1px solid var(--line); }
.budget { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.budget-bar { flex: 1; height: 10px; border-radius: 999px; background: rgba(0, 0, 0, .4); overflow: hidden; }
.budget-bar i { display: block; height: 100%; background: linear-gradient(90deg, #7fb069, var(--gold)); }
#budget-text { font-weight: 800; white-space: nowrap; }
.chosen { display: flex; gap: 6px; overflow-x: auto; padding: 10px 0 2px; min-height: 76px; }
.chosen button { position: relative; flex: none; width: 52px; height: 68px; padding: 0; border-radius: 8px; overflow: hidden; border: 2px solid var(--line); cursor: pointer; background: #000; }
.chosen img { width: 100%; height: 100%; object-fit: cover; }
.chosen button.gen { border-color: var(--gold); cursor: default; }
.chosen button::after { content: '✕'; position: absolute; top: 1px; right: 3px; font-size: 12px; color: #fff; text-shadow: 0 0 3px #000; }
.chosen button.gen::after { content: '👑'; }
.unit-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; padding: 16px; max-width: 1100px; margin: 0 auto; }
.ucard { position: relative; border-radius: 12px; overflow: hidden; border: 2px solid var(--line); background: #000; cursor: pointer; text-align: left; color: var(--ink); padding: 0; }
.ucard img { width: 100%; aspect-ratio: 3 / 4; object-fit: cover; display: block; }
.ucard .info { position: absolute; left: 0; right: 0; bottom: 0; padding: 30px 8px 8px; background: linear-gradient(180deg, transparent, rgba(10, 7, 4, .95) 40%); }
.ucard b { display: block; font-size: 17px; }
.ucard .role { color: var(--muted); font-size: 13px; }
.ucard .cost { position: absolute; top: 6px; right: 6px; background: rgba(0, 0, 0, .7); border: 1px solid var(--gold); color: var(--gold); border-radius: 999px; padding: 2px 8px; font-weight: 800; font-size: 14px; }
.ucard .men { position: absolute; top: 6px; left: 6px; background: rgba(0, 0, 0, .7); border-radius: 999px; padding: 2px 8px; font-weight: 700; font-size: 13px; }
.ucard .stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 2px; font-size: 12px; margin-top: 4px; text-align: center; }
.ucard .stats span { background: rgba(255, 255, 255, .08); border-radius: 4px; padding: 1px 0; }
.ucard .stats em { display: block; font-style: normal; color: var(--muted); font-size: 10px; }
.ucard .blurb { font-size: 12.5px; color: #e4d6bc; margin-top: 4px; line-height: 1.25; }
.ucard.cant { opacity: .45; }
.ucard:hover { border-color: var(--gold); }

/* Map picker */
.maps { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; }
.mapc { position: relative; border-radius: 10px; overflow: hidden; border: 2px solid var(--line); cursor: pointer; padding: 0; background: #000; color: #fff; text-align: left; }
.mapc img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; display: block; }
.mapc span { position: absolute; left: 0; right: 0; bottom: 0; padding: 14px 8px 6px; background: linear-gradient(180deg, transparent, rgba(0, 0, 0, .85)); font-weight: 800; }
.mapc[aria-pressed="true"] { border-color: var(--gold); box-shadow: 0 0 0 2px var(--gold); }

/* Lobby */
.room { font-weight: 800; color: var(--gold); text-align: right; }
.share-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; padding: 10px 12px; border-radius: 10px; background: rgba(217, 164, 65, .12); border: 1px solid rgba(217, 164, 65, .4); }
.share-row b { color: var(--gold); letter-spacing: 1px; }
.teams { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.team { border-radius: 12px; padding: 10px; border: 1px solid var(--line); }
.team.t0 { background: rgba(93, 147, 240, .12); }
.team.t1 { background: rgba(224, 96, 90, .12); }
.team h3 { margin: 0 0 6px; }
.team ul { list-style: none; padding: 0; margin: 0 0 8px; min-height: 40px; font-size: 15px; }
.team li { padding: 4px 0; border-bottom: 1px solid var(--line); }
.team li small { color: var(--muted); }

/* Battle */
#battle { overflow: hidden; background: #1d2617; }
#world { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.hud { position: absolute; inset: 0; pointer-events: none; }
.hud > *, .hud button { pointer-events: auto; }
.minimap { position: absolute; left: max(10px, env(safe-area-inset-left)); top: max(10px, env(safe-area-inset-top)); width: 150px; height: 100px;
    border-radius: 8px; border: 1px solid var(--line); box-shadow: 0 4px 14px rgba(0, 0, 0, .5); }
.top-mid { position: absolute; left: 50%; top: max(10px, env(safe-area-inset-top)); transform: translateX(-50%); pointer-events: none; }
.top-right { position: absolute; right: max(10px, env(safe-area-inset-right)); top: max(10px, env(safe-area-inset-top)); display: flex; gap: 6px; }
.top-right .btn { background: rgba(20, 15, 10, .7); }
.pill { display: inline-block; background: rgba(20, 15, 10, .75); border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px; font-weight: 800; font-size: 15px; white-space: nowrap; }
.deploy { position: absolute; left: 50%; top: calc(max(10px, env(safe-area-inset-top)) + 44px); transform: translateX(-50%); display: flex; align-items: center; gap: 12px;
    background: rgba(20, 15, 10, .88); border: 1px solid var(--gold); border-radius: 12px; padding: 8px 12px; max-width: calc(100vw - 32px); }
.deploy span { font-size: 14px; color: var(--muted); }
.banner { position: absolute; left: 50%; top: 24%; transform: translateX(-50%); pointer-events: none; font-family: 'Oswald', sans-serif; font-weight: 800;
    font-size: 34px; color: #f6dfa5; text-shadow: 0 3px 16px rgba(0, 0, 0, .8); white-space: nowrap; animation: banner 2.8s ease forwards; }
@keyframes banner { 0% { opacity: 0; transform: translate(-50%, 8px); } 12%, 75% { opacity: 1; transform: translate(-50%, 0); } 100% { opacity: 0; } }
.cmds { position: absolute; right: max(10px, env(safe-area-inset-right)); bottom: calc(max(10px, env(safe-area-inset-bottom)) + 96px); display: flex; flex-direction: column; gap: 6px; }
.cmd { width: 48px; height: 44px; border-radius: 10px; border: 1px solid var(--line); background: rgba(20, 15, 10, .78); color: var(--ink); font-weight: 800; font-size: 18px; cursor: pointer; }
.cmd[aria-pressed="true"] { background: var(--gold); color: #20160a; border-color: var(--gold); }
.cards { position: absolute; left: max(8px, env(safe-area-inset-left)); right: max(8px, env(safe-area-inset-right)); bottom: max(8px, env(safe-area-inset-bottom));
    display: flex; gap: 5px; overflow-x: auto; padding: 4px; justify-content: center; }
.card { position: relative; flex: none; width: 56px; height: 80px; border-radius: 8px; overflow: hidden; border: 2px solid rgba(0, 0, 0, .6); background: #000; padding: 0; cursor: pointer; }
.card img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card .men { position: absolute; left: 0; right: 0; bottom: 0; background: rgba(0, 0, 0, .72); font-size: 12px; font-weight: 800; color: #fff; text-align: center; padding: 1px 0; }
.card .mor { position: absolute; left: 0; right: 0; bottom: 18px; height: 4px; background: rgba(0, 0, 0, .6); }
.card .mor i { display: block; height: 100%; }
.card .st { position: absolute; top: 2px; right: 2px; font-size: 13px; text-shadow: 0 0 3px #000; }
.card .ammo { position: absolute; top: 2px; left: 3px; font-size: 11px; font-weight: 800; color: #fff; text-shadow: 0 0 3px #000; }
.card.sel { border-color: #ffe066; box-shadow: 0 0 0 2px #ffe066; }
.card.waver { animation: flash 0.8s steps(2) infinite; }
.card.rout, .card.gone { filter: grayscale(1) brightness(.6); }
@keyframes flash { 50% { border-color: #f2c14e; } }
.keys { position: absolute; left: 50%; bottom: 96px; transform: translateX(-50%); margin: 0; font-size: 12px; color: rgba(255, 255, 255, .55); pointer-events: none; white-space: nowrap; }
@media (pointer: coarse) { .keys { display: none; } }
@media (max-height: 460px) {
    .card { width: 46px; height: 64px; }
    .cmds { bottom: calc(max(8px, env(safe-area-inset-bottom)) + 76px); gap: 4px; display: grid; grid-template-columns: repeat(2, 42px); direction: rtl; }
    .cmd { width: 42px; height: 36px; font-size: 16px; }
    .minimap { width: 120px; height: 80px; }
}
.over { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(10, 7, 4, .6); padding: 16px; }
.over-box { width: min(560px, 100%); background: var(--panel); border: 1px solid var(--gold); border-radius: 16px; padding: 18px; text-align: center; }
.over-box h2 { font-family: 'Oswald', sans-serif; font-size: 40px; margin: 0; color: #f6dfa5; }
.score { width: 100%; border-collapse: collapse; margin: 10px 0 14px; font-size: 15px; }
.score th { color: var(--muted); text-align: right; padding: 4px; }
.score th:first-child, .score td:first-child { text-align: left; }
.score td { text-align: right; padding: 5px 4px; border-top: 1px solid var(--line); }
.score tr.t0 td:first-child { color: var(--blue); }
.score tr.t1 td:first-child { color: var(--red); }
.score tr.me td { font-weight: 800; }
.toast { position: fixed; left: 50%; bottom: 110px; transform: translateX(-50%); z-index: 20; background: #000d; padding: 10px 16px; border-radius: 999px; font-weight: 700; max-width: calc(100vw - 32px); }
@media (max-width: 640px) {
    .menu-grid { grid-template-columns: 1fr; }
    .logo { font-size: 46px; }
    .army-top { top: 57px; }
    .unit-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; padding: 10px; }
}

.logo span { color: #e3554d; }
.how { margin-top: 16px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; }
.how summary { cursor: pointer; font-weight: 700; }
.how ul { margin: 8px 0 0; padding-left: 18px; color: #d5ddcd; font-size: 15px; line-height: 1.4; }
.mapc .prev { width: 100%; aspect-ratio: 3 / 2; display: block; background: #222; }
.feed { position: absolute; right: max(10px, env(safe-area-inset-right)); top: calc(max(10px, env(safe-area-inset-top)) + 42px); display: flex; flex-direction: column; gap: 4px; align-items: flex-end; pointer-events: none; }
.feed div { background: rgba(10, 14, 10, .75); border: 1px solid var(--line); border-radius: 8px; padding: 4px 9px; font-size: 13px; font-weight: 700; }
.alert { position: absolute; left: 50%; top: calc(max(10px, env(safe-area-inset-top)) + 46px); transform: translateX(-50%); pointer-events: none;
    background: rgba(150, 20, 15, .85); border: 1px solid #ff8a80; color: #fff; font-weight: 800; padding: 8px 16px; border-radius: 10px; animation: banner 2.4s ease forwards; }
.modes { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(max(8px, env(safe-area-inset-bottom)) + 66px); display: flex; gap: 5px; align-items: center;
    background: rgba(10, 14, 10, .7); border: 1px solid var(--line); border-radius: 12px; padding: 5px; }
.mode { width: 52px; height: 48px; border-radius: 9px; border: 1px solid var(--line); background: rgba(255, 255, 255, .06); color: var(--ink); font-size: 19px; cursor: pointer; line-height: 1; }
.mode small { display: block; font-size: 10px; font-weight: 700; margin-top: 2px; }
.mode[aria-pressed="true"] { background: var(--gold); color: #1a1406; border-color: var(--gold); }
.modes .sep { width: 1px; align-self: stretch; background: var(--line); margin: 0 3px; }
.cards { justify-content: center; }
.card.snip { width: 92px; height: 56px; background: rgba(10, 14, 10, .82); color: var(--ink); text-align: left; padding: 4px 6px; font-size: 12px; font-weight: 700; border: 2px solid var(--line); }
.card.snip b { display: block; font-size: 13px; }
.card.snip .hp { color: #ff6b62; letter-spacing: 1px; }
.card.snip.t0 { border-left: 5px solid var(--blue); }
.card.snip.dead { opacity: .4; }
.scope { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: crosshair; z-index: 5; background: #000; }
.scope-ui { position: absolute; left: 50%; bottom: max(14px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 6; display: flex; gap: 10px; align-items: center;
    background: rgba(0, 0, 0, .6); padding: 6px 10px; border-radius: 12px; }
.scope-ui .hint { white-space: nowrap; }
@media (max-height: 460px) {
    .mode { width: 44px; height: 40px; font-size: 16px; }
    .mode small { font-size: 9px; }
    .modes { bottom: calc(max(6px, env(safe-area-inset-bottom)) + 58px); }
    .card.snip { width: 80px; height: 48px; }
}
@media (max-width: 600px) and (orientation: portrait) { .mode { width: 38px; } .mode small { display: none; } }
.keys { bottom: 136px; }
@media (max-height: 460px) { .keys { display: none; } }
.scope-ui .btn { white-space: nowrap; }
.card.snip { height: auto; min-height: 50px; line-height: 1.2; }
@media (max-height: 460px) {
    .scope-ui .hint { display: none; }
    .scope-ui { gap: 6px; padding: 4px 6px; }
    .card.snip { width: 96px; min-height: 0; font-size: 11px; padding: 3px 5px; }
    .card.snip b { font-size: 12px; }
}
