:root {
  --bg: #10202e;
  --panel: #f3efe4;
  --panel-2: #e7e1d1;
  --ink: #1d2328;
  --ink-2: #5a5f63;
  --line: #cfc7b3;
  --accent: #1f4766;
  --attack: #c0392b;
  --ok: #3d7a3a;
  --warn: #b7791f;
  --radius: 10px;
  --cond: "Bahnschrift SemiCondensed", "Bahnschrift", "DIN Condensed", "Avenir Next Condensed", "Arial Narrow", "Roboto Condensed", sans-serif;
  --map: "Copperplate", "Copperplate Gothic Light", "Palatino Linotype", "Book Antiqua", Palatino, Georgia, serif;
  --body: -apple-system, "Segoe UI", system-ui, Roboto, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font-family: var(--body); overflow: hidden; -webkit-tap-highlight-color: transparent; }
body { position: fixed; inset: 0; touch-action: none; }
button { font: inherit; color: inherit; }

#app { position: absolute; inset: 0; display: grid; grid-template-rows: auto 1fr; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 8px; padding: calc(6px + var(--safe-t)) 10px 6px;
  background: #0b1722; color: #e9e4d6; border-bottom: 1px solid #000; min-height: 48px; z-index: 5;
}
.power-chip { display: flex; align-items: center; gap: 7px; font-family: var(--cond); font-size: 18px; letter-spacing: .02em; text-transform: uppercase; white-space: nowrap; }
.power-chip .sw { width: 14px; height: 22px; border-radius: 3px; border: 1px solid #0006; }
.phase-lbl { flex: 1; min-width: 0; font-size: 13px; color: #b9b3a3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.phase-lbl b { color: #e9e4d6; font-weight: 600; }
.ipc { font-family: var(--cond); font-size: 18px; background: #d9b44a; color: #1d1a10; border-radius: 6px; padding: 2px 8px; white-space: nowrap; }
.iconbtn { background: none; border: 0; padding: 6px; border-radius: 8px; cursor: pointer; color: #e9e4d6; display: grid; place-items: center; }
.iconbtn:hover { background: #ffffff14; }
.iconbtn svg { width: 22px; height: 22px; }

/* ---------- main area ---------- */
.main { position: relative; display: grid; grid-template-columns: 1fr; min-height: 0; }
.mapwrap { position: absolute; inset: 0; overflow: hidden; }
svg.map { display: block; background: #40bcc5; touch-action: none; user-select: none; -webkit-user-select: none; cursor: grab; }
svg.map text { font-family: var(--cond); }
.sea-lbl { font-family: var(--map); font-size: 6.2px; fill: #0d4a55; font-style: italic; letter-spacing: .04em; paint-order: stroke; stroke: #bff1ef; stroke-width: 1.2px; stroke-opacity: .6; }
.sea-num { font-family: var(--map); font-size: 6px; font-weight: 700; fill: #1d4f5c; }
.land-lbl { font-family: var(--map); font-size: 7px; fill: #1c160d; font-weight: 700; paint-order: stroke; stroke: #fbf3df; stroke-width: 1.5px; stroke-opacity: .75; letter-spacing: .03em; }
.land-lbl.small { font-size: 5.6px; }
.land-lbl.neutral { fill: #5b5140; font-weight: 400; font-style: italic; }
.ipc-lbl { font-family: var(--map); font-size: 5.6px; fill: #1c160d; font-weight: 700; paint-order: stroke; stroke: #fbf3df; stroke-width: 1.4px; stroke-opacity: .7; }
.cnt { font-family: var(--cond); fill: #fff; font-weight: 700; paint-order: stroke; stroke: #15120d; }
.compass-n { font-family: var(--map); font-size: 7px; font-weight: 700; fill: #1d4f5c; }
.hl { pointer-events: none; }
.hl-sel { fill: #ffffff26; stroke: #fff; stroke-width: 1.6; }
.hl-move { fill: #34a85a70; stroke: #d2f7dc; stroke-width: 1.8; }
.hl-attack { fill: #d9402f8c; stroke: #ffe1da; stroke-width: 1.8; }
.hl-load { fill: #e2b43a80; stroke: #fff0c2; stroke-width: 1.8; }
.hl-place { fill: #9fe3ff59; stroke: #ffffff; stroke-width: 2; }
.hl-battle { fill: #c0392b40; stroke: #ff7a66; stroke-width: 1.4; stroke-dasharray: 3 2; }

.zoom { position: absolute; right: 10px; top: 10px; display: grid; gap: 6px; z-index: 3; }
.zoom button { width: 40px; height: 40px; border-radius: 10px; border: 1px solid #0007; background: #0b1722cc; color: #e9e4d6; font-size: 22px; cursor: pointer; }

/* ---------- panel (bottom sheet on phones, side panel on wide screens) ---------- */
.panel {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 4;
  background: var(--panel); border-radius: 16px 16px 0 0; box-shadow: 0 -6px 24px #0007;
  display: flex; flex-direction: column; max-height: 58%; transition: max-height .2s ease;
}
.panel.collapsed { max-height: calc(108px + var(--safe-b)); }
.grab { border: 0; background: none; padding: 7px 0 3px; cursor: pointer; display: grid; place-items: center; width: 100%; }
.grab span { width: 42px; height: 5px; border-radius: 3px; background: #b9b09a; }
.pbody { overflow-y: auto; padding: 2px 14px 10px; flex: 1; min-height: 0; overscroll-behavior: contain; touch-action: pan-y; }
.pfoot { display: flex; gap: 8px; padding: 8px 12px calc(10px + var(--safe-b)); border-top: 1px solid var(--line); background: var(--panel-2); }
@media (min-width: 900px) {
  .panel { top: 0; left: auto; width: 380px; max-height: none; border-radius: 0; box-shadow: -6px 0 24px #0006; }
  .panel.collapsed { max-height: none; }
  .grab { display: none; }
  .pbody { padding-top: 12px; }
  .zoom { right: 392px; }
}

h2 { font-family: var(--cond); font-weight: 600; font-size: 20px; margin: 6px 0 2px; letter-spacing: .01em; }
h3 { font-family: var(--cond); font-weight: 600; font-size: 16px; margin: 12px 0 4px; color: var(--ink-2); text-transform: uppercase; letter-spacing: .05em; }
.hint { font-size: 13.5px; color: var(--ink-2); margin: 2px 0 8px; line-height: 1.35; }
.muted { color: var(--ink-2); }
.small { font-size: 12.5px; }

.btn {
  border: 1px solid #0003; background: #fff; border-radius: 10px; padding: 10px 14px; cursor: pointer;
  font-weight: 600; font-size: 15px; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); color: #fff; border-color: #0005; flex: 1; }
.btn.danger { background: var(--attack); color: #fff; }
.btn.ghost { background: transparent; }
.btn.sm { min-height: 34px; padding: 5px 10px; font-size: 13.5px; border-radius: 8px; }
.row { display: flex; align-items: center; gap: 8px; }
.grow { flex: 1; min-width: 0; }

.ico { width: 22px; height: 22px; fill: currentColor; flex: none; }
.uicon { width: 42px; height: 32px; border-radius: 8px; display: grid; place-items: center; flex: none; background: radial-gradient(circle at 50% 40%, #fbf6ea, #e4dcc7); border: 1px solid #0002; }
.uicon .ico { width: 36px; height: 26px; filter: drop-shadow(0 1px 1px #0006); }

.list { display: grid; gap: 6px; }
.item { display: flex; align-items: center; gap: 8px; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 6px 8px; }
.item.on { border-color: var(--accent); box-shadow: 0 0 0 2px #1f476633; }
.item .name { font-weight: 600; font-size: 14.5px; line-height: 1.15; }
.item .sub { font-size: 12px; color: var(--ink-2); }
.stepper { display: flex; align-items: center; gap: 2px; }
.stepper button { width: 36px; height: 36px; border-radius: 8px; border: 1px solid #0002; background: var(--panel-2); font-size: 20px; cursor: pointer; line-height: 1; }
.stepper .n { min-width: 26px; text-align: center; font-family: var(--cond); font-size: 19px; }
.tag { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 99px; background: var(--panel-2); color: var(--ink-2); font-weight: 600; }
.terr-head { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.terr-head .sw { width: 12px; height: 32px; border-radius: 3px; }
.stats { display: flex; gap: 10px; font-size: 12.5px; color: var(--ink-2); flex-wrap: wrap; }
.divider { height: 1px; background: var(--line); margin: 12px 0 4px; }
.warnbox { background: #fff4dc; border: 1px solid #e9c46a; border-radius: 10px; padding: 8px 10px; font-size: 13.5px; margin: 8px 0; }

/* ---------- overlays ---------- */
.overlay { position: absolute; inset: 0; z-index: 20; background: #050b11cc; display: grid; place-items: center; padding: 12px; }
.sheet { background: var(--panel); border-radius: 16px; width: min(560px, 100%); max-height: 100%; display: flex; flex-direction: column; box-shadow: 0 10px 40px #000a; overflow: hidden; }
.sheet .shead { padding: 14px 16px 8px; display: flex; align-items: center; gap: 10px; }
.sheet .sbody { flex: 1; padding: 0 16px 12px; overflow-y: auto; touch-action: pan-y; overscroll-behavior: contain; }
.sheet .sfoot { padding: 10px 14px calc(12px + var(--safe-b)); display: flex; gap: 8px; flex-wrap: wrap; border-top: 1px solid var(--line); background: var(--panel-2); }
@media (max-width: 600px) {
  .overlay.full { padding: 0; }
  .overlay.full .sheet { border-radius: 0; height: 100%; width: 100%; padding-top: var(--safe-t); }
}

.handoff { text-align: center; color: #fff; display: grid; gap: 14px; justify-items: center; max-width: 420px; }
.handoff .flag { width: 88px; height: 60px; border-radius: 8px; border: 2px solid #0006; box-shadow: 0 6px 20px #0008; }
.handoff h1 { font-family: var(--cond); font-size: 40px; margin: 0; letter-spacing: .02em; text-transform: uppercase; }
.handoff .loglines { font-size: 13px; color: #c9c3b5; text-align: left; max-height: 30vh; overflow: auto; background: #ffffff10; border-radius: 10px; padding: 8px 12px; width: 100%; touch-action: pan-y; }
.handoff .loglines div { padding: 2px 0; }

/* battle */
.sides { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.side { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 8px; min-width: 0; }
.side h4 { margin: 0 0 6px; font-family: var(--cond); font-size: 15px; display: flex; align-items: center; gap: 6px; }
.side h4 .sw { width: 10px; height: 18px; border-radius: 2px; }
.bunit { display: flex; align-items: center; gap: 6px; font-size: 13px; padding: 2px 0; }
.bunit .uicon { width: 34px; height: 26px; }
.bunit .uicon .ico { width: 30px; height: 22px; }
.bunit .v { margin-left: auto; font-family: var(--cond); font-size: 14px; color: var(--ink-2); }
.dice { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 3px; }
.die { width: 26px; height: 26px; filter: drop-shadow(0 1px 1px #0005); }
.die rect { fill: #fdfbf5; stroke: #3a352c; stroke-width: 1; }
.die circle { fill: #1d1a14; }
.die.hit rect { fill: #b8231b; stroke: #5e120c; }
.die.hit circle { fill: #fff; }
.rollgrp { font-size: 12.5px; margin: 6px 0; }
.rollgrp .lbl { color: var(--ink-2); }
.summary { font-size: 13.5px; background: #fff; border-radius: 10px; border: 1px solid var(--line); padding: 8px 10px; margin-top: 8px; }
.cas { margin-top: 10px; background: #fff; border: 2px solid var(--attack); border-radius: 10px; padding: 8px; }
.cas .err { color: var(--attack); font-size: 13px; margin-top: 4px; }

.toast { position: absolute; left: 50%; top: 64px; transform: translateX(-50%); background: #111d; color: #fff; padding: 8px 14px; border-radius: 10px; font-size: 14px; z-index: 30; max-width: 90%; text-align: center; pointer-events: none; }
.menu-list { display: grid; gap: 8px; }
.menu-list .btn { justify-content: flex-start; }
.rules { font-size: 14px; line-height: 1.45; }
.rules table { border-collapse: collapse; width: 100%; font-size: 13px; }
.rules td, .rules th { border-bottom: 1px solid var(--line); padding: 4px; text-align: left; }
.loglist { font-size: 13px; display: grid; gap: 4px; }
.seg { display: flex; border: 1px solid #0003; border-radius: 10px; overflow: hidden; }
.seg button { flex: 1; border: 0; padding: 8px; background: #fff; cursor: pointer; font-weight: 600; }
.seg button.on { background: var(--accent); color: #fff; }
label.check { display: flex; gap: 10px; align-items: center; font-size: 14.5px; padding: 6px 0; }
label.check input { width: 22px; height: 22px; }
.overlay.solid { background: radial-gradient(circle at 50% 30%, #1d3a52, #070f16 75%); }
.hl.fillonly { stroke: none; }
.hl.lineonly { fill: none; }

.roundel { display: inline-block; flex: none; }
.roundel.xs { width: 18px; height: 18px; }
.roundel.sm { width: 26px; height: 26px; filter: drop-shadow(0 1px 2px #0008); }
.roundel.xl { width: 104px; height: 104px; filter: drop-shadow(0 8px 18px #000a); }

.roundel.md { width: 34px; height: 34px; filter: drop-shadow(0 1px 2px #0006); }
.ai-head { display: flex; gap: 10px; align-items: center; margin-top: 6px; }
.ai-status { font-size: 16px; font-weight: 600; margin: 12px 0; min-height: 2.6em; color: var(--ink); }
.picks { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 6px; }
.picks.two { margin-top: 8px; }
.pick { display: flex; flex-direction: column; align-items: flex-start; gap: 3px; text-align: left; padding: 10px 12px; border-radius: 12px; border: 1px solid #0002; background: #fff; cursor: pointer; font: inherit; color: inherit; min-height: 56px; }
.pick b { display: flex; align-items: center; gap: 4px; font-size: 15px; }
.pick span { font-size: 12px; color: var(--ink-2); }
.pick.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); background: #f5f9fc; }
.powers { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-top: 6px; }
.pick.power { align-items: center; padding: 8px 4px; min-height: 0; }
.pick.power b { font-size: 13px; }
.seg.small button { padding: 6px 8px; font-size: 13px; }
@media (max-width: 420px) { .picks { grid-template-columns: 1fr; } }
