/* ============================================================
   KOTH — components.css   ·   shared chrome (brutalist)
   Hairline rules, square frames, mono labels, hard offset
   shadows, invert-on-hover. Class names preserved so the
   existing JS keeps targeting them.
   ============================================================ */

/* ── Layout shell ── */
.page-wrap { max-width: var(--shell); margin: 0 auto; padding: 0 28px 96px; }
.page-wrap-wide { max-width: 1560px; margin: 0 auto; padding: 0 28px 96px; }
.section { margin-bottom: var(--gap-lg); }

/* ── Nav ── */
.nav {
  position: sticky; top: 0; z-index: 200;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 28px; height: 60px;
  background: var(--paper);
  border-bottom: 2px solid var(--rule);
}
.nav-brand {
  display: flex; align-items: baseline; gap: 7px;
  font-family: var(--display); font-size: 17px; font-weight: 800; letter-spacing: -0.02em;
  color: var(--text); text-transform: uppercase;
}
.nav-brand strong { color: var(--accent); font-weight: 800; }
.nav-links { display: flex; align-items: center; gap: 0; }
.nav-link {
  display: flex; align-items: center; gap: 7px;
  padding: 8px 14px; border-radius: 0;
  font-family: var(--mono); font-size: 11px; font-weight: 600; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--sub);
  border: none; background: none;
  transition: color var(--transition), background var(--transition);
}
.nav-link:hover { color: var(--text); }
.nav-link.active { color: var(--paper); background: var(--text); }
.nav-link svg { display: none; }
.nav-right { display: flex; align-items: center; gap: 14px; }
.nav-username { font-family: var(--mono); font-size: 11px; font-weight: 600; color: var(--text); text-transform: uppercase; letter-spacing: 0.04em; }

/* ── Game status banner ── */
.game-banner {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  padding: 8px 28px; font-family: var(--mono); font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.08em;
  border-bottom: 1px solid var(--border); color: var(--sub);
  background: var(--paper);
}
.game-banner.active { background: var(--text); color: var(--paper); }
.game-banner.inactive { color: var(--muted); }
.game-dot { width: 7px; height: 7px; border-radius: 0; background: var(--muted); flex-shrink: 0; }
.game-banner.active .game-dot { background: var(--accent); animation: pulse-dot 1.4s steps(1) infinite; }
@keyframes pulse-dot { 0%, 100% { opacity: 1; } 50% { opacity: 0.2; } }
.game-banner .king-live { color: var(--accent); font-weight: 700; }
.game-banner .elapsed { color: inherit; }
.game-banner.active .text-green { color: var(--paper) !important; }

/* ── WS pill ── */
.ws-pill {
  display: flex; align-items: center; gap: 7px;
  padding: 4px 10px; border-radius: 0;
  border: 1.5px solid var(--text);
  font-family: var(--mono); font-size: 9.5px; font-weight: 600; color: var(--text);
  text-transform: uppercase; letter-spacing: 0.08em;
}
.ws-dot { width: 6px; height: 6px; border-radius: 0; background: var(--muted); }
.ws-dot.live { background: var(--accent); animation: pulse-dot 1.4s steps(1) infinite; }

/* ── Cards ── */
.card {
  background: var(--card);
  border: 1px solid var(--text);
  border-radius: 0;
  padding: 22px 24px;
}
.card + .card { margin-top: 16px; }
.card-title {
  font-family: var(--mono); font-size: 11px; font-weight: 700;
  letter-spacing: 0.1em; text-transform: uppercase; color: var(--text); margin-bottom: 16px;
}
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.card-header .card-title { margin-bottom: 0; }

/* ── Tables ── */
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th {
  text-align: left; padding: 12px 16px;
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.08em; font-weight: 700;
  text-transform: uppercase; color: var(--text);
  border-bottom: 2px solid var(--rule);
}
.tbl td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: none; }
.tbl tbody tr { transition: background var(--transition); }
.tbl tbody tr:hover td { background: var(--card-hv); }

