:root {
  --bg: #ffffff;
  --panel: rgba(255, 255, 255, 0.96);
  --fg: #1b1b22;
  --muted: #6b6b78;
  --line: #e2e2ea;
  --soft: #f3f3f7;
  --accent: #2b6cff;
  --accent-fg: #ffffff;
  --ok: #1f9d55;
  --warn: #c98a00;
  --bad: #d23c3c;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.14);
  --panel-w: 380px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121217;
    --panel: rgba(24, 24, 31, 0.96);
    --fg: #ececf1;
    --muted: #9a9aa8;
    --line: #2e2e39;
    --soft: #1f1f28;
    --accent: #6e9bff;
    --accent-fg: #0b0b10;
    --ok: #3ecf6e;
    --warn: #f0b429;
    --bad: #ff6b6b;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.5);
  }
  .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(0.92) contrast(0.9); }
  .leaflet-container { background: #1a1a20; }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; } /* .host, .row etc. set display, which would beat the attribute */
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--fg); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overflow: hidden; }

#map { position: fixed; inset: 0 var(--panel-w) 0 0; }
#map.picking { cursor: crosshair; }

#panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: var(--panel-w);
  background: var(--panel); border-left: 1px solid var(--line); box-shadow: var(--shadow);
  overflow-y: auto; padding: 18px 18px 28px; z-index: 1000;
}
.sheet-toggle { display: none; }

h1 { font-size: 22px; margin: 4px 0 6px; }
h2 { font-size: 19px; margin: 2px 0; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 20px 0 8px; }
.muted { color: var(--muted); }
.eyebrow { font-size: 12px; color: var(--muted); }
.eyebrow strong { color: var(--fg); letter-spacing: 0.12em; }
code { font-size: 12px; background: var(--soft); padding: 1px 4px; border-radius: 4px; }
a { color: var(--accent); }

label { display: block; font-size: 12px; color: var(--muted); margin: 12px 0 4px; }
label.check { display: flex; gap: 8px; align-items: center; color: var(--fg); font-size: 13px; }
input[type=text], input:not([type]), input[type=number] {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--fg); font: inherit;
}
input[type=number] { width: 86px; flex: none; }
input[type=range] { flex: 1; accent-color: var(--accent); }
.room-input { text-transform: uppercase; letter-spacing: 0.25em; font-weight: 600; }
.row { display: flex; gap: 8px; align-items: center; }

button {
  font: inherit; font-weight: 600; border: 0; border-radius: 8px; padding: 9px 14px; cursor: pointer;
  background: var(--accent); color: var(--accent-fg);
}
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.secondary { background: var(--soft); color: var(--fg); border: 1px solid var(--line); }
button.link { background: none; color: var(--muted); padding: 4px; font-weight: 400; text-decoration: underline; }
form > button[type=submit] { width: 100%; margin-top: 14px; }

.room-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.conn { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--bad); margin-left: 4px; vertical-align: middle; }
.conn.on { background: var(--ok); }

.banner { position: relative; margin: 14px 0; padding: 12px 14px; border-radius: 10px; background: var(--soft); border: 1px solid var(--line); font-size: 13px; }
.banner ol { margin: 6px 0; padding-left: 18px; }
.banner li { margin: 3px 0; }
.banner p { margin: 6px 0 0; font-size: 12px; }
.banner-close { position: absolute; top: 4px; right: 4px; background: none; color: var(--muted); padding: 2px 8px; font-size: 18px; }

