* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, -apple-system, "Segoe UI", sans-serif; color: #1f2937; background: #f3f1ea; }
button { font: inherit; padding: 0.35rem 0.75rem; border: 1px solid #9ca3af; background: #fff; border-radius: 6px; cursor: pointer; }
button:hover { background: #f9fafb; }
button.primary { background: #1f2937; color: #fff; border-color: #1f2937; }
button:disabled { opacity: 0.45; cursor: default; }
.top { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem 1rem; padding: 0.5rem 1rem; background: #14532d; color: #f0fdf4; }
.top h1 { margin: 0; font-size: 1.4rem; letter-spacing: 0.02em; }
.top .back { color: #bbf7d0; font-size: 0.85rem; text-decoration: none; }
.top .status { flex: 1 1 18rem; margin: 0; font-weight: 600; }
.top .tools { display: flex; gap: 0.4rem; }
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 24rem; gap: 0.8rem; padding: 0.8rem; }
@media (max-width: 1000px) { .layout { grid-template-columns: minmax(0, 1fr); } }
.board, .side, .side > * { min-width: 0; }
.board { background: #dbe7ef; border-radius: 10px; padding: 0.4rem; }
#map { width: 100%; height: auto; display: block; }
.edge { stroke: #6b7280; stroke-width: 2; }
.edge.sea { stroke: #2563eb; stroke-dasharray: 6 5; stroke-width: 1.6; opacity: 0.7; }
.terr { cursor: pointer; }
.terr circle.body { stroke-width: 5; }
.terr .count { fill: #fff; font-weight: 800; font-size: 16px; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.terr .count.dark { fill: #111827; }
.label { font-size: 11px; text-anchor: middle; fill: #111827; font-weight: 600; pointer-events: none; paint-order: stroke; stroke: #e6eef4; stroke-width: 5px; stroke-linejoin: round; }
.terr .badge { font-size: 10px; font-weight: 700; fill: #111827; text-anchor: start; pointer-events: none; paint-order: stroke; stroke: #fff; stroke-width: 3px; }
path.edge { fill: none; }
.terr .ring { fill: none; stroke: #111827; stroke-width: 3; }
.terr .target { fill: none; stroke: #f59e0b; stroke-width: 4; stroke-dasharray: 5 4; }
.terr.flash circle.body { filter: drop-shadow(0 0 6px #f59e0b); }
.legend { display: flex; flex-wrap: wrap; gap: 0.3rem 0.8rem; padding: 0.4rem 0.3rem 0.1rem; font-size: 0.82rem; }
.legend .chip { display: inline-flex; align-items: center; gap: 0.3rem; }
.legend .sw { width: 0.9rem; height: 0.9rem; border-radius: 50%; border: 3px solid; background: #fff; }
.side { display: grid; gap: 0.6rem; align-content: start; }
.panel { background: #fff; border-radius: 10px; padding: 0.7rem 0.85rem; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08); }
.panel h2 { margin: 0 0 0.4rem; font-size: 1.05rem; }
.panel h3 { margin: 0.6rem 0 0.3rem; font-size: 0.95rem; }
.panel p { margin: 0.35rem 0; }
.small { font-size: 0.85rem; color: #4b5563; }
.seats { display: grid; gap: 0.2rem; margin: 0.3rem 0; }
.seat { display: flex; align-items: center; gap: 0.4rem; font-size: 0.9rem; }
.seat .dot { width: 0.8rem; height: 0.8rem; border-radius: 50%; }
.seat.now { font-weight: 700; }
.seat.out { text-decoration: line-through; opacity: 0.5; }
.roster { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.roster th, .roster td { padding: 0.2rem 0.3rem; border-bottom: 1px solid #e5e7eb; text-align: right; }
.roster th:first-child, .roster td:first-child { text-align: left; }
.roster tr.pick { cursor: pointer; }
.roster tr.pick:hover { background: #fef3c7; }
.actions { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.5rem 0 0.2rem; }
.log { max-height: 16rem; overflow: auto; margin: 0; padding-left: 1.4rem; font-size: 0.82rem; }
.log li { margin: 0.15rem 0; }
.log li.battle { color: #1f2937; }
.result { padding: 0.5rem 0.6rem; border-radius: 8px; background: #f3f4f6; margin: 0.4rem 0; }
.result.win { background: #dcfce7; }
.result.loss { background: #fee2e2; }
.modal { position: fixed; inset: 0; background: rgba(17, 24, 39, 0.45); display: grid; place-items: center; z-index: 10; padding: 1rem; }
.modal.hidden { display: none; }
.modal-box { background: #fff; border-radius: 12px; padding: 1rem 1.2rem; max-width: 36rem; width: 100%; max-height: 90vh; overflow: auto; }
.modal-box label { display: block; margin: 0.4rem 0; }
.pct { font-variant-numeric: tabular-nums; }

/* tables scroll inside their panel or dialog; on phones the less essential columns hide */
.tw { overflow-x: auto; max-width: 100%; }
@media (max-width: 560px) {
  .roster .opt { display: none; }
  .modal { padding: 0.4rem; }
  .modal-box { padding: 0.8rem 0.9rem; }
}
.modal-box .actions.sticky { position: sticky; bottom: -1rem; background: #fff; padding: 0.5rem 0 0.4rem; margin-bottom: 0; }
.lengths { display: grid; grid-template-columns: max-content 1fr; gap: 0.5rem 0.8rem; align-items: center; margin: 0.6rem 0; }
.modal-box label { display: block; margin: 0.35rem 0; }
