@font-face {
  font-family: "Roboto";
  src: url("fonts/Roboto-VariableFont_wdth_wght.ttf") format("truetype");
  font-weight: 100 900;
  font-stretch: 75% 100%;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Michroma";
  src: url("fonts/Michroma-Regular.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  /* Brand palette: Core Black, Sideline White, Pulse Blue. */
  --core-black: #0d0d0d;
  --sideline-white: #ffffff;
  --pulse-blue: #00aaff;

  --bg: var(--core-black);
  --surface: #171717;
  --line: #2e2e2e;
  --muted: #b3b3b3;
  --text: var(--sideline-white);
  --accent: var(--pulse-blue);

  /* Functional round-state colors. */
  --open-bg: #04170b;
  --open-card: #072312;
  --open-border: rgba(40, 210, 100, .45);
  --open-accent: #3ee07a;
  --close-accent: #ffae42;
  --caution: #ff6b6b;

  --radius: 16px;
  font-family: "Roboto", system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

body {
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  line-height: 1.45;
  transition: background .5s ease;
}

body.round-open { background: var(--open-bg); }

button, input { font: inherit; }

/* ── Header ─────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  font-family: "Michroma", "Roboto", sans-serif;
  font-size: 16px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--accent);
}

body.round-open .brand { color: var(--open-accent); }

.topbar-meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }

.event-pill {
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 1px;
  text-transform: uppercase;
  background: var(--line);
  border-radius: 999px;
  padding: 5px 14px;
}

.device-name { font-size: 13px; color: var(--muted); }

/* ── Layout ─────────────────────────────────────────── */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 20px;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}

main > section[data-view="active"] { display: flex; flex-direction: column; gap: 16px; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 32px 28px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

h1 { font-size: 26px; font-weight: 800; line-height: 1.2; }
h2 { font-size: 18px; font-weight: 700; }
.lead { font-size: 17px; }
.muted { color: var(--muted); font-size: 14px; }

.notice {
  border: 1px solid var(--accent);
  background: rgba(0, 170, 255, .08);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 15px;
}

/* ── Buttons ────────────────────────────────────────── */
.btn-primary, .btn-secondary, .btn-caution, .btn-small {
  border-radius: 12px;
  cursor: pointer;
  font-weight: 700;
  touch-action: manipulation;
}

.btn-primary {
  padding: 16px 22px;
  font-size: 18px;
  background: var(--accent);
  color: var(--core-black);
  border: 1px solid var(--accent);
  align-self: flex-start;
}

.btn-secondary {
  padding: 10px 18px;
  font-size: 15px;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--muted);
}

.btn-caution {
  padding: 10px 18px;
  font-size: 15px;
  background: rgba(255, 107, 107, .08);
  color: var(--caution);
  border: 1px solid var(--caution);
}

.btn-small {
  font-size: 12px;
  font-weight: 500;
  padding: 6px 14px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
}

.btn-small:hover { color: var(--text); border-color: var(--muted); }
button:disabled { opacity: .4; cursor: default; }
button:focus-visible, a:focus-visible, input:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ── Pairing ────────────────────────────────────────── */
.pairing-code {
  font-family: "Roboto", sans-serif;
  font-weight: 700;
  font-size: clamp(40px, 8vw, 72px);
  letter-spacing: .18em;
  white-space: nowrap;
  color: var(--sideline-white);
  text-align: center;
  padding: 18px 0;
  font-variant-numeric: tabular-nums;
}

.countdown { text-align: center; color: var(--muted); font-size: 16px; }

/* ── Dashboard ──────────────────────────────────────── */
.dash-header { margin-bottom: 14px; }
.dash-engagement { margin-bottom: 22px; }
.dash-engagement h2 { font-size: 15px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; color: var(--muted); margin: 0 0 10px; overflow-wrap: anywhere; }
.dash-engagement-dates { font-size: 13px; color: var(--muted); margin: -6px 0 10px; }
.dash-ended { margin-bottom: 22px; }
.dash-ended > summary { cursor: pointer; font-size: 15px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; color: var(--muted); margin-bottom: 12px; }
#accessWarning { margin-bottom: 12px; }
.dash-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.dash-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.dash-card.has-open { border: 2px solid var(--open-accent); background: var(--open-card); }
.dash-card-header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.dash-card-badges { display: flex; flex-wrap: wrap; gap: 6px; }
.dash-card-title { font-size: 18px; font-weight: 700; overflow-wrap: anywhere; }
.dash-card-event { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.live-badge {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: .5px;
  color: var(--core-black);
  background: var(--open-accent);
  border-radius: 999px;
  padding: 3px 12px;
  white-space: nowrap;
}
.dash-games { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.dash-game { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: baseline; font-size: 14px; }
.dash-game-name { font-weight: 700; min-width: 48px; }
.dash-game-state { color: var(--muted); }
.dash-game.is-open .dash-game-state { color: var(--open-accent); font-weight: 600; }
.dash-operate { margin-top: auto; }
.stale-flag {
  font-size: 12px;
  font-weight: 700;
  color: var(--core-black);
  background: var(--close-accent);
  border-radius: 999px;
  padding: 2px 10px;
}

.event-header { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 8px; }
.event-title { font-size: 18px; font-weight: 700; overflow-wrap: anywhere; }

/* ── Computer access ───────────────────────────────── */
.access {
  border-top: 1px solid var(--line);
  padding-top: 18px;
  margin-top: 12px;
}

.access > * + * { margin-top: 12px; }

.access > summary {
  cursor: pointer;
  font-size: 15px;
  font-weight: 700;
  color: var(--muted);
  list-style-position: inside;
}
.access[open] > summary { color: var(--text); }

.access-action { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.access-action p { font-size: 14px; color: var(--muted); flex: 1; min-width: 220px; }

/* ── Game selector ──────────────────────────────────── */
#selectorView { display: flex; flex-direction: column; align-items: center; gap: 24px; padding: 32px 0; }
#selectorView[hidden] { display: none; }

.selector-prompt { font-size: 13px; font-weight: 600; letter-spacing: 2px; text-transform: uppercase; color: var(--muted); }

.game-options { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; width: 100%; max-width: 420px; }

.game-option {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px 16px;
  color: var(--text);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.game-option:hover { border-color: var(--accent); }
.game-option-icon { font-size: 32px; }
.game-option-name { font-size: 20px; font-weight: 800; letter-spacing: 1px; text-transform: uppercase; font-stretch: 87.5%; }

.live-dot {
  display: none;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--open-accent);
}

.game-option.has-open-round .live-dot, body.round-open .round-header .live-dot { display: flex; }

.live-dot-pulse {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--open-accent);
  animation: livepulse 1.4s ease-in-out infinite;
}

@keyframes livepulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: .4; transform: scale(.7); }
}

/* ── Round view ─────────────────────────────────────── */
#roundView, #resultsView { display: flex; flex-direction: column; gap: 16px; }
#roundView[hidden], #resultsView[hidden] { display: none; }

.round-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.round-header-right { display: flex; align-items: center; gap: 10px; }

.round-game-name {
  font-size: 40px;
  font-weight: 900;
  font-stretch: 75%;
  letter-spacing: 1px;
  line-height: 1;
  text-transform: uppercase;
}

body.round-open .round-game-name { color: var(--open-accent); }

.state-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
}

