/* doom_stats UI — hand-rolled dark theme, no CSS framework.
   Layout: sticky header + filter bar, virtualized table, side drawer. */

:root {
  color-scheme: dark;
  --bg: #101114;
  --bg-accent: #16181d;
  --panel: #1a1c22;
  --panel-raised: #212329;
  --border: #2a2c33;
  --text: #e8e6e3;
  --muted: #8c8f98;
  --accent: #e5484d; /* DOOM red */
  --accent-soft: rgba(229, 72, 77, 0.14);
  --live: #46b45e;
  --warn: #e0a33c;
  --row-h: 44px;
  --cols: 2.5rem minmax(0, 1.5fr) 8.5rem 5rem 9rem 7.5rem 6.5rem 4rem 6.5rem;
  --radius: 6px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  background:
    radial-gradient(1200px 500px at 50% -200px, rgba(229, 72, 77, 0.06), transparent),
    var(--bg);
  color: var(--text);
  font: 14.5px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}

.muted { color: var(--muted); }

/* Visually hidden, still announced by screen readers. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 1rem;
}

/* ---------------------------------------------------------------- header */

.header { padding: 1rem 0 0.75rem; }

.title-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.title-row h1 {
  margin: 0;
  font-size: 1.45rem;
  letter-spacing: 0.02em;
}

.live-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.auth-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.pill {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 0.18rem 0.55rem;
  border-radius: 99px;
  border: 1px solid var(--border);
}
.pill.live {
  color: var(--live);
  border-color: color-mix(in srgb, var(--live) 40%, transparent);
  background: color-mix(in srgb, var(--live) 12%, transparent);
}
.pill.offline {
  color: var(--muted);
  background: var(--bg-accent);
}
.pill.paused {
  color: var(--warn);
  border-color: color-mix(in srgb, var(--warn) 40%, transparent);
  background: color-mix(in srgb, var(--warn) 12%, transparent);
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
}

.pause, .reset {
  padding: 0.25rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
}
.pause:hover, .reset:hover { border-color: var(--muted); }

/* "updated Xs ago" sits at the right edge of .live-row, so every time its text
   width changes (9s → 10s, 59s → 1m, "loading…") the row grows leftwards and
   shoves the pill and pause button with it. Reserve a fixed slot and align the
   text to its right edge: the counter ticks in place and never moves anything.
   min-width fits the longest label ("updated 59m ago"); tabular-nums keeps the
   digits themselves from jittering inside that slot. */