.photo { margin: 14px 0 0; }
.photo img { width: 100%; max-height: 260px; object-fit: contain; background: #000; border-radius: 8px; display: block; }
.photo figcaption { font-size: 11px; color: var(--muted); margin-top: 4px; }

.guess { margin-top: 14px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; }
.host { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.host button { flex: 1 1 auto; }
.note { font-size: 12px; margin: 8px 0 0; }

.answer { margin-top: 14px; padding: 10px 14px; border-radius: 10px; background: var(--soft); border-left: 4px solid var(--fg); }
.answer .big { font-size: 18px; font-weight: 700; }

.cards { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.card { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: var(--bg); }
.card.me { border-color: var(--accent); }
.card-top { display: flex; align-items: center; gap: 8px; }
.rank { font-weight: 700; color: var(--muted); width: 1.6em; text-align: right; flex: none; }
.swatch { width: 12px; height: 12px; border-radius: 50%; flex: none; border: 2px solid rgba(255, 255, 255, 0.8); box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25); }
.name { font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.total { font-weight: 700; font-variant-numeric: tabular-nums; font-size: 16px; }
.status { font-size: 12px; color: var(--muted); }
.status.ok { color: var(--ok); font-weight: 600; }
.tag { font-size: 10px; text-transform: uppercase; letter-spacing: 0.05em; padding: 1px 5px; border-radius: 4px; background: var(--soft); color: var(--muted); }
.card-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 12px; margin-top: 8px; font-size: 12px; font-variant-numeric: tabular-nums; }
.card-grid .k { color: var(--muted); }
.card-grid b { font-weight: 600; }
.bar { height: 4px; border-radius: 2px; background: var(--soft); margin-top: 8px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); }

.standings { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.standings td { padding: 5px 4px; border-bottom: 1px solid var(--line); }
.standings td:first-child { color: var(--muted); width: 2em; }
.standings td:last-child { text-align: right; font-weight: 700; }

.toast {
  position: fixed; left: 50%; top: 16px; transform: translateX(-50%); z-index: 2000; max-width: min(90vw, 520px);
  background: var(--fg); color: var(--bg); padding: 8px 14px; border-radius: 8px; box-shadow: var(--shadow); font-size: 13px;
}

/* tabs: live round | daily */
.tabs { display: flex; gap: 4px; margin: 12px 0 2px; padding: 3px; background: var(--soft); border: 1px solid var(--line); border-radius: 10px; }
.tab { flex: 1; background: none; color: var(--muted); padding: 6px 10px; border-radius: 7px; }
.tab[aria-selected=true] { background: var(--bg); color: var(--fg); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15); }

/* daily board */
select {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--fg); font: inherit;
}
.daily-pick-row label { margin-top: 10px; }
.daily-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; margin-top: 14px; }
.room-link { font-size: 12px; white-space: nowrap; margin-top: 4px; }
#board-view .eyebrow a { color: var(--muted); }
.daily-play .photo { margin-top: 6px; }
.daily-play .guess > button, .daily-play .guess > form > button { width: 100%; margin-top: 12px; }
#d-review button { width: 100%; margin-top: 10px; }

.table-wrap { overflow-x: auto; margin: 0 -2px; }
.daily-table { width: 100%; border-collapse: separate; border-spacing: 2px; table-layout: fixed; font-variant-numeric: tabular-nums; font-size: 12px; }
.daily-table th { font-size: 11px; font-weight: 600; color: var(--muted); padding: 4px 0; text-align: center; }
.daily-table .rk { width: 1.7em; text-align: right; padding-right: 2px; color: var(--muted); font-weight: 600; }
.daily-table .pl { text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-left: 2px; }
.daily-table .pl .swatch { display: inline-block; vertical-align: -1px; margin-right: 5px; width: 10px; height: 10px; }
.daily-table tr.me .nm { font-weight: 700; }
.daily-table th.rh { width: 34px; cursor: pointer; border-radius: 6px; }
.daily-table th.rh:hover { background: var(--soft); color: var(--fg); }
.daily-table .tot { width: 52px; text-align: right; padding-right: 2px; }
.daily-table th.tot { font-size: 13px; }
.daily-table td.tot b { font-size: 13px; }
.daily-table .tot small { display: block; font-size: 10px; color: var(--muted); line-height: 1.1; }
.daily-table .cell { text-align: center; padding: 6px 0; border-radius: 6px; cursor: pointer; letter-spacing: -0.02em; }
.daily-table .cell.none { color: var(--muted); cursor: default; }
.daily-table .cell.hidden { color: var(--muted); background: var(--soft); font-size: 10px; opacity: 0.8; }
.daily-table .cell.b0 { background: rgba(31, 157, 85, 0.24); }
.daily-table .cell.b1 { background: rgba(214, 170, 0, 0.26); }
.daily-table .cell.b2 { background: rgba(240, 130, 20, 0.26); }
.daily-table .cell.b3 { background: rgba(220, 60, 60, 0.24); }
.daily-table .cell.b4 { background: rgba(110, 110, 125, 0.28); }
.daily-table .sel { box-shadow: inset 0 0 0 2px var(--accent); }
.daily-table th.rh.sel { color: var(--fg); }
.daily-table .empty { text-align: center; padding: 12px 0; }

