:root {
  --bg: #1d3350;
  --panel: rgba(14, 21, 33, 0.66);
  --card: rgba(16, 24, 38, 0.94);
  --line: #3a4d6b;
  --text: #eef2fa;
  --dim: #9aabbf;
  --gold: #e0ab34;
  --btn: #26354d;
  --btn-hover: #34486a;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font: 14px system-ui, sans-serif; }
#map { position: fixed; inset: 0; width: 100%; height: 100%; cursor: crosshair; }
body.in-menu #map { cursor: default; }
body.in-menu #hud, body.in-menu #side, body.in-menu #bottom { display: none; }

.panel { position: fixed; background: var(--panel); border: 1px solid rgba(255, 255, 255, 0.06); border-radius: 10px; padding: 10px 12px; }
.label { color: var(--dim); margin-right: 8px; }
.row { display: flex; justify-content: space-between; gap: 16px; margin: 2px 0; }
button { background: var(--btn); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 5px 11px; font: inherit; cursor: pointer; }
button:hover { background: var(--btn-hover); }
button.on { background: var(--gold); border-color: var(--gold); color: #141414; font-weight: 600; }
.seg { display: flex; gap: 4px; }

#hud { top: 10px; left: 10px; min-width: 230px; }
.clock { display: flex; justify-content: space-between; align-items: baseline; padding-bottom: 6px; margin-bottom: 6px; border-bottom: 1px solid rgba(255, 255, 255, 0.08); }
#clock { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
#clock.low { color: #ff7b6b; }
.bar { position: relative; height: 7px; background: var(--btn); border-radius: 4px; margin: 4px 0 6px; }
#fill { height: 100%; background: var(--gold); border-radius: 4px; }
#attacks { margin-top: 6px; color: #ffcf8a; font-size: 13px; }
#attacks .in { color: #ff7b6b; font-weight: 600; }
#attacks .out { color: #ffd54a; }
#hud.hit { animation: hit 0.9s ease-out; }
@keyframes hit { 0%, 30% { box-shadow: 0 0 0 3px #ff4632, 0 0 24px #ff4632; } 100% { box-shadow: none; } }
#map { touch-action: none; }

/* Panels never block the map: clicks, drags and the wheel pass through them to the map below.
   Only their buttons take input. */
#hud, #side, #bottom, #zoomctl { pointer-events: none; }
#side button, #bottom button, #zoomctl button { pointer-events: auto; }
#zoomctl { bottom: 10px; left: 10px; display: flex; gap: 4px; padding: 6px; }
#zoomctl button { min-width: 34px; font-weight: 700; }
body.in-menu #zoomctl { display: none; }
#feed { display: flex; flex-direction: column; gap: 2px; font-size: 13px; max-width: 260px; }
#feed:empty { display: none; }
#tip { position: fixed; z-index: 6; pointer-events: none; background: rgba(10, 14, 22, 0.92); border: 1px solid rgba(255, 255, 255, 0.12); border-radius: 8px; padding: 8px 12px; font-size: 13px; line-height: 1.5; font-variant-numeric: tabular-nums; min-width: 190px; }
#tip b { font-size: 14px; }
#tip .r { display: flex; justify-content: space-between; gap: 16px; }
#tip .r span:first-child { color: var(--dim); }

#side { top: 10px; right: 10px; display: flex; flex-direction: column; gap: 8px; }
.side-row { display: flex; justify-content: space-between; gap: 8px; }
#board { border-collapse: collapse; font-variant-numeric: tabular-nums; }
#board td { padding: 1px 6px; white-space: nowrap; }
#board td.rank { color: var(--dim); padding-left: 0; }
#board tr.gap td { padding: 0; line-height: 0.6; color: var(--dim); }
#board td:nth-child(n+3) { text-align: right; }
#board tr.me { color: var(--gold); font-weight: 600; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; }

#bottom { bottom: 10px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 10px; white-space: nowrap; }
#shares button { font-variant-numeric: tabular-nums; }
#shares button b { font-weight: 600; margin-left: 6px; }
#hover { color: var(--dim); min-width: 150px; }

#msg, #paused, #start { position: fixed; top: 14px; left: 50%; transform: translateX(-50%); background: rgba(14, 21, 33, 0.92); padding: 8px 14px; border-radius: 6px; pointer-events: none; z-index: 5; }
#msg, #paused { top: 56px; }
#start { font-weight: 600; color: var(--gold); }

#coach { position: fixed; top: 14px; left: 50%; transform: translateX(-50%); z-index: 5; display: flex; align-items: center; gap: 10px; max-width: calc(100% - 20px); background: rgba(14, 21, 33, 0.92); border: 1px solid var(--gold); padding: 8px 10px 8px 14px; border-radius: 6px; }
#coach button { padding: 4px 10px; flex: none; }
#coach button.primary { margin: 0; font-size: 14px; }
.focus { outline: 2px solid var(--gold); outline-offset: 2px; border-radius: 4px; }
body.tutorial .clock { display: none; }
.screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(8, 14, 24, 0.45); z-index: 10; }
.card { background: var(--card); border: 1px solid rgba(255, 255, 255, 0.08); border-radius: 14px; padding: 26px 30px; width: 100%; max-width: 440px; max-height: 100%; overflow-y: auto; box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45); display: flex; flex-direction: column; gap: 8px; }
.card.small { max-width: 360px; text-align: center; }
.graph { display: block; width: 100%; height: 160px; }
#takenBox ul { list-style: none; padding: 0; margin: 0 0 6px; max-height: 8.5em; overflow-y: auto; text-align: left; color: var(--dim); line-height: 1.4; }
.card h1 { margin: 0; font-size: 40px; letter-spacing: 1px; }
.card h2 { margin: 0 0 8px; }
.card h3 { margin: 12px 0 2px; font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: var(--dim); }
.card .sub { margin: 2px 0 6px; color: var(--dim); }
.card ul { margin: 0 0 8px; padding-left: 18px; line-height: 1.5; }
.card li { margin-bottom: 6px; }
button.primary { background: var(--gold); border-color: var(--gold); color: #141414; font-weight: 700; padding: 10px; font-size: 16px; margin-top: 10px; }
button.primary:hover { background: #f0bd4a; }
button.ghost { background: transparent; padding: 8px; }
button.ghost:hover { background: var(--btn); }
.seg.wide button { flex: 1; }
.seg.grid { display: grid; grid-template-columns: repeat(3, 1fr); }

.card .note { margin: 2px 0 0; font-size: 12px; color: var(--dim); min-height: 1em; }
#lineup .lv { display: flex; align-items: center; gap: 10px; padding: 3px 0; }
#lineup .name { flex: 1; }
#lineup .name small { color: var(--dim); margin-left: 6px; }
#lineup .count { width: 22px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
#lineup button { width: 30px; padding: 3px 0; }
#lineup .seg button { width: auto; padding: 5px 0; }
#oneLevel { margin-bottom: 4px; }
/* Summary and Play stay in view at the bottom of the card however far it scrolls. */
.card .foot { position: sticky; bottom: -26px; margin: 6px -30px -26px; padding: 8px 30px 22px; background: var(--card); border-top: 1px solid rgba(255, 255, 255, 0.08); display: flex; flex-direction: column; gap: 4px; }
#summary { margin: 0; text-align: center; color: var(--dim); font-size: 13px; }
.card .foot button.primary { margin-top: 2px; }

/* map picker */
#mapPick { display: flex; align-items: center; gap: 12px; width: 100%; padding: 6px; text-align: left; }
#mapPick canvas, .mapTile canvas { display: block; width: 96px; height: 56px; border-radius: 4px; border: 1px solid var(--line); }
#mapPick .info { flex: 1; display: flex; flex-direction: column; gap: 2px; }
#mapPick small { color: var(--dim); font-size: 12px; }
#mapPick .change { color: var(--dim); font-size: 12px; padding-right: 6px; }
.card.wide { max-width: 760px; }
#mapSearch { width: 100%; background: var(--btn); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 7px 10px; font: inherit; }
#regions { display: flex; flex-wrap: wrap; gap: 4px; }
#regions button { font-size: 13px; padding: 4px 10px; }
#mapGrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin: 4px 0; }
.mapTile { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px; }
.mapTile canvas { width: 100%; height: auto; aspect-ratio: 96 / 56; }
.mapTile .tname { font-weight: 600; }
.mapTile .tbadge { font-size: 12px; color: var(--dim); }
.mapTile.on .tbadge { color: #141414; }
.mapTile.on canvas { border-color: #141414; }
#mapGrid .none { grid-column: 1 / -1; margin: 12px 0; text-align: center; color: var(--dim); }

#stats { margin: 4px auto 6px; border-collapse: collapse; font-variant-numeric: tabular-nums; }
#stats td { padding: 2px 10px; }
#stats td:first-child { color: var(--dim); text-align: left; }
#stats td:last-child { text-align: right; font-weight: 600; }

.card .links { display: flex; gap: 4px; }
.card .links button { flex: 1; }
.stbl { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.stbl th { color: var(--dim); font-weight: 400; text-align: right; padding: 2px 6px; }
.stbl td { padding: 2px 6px; text-align: right; }
.stbl th:first-child, .stbl td:first-child { text-align: left; padding-left: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 150px; }
.stbl.top td:last-child { font-weight: 600; }
.stscroll { max-height: 190px; overflow-y: auto; }
#statsBody .none { color: var(--dim); text-align: center; margin: 14px 0; }

[hidden] { display: none !important; }

@media (max-width: 700px) {
  #side { top: auto; bottom: 64px; right: 10px; }
  #zoomctl { bottom: 116px; }
  #board { display: none; }
  #bottom { justify-content: center; width: calc(100% - 20px); gap: 6px; padding: 8px; }
  #shares button { padding: 5px 7px; }
  #shares button b { margin-left: 3px; }
  #hover { display: none; }
  #coach { top: auto; bottom: 150px; }
  .card { padding: 20px; }
  .card .foot { bottom: -20px; margin: 6px -20px -20px; padding: 8px 20px 16px; }
  .card h1 { font-size: 32px; }
  #mapGrid { grid-template-columns: repeat(2, 1fr); }
}

/* How to play */
.how { display: flex; flex-direction: column; gap: 12px; margin-bottom: 8px; }
.how section { border-left: 2px solid var(--line); padding-left: 12px; }
.how h3 { margin: 0 0 3px; }
.how p { margin: 0; line-height: 1.45; }
.how p.dim { color: var(--dim); font-size: 12.5px; margin-top: 5px; }
.how .chips { display: flex; flex-wrap: wrap; gap: 5px 12px; margin: 2px 0; }
.how .chips span { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.how .chips i { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.how .chips i.multi { background: linear-gradient(90deg, #4a8fe0 0 33%, #c05ab0 33% 66%, #5cc0a0 66%); }
.how .keys { display: grid; grid-template-columns: auto 1fr; gap: 5px 14px; align-items: center; }
.how .keys span:nth-child(odd) { color: var(--dim); }
.how kbd { display: inline-block; min-width: 1.4em; padding: 0 5px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; background: var(--btn); color: var(--text); font: 12px system-ui, sans-serif; text-align: center; line-height: 1.6; }
@media (min-width: 860px) {
  .card.howcard { max-width: 780px; }
  .how { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 26px; align-items: start; }
}