.updated {
  display: inline-block;
  min-width: 7.5rem;
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.stats-row {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  flex-wrap: wrap;
  margin-top: 0.6rem;
}

.stat-big {
  font-size: 1.25rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.stat-big small {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--muted);
  margin-left: 0.3rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.chips { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-left: auto; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0.6rem;
  border-radius: 99px;
  border: 1px solid var(--border);
  background: var(--panel);
  font-size: 0.8rem;
}
.chip::before {
  content: "";
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--src, var(--muted));
}
.chip.on {
  border-color: color-mix(in srgb, var(--src, var(--accent)) 55%, transparent);
  background: color-mix(in srgb, var(--src, var(--accent)) 16%, var(--panel));
}
.chip.off { opacity: 0.45; filter: saturate(0.4); }
.chip:hover { border-color: var(--muted); }
.chip.on:hover {
  border-color: color-mix(in srgb, var(--src, var(--accent)) 80%, transparent);
}
.chip-count {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}
.chip-players { font-variant-numeric: tabular-nums; font-size: 0.75rem; }

/* --------------------------------------------------------------- filters */

.filters {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  padding: 0.5rem 0.75rem;
  margin: 0.25rem 0 0.75rem;
  background: var(--bg-accent);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* On phones the advanced filters collapse behind this button; the search box
   stays visible. On wider screens the button is hidden and the body's children
   participate directly in the filter row. */
.filters-toggle {
  display: none;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  font-size: 0.85rem;
  white-space: nowrap;
}
.filters-toggle:hover { border-color: var(--muted); }
.filters-body { display: contents; }

.search {
  flex: 1 1 14rem;
  min-width: 10rem;
  max-width: 28rem;
}

input[type="search"] {
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.35rem 0.55rem;
}
input[type="search"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

input[type="checkbox"] { accent-color: var(--accent); }

.multiselect { position: relative; flex: 0 0 auto; }

.multiselect-button {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  width: 10.5rem;
  padding: 0.35rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
}
.multiselect-button:hover { border-color: var(--muted); }
.multiselect-button[aria-expanded="true"] {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}
.multiselect-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: left;
}
.multiselect-caret { color: var(--muted); font-size: 0.7rem; }

.multiselect-panel {
  position: absolute;
  top: calc(100% + 0.3rem);
  left: 0;
  z-index: 50;
  width: min(19rem, calc(100vw - 2rem));
  max-height: 60vh;
  overflow-y: auto;
  padding: 0.35rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
}

.multiselect-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.15rem 0.35rem 0.4rem;
  margin-bottom: 0.25rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.multiselect-clear {
  color: var(--accent);
  font-size: 0.8rem;
  text-transform: none;
  letter-spacing: 0;
}
.multiselect-clear:hover { text-decoration: underline; }

.multiselect-search {
  width: 100%;
  margin-bottom: 0.35rem;
  font: inherit;
  font-size: 0.85rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.3rem 0.45rem;
}
.multiselect-search:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.multiselect-group + .multiselect-group {
  margin-top: 0.25rem;
  padding-top: 0.25rem;
  border-top: 1px solid var(--border);
}
.multiselect-group-head,
.multiselect-option {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.2rem 0.35rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
}
.multiselect-group-head:hover,
.multiselect-option:hover { background: var(--bg-accent); }
.multiselect-group-head { font-weight: 600; }
/* Countries sit under their region head; flat lists (modes, games) do not. */
.multiselect-group .multiselect-option { padding-left: 1.6rem; }
.multiselect-option-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.multiselect-count {
  color: var(--muted);
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
}
.multiselect-option .flag { flex: none; }

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.showing {
  margin-left: auto;
  flex: 0 0 auto;
  width: 11rem;
  font-size: 0.8rem;
  text-align: right;
  white-space: nowrap;
}

/* ----------------------------------------------------------------- table */

.table {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

/* The ARIA table element: everything except the mobile sort toolbar. */
.table-grid {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.thead {
  display: grid;
  grid-template-columns: var(--cols);
  gap: 0 0.5rem;
  align-items: center;
  height: var(--row-h);
  padding: 0 0.75rem;
  border-bottom: 1px solid var(--border);
  background: var(--panel-raised);
}

.th-wrap {
  display: flex;
  align-items: center;
  min-width: 0;
  height: 100%;
}
.th {
  display: block;
  width: 100%;
  text-align: left;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0;
}
.th.sortable { cursor: pointer; }
.th.sortable:hover { color: var(--text); }
.th.sorted { color: var(--text); }
.th-lock { text-align: center; }
.sort-arrow { margin-left: 0.25rem; color: var(--accent); }

.viewport {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.spacer { position: relative; }
.window { position: absolute; top: 0; left: 0; width: 100%; }

.row {
  display: grid;
  grid-template-columns: var(--cols);
  gap: 0 0.5rem;
  align-items: center;
  height: var(--row-h);
  padding: 0 0.75rem;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 60%, transparent);
  cursor: pointer;
}
.row:hover { background: var(--bg-accent); }
.row:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.row.selected {
  background: var(--accent-soft);
  box-shadow: inset 2px 0 0 var(--accent);
}
.row.pending .cell { color: var(--muted); font-style: italic; }

/* Card layout markup: hidden while the table columns are in use. */
.card { display: none; }

.cell {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}
.cell.lock { text-align: center; }
.cell.name { font-weight: 600; }
.cell.map, .cell.mode { font-variant-numeric: normal; }
.cell.players { display: flex; align-items: baseline; gap: 0.25rem; }
/* First WAD name plus a "+N" remainder that stays visible when the name is
   truncated. */
.cell.wads { display: flex; align-items: baseline; gap: 0.3rem; }
.wad-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wad-count { flex: none; color: var(--muted); font-size: 0.75rem; }

.mini {
  font-size: 0.72rem;
  color: var(--muted);
}

.src {
  display: inline-block;
  padding: 0.1rem 0.45rem;
  border-radius: 99px;
  font-size: 0.75rem;
  background: color-mix(in srgb, var(--src, var(--muted)) 18%, transparent);
  border: 1px solid color-mix(in srgb, var(--src, var(--muted)) 45%, transparent);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Country flags are Unicode regional-indicator pairs (see util.js). Keeping
   them in the text font avoids an external stylesheet and its SVG assets; the
   emoji font list keeps the flag glyph from falling back to monochrome boxes on
   platforms that ship a colour emoji font. */
.flag {
  display: inline-block;
  margin-right: 0.15rem;
  font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
  font-size: 1.05em;
  font-style: normal;
  line-height: 1;
  vertical-align: -0.12em;
}

.table-state {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 12rem;
  padding: 0 1rem;
  color: var(--muted);
  font-style: italic;
  text-align: center;
}

/* Compact sort control shown instead of the table header on card layouts. */
.mobile-sort {
  display: none;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.75rem;
  border-bottom: 1px solid var(--border);
  background: var(--panel-raised);
  font-size: 0.8rem;
}
.mobile-sort label { display: flex; align-items: center; gap: 0.4rem; }
.mobile-sort select {
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.2rem 0.4rem;
}
.mobile-sort .sort-dir {
  padding: 0.2rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
}

/* --------------------------------------------------------------- drawer */

.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(8, 9, 11, 0.55);
  z-index: 40;
}

/* The plain-DOM drawers (Nightdive page) start hidden and are toggled with the
   `hidden` attribute; without this, the class display rules above win. */
.backdrop[hidden],
.drawer[hidden] { display: none; }

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(30rem, 100vw);
  background: var(--panel);
  border-left: 1px solid var(--border);
  box-shadow: -1rem 0 3rem rgba(0, 0, 0, 0.45);
  z-index: 50;
  display: flex;
  flex-direction: column;
}

.drawer-header {
  padding: 1rem 1.1rem 0.9rem;
  border-bottom: 1px solid var(--border);
  background:
    linear-gradient(160deg, var(--accent-soft), transparent 60%),
    var(--panel-raised);
  position: relative;
}

.drawer-header .src { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; }

.drawer-header h2 {
  margin: 0.45rem 2.5rem 0.5rem 0;
  font-size: 1.15rem;
  word-break: break-word;
}

.drawer-close {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  width: 1.9rem;
  height: 1.9rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--panel);
  font-size: 1rem;
  line-height: 1;
}
.drawer-close:hover { border-color: var(--muted); }

.drawer-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 1rem 1.1rem 2rem;
}

.drawer-body section { margin-bottom: 1.4rem; }

.drawer-note {
  margin: 0;
  font-size: 0.85rem;
  line-height: 1.55;
}

/* Network statistics drawer. */
.stats-drawer { width: min(40rem, 100vw); }

/* Settings drawer. */
.settings-drawer { width: min(26rem, 100vw); }

.settings-form {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  margin-bottom: 1.6rem;
}

.settings-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.85rem;
}

