:root {
  --bg: #0d1217;
  --card: #151c23;
  --line: #26313b;
  --text: #dfe6ec;
  --muted: #8796a3;
  --blue: #4ea1ff;
  --red: #ff5d5d;
  --accent: #ffb020;
  --turret: #3fd0b0;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; overflow: hidden; }
canvas#view, canvas#overlay { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; }
canvas#overlay { pointer-events: none; }
[hidden] { display: none !important; }

.overlay { position: fixed; inset: 0; overflow: auto; padding: 24px 16px; background: rgba(9, 13, 17, 0.88); backdrop-filter: blur(3px); }
.lobby-grid { max-width: 1180px; margin: 0 auto; display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 18px; }
.intro { grid-row: span 2; }
h1 { margin: 0 0 6px; font-size: 30px; letter-spacing: 0.02em; }
h2 { margin: 0 0 12px; font-size: 17px; }
h3 { margin: 0 0 6px; font-size: 13px; color: var(--muted); font-weight: 600; }
.tagline { color: var(--muted); margin: 0 0 16px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.row-between { display: flex; justify-content: space-between; align-items: baseline; }
.pill { background: #1e2a35; border-radius: 99px; padding: 2px 10px; font-size: 12px; color: var(--muted); }

.field { display: block; margin-bottom: 14px; color: var(--muted); font-size: 12px; }
.field input { display: block; width: 100%; margin-top: 4px; background: #0f151b; border: 1px solid var(--line); color: var(--text); border-radius: 8px; padding: 9px 10px; font-size: 15px; }
.seg { display: flex; gap: 6px; margin-top: 4px; flex-wrap: wrap; }
button { background: #1d2731; color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; font: inherit; cursor: pointer; flex: 1; }
button:hover { border-color: #3a4855; }
button.active { border-color: var(--accent); background: #2a2416; }
button.blue.active { border-color: var(--blue); background: #15263a; }
button.red.active { border-color: var(--red); background: #3a1717; }
button.primary { background: var(--accent); color: #1a1205; border: none; font-weight: 700; font-size: 16px; padding: 12px; width: 100%; margin-top: 4px; }
.controls { margin-top: 14px; color: var(--muted); font-size: 12px; border-top: 1px solid var(--line); padding-top: 10px; }
.controls summary { cursor: pointer; color: var(--text); font-weight: 600; font-size: 13px; list-style: none; }
.controls summary::-webkit-details-marker { display: none; }
.controls summary::before { content: '▸ '; color: var(--accent); }
.controls[open] summary::before { content: '▾ '; }
.controls dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 10px 0 8px; }
.controls dt { color: var(--text); font-weight: 600; white-space: nowrap; }
.controls dd { margin: 0; }
.controls p { margin: 0; }

.hero { max-width: 1180px; margin: 8px auto 22px; text-align: center; }
.hero-logo { width: min(520px, 86vw); height: auto; display: block; margin: 0 auto; filter: drop-shadow(0 8px 30px rgba(78, 161, 255, 0.18)); }
.claim { margin: 10px 0 6px; font-size: clamp(20px, 3.2vw, 30px); font-weight: 700; letter-spacing: 0.01em; background: linear-gradient(90deg, var(--blue), #f4f7fa 50%, var(--red)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.pitch { margin: 0 auto 20px; max-width: 640px; color: var(--muted); font-size: 15px; }
.pitch b { color: var(--accent); }
.features { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; text-align: left; }
.features li { background: linear-gradient(180deg, #18212a, var(--card)); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; color: var(--muted); font-size: 13px; }
.features b { display: block; color: var(--text); font-size: 15px; margin-bottom: 4px; }
.features .ico { float: right; color: var(--accent); font-size: 18px; line-height: 1; opacity: 0.85; }
.admin-box { border: 1px dashed #5a4a20; border-radius: 8px; padding: 6px 10px; margin-bottom: 10px; }
.admin-box .ff-row { margin: 3px 0; }

.front-side { margin-bottom: 10px; }
.front-side .label { font-size: 12px; margin-bottom: 4px; display: flex; justify-content: space-between; }
.bars { display: grid; grid-template-columns: repeat(10, 1fr); gap: 3px; }
.bar { height: 26px; background: #0f151b; border-radius: 3px; position: relative; overflow: hidden; }
.bar > i { position: absolute; left: 0; bottom: 0; width: 100%; }
.bar.hq { outline: 1px solid #ffffff33; }
.bar.dead { background: repeating-linear-gradient(45deg, #1a1f24, #1a1f24 4px, #22282e 4px, #22282e 8px); }

#chart { width: 100%; height: 150px; display: block; }
.legend { color: var(--muted); margin: 6px 0 10px; display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; }
.sw { display: inline-block; width: 12px; height: 3px; border-radius: 2px; margin-right: 4px; vertical-align: middle; }
.sw.plane { background: var(--accent); }
.sw.turret { background: var(--turret); }
.sw.div { background: #b48cff; }
.pools { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; font-size: 12px; }
.pools > div { background: #0f151b; border-radius: 8px; padding: 8px 10px; }
.pools b { display: block; font-size: 13px; margin-bottom: 2px; }
.tops { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tops ol { margin: 0; padding-left: 20px; font-size: 12px; }
.tops li { margin-bottom: 3px; }
.tops .gen { color: var(--muted); }
.tag { font-size: 10px; padding: 0 5px; border-radius: 4px; background: #253240; color: var(--muted); margin-left: 4px; }
.tag.human { background: #3a2f12; color: var(--accent); }

#hud { position: fixed; inset: 0; pointer-events: none; }
.hud-box { position: absolute; background: rgba(13, 18, 23, 0.78); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; }
#hud-left { left: 12px; top: 12px; min-width: 200px; }
#hud-top { left: 50%; top: 12px; transform: translateX(-50%); text-align: center; font-variant-numeric: tabular-nums; }
#hud-right { right: 12px; top: 12px; font-variant-numeric: tabular-nums; font-size: 12px; }
#legend { left: 12px; bottom: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; max-width: calc(100vw - 300px); }
.lg { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-left: 6px; }
.lg.replay { border: 2px solid #fff; }
.lg.diverged { border: 2px solid var(--accent); }
.lg.bot { background: #55606b; }
#feed { position: absolute; left: 12px; bottom: 56px; display: grid; gap: 3px; font-size: 12px; }
#feed div { background: rgba(13, 18, 23, 0.7); padding: 2px 8px; border-radius: 6px; border-left: 3px solid var(--muted); }
#feed .blue { border-color: var(--blue); }
#feed .red { border-color: var(--red); }
#feed .mine { color: var(--accent); }
#death { left: 50%; top: 38%; transform: translateX(-50%); text-align: center; pointer-events: auto; display: grid; gap: 8px; min-width: 280px; }
.death-title { font-size: 22px; font-weight: 700; color: var(--red); }
.hp { height: 6px; background: #2a333c; border-radius: 3px; margin: 4px 0 6px; overflow: hidden; }
.hp > i { display: block; height: 100%; background: #5fd17a; }
.timer { font-size: 22px; font-weight: 700; }

.result-card { max-width: 560px; margin: 8vh auto 0; }
.result-card .seg { margin-top: 16px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; margin: 10px 0; }
.stats div { background: #0f151b; border-radius: 8px; padding: 8px 10px; }
.stats b { display: block; font-size: 20px; }
.note { background: #1a2129; border-left: 3px solid var(--accent); padding: 8px 12px; border-radius: 6px; margin-top: 8px; font-size: 13px; }

@media (max-width: 760px) {
  #legend { display: none; }
  #hud-top { left: auto; right: 12px; transform: none; }
  #hud-right { top: auto; bottom: calc(20vw + 24px); }
  #feed { bottom: calc(20vw + 24px); max-width: 45vw; }
}

.mags { display: flex; gap: 4px; align-items: flex-end; margin: 4px 0 6px; }
.mags span { width: 10px; height: 28px; background: #2a333c; border-radius: 2px; position: relative; overflow: hidden; }
.mags i { position: absolute; left: 0; bottom: 0; width: 100%; background: var(--accent); }
.mags b { margin-left: 6px; font-size: 13px; font-variant-numeric: tabular-nums; }

.ff-row { margin-bottom: 12px; font-size: 13px; align-items: center; }
.pill.on { background: #3a2f12; color: var(--accent); }
.small-btn { flex: none; padding: 4px 10px; font-size: 12px; }

.lit-warn { color: #fff2a0; font-weight: 700; letter-spacing: 0.04em; animation: blink 0.6s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0.35; } }

#hud .aim-switch { pointer-events: auto; display: flex; gap: 4px; align-items: center; margin: 4px 0; font-size: 12px; }
#hud .aim-switch button { flex: none; padding: 2px 8px; font-size: 12px; }
.towers { display: flex; gap: 6px; margin-bottom: 4px; }
.tower-bar { position: relative; width: 120px; height: 14px; background: #2a333c; border-radius: 3px; overflow: hidden; font-size: 10px; }
.tower-bar i { position: absolute; left: 0; top: 0; bottom: 0; }
.tower-bar span { position: relative; padding-left: 4px; line-height: 14px; color: #fff; text-shadow: 0 0 3px #000; }

.side-btn { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 6px 10px; }
.crest { height: 40px; width: auto; }
.crest-sm { height: 18px; width: auto; vertical-align: -4px; margin-right: 5px; }
.crest-hud { height: 26px; width: auto; vertical-align: -8px; margin-right: 6px; }
.res-crest { display: block; height: 110px; margin: 0 auto 8px; }

.heat { display: flex; align-items: center; gap: 6px; font-size: 12px; margin: 4px 0; }
.heat > div { flex: 1; height: 7px; background: #2a333c; border-radius: 3px; overflow: hidden; }
.heat i { display: block; height: 100%; }

.music-btn { width: 100%; margin-top: 8px; font-size: 13px; }

.towers > div { display: grid; gap: 2px; }
.tower-hp { width: 120px; height: 4px; background: #2a333c; border-radius: 2px; overflow: hidden; }
.tower-hp i { display: block; height: 100%; background: #c9c2b2; }

.sound-row { margin-top: 8px; }
.sound-row .music-btn { margin-top: 0; }

.account .seg { margin-top: 4px; }
.acc-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 4px; color: var(--text); font-size: 14px; }
.acc-form { display: grid; gap: 6px; margin-top: 8px; }
.acc-form input { margin-top: 0; }
.acc-form .seg { margin-top: 0; }
.acc-error { color: var(--red); font-size: 12px; min-height: 0; }
.acc-error:empty { display: none; }
button.danger { border-color: var(--red); background: #3a1717; }

/* ---------- Phones and tablets ---------- */
.touch-only { display: none; }
body.touch .touch-only { display: revert; }
.controls dl.touch-only { display: none; }
body.touch .controls dl.touch-only { display: grid; }
body.touch .desk-only { display: none !important; }
body.in-battle { touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }

#touch { position: absolute; inset: 0; pointer-events: none; }
#touch button { pointer-events: auto; touch-action: none; -webkit-user-select: none; user-select: none; flex: none; border-radius: 50%;
  background: rgba(20, 28, 36, 0.55); border: 2px solid rgba(223, 230, 236, 0.35); color: #fff; font-weight: 700; font-size: 15px;
  backdrop-filter: blur(2px); display: grid; place-items: center; padding: 0; }
#touch button.down { background: rgba(255, 176, 32, 0.45); border-color: var(--accent); transform: scale(0.95); }
#touch .t-left, #touch .t-right { position: absolute; bottom: max(16px, env(safe-area-inset-bottom)); display: flex; align-items: flex-end; gap: 14px; }
#touch .t-left { left: max(18px, env(safe-area-inset-left)); }
#touch .t-right { right: max(18px, env(safe-area-inset-right)); }
#touch .t-big { width: 96px; height: 96px; }
#touch .t-fire { border-color: rgba(255, 93, 93, 0.7); }
#touch .t-mid { width: 68px; height: 68px; font-size: 13px; }
#touch .t-pad { display: grid; grid-template-columns: repeat(3, 58px); grid-template-rows: repeat(3, 58px); }
#touch .t-pad button { width: 58px; height: 58px; border-radius: 14px; font-size: 18px; }
#touch .t-up { grid-area: 1 / 2; }
#touch .t-l { grid-area: 2 / 1; }
#touch .t-r { grid-area: 2 / 3; }
#touch .t-down { grid-area: 3 / 2; }
#touch[data-role="plane"] .t-tank, #touch[data-role="turret"] .t-plane { display: none; }
#touch .t-sys { position: absolute; left: 50%; bottom: max(10px, env(safe-area-inset-bottom)); transform: translateX(-50%); display: flex; gap: 8px; }
#touch .t-sys button { border-radius: 99px; width: auto; height: 34px; padding: 0 14px; font-size: 12px; font-weight: 600; }

#rotate-hint { display: none; }
@media (orientation: portrait) {
  body.touch.in-battle #rotate-hint { display: block; position: absolute; left: 50%; top: 40%; transform: translateX(-50%); background: rgba(13, 18, 23, 0.85);
    border: 1px solid var(--accent); border-radius: 10px; padding: 10px 16px; font-weight: 700; pointer-events: none; }
}

body.touch #legend { display: none; }
body.touch #feed { left: auto; right: 4px; bottom: auto; transform: none; max-width: none; gap: 2px; font-size: 10px; }
body.touch #feed div { padding: 1px 5px; border-left-width: 2px; background: rgba(13, 18, 23, 0.55); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
body.touch .hud-box { font-size: 11px; padding: 3px 6px; border-radius: 6px; background: rgba(13, 18, 23, 0.55); }
body.touch #hud-left { left: 4px; top: 4px; min-width: 0; width: 130px; }
body.touch #hud-left .hp { margin: 2px 0 0; }
body.touch #hud-top { top: 4px; padding: 3px; }
body.touch #hud-top .towers { margin: 0; gap: 3px; }
body.touch #hud-top .tower-bar { width: 128px; }
body.touch #hud-right { right: 4px; bottom: auto; font-size: 10px; padding: 1px 5px; }
body.touch #death { top: 18%; min-width: 0; }

/* ---------- Sub pages ---------- */
.lobby-grid { align-items: start; }
.intro { grid-row: auto; }
.more-link { display: block; margin-top: 12px; color: var(--accent); text-decoration: none; font-weight: 600; font-size: 13px; }
.more-link:hover { text-decoration: underline; }
html:has(body.page), body.page { overflow: auto; height: auto; }
.page-wrap { max-width: 1100px; margin: 0 auto; padding: 20px 16px 48px; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 18px; }
.page-logo { height: 44px; width: auto; display: block; }
.primary-link { background: var(--accent); color: #1a1205; font-weight: 700; padding: 9px 16px; border-radius: 8px; text-decoration: none; white-space: nowrap; }
.page h1 { font-size: clamp(24px, 4vw, 34px); margin: 0 0 6px; }
.pitch.left { margin: 0 0 18px; text-align: left; }
.explain { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; margin-bottom: 18px; }
.explain > div { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; color: var(--muted); font-size: 13px; }
.explain b { display: block; color: var(--text); margin-bottom: 4px; font-size: 14px; }
.page .card p { margin: 8px 0 10px; }
.hint { margin-top: 4px; font-size: 11px; color: var(--muted); opacity: 0.8; }

/* ---------- Lobby on a phone held sideways ---------- */
@media (orientation: landscape) and (max-height: 520px) {
  .overlay { padding: 8px max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left)); }
  .hero { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 2px 14px; text-align: left; margin: 0 auto 8px; }
  .hero-logo { width: 190px; grid-row: span 2; margin: 0; }
  .claim { margin: 0; font-size: 18px; }
  .pitch { margin: 0; font-size: 12px; max-width: none; }
  .features { grid-column: 1 / -1; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 6px; }
  .features li { padding: 6px 8px; font-size: 0; }
  .features b { font-size: 12px; margin: 0; }
  .features .ico { font-size: 12px; }
  .lobby-grid { grid-template-columns: 3fr 2fr; gap: 10px; }
  .card { padding: 10px 12px; }
  .intro { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; align-items: start; }
  .intro > h2, .intro > .account, .intro > #start, .intro > .note, .intro > .sound-row, .intro > .controls { grid-column: 1 / -1; }
  .intro > h2 { margin-bottom: 6px; }
  .field { margin-bottom: 8px; }
  .field input { padding: 6px 8px; font-size: 14px; }
  button { padding: 6px 10px; }
  .crest { height: 24px; }
  .side-btn { padding: 4px 8px; }
  #start { position: sticky; bottom: 6px; z-index: 2; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.55); padding: 10px; }
  .front-side .bars { gap: 2px; }
  .bar { height: 18px; }
  #result .result-card { padding: 12px; }
  .res-crest { height: 60px; }
}