/* ── Leaderboard ── */
.lb-table { width: 100%; border-collapse: collapse; }
.lb-table th {
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.08em; font-weight: 700;
  text-transform: uppercase; color: var(--text);
  padding: 12px 0; text-align: left; border-bottom: 2px solid var(--rule);
}
.lb-row { border-bottom: 1px solid var(--border); transition: background var(--transition); }
.lb-row:hover { background: var(--card-hv); }
.lb-row.is-king { background: var(--red-dim); box-shadow: inset 5px 0 0 var(--accent); }
.lb-row.is-me   { box-shadow: inset 5px 0 0 var(--text); }
.lb-cell { padding: 14px 0; vertical-align: middle; }
.lb-rank { font-family: var(--mono); font-size: 15px; font-weight: 700; color: var(--muted); width: 52px; padding-left: 12px; }
.lb-rank.r1 { color: var(--accent); }
.lb-rank.r2 { color: var(--text); }
.lb-rank.r3 { color: var(--text); }
.lb-avatar { width: 30px; height: 30px; border-radius: 50%; overflow: hidden; flex-shrink: 0; background: var(--surface); border: 1.5px solid var(--text); display: inline-flex; align-items: center; justify-content: center; }
.lb-avatar img { width: 100%; height: 100%; object-fit: cover; }
.lb-name-wrap { display: flex; align-items: center; gap: 10px; }
.lb-name { font-family: var(--display); font-size: 15px; font-weight: 700; color: var(--text); letter-spacing: -0.01em; }
.lb-team { font-size: 10.5px; color: var(--sub); margin-top: 1px; font-family: var(--mono); text-transform: uppercase; letter-spacing: 0.04em; }
.lb-pts  { font-family: var(--mono); font-size: 13px; font-weight: 600; text-align: right; }
.lb-pts .king-pts { color: var(--accent); }
.lb-pts .flag-pts { color: var(--sub); font-size: 11px; }
.lb-bar-wrap { width: 90px; padding-right: 12px; }
.lb-bar-bg  { height: 6px; background: transparent; border: 1px solid var(--text); border-radius: 0; overflow: hidden; }
.lb-bar-fill { height: 100%; background: var(--text); border-radius: 0; transition: width 0.5s ease; }
.lb-row.is-king .lb-bar-fill { background: var(--accent); }
.lb-crown-icon { color: var(--accent); flex-shrink: 0; display: flex; }

/* ── Flags grid ── */
.flags-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0; border-top: 1px solid var(--text); border-left: 1px solid var(--text); }
.flag-card {
  padding: 18px 20px;
  background: var(--card);
  border-right: 1px solid var(--text); border-bottom: 1px solid var(--text);
  border-radius: 0; position: relative; overflow: hidden;
  transition: background var(--transition);
}
.flag-card::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: var(--accent); }
.flag-card:hover { background: var(--card-hv); }
.flag-name { font-family: var(--mono); font-size: 12px; font-weight: 600; color: var(--text); margin-bottom: 10px; text-transform: uppercase; letter-spacing: 0.04em; }
.flag-pts-big { font-family: var(--mono); font-size: 26px; font-weight: 700; color: var(--text); }
.flag-meta { font-family: var(--mono); font-size: 10.5px; color: var(--sub); margin-top: 6px; text-transform: uppercase; letter-spacing: 0.04em; }
.flag-captured { opacity: 0.45; }
.flag-captured::before { background: var(--green); }