.settings-field select {
  min-width: 11rem;
  max-width: 60%;
  font: inherit;
  font-size: 0.8rem;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.25rem 0.45rem;
}
.settings-field select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.settings-about {
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.settings-list {
  margin: 0;
  font-size: 0.82rem;
}
.settings-list div {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.2rem 0;
}
.settings-list dt { color: var(--muted); }
.settings-list dd { margin: 0; font-variant-numeric: tabular-nums; }

/* Optional named-token access to private server data. */
.settings-private {
  padding-top: 1rem;
  margin-bottom: 1.6rem;
  border-top: 1px solid var(--border);
}
.settings-private h3 { margin: 0 0 0.6rem; }
.settings-private-form {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.settings-private-form .settings-field {
  flex-direction: column;
  align-items: stretch;
  gap: 0.35rem;
}
.settings-field input[type="password"] {
  width: 100%;
  font: inherit;
  font-size: 0.8rem;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.3rem 0.45rem;
}
.settings-field input[type="password"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}
.settings-private-status,
.settings-note {
  margin: 0 0 0.6rem;
  font-size: 0.82rem;
  line-height: 1.5;
}
.settings-button {
  align-self: flex-start;
  font: inherit;
  font-size: 0.8rem;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.3rem 0.7rem;
  cursor: pointer;
}
.settings-button:hover:not(:disabled) { border-color: var(--accent); }
.settings-button:disabled { opacity: 0.55; cursor: default; }
.settings-error {
  margin: 0;
  color: var(--accent);
  font-size: 0.8rem;
}

/* Private detail rows in the server drawer. */
.server-address { font-size: 0.8rem; word-break: break-all; }

/* Keep long, unbroken player names inside the drawer and stop them from
   squeezing or pushing the spectator/bot tags out of alignment. */
.player-table { table-layout: fixed; }
.player-table th:not(:first-child),
.player-table td:not(:first-child) {
  width: 4rem;
  text-align: right;
}
.player-cell {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.2rem 0.4rem;
  min-width: 0;
}
.player-name {
  flex: 1 1 8rem;
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.player-tags {
  display: inline-flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  gap: 0.3rem;
  align-items: center;
}
.player-tag {
  display: inline-block;
  padding: 0 0.3rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}

.stats-kicker {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.stats-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 1rem;
  font-size: 0.8rem;
}

.range-btn {
  padding: 0.22rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 99px;
  background: var(--panel-raised);
  font-size: 0.78rem;
}
.range-btn:hover { border-color: var(--muted); }
.range-btn.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.stats-updated { margin-left: auto; white-space: nowrap; }

.stats-select {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8rem;
}
.stats-select select {
  max-width: 10rem;
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.2rem 0.4rem;
}
.stats-select select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.stats-series {
  margin-left: 0.3rem;
  font-size: 0.72rem;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--muted);
}

.hour-chart {
  position: relative;
  display: flex;
  align-items: stretch;
  gap: 2px;
  height: 7rem;
  border-bottom: 1px solid var(--border);
}
.chart-gridlines {
  position: absolute;
  top: 0.9rem;
  right: 0;
  bottom: 1rem;
  left: 0;
  z-index: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  pointer-events: none;
}
.chart-gridlines span {
  border-top: 1px dashed color-mix(in srgb, var(--border) 75%, transparent);
}
.hour-col {
  position: relative;
  z-index: 1;
  display: grid;
  flex: 1;
  grid-template-rows: 0.9rem minmax(0, 1fr) 1rem;
  min-width: 0;
  height: 100%;
  outline: none;
}
.hour-col:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 3px;
}
.hour-value {
  overflow: hidden;
  font-size: 0.55rem;
  line-height: 0.9rem;
  color: var(--muted);
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.hour-bar-slot {
  display: flex;
  align-items: flex-end;
  width: 100%;
  min-height: 0;
}
.hour-bar {
  display: block;
  width: 100%;
  min-height: 0;
  background: var(--accent);
  border-radius: 2px 2px 0 0;
}
.hour-bar:not(.empty) { min-height: 1px; }
.hour-col.busiest .hour-bar { background: var(--warn); }
.hour-label {
  height: 1rem;
  overflow: hidden;
  font-size: 0.6rem;
  line-height: 1rem;
  color: var(--muted);
  text-align: center;
}
.chart-tooltip {
  position: absolute;
  top: 0.1rem;
  z-index: 3;
  display: flex;
  flex-direction: column;
  gap: 0.05rem;
  padding: 0.28rem 0.5rem;
  background: var(--panel-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
  color: var(--text);
  font-size: 0.72rem;
  line-height: 1.3;
  white-space: nowrap;
  pointer-events: none;
  transform: translateX(-50%);
}
.chart-tooltip.start { transform: translateX(0); }
.chart-tooltip.end { transform: translateX(-100%); }

.stats-hint {
  margin: 0.45rem 0 0;
  font-size: 0.72rem;
}

.chart { display: flex; align-items: flex-start; gap: 0.45rem; }
.chart-main { flex: 1; min-width: 0; }
.chart-y {
  display: flex;
  flex: none;
  flex-direction: column;
  justify-content: space-between;
  height: 9rem;
  min-width: 2rem;
  font-size: 0.62rem;
  line-height: 1;
  color: var(--muted);
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.chart-grid {
  stroke: var(--border);
  stroke-width: 1;
  stroke-dasharray: 2 4;
  vector-effect: non-scaling-stroke;
}
.chart-caption {
  margin: 0.35rem 0 0;
  font-size: 0.72rem;
}

.spark { display: flex; flex-direction: column; gap: 0.3rem; }
.spark-svg {
  display: block;
  width: 100%;
  height: 9rem;
  border-bottom: 1px solid var(--border);
}
.spark-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}
.spark-area { fill: color-mix(in srgb, var(--accent) 16%, transparent); }
.spark-dot { fill: var(--accent); }
.spark-dot.active {
  stroke: var(--panel);
  stroke-width: 1.5;
}
.spark-plot {
  position: relative;
  outline: none;
  cursor: crosshair;
}
.spark-plot:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.spark-crosshair {
  stroke: var(--muted);
  stroke-width: 1;
  stroke-dasharray: 2 3;
  vector-effect: non-scaling-stroke;
}
.spark-tooltip {
  position: absolute;
  top: 0.1rem;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 0.05rem;
  padding: 0.28rem 0.5rem;
  background: var(--panel-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
  font-size: 0.72rem;
  line-height: 1.3;
  white-space: nowrap;
  pointer-events: none;
  transform: translateX(-50%);
}
.spark-tooltip.start { transform: translateX(0); }
.spark-tooltip.end { transform: translateX(-100%); }
.spark-axis {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  color: var(--muted);
}
.server-spark .spark-svg { height: 5rem; }
.chart-bars .chart-y { height: 5.1rem; margin-top: 0.9rem; }
.server-spark .chart-y { height: 5rem; }

.bar-list { display: flex; flex-direction: column; gap: 0.6rem; }
.bar-row { display: flex; flex-direction: column; gap: 0.2rem; }
.bar-row-action {
  width: 100%;
  padding: 0.15rem 0.25rem;
  border: 0;
  border-radius: var(--radius);
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.bar-row-action:hover { background: var(--bg-accent); }
.bar-row-action:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.bar-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  font-size: 0.82rem;
}
.bar-label { min-width: 0; overflow-wrap: anywhere; }
.bar-value {
  flex: none;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.bar-value .muted { margin-left: 0.2rem; font-size: 0.72rem; }
.bar-share {
  margin-left: 0.35rem;
  color: var(--muted);
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
}
.bar-track {
  display: block;
  height: 0.4rem;
  overflow: hidden;
  background: var(--panel-raised);
  border-radius: 99px;
}
.bar-fill {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: inherit;
}

.content-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
  gap: 1rem 1.4rem;
  margin-bottom: 0.9rem;
}
.content-block h4 {
  margin: 0 0 0.45rem;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.content-block .bar-list { gap: 0.45rem; }

.drawer-body h3 {
  margin: 0 0 0.5rem;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr));
  gap: 0.6rem 1rem;
}
.stat { min-width: 0; }
/* Full-width rows in the drawer facts grid: the country/region pair and the
   WAD list, which needs the extra horizontal room. */
.drawer-body .stat-wide,
.drawer-body .stat-pair { grid-column: 1 / -1; }
.stat-pair .stat-label,
.stat-pair .stat-value {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 1rem;
}
.stat-pair .stat-value { align-items: baseline; }

.stat-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.stat-value {
  font-weight: 600;
  overflow-wrap: anywhere;
}

/* Nightdive room code with a copy button. */
.room-code {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.room-code code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.95rem;
  letter-spacing: 0.08em;
  padding: 0.1rem 0.45rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
}
.copy-btn {
  padding: 0.15rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel-raised);
  font-size: 0.78rem;
}
.copy-btn:hover { border-color: var(--muted); }
.copy-btn.ok { color: var(--live); }
.copy-btn.fail { color: var(--accent); }

.grid-table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
  font-size: 0.85rem;
}
.grid-table th {
  text-align: left;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  padding: 0.25rem 0.5rem;
  border-bottom: 1px solid var(--border);
}
.grid-table td {
  padding: 0.25rem 0.5rem;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 50%, transparent);
  overflow-wrap: anywhere;
}
.grid-table tr:last-child td { border-bottom: none; }