.round-rows { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 4px; font-variant-numeric: tabular-nums; }
.round-rows li { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.round-rows .nm { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.round-rows .muted { font-size: 12px; }
.answer .thumb { width: 100%; max-height: 160px; object-fit: contain; background: #000; border-radius: 8px; margin-top: 8px; display: block; }
.answer .credit { font-size: 11px; color: var(--muted); margin-top: 2px; }

.spoiler-row { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; padding: 10px 12px; border: 1px dashed var(--line); border-radius: 10px; font-size: 12px; }
.share { margin-top: 14px; }
.share .row button { flex: 1 1 auto; white-space: nowrap; padding-inline: 10px; }
.share-preview {
  white-space: pre-wrap; word-break: break-word; margin: 8px 0 0; padding: 8px 10px; border-radius: 8px;
  background: var(--soft); border: 1px solid var(--line); font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.daily-link { display: block; margin-top: 8px; font-size: 12px; word-break: break-all; }

/* map markers */
.pin { width: 18px; height: 18px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.45); }
.pin-answer {
  width: 26px; height: 26px; border-radius: 50%; background: #111; border: 3px solid #fff;
  box-shadow: 0 0 0 3px #111, 0 2px 8px rgba(0, 0, 0, 0.5); display: grid; place-items: center; color: #ffd84d; font-size: 15px; line-height: 1;
}
.leaflet-tooltip.pin-label { font-weight: 600; padding: 2px 6px; border-radius: 6px; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); }
.leaflet-tooltip.pin-label-answer { background: #111; color: #fff; border-color: #111; }
.leaflet-tooltip.pin-label-answer::before { border-top-color: #111; }

@media (max-width: 700px) {
  #map { inset: 0 0 var(--sheet-h, 46vh) 0; }
  #panel {
    top: auto; left: 0; width: auto; height: var(--sheet-h, 46vh); border-left: 0; border-top: 1px solid var(--line);
    border-radius: 14px 14px 0 0; padding: 22px 16px 24px;
  }
  body.sheet-collapsed { --sheet-h: 96px; }
  .sheet-toggle {
    display: block; position: absolute; top: 0; left: 50%; transform: translateX(-50%);
    width: 96px; height: 22px; padding: 0; background: none;
  }
  .sheet-toggle::before { content: ""; display: block; width: 44px; height: 5px; margin: 8px auto 0; border-radius: 3px; background: var(--line); }
  .photo img { max-height: 180px; }
  .daily-table th.rh { width: 30px; }
  .daily-table .tot { width: 46px; }
  .daily-table { font-size: 11px; }
}

/* Player code (minimal; the redesign restyles it) */
.code-box { margin-top: 1.25rem; }
.code-box summary { cursor: pointer; }
.code-box code { font-size: 1.05rem; letter-spacing: 0.04em; user-select: all; word-break: break-all; }
.card-top .release { margin-left: auto; font-size: 0.85em; }