body.round-open .state-card { background: var(--open-card); border-color: var(--open-border); }

.state-label, .meta-label { font-size: 11px; font-weight: 600; letter-spacing: 1.5px; text-transform: uppercase; color: var(--muted); }
.state-status { font-size: 28px; font-weight: 900; font-stretch: 75%; letter-spacing: 1px; text-transform: uppercase; color: var(--muted); margin: 6px 0 16px; }
body.round-open .state-status { color: var(--open-accent); }

.state-meta { display: flex; gap: 24px; flex-wrap: wrap; }
.meta-item { display: flex; flex-direction: column; gap: 2px; }
.meta-value { font-size: 16px; font-weight: 700; }
.meta-value.warn-low { color: var(--close-accent); }
.meta-value.warn-none { color: var(--caution); }
.live-count-num { font-size: 22px; font-weight: 900; color: var(--open-accent); line-height: 1; }

.action-btn {
  display: block;
  width: 100%;
  padding: 24px;
  font-size: 26px;
  font-weight: 900;
  font-stretch: 75%;
  letter-spacing: 2px;
  text-transform: uppercase;
  text-align: center;
  text-decoration: none;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
}

.btn-open-round { background: rgba(62, 224, 122, .14); border-color: var(--open-accent); color: var(--open-accent); }
.btn-close-round { background: rgba(255, 174, 66, .12); border-color: var(--close-accent); color: var(--close-accent); }
.btn-show-board { background: rgba(0, 170, 255, .12); border-color: var(--accent); color: var(--accent); }