.wad-hash {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.7rem;
  color: var(--muted);
  word-break: break-all;
}

/* Drawer summary WADs: one filename per line so boundaries are obvious and a
   whole name can be selected with a double-click. Very long names stay on one
   line and scroll horizontally instead of wrapping into the next filename. */
.wad-list {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  overflow-x: auto;
  padding-bottom: 0.1rem;
  scrollbar-width: thin;
}
.wad-file,
.wad-file-cell { user-select: text; }
.wad-file {
  display: block;
  white-space: nowrap;
  overflow-wrap: normal;
}
.wad-list .wad-file {
  width: max-content;
  min-width: 100%;
}
.wad-table-wrap { overflow-x: auto; }
.wad-table td:first-child { white-space: nowrap; }

.kv { margin: 0; }
.kv-row {
  display: grid;
  grid-template-columns: minmax(8rem, 11rem) 1fr;
  gap: 0.5rem;
  padding: 0.3rem 0;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 50%, transparent);
}
.kv-row dt { color: var(--muted); font-size: 0.8rem; }
.kv-row dd { margin: 0; overflow-wrap: anywhere; }

.type {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.swatch {
  display: inline-block;
  width: 0.9rem;
  height: 0.9rem;
  margin-right: 0.35rem;
  border-radius: 3px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  vertical-align: -0.15em;
}

.raw summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.8rem;
  padding: 0.4rem 0;
}
.raw pre {
  margin: 0;
  padding: 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.72rem;
  line-height: 1.5;
  overflow: auto;
  max-height: 30rem;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Keyboard focus must be visible everywhere, not just on the text inputs
   (which have their own focus treatment above). */
:where(button, a, select, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* --------------------------------------------------------------- footer */

.footer {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 0.6rem 0.25rem;
  font-size: 0.8rem;
  color: var(--muted);
}
.footer a { color: var(--muted); }
.footer a:hover { color: var(--text); }
.footer-version { margin-left: auto; font-variant-numeric: tabular-nums; }

/* -------------------------------------------------------------- auth page */

.auth-page {
  max-width: 46rem;
  margin: 0 auto;
  padding: 2rem 1rem 4rem;
}
.auth-page h1 { font-size: 1.45rem; }
.auth-page h2 { margin: 0 0 0.75rem; font-size: 1rem; }

.auth-card {
  margin-top: 1rem;
  padding: 1rem 1.1rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.auth-status {
  margin: 0 0 0.75rem;
  overflow-wrap: anywhere;
  font-variant-numeric: tabular-nums;
}
.auth-status.ok { color: var(--live); }
.auth-status.bad { color: var(--accent); }

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}
.auth-form label { font-size: 0.8rem; color: var(--muted); }
.auth-form input {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.45rem 0.6rem;
}
.auth-form input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}
.auth-form button {
  align-self: flex-start;
  margin-top: 0.35rem;
  padding: 0.45rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel-raised);
}
.auth-form button:hover:not(:disabled) { border-color: var(--muted); }
.auth-form button:disabled { opacity: 0.55; cursor: progress; }
.field-hint { margin: 0 0 0.35rem; font-size: 0.75rem; }