/* ── History list ── */
.hist-list { display: flex; flex-direction: column; gap: 0; }
.hist-row {
  display: grid; grid-template-columns: 28px 1fr auto auto;
  align-items: center; gap: 14px;
  padding: 11px 0; border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.hist-row:last-child { border-bottom: none; }
.hist-rank { font-family: var(--mono); font-size: 11px; color: var(--accent); font-weight: 700; text-align: right; }
.hist-name { font-family: var(--display); color: var(--text); font-weight: 700; }
.hist-dur  { font-family: var(--mono); font-size: 11px; color: var(--sub); text-align: right; }
.hist-time { font-family: var(--mono); font-size: 10px; color: var(--muted); text-align: right; }

/* ── Event log ── */
.evt-list { display: flex; flex-direction: column; gap: 0; max-height: 300px; overflow-y: auto; }
.evt-row { display: flex; gap: 14px; align-items: baseline; padding: 6px 0; font-size: 12.5px; font-family: var(--mono); border-bottom: 1px dotted var(--border); }
.evt-ts { font-size: 10px; color: var(--muted); flex-shrink: 0; }
.evt-msg { color: var(--sub); line-height: 1.45; }
.evt-msg.king  { color: var(--accent); font-weight: 600; }
.evt-msg.empty { color: var(--sub); }
.evt-msg.flag  { color: var(--green); }

/* ── Machines ── */
.machine-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.machine-card { padding: 16px; background: var(--card); border: 1px solid var(--text); border-radius: 0; }
.machine-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.machine-name { font-family: var(--display); font-size: 14px; font-weight: 700; color: var(--text); }
.machine-ip { font-family: var(--mono); font-size: 10.5px; color: var(--sub); }
.machine-reported { font-family: var(--mono); font-size: 11px; color: var(--muted); margin-top: 6px; }
.machine-reported strong { color: var(--accent); }

/* ── Stats row ── */
.stats-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0; border: 1px solid var(--text); margin-bottom: 28px; }
.stat-card { padding: 22px 20px; background: var(--card); border-right: 1px solid var(--text); }
.stat-card:last-child { border-right: none; }
.stat-val { font-family: var(--mono); font-size: 32px; font-weight: 700; color: var(--text); line-height: 1; margin-bottom: 8px; }
.stat-val.red   { color: var(--accent); }
.stat-val.green { color: var(--green); }
.stat-val.amber { color: var(--amber); }
.stat-lbl { font-family: var(--mono); font-size: 10px; color: var(--sub); letter-spacing: 0.08em; text-transform: uppercase; }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 500;
  background: rgba(20,18,15,0.45);
  display: none; align-items: center; justify-content: center; padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--paper-2);
  border: 2px solid var(--text); border-radius: 0;
  padding: 30px; width: 100%; max-width: 460px;
  position: relative;
  box-shadow: 12px 12px 0 var(--text);
  animation: modal-in .16s ease;
}
@keyframes modal-in { from { transform: translate(8px,8px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-close {
  position: absolute; top: 16px; right: 16px;
  background: none; border: none; color: var(--text);
  padding: 4px; border-radius: 0; transition: color var(--transition); display: flex;
}
.modal-close:hover { color: var(--accent); }
.modal-title { font-family: var(--display); font-size: 22px; font-weight: 800; letter-spacing: -0.02em; margin-bottom: 6px; }
.modal-sub { font-family: var(--mono); font-size: 11.5px; color: var(--sub); margin-bottom: 24px; }
.modal-sep { height: 1px; background: var(--text); margin: 20px 0; }
.modal-footer { margin-top: 24px; }

/* ── Toast ── */
.toast {
  position: fixed; bottom: 28px; right: 28px; z-index: 999;
  background: var(--text); border: none; color: var(--paper);
  padding: 13px 18px; border-radius: 0;
  font-family: var(--mono); font-size: 12px; letter-spacing: 0.02em;
  box-shadow: 6px 6px 0 var(--accent);
  transform: translateY(90px); opacity: 0;
  transition: transform 0.22s ease, opacity 0.22s ease;
  max-width: 340px; pointer-events: none;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast.err { box-shadow: 6px 6px 0 var(--accent); }
.toast.ok  { box-shadow: 6px 6px 0 var(--green); }

/* ── Avatar preview ── */
.avatar-preview-wrap { display: flex; align-items: center; gap: 16px; }
.avatar-preview {
  width: 58px; height: 58px; border-radius: 50%;
  background: var(--surface); border: 1.5px solid var(--text);
  overflow: hidden; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.avatar-preview img { width: 100%; height: 100%; object-fit: cover; }

/* ── Toggle switch ── */
.switch { position: relative; display: inline-block; width: 38px; height: 20px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; inset: 0; background-color: var(--paper); transition: .15s; border-radius: 0; border: 1.5px solid var(--text); }
.slider:before { position: absolute; content: ""; height: 12px; width: 12px; left: 2px; bottom: 2px; background-color: var(--text); transition: .16s ease; border-radius: 0; }
input:checked + .slider { background-color: var(--accent); border-color: var(--accent); }
input:checked + .slider:before { transform: translateX(18px); background-color: #fff; }

/* ── Game stat chips ── */
.game-stat-chips { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.game-chip {
  display: inline-flex; align-items: center; gap: 7px;
  background: transparent; border: 1.5px solid var(--text);
  border-radius: 0; padding: 5px 13px;
  font-family: var(--mono); font-size: 11px; color: var(--sub); text-transform: uppercase; letter-spacing: 0.06em;
}
.game-chip-val { font-weight: 700; color: var(--text); }

/* ── Reset-request button ── */
.reset-req-btn {
  display: inline-flex; align-items: center; gap: 7px;
  background: none; border: 1.5px solid var(--text);
  border-radius: 0; padding: 8px 15px; cursor: pointer;
  font-family: var(--mono); font-size: 11px; color: var(--text); text-transform: uppercase; letter-spacing: 0.06em;
  transition: background var(--transition), color var(--transition);
}
.reset-req-btn:hover { background: var(--amber); border-color: var(--amber); color: #fff; }

/* ── Alert popup overlay ── */
.alert-overlay {
  position: fixed; inset: 0; z-index: 9000;
  display: flex; align-items: center; justify-content: center;
  background: rgba(20,18,15,0.5);
  animation: fade-in .16s ease;
}
.alert-popup {
  background: var(--paper-2); border: 2px solid var(--accent);
  border-radius: 0; padding: 30px 34px; max-width: 440px; width: 90%;
  box-shadow: 12px 12px 0 var(--accent);
  animation: slide-up .18s ease;
}
.alert-popup-icon {
  width: 44px; height: 44px; border-radius: 0;
  background: var(--accent); border: none;
  display: flex; align-items: center; justify-content: center;
  color: #fff; margin: 0 auto 18px;
}
.alert-popup-title { text-align: center; font-family: var(--display); font-size: 18px; font-weight: 800; color: var(--text); margin-bottom: 8px; letter-spacing: -0.01em; }
.alert-popup-sender { text-align: center; font-family: var(--mono); font-size: 11px; color: var(--muted); margin-bottom: 16px; text-transform: uppercase; letter-spacing: 0.06em; }
.alert-popup-msg {
  background: var(--paper); border: 1px solid var(--text);
  border-radius: 0; padding: 16px 18px;
  font-size: 14px; color: var(--text); line-height: 1.6; text-align: center;
  margin-bottom: 22px; font-family: var(--mono);
}
@keyframes slide-up { from { transform: translate(6px,10px); opacity: 0; } to { transform: translate(0,0); opacity: 1; } }
@keyframes fade-in  { from { opacity: 0; } to { opacity: 1; } }

/* ── Past-game leaderboard modal ── */
.past-lb-table { width: 100%; border-collapse: collapse; }
.past-lb-table th, .past-lb-table td { padding: 10px 12px; text-align: left; font-size: 12px; border-bottom: 1px solid var(--border); font-family: var(--mono); }
.past-lb-table th { color: var(--text); font-weight: 700; font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; border-bottom: 2px solid var(--rule); }
.past-lb-table td { color: var(--sub); }
.past-lb-rank { font-family: var(--mono); font-weight: 700; color: var(--accent); width: 36px; }

/* ── Chart ── */
.chart-wrap { padding: 0; height: 240px; position: relative; }

/* ── Page loader ── */
#page-loader {
  position: fixed; inset: 0; z-index: 9999;
  background: var(--paper);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 22px;
  transition: opacity 0.22s ease, visibility 0.22s ease;
}
#page-loader.pl-done { opacity: 0; visibility: hidden; pointer-events: none; }
.pl-logo { font-family: var(--display); font-size: 26px; font-weight: 800; letter-spacing: -0.02em; color: var(--text); text-transform: uppercase; }
.pl-logo span { color: var(--accent); }
.pl-bar { width: 160px; height: 4px; background: transparent; border: 1px solid var(--text); border-radius: 0; overflow: hidden; }
.pl-bar-fill { height: 100%; width: 40%; background: var(--accent); border-radius: 0; animation: pl-sweep 0.9s linear infinite; }
@keyframes pl-sweep { 0% { transform: translateX(-100%); } 100% { transform: translateX(360%); } }
.pl-label { font-family: var(--mono); font-size: 9.5px; letter-spacing: 0.18em; color: var(--muted); text-transform: uppercase; animation: pl-blink 1s steps(1) infinite; }
@keyframes pl-blink { 0%,49%{opacity:1} 50%,100%{opacity:0.3} }

/* ── Machine game card (throne) ── */
.mgc-wrap {
  border-radius: 0; overflow: hidden;
  background: var(--card); border: 1.5px solid var(--text);
  max-width: 480px; margin: 0 auto 28px;
  box-shadow: 8px 8px 0 var(--text);
}
.mgc-eyebrow {
  padding: 11px 16px; text-align: center;
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.16em;
  text-transform: uppercase; color: var(--accent);
  border-bottom: 1.5px solid var(--text); background: var(--card);
}
.mgc-eyebrow::before { content: '// '; color: var(--muted); }
.mgc-bg { width: 100%; height: 170px; object-fit: cover; display: block; background: var(--surface); position: relative; filter: grayscale(0.4) contrast(1.05); border-bottom: 1.5px solid var(--text); }
.mgc-bg-placeholder { width: 100%; height: 120px; background: repeating-linear-gradient(45deg, var(--surface), var(--surface) 10px, var(--card-hv) 10px, var(--card-hv) 20px); border-bottom: 1.5px solid var(--text); }
.mgc-avatar-row { display: flex; justify-content: center; margin-top: -40px; position: relative; z-index: 2; }
.mgc-avatar-ring {
  width: 80px; height: 80px; border-radius: 50%;
  border: 2px solid var(--text); background: var(--surface);
  overflow: hidden; flex-shrink: 0;
  box-shadow: 0 0 0 4px var(--paper-2);
}
.mgc-avatar-ring img { width: 100%; height: 100%; object-fit: cover; }
.mgc-avatar-ring .mgc-avatar-placeholder {
  width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
  background: var(--surface); color: var(--accent);
}
.mgc-body { padding: 14px 24px 24px; text-align: center; }
.mgc-name { font-family: var(--display); font-size: 22px; font-weight: 800; letter-spacing: -0.02em; color: var(--text); margin-bottom: 4px; text-transform: uppercase; }
.mgc-ip { font-family: var(--mono); font-size: 12px; color: var(--accent); margin-bottom: 10px; }
.mgc-desc { font-size: 13px; color: var(--sub); line-height: 1.6; }
.mgc-tags { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-top: 16px; }
.mgc-tag {
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase;
  background: transparent; color: var(--text);
  border: 1.5px solid var(--text); border-radius: 0; padding: 3px 10px;
}
.mgc-tag.green { background: var(--green); color: #fff; border-color: var(--green); }

/* ── Image cropper ── */
.cropper-viewport {
  position: relative; overflow: hidden; margin: 18px auto 0;
  border-radius: 0; background: #000;
  border: 1.5px solid var(--text);
  touch-action: none; cursor: grab; user-select: none;
}
.cropper-viewport:active { cursor: grabbing; }
.cropper-viewport.round { border-radius: 50%; }
.cropper-img { position: absolute; top: 0; left: 0; transform-origin: top left; pointer-events: none; max-width: none; }
.cropper-grid {
  position: absolute; inset: 0; pointer-events: none;
  background-image:
    linear-gradient(rgba(255,255,255,0.3) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.3) 1px, transparent 1px);
  background-size: 33.333% 33.333%;
}
