:root {
  --bg: #0e1116; --panel: #141922; --line: #232a35; --text: #e6edf3; --muted: #8b97a8;
  --must: #f5b542; --lao: #b88cff; --w3: #5fb3ff; --me: #34d3b6; --red: #ff5a5a; --silver: #e6e6e6; --gray: #4b5563;
  --badge: 56px; /* overwritten by app.js fitStage(): clamp(44px, 12% of the map's displayed width, 60px) */
  /* crossed swords, inline SVG so the fight marker looks the same on every phone / desktop font */
  --swords: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 4l13 13M20 4L7 17M13 19l6-6M5 13l6 6M17 17l3.5 3.5M7 17l-3.5 3.5'/%3E%3C/svg%3E");
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; }
body {
  height: 100vh; height: 100dvh; background: var(--bg); color: var(--text);
  font: 16px/1.3 -apple-system, "PingFang SC", "Noto Sans CJK SC", sans-serif;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button { font: inherit; font-weight: 700; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; min-height: 44px; padding: 0 12px; touch-action: manipulation; }
button:active { background: #1c232e; }
button:disabled { opacity: .35; }
.swords { display: inline-block; width: 20px; height: 20px; margin-right: 6px; vertical-align: -5px; border-radius: 10px; background: var(--red) var(--swords) center / 14px no-repeat; }

/* layout: the map fills the height, an info-only column on the right (landscape) or a row at the bottom (portrait) */
#board { display: flex; height: 100%; overflow: hidden; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
#mapbox { position: relative; flex: 1; min-width: 0; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 6px; touch-action: none; }
#stage { position: relative; flex: none; border-radius: 8px; }
#stage img { display: block; width: 100%; height: 100%; border-radius: 8px; pointer-events: none; -webkit-user-drag: none; }
/* a faint inner shadow over the picture so the map reads as set into the panel; sits under the badge layers */
#stage::after { content: ""; position: absolute; inset: 0; z-index: 1; border-radius: 8px; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .35), inset 0 2px 14px rgba(0, 0, 0, .45); pointer-events: none; }
#badges, #marks { position: absolute; inset: 0; z-index: 2; pointer-events: none; }
.badge, .mark { pointer-events: auto; }
body[data-phase="start"] #badges { filter: brightness(.6); }

/* start: modal floating over the map, buttons coloured by spawn group */
#startmodal { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 5; width: min(440px, calc(100% - 24px)); padding: 14px 16px 16px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 10px 30px rgba(0, 0, 0, .55); }
#startmodal h1 { margin: 0 0 12px; font-size: 20px; line-height: 1.2; text-align: center; }
#spawnbtns { display: grid; grid-template-columns: 48px repeat(3, 1fr); gap: 8px; align-items: center; }
#spawnbtns em { font-style: normal; font-size: 13px; font-weight: 700; color: var(--muted); text-align: right; padding-right: 2px; }
button.spawn { min-height: 56px; font-size: 20px; padding: 0 6px; background: var(--bg); border: 2px solid var(--c); color: var(--c); }
button.spawn:active { background: var(--c); color: var(--bg); }
.g-must { --c: var(--must); } .g-lao { --c: var(--lao); } .g-w3 { --c: var(--w3); }
body[data-phase="game"] #startmodal { display: none; }

/* right column: countdown, counts, extraction times, two trays, two buttons — nothing else */
#panel { width: clamp(150px, 19vw, 170px); flex: none; display: flex; flex-direction: column; gap: 8px; padding: 8px; background: var(--panel); border-left: 1px solid var(--line); touch-action: none; }
.stat { display: flex; flex-direction: column; gap: 2px; }
#clock { font-size: clamp(32px, 4vw, 36px); font-weight: 700; font-variant-numeric: tabular-nums; text-align: center; line-height: 1.1; }
#clock.warn { color: var(--red); }
#counts { display: flex; justify-content: center; gap: 6px; color: var(--muted); font-size: 14px; white-space: nowrap; }
#counts b { color: var(--text); font-size: 16px; }
/* extraction points under the counts (丢包 9:00, 飞升 14:40): muted label + text-colour value while counting down, whole row text colour and bold once open */
#evac { display: flex; flex-direction: column; gap: 1px; margin-top: 4px; font-size: 14px; line-height: 1.25; color: var(--muted); white-space: nowrap; }
#evac > div { display: flex; justify-content: center; gap: 8px; border-radius: 4px; }
#evac em { flex: none; min-width: 5.2em; font-style: normal; font-variant-numeric: tabular-nums; color: var(--text); }
#evac > div.open { color: var(--text); font-weight: 700; }
body[data-phase="start"] :is(#clock, #counts, #evac, .tray) { opacity: .4; }
.tray { position: relative; flex: 1; min-height: 56px; border: 1px dashed var(--line); border-radius: 10px; padding: 26px 6px 6px; display: flex; flex-wrap: wrap; align-content: flex-start; gap: 6px; }
.tray > span { position: absolute; top: 5px; left: 9px; color: var(--muted); font-size: 13px; font-weight: 700; pointer-events: none; }
.tray.over { border-style: solid; border-color: var(--text); }
.ops { display: flex; gap: 8px; }
.ops button { flex: 1; height: 44px; min-height: 44px; padding: 0 4px; font-size: 15px; }
#newgame.armed { border-color: var(--red); color: var(--red); }
/* voice: tap = wake mode on/off ("雷达雷达" + command), hold = push-to-talk; the dot pulses while listening */
.voice { display: flex; }
#mic { position: relative; flex: 1; height: 44px; min-height: 44px; padding: 0 4px 0 22px; font-size: 15px; white-space: nowrap; }
#mic.off { color: var(--muted); }
#mic.on { border-color: var(--me); color: var(--me); }
#mic.on::before { content: ""; position: absolute; left: 10px; top: 50%; width: 8px; height: 8px; margin-top: -4px; border-radius: 50%; background: var(--me); animation: micpulse 1.6s ease-in-out infinite; }
#mic.armed { border-color: var(--me); background: var(--me); color: var(--bg); }
#mic.ptt { border-color: var(--red); background: var(--red); color: var(--bg); }
@keyframes micpulse { 0%, 100% { opacity: .3; } 50% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { #mic.on::before { animation: none; } }
/* what the board heard, at the bottom of the map */
#toast { position: absolute; z-index: 6; left: 50%; bottom: 12px; transform: translateX(-50%); max-width: calc(100% - 24px); padding: 8px 14px; border-radius: 10px; background: var(--panel); border: 1px solid var(--me); color: var(--text); font-size: 15px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; box-shadow: 0 6px 20px rgba(0, 0, 0, .5); pointer-events: none; }
#toast.bad { border-color: var(--red); color: var(--muted); }

/* badges: one per spawn; left/top are % of the stage, margin centres the circle; diameter is --badge */
.badge { position: absolute; width: var(--badge); height: var(--badge); margin: calc(var(--badge) / -2) 0 0 calc(var(--badge) / -2); border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: clamp(14px, calc(var(--badge) * .3), 17px); font-weight: 700; line-height: 1; border: 3px solid var(--c); color: var(--c); background: rgba(14, 17, 22, .72); box-shadow: 0 1px 3px rgba(0, 0, 0, .5); touch-action: none; cursor: grab; }
.badge.unknown { border-style: dashed; }
.badge.confirmed, body[data-phase="start"] .badge { background: var(--c); color: var(--bg); border-style: solid; }
.badge.me { --c: var(--me); background: var(--c); color: var(--bg); }
/* merged: "one of these two is left, no idea which" — silver ring, dark fill, both names stacked inside */
.badge.merged { --c: var(--silver); background: #1a1f29; color: var(--text); border-style: solid; }
.badge.merged .name { display: flex; flex-direction: column; align-items: center; font-size: 12px; line-height: 1.1; }
.badge.merged .name i { font-style: normal; }
.badge.merged .name i + i { margin-top: 2px; padding-top: 2px; border-top: 1px solid rgba(230, 230, 230, .55); }
.badge.fight { border-color: var(--red); border-style: solid; }
.badge.fight::before { content: ""; position: absolute; top: -8px; left: -8px; width: 20px; height: 20px; border-radius: 10px; background: var(--red) var(--swords) center / 14px no-repeat; box-shadow: 0 1px 2px rgba(0, 0, 0, .5); }
.badge.faded { opacity: .5; }
.badge.target { transform: scale(1.12); box-shadow: 0 0 0 3px var(--text); }
.badge .age { position: absolute; top: -9px; right: -9px; min-width: 20px; height: 20px; line-height: 20px; padding: 0 5px; border-radius: 10px; background: var(--text); color: var(--bg); font-size: 13px; font-weight: 700; }
/* region name: visible while dragging (on the ghost) and for a moment after a drop (.show), then fades out */
.badge .loc { position: absolute; top: 100%; left: 50%; transform: translateX(-50%); margin-top: 4px; padding: 0 6px; line-height: 20px; white-space: nowrap; border-radius: 6px; background: rgba(14, 17, 22, .88); color: var(--text); font-size: 13px; font-weight: 700; pointer-events: none; opacity: 0; transition: opacity .6s ease; }
.badge .loc.show, .badge.ghost .loc { opacity: 1; transition: none; }
.badge .age:empty, .badge .loc:empty { display: none; }
.badge.dragging { opacity: .25; }
.badge.ghost { position: fixed; margin: 0; transform: translate(-50%, -50%) scale(1.1); pointer-events: none; z-index: 50; opacity: .95; }
/* chips in the trays: small, grey, no ring */
.badge.chip { position: static; margin: 0; width: 34px; height: 34px; font-size: 13px; opacity: 1; background: var(--gray); border-color: var(--gray); color: #d5dbe4; box-shadow: none; }
.badge.chip .age, .badge.chip .loc, .badge.chip::before { display: none; }

/* trace marks (body / door / searched / shots) */
.mark { position: absolute; width: 28px; height: 28px; margin: -14px 0 0 -14px; border-radius: 6px; background: rgba(230, 237, 243, .94); color: var(--bg); display: flex; align-items: center; justify-content: center; font-size: 15px; font-weight: 700; touch-action: none; }
.mark small { position: absolute; top: 100%; left: 50%; transform: translateX(-50%); margin-top: 2px; padding: 0 4px; line-height: 18px; border-radius: 4px; background: rgba(14, 17, 22, .88); color: var(--text); font-size: 13px; font-weight: 700; }

/* overlays: fight / merged-badge chooser at the top, long-press mark menu at the finger */
#fightbar, #markmenu { position: fixed; z-index: 60; display: flex; align-items: center; gap: 8px; padding: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 6px 20px rgba(0, 0, 0, .5); }
#fightbar { top: calc(10px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); flex-direction: column; align-items: stretch; max-width: calc(100vw - 16px); }
#fightbar.fight { border-color: var(--red); }
#fightbar.resolve { border-color: var(--silver); }
#fightbar .q { padding: 0 4px; font-weight: 700; white-space: nowrap; text-align: center; }
#fightbar .btns { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
#fightbar button, #markmenu button { min-height: 40px; font-size: 15px; white-space: nowrap; }
#fightbar button.plain { color: var(--muted); }

@media (orientation: portrait) {
  #board { flex-direction: column; }
  #panel { width: auto; flex-direction: row; align-items: stretch; min-height: 112px; border-left: 0; border-top: 1px solid var(--line); }
  .stat { flex: none; justify-content: center; padding: 0 4px; }
  .tray { min-height: 0; }
  .ops { flex: none; flex-direction: column; width: 80px; }
  .ops button { height: auto; min-height: 40px; }
  .voice { flex: none; width: 76px; }
  #mic { height: auto; padding-left: 18px; }
  #mic.on::before { left: 6px; }
}