.auth-result {
  margin: 1rem 0 0;
  padding: 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 0.82rem;
  line-height: 1.5;
}

/* ------------------------------------------------------------- responsive */

/* The name track is `minmax(0, …fr)` everywhere so a narrow window squeezes
   the name (which ellipsizes) instead of pushing the last columns out of the
   table and clipping them. Breakpoints drop the least useful columns in turn
   so the name keeps a readable width rather than collapsing to nothing. */

@media (max-width: 1100px) {
  /* lock name source map mode players country version (wads hidden) */
  :root { --cols: 2.5rem minmax(0, 1.5fr) 8.5rem 5rem 9rem 7.5rem 4rem 6.5rem; }
  .th-wrap-wads, .cell.wads { display: none; }
}

@media (max-width: 900px) {
  /* lock name source map mode players country (wads/version hidden) */
  :root { --cols: 2rem minmax(0, 1.4fr) 8rem 6.5rem 9rem 7.5rem 3.5rem; }
  .th-wrap-version, .cell.version { display: none; }
  .th-wrap-wads, .cell.wads { display: none; }
}

@media (max-width: 780px) {
  /* lock name source map players country (wads/version/mode hidden) */
  :root { --cols: 2rem minmax(0, 1.4fr) 7rem 6rem 6.5rem 3.5rem; }
  .th-wrap-version, .cell.version { display: none; }
  .th-wrap-mode, .cell.mode { display: none; }
  .th-wrap-wads, .cell.wads { display: none; }
  .chips { margin-left: 0; }
  .drawer { width: 100vw; }
}

