:root {
  --bg: #0b0e13;
  --bg-2: #11151d;
  --panel: #0e1219;
  --sea: #0b0e13;
  --line: #1d2733;
  --line-2: #2a3645;
  --ink: #e7edf4;
  --ink-dim: #93a1b3;
  --ink-faint: #5d6b7d;
  --accent: #4dd6c1;
  --accent-2: #ffd166;
  --land: #1b2530;
  --land-hi: #2b3a49;
  --stroke: #3a4a5c;
  --select: #ffd166;
  --radius: 10px;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: "Space Grotesk", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

#app {
  display: grid;
  grid-template-columns: 1fr 340px;
  grid-template-rows: auto 1fr;
  grid-template-areas: "top top" "stage panel";
  height: 100vh;
  height: 100dvh;
}

/* ---- top bar ---- */
#topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 12px 18px;
  background: linear-gradient(180deg, var(--bg-2), var(--bg));
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.brand { display: flex; flex-direction: column; line-height: 1.05; }
.brand .mark { font-size: 19px; font-weight: 700; letter-spacing: .04em; }
.brand .mark b { color: var(--accent); font-weight: 700; }
.brand .tag { font-size: 11px; color: var(--ink-faint); letter-spacing: .02em; margin-top: 2px; }

.controls { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.seg { display: inline-flex; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button {
  font-family: var(--mono); font-size: 12px; letter-spacing: .03em;
  color: var(--ink-dim); background: transparent; border: 0; padding: 7px 13px;
  cursor: pointer; transition: background .15s, color .15s;
}
.seg button:hover:not(:disabled) { color: var(--ink); background: var(--bg-2); }
.seg button.on { color: var(--bg); background: var(--accent); font-weight: 600; }
.seg button:disabled { color: var(--ink-faint); cursor: not-allowed; opacity: .55; }

.search { position: relative; }
.search input {
  font-family: var(--mono); font-size: 13px; color: var(--ink);
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 12px; width: 190px; outline: none;
}
.search input:focus { border-color: var(--accent); }
.results {
  position: absolute; top: calc(100% + 6px); right: 0; width: 260px; z-index: 30;
  background: var(--panel); border: 1px solid var(--line-2); border-radius: 8px;
  overflow: hidden; box-shadow: 0 14px 40px rgba(0,0,0,.5);
}
.results button {
  display: flex; justify-content: space-between; gap: 10px; width: 100%;
  text-align: left; background: transparent; border: 0; color: var(--ink);
  padding: 9px 12px; cursor: pointer; font-family: var(--sans); font-size: 13px;
  border-bottom: 1px solid var(--line);
}
.results button:last-child { border-bottom: 0; }
.results button:hover { background: var(--bg-2); }
.results .code { font-family: var(--mono); font-size: 11px; color: var(--ink-faint); }

/* ---- stage / map ---- */
#stage { grid-area: stage; position: relative; background:
  radial-gradient(120% 90% at 50% 0%, #0d141d 0%, var(--sea) 70%); overflow: hidden; }
#map { width: 100%; height: 100%; display: block; cursor: grab; }
#map:active { cursor: grabbing; }

.seat {
  fill: var(--land);
  stroke: var(--stroke);
  stroke-width: .25;
  stroke-linejoin: round;
  transition: fill .12s ease;
  cursor: pointer;
}
.seat:hover { fill: var(--land-hi); }
.seat.dim { opacity: .28; }
.seat.match { stroke: var(--accent); stroke-width: .6; }
.seat.sel {
  stroke: var(--select);
  stroke-width: .9;
  paint-order: stroke;
}
#seats.has-data .seat { stroke-width: .18; }

#tooltip {
  position: absolute; z-index: 20; pointer-events: none;
  background: rgba(8,11,16,.94); border: 1px solid var(--line-2);
  border-radius: 7px; padding: 6px 10px; font-size: 12px; color: var(--ink);
  transform: translate(-50%, -130%); white-space: nowrap;
  box-shadow: 0 6px 22px rgba(0,0,0,.5);
}
#tooltip .t-code { font-family: var(--mono); color: var(--accent); font-size: 10px; }
#tooltip .t-state { color: var(--ink-faint); font-size: 11px; }
#tooltip .t-win { margin-top: 4px; padding-top: 4px; border-top: 1px solid var(--line);
  font-size: 11px; color: var(--ink-dim); display: flex; align-items: center; gap: 6px; }
#tooltip .pill { font-size: 10px; padding: 1px 6px; }

/* coalition seat-share bar (overview) */
.sharebar { display: flex; height: 12px; border-radius: 4px; overflow: hidden; margin: 16px 0 8px; }
.sharebar span { display: block; height: 100%; }
.sharebar-key { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 11px; color: var(--ink-dim); }
.sharebar-key b { color: var(--ink); font-family: var(--mono); font-weight: 500; }

#reset {
  position: absolute; left: 16px; bottom: 16px; z-index: 15;
  font-family: var(--mono); font-size: 12px; color: var(--ink);
  background: rgba(14,18,25,.9); border: 1px solid var(--line-2);
  border-radius: 8px; padding: 8px 12px; cursor: pointer; backdrop-filter: blur(6px);
}
#reset:hover { border-color: var(--accent); }

#loading {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-family: var(--mono); font-size: 13px; color: var(--ink-faint);
  pointer-events: none;
}
#loading[hidden] { display: none; }

/* ---- panel ---- */
#panel {
  grid-area: panel; background: var(--panel); border-left: 1px solid var(--line);
  padding: 20px 18px; overflow-y: auto;
}
#panel h2 { font-size: 16px; margin: 0 0 6px; letter-spacing: .01em; }
.muted { color: var(--ink-dim); }
.src { font-size: 11px; margin-top: 22px; }

.legend { margin: 20px 0 10px; display: flex; flex-direction: column; gap: 5px; }
.legend .row { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--ink-dim); }
.legend .sw { width: 12px; height: 12px; border-radius: 3px; flex: 0 0 auto; }

.summary { margin: 6px 0 0; display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; }
.summary dt { color: var(--ink-faint); font-size: 12px; }
.summary dd { margin: 0; font-family: var(--mono); font-size: 13px; text-align: right; }

/* seat panel */
.seat-head { border-bottom: 1px solid var(--line); padding-bottom: 14px; margin-bottom: 14px; }
.seat-head .kicker { font-family: var(--mono); font-size: 11px; color: var(--accent); letter-spacing: .08em; }
.seat-head h2 { font-size: 22px; margin: 4px 0 2px; }
.seat-head .where { font-size: 13px; color: var(--ink-dim); }
.seat-head .where b { color: var(--ink); font-weight: 500; }

.rows { display: grid; grid-template-columns: auto 1fr; gap: 10px 14px; align-items: baseline; }
.rows dt { color: var(--ink-faint); font-size: 12px; white-space: nowrap; }
.rows dd { margin: 0; text-align: right; font-size: 14px; }
.rows dd.mono { font-family: var(--mono); }

.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600;
  font-family: var(--mono); color: #0b0e13; }
.placeholder { color: var(--ink-faint); font-style: italic; font-size: 13px; }

.note { margin-top: 18px; padding: 11px 12px; background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; font-size: 12px; color: var(--ink-dim); line-height: 1.5; }
.note b { color: var(--ink); }

@media (max-width: 820px) {
  #app { grid-template-columns: 1fr; grid-template-rows: auto 1fr auto;
    grid-template-areas: "top" "stage" "panel"; }
  #panel { border-left: 0; border-top: 1px solid var(--line); max-height: 42vh; }
  .controls { width: 100%; }
}