.link-btn {
  display: block;
  width: 100%;
  padding: 14px;
  text-align: center;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  text-decoration: none;
  border-radius: var(--radius);
  border: 1px solid var(--accent);
  background: rgba(0, 170, 255, .06);
  color: var(--accent);
  cursor: pointer;
}

.link-btn-disabled { opacity: .4; cursor: default; border-color: var(--line); color: var(--muted); }

.url-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
}

.url-label { font-size: 11px; font-weight: 600; letter-spacing: 1px; text-transform: uppercase; color: var(--muted); white-space: nowrap; }
.url-val { font-size: 13px; color: var(--accent); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Leaderboard ────────────────────────────────────── */
.leaderboard { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.lb-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.lb-title { font-size: 14px; font-weight: 800; letter-spacing: 2px; text-transform: uppercase; color: var(--accent); }
body.round-open .lb-title { color: var(--open-accent); }

.lb-cols, .lb-row { display: grid; grid-template-columns: 36px 1fr 90px 72px; gap: 0 8px; align-items: center; padding: 8px 18px; }
.lb-cols { font-size: 10px; font-weight: 600; letter-spacing: 1.2px; text-transform: uppercase; color: var(--muted); border-bottom: 1px solid var(--line); }
.lb-row { padding: 11px 18px; border-left: 3px solid transparent; }
.lb-row.tier-allstar { border-left-color: var(--open-accent); }
.lb-row.tier-pro { border-left-color: var(--accent); }
.lb-rank { font-weight: 800; color: var(--muted); text-align: center; }
.lb-tag { font-size: 18px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lb-score { font-size: 18px; font-weight: 800; text-align: right; }
.lb-tier { font-size: 10px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase; text-align: right; justify-self: end; padding: 3px 8px; border-radius: 6px; border: 1px solid var(--line); color: var(--muted); }
.lb-tier.allstar { color: var(--open-accent); border-color: var(--open-border); }
.lb-tier.pro { color: var(--accent); border-color: var(--accent); }
.lb-empty { font-size: 14px; color: var(--muted); text-align: center; padding: 28px 0; }
.align-right { text-align: right; }

/* ── Activity log ───────────────────────────────────── */
.log-toggle { font-size: 12px; color: var(--muted); background: none; border: none; cursor: pointer; }
#logPanel {
  margin-top: 6px;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
  max-height: 180px;
  overflow: auto;
  white-space: pre-wrap;
  font-family: ui-monospace, monospace;
}

/* ── Dialogs ────────────────────────────────────────── */
.dialog {
  margin: auto;
  max-width: 440px;
  width: calc(100% - 32px);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 26px 24px;
}

.dialog::backdrop { background: rgba(0, 0, 0, .7); }
.dialog h2 { margin-bottom: 10px; font-size: 20px; }
.dialog p { font-size: 15px; color: var(--muted); margin-bottom: 14px; }
.dialog-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.dialog-actions .btn-primary { align-self: auto; padding: 10px 18px; font-size: 15px; }

@media (max-width: 480px) {
  .panel { padding: 24px 18px; }
  .round-game-name { font-size: 32px; }
  .action-btn { font-size: 22px; padding: 20px; }
}