/* Card layout: nine columns are unreadable on a phone, so each server becomes
   a two-line card and the header is replaced by the compact sort control. */
@media (max-width: 620px) {
  :root { --row-h: 62px; }

  .thead { display: none; }
  .mobile-sort { display: flex; }

  /* Keep the header compact so the table gets a useful amount of height. */
  .header { padding: 0.55rem 0 0.5rem; }
  .title-row h1 { font-size: 1.2rem; }
  .stats-row { gap: 0.75rem; margin-top: 0.4rem; }
  .stat-big { font-size: 1.1rem; }
  .stat-big small { font-size: 0.65rem; }

  /* Search stays visible; the rest of the filters live in a collapsible
     sheet so they cannot consume the whole viewport. */
  .filters { padding: 0.45rem 0.6rem; margin-bottom: 0.5rem; }
  .search { flex: 1 1 8rem; max-width: none; }
  .filters-toggle { display: inline-flex; }
  .filters-body {
    display: none;
    flex: 1 1 100%;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    padding-top: 0.45rem;
    border-top: 1px solid var(--border);
  }
  .filters-body.open { display: flex; }
  .filters-body .showing { margin-left: 0; }

  /* Six source chips wrap into three rows on a phone; scroll them sideways
     instead so the server list keeps the vertical space. */
  .chips {
    flex: 1 1 100%;
    flex-wrap: nowrap;
    align-items: center;
    min-width: 0;
    overflow-x: auto;
    padding-bottom: 0.15rem;
    scrollbar-width: none;
  }
  .chips > * { flex: none; }
  .chips::-webkit-scrollbar { display: none; }

  /* The footer is reference material; on a phone the table is more useful. */
  .footer { display: none; }

  .row {
    display: block;
    height: var(--row-h);
    padding: 0;
  }
  .row > .cell { display: none; }

  .card {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 0.2rem;
    height: 100%;
    padding: 0.3rem 0.75rem;
  }
  .card-top {
    display: flex;
    align-items: baseline;
    gap: 0.35rem;
    min-width: 0;
  }
  .card-lock { flex: none; }
  .card-name {
    flex: 1 1 0;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 600;
  }
  .row.pending .card-name {
    color: var(--muted);
    font-style: italic;
  }
  .card-players {
    display: flex;
    align-items: baseline;
    gap: 0.25rem;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
  }
  .card-meta {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    min-width: 0;
    overflow: hidden;
    font-size: 0.78rem;
    color: var(--muted);
  }
  .card-meta > * {
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .card-meta .src { flex: none; font-size: 0.7rem; }
  .card-meta .flag { margin-right: 0; }
}
