:root {
  --bg: #121416; --side: #16181a; --card: #1e2124; --card2: #24282c; --line: #2c3136;
  --ink: #ece9e2; --mute: #9aa1a8; --acc: #e3a23a; --acc2: #c8841f; --blue: #33485f; --blue2: #3f5a77;
  --ok: #7fbf5a; --bad: #e0665a; --allied: #6f8a3a; --german: #9aa0a6;
  --r: 8px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Inter, Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
.muted { color: var(--mute); } .small { font-size: 12px; }
.err { color: var(--bad); min-height: 0; font-size: 13px; }
.err:not(:empty) { padding: 6px 14px; }

/* buttons and inputs */
.btn, button { font: inherit; color: var(--ink); background: var(--card2); border: 1px solid #3a4046; border-radius: 6px; padding: 8px 14px; cursor: pointer; }
.btn:hover { border-color: #56606a; }
.btn.primary { background: linear-gradient(#eaa944, var(--acc2)); color: #1b1408; border-color: #b97418; font-weight: 700; }
.btn.blue { background: linear-gradient(#3f5873, var(--blue)); border-color: #4c6886; font-weight: 600; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .45; cursor: default; }
input, select { font: inherit; background: #0f1113; color: var(--ink); border: 1px solid #3a4046; border-radius: 6px; padding: 8px 10px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* top bar */
#top { display: flex; align-items: center; gap: 12px; height: 44px; padding: 0 14px; border-bottom: 1px solid var(--line); background: var(--side); }
.brand { font-weight: 800; letter-spacing: .08em; font-size: 14px; }
.status { color: var(--mute); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.grow { flex: 1; }

/* lobby / login */
.page { max-width: 760px; margin: 28px auto; padding: 0 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; margin-bottom: 10px; }
.card.narrow { max-width: 420px; margin: 40px auto; }
.card h2 { margin: 0 0 8px; font-size: 18px; }
.card h3 { margin: 0 0 8px; font-size: 13px; font-weight: 700; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.card-head h3 { margin: 0; }
.card-head select { padding: 3px 6px; font-size: 12px; }
.game-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.tag { font-size: 11px; padding: 1px 7px; border-radius: 9px; background: var(--card2); color: var(--mute); }

/* game layout */
#game { display: none; position: relative; height: calc(100vh - 44px); }
#game.on { display: flex; }
#mapbox { flex: 1; overflow: auto; position: relative; background: #0e100d; overscroll-behavior: contain; }
#map { display: block; touch-action: pan-x pan-y; }
#tip { position: absolute; z-index: 5; min-width: 180px; max-width: 260px; background: rgba(22,24,26,.96); border: 1px solid #3a4046; border-radius: 6px;
  padding: 8px 10px; font-size: 12.5px; line-height: 1.5; pointer-events: none; box-shadow: 0 6px 20px rgba(0,0,0,.45); }
#tip b { font-size: 13.5px; }
#mapctl { position: absolute; left: 12px; bottom: 12px; z-index: 6; display: flex; gap: 8px; }
.seg { display: flex; align-items: center; gap: 2px; background: rgba(22,24,26,.92); border: 1px solid #3a4046; border-radius: 8px; padding: 4px; }
.seg button { background: var(--card2); border: 1px solid #3a4046; width: 34px; height: 30px; padding: 0; font-size: 18px; border-radius: 5px; }
.seg span#zpct { min-width: 52px; text-align: center; color: var(--ink); font-size: 13px; }
.seg.toggle { gap: 10px; padding: 7px 14px 7px 10px; color: var(--ink); }
.sw { width: 30px; height: 16px; border-radius: 9px; background: #3a4046; position: relative; transition: background .15s; }
.sw::after { content: ""; position: absolute; left: 2px; top: 2px; width: 12px; height: 12px; border-radius: 50%; background: #d8d8d8; transition: left .15s; }
.toggle[aria-pressed="true"] .sw { background: #c0503f; }
.toggle[aria-pressed="true"] .sw::after { left: 16px; }

/* sidebar */
#side { width: 400px; background: var(--side); border-left: 1px solid var(--line); display: flex; flex-direction: column; overflow-y: auto; }
.grab, .tabs { display: none; }
#side > * { flex-shrink: 0; }
.ulist { max-height: 112px; overflow-y: auto; }
.ulist .u { padding: 4px 8px; }
.phase { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 14px 16px 10px; border-bottom: 1px solid var(--line); }
.phase-title { font-size: 19px; font-weight: 700; }
.icon { width: 30px; height: 30px; border-radius: 6px; padding: 0; font-weight: 700; color: var(--mute); }
.actions { display: grid; grid-template-columns: 1fr 1.4fr; gap: 10px; padding: 0 12px 10px; order: 2; }
.actions .btn { padding: 11px 12px; }
.cards { padding: 10px 12px 0; display: flex; flex-direction: column; order: 1; }
#side .card { margin-bottom: 8px; padding: 10px 12px; }
#side > #logCard { order: 3; margin: 0 12px 12px; }
#side > .err { order: 4; }

.player { display: grid; grid-template-columns: 14px 1fr auto; gap: 8px; align-items: center; padding: 3px 0; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #666; }
.dot.on { background: var(--ok); }
.scen-title { font-weight: 700; font-size: 15px; }
.bar { height: 10px; border-radius: 5px; background: #2b3035; overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 5px; }
.vic { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center; margin: 6px 0; font-size: 12.5px; }
.lost { display: flex; gap: 20px; font-size: 13px; margin-top: 6px; }
details { margin-top: 8px; font-size: 12.5px; color: #cfd2d6; }
details summary { cursor: pointer; color: var(--mute); }
details p { margin: 6px 0; }

.unit-head { display: grid; grid-template-columns: 76px 1fr; gap: 12px; align-items: center; }
.unit-head canvas { width: 76px; height: 76px; }
.stats { display: grid; grid-template-columns: repeat(3, auto); gap: 2px 14px; font-size: 13px; color: var(--mute); margin-top: 4px; }
.stats b { color: var(--ink); font-weight: 600; }
.ulist .u { display: flex; justify-content: space-between; gap: 6px; padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.ulist .u:hover, .ulist .u.sel { background: var(--card2); }
.ulist .u.fg { box-shadow: inset 0 0 0 2px var(--acc); }

.fire-top { display: grid; grid-template-columns: 1fr auto; grid-template-areas: "minis minis" "txt btn"; gap: 8px 10px; align-items: center; }
.fire-top .minis { grid-area: minis; } .fire-top .ftxt { grid-area: txt; } .fire-top .fire-btn { grid-area: btn; }
#side.firing #fireCard { order: -1; }
.player { padding: 1px 0; }
.minis { display: flex; gap: 4px; flex-wrap: wrap; }
.minis canvas { width: 40px; height: 40px; }
.fire-btn { padding: 12px 26px; font-size: 18px; }
.results { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line); border-radius: 6px; margin-top: 8px; }
.results div { text-align: center; padding: 8px 4px; border-right: 1px solid var(--line); color: var(--mute); font-size: 12px; }
.results div:last-child { border-right: 0; }
.results b { display: block; color: var(--ink); font-size: 22px; font-weight: 700; }
.note { font-size: 12px; color: var(--mute); margin-top: 6px; }
.note.acc { color: var(--acc); }
label.chk { display: flex; gap: 8px; align-items: center; font-size: 12.5px; margin-top: 8px; }

#log { font-size: 12.5px; max-height: 260px; overflow-y: auto; }
.lg { display: grid; grid-template-columns: 40px 10px 1fr; gap: 8px; align-items: baseline; padding: 3px 0; }
.lg time { color: var(--mute); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.lg .dot { width: 8px; height: 8px; }
.card.info { font-size: 12px; color: var(--mute); }

/* phone: full-screen map, bottom sheet */
@media (max-width: 760px) {
  #top { height: 40px; gap: 8px; }
  .brand { font-size: 0; } .brand::after { content: "AHW"; font-size: 14px; }
  #top .status { font-size: 12px; }
  #game { height: calc(100dvh - 40px); }
  #game.on { display: block; }
  #mapbox { position: absolute; inset: 0; }
  #mapctl { left: 8px; bottom: auto; top: 8px; }
  .seg button { width: 40px; height: 36px; }
  .seg.toggle { padding: 8px 12px 8px 10px; }
  #side { position: fixed; left: 0; right: 0; bottom: 0; width: auto; max-height: 46dvh; border-left: 0; border-top: 1px solid var(--line);
    border-radius: 14px 14px 0 0; box-shadow: 0 -8px 24px rgba(0,0,0,.5); z-index: 10; transition: max-height .2s; padding-bottom: env(safe-area-inset-bottom); }
  #side.open { max-height: 82dvh; }
  .grab { display: flex; justify-content: center; padding: 8px 0 2px; cursor: pointer; }
  .grab span { width: 44px; height: 5px; border-radius: 3px; background: #4a5056; }
  .phase { padding: 6px 14px 8px; border-bottom: 0; }
  .phase-title { font-size: 16px; }
  .actions, .cards, #side > #logCard, #side > .err { order: 0; }
  .actions { padding: 0 12px 8px; }
  .actions .btn { padding: 12px; font-size: 15px; }
  .tabs { display: flex; gap: 4px; padding: 0 10px 8px; overflow-x: auto; }
  .tabs button { flex: 1; padding: 8px 6px; font-size: 13px; border-radius: 18px; background: transparent; border-color: #3a4046; white-space: nowrap; }
  .tabs button.on { background: var(--card2); border-color: #6a737c; }
  .cards { padding-top: 0; }
  #side .card { display: none; }
  #side[data-tab="unit"] .card[data-tab~="unit"], #side[data-tab="fire"] .card[data-tab~="fire"],
  #side[data-tab="scen"] .card[data-tab~="scen"], #side[data-tab="players"] .card[data-tab~="players"],
  #side[data-tab="log"] .card[data-tab~="log"] { display: block; }
  #side[data-tab="unit"] #fireCard { order: 0; }
  #tip { display: none !important; }
  #log { max-height: none; }
  .fire-btn { padding: 12px 22px; }
  .fire-top { grid-template-columns: 1fr auto; grid-template-areas: "minis minis" "txt btn"; }
}
