:root {
  --bg: #04060b;
  --bg-2: #0a0f1c;
  --surface: rgba(14, 22, 42, 0.72);
  --border: rgba(96, 165, 250, 0.16);
  --border-strong: rgba(96, 165, 250, 0.38);
  --text: #e6edf9;
  --muted: #8796b4;
  --blue: #3b82f6;
  --blue-2: #60a5fa;
  --blue-deep: #1d4ed8;
  --ok: #34d399;
  --warn: #fbbf24;
  --danger: #f87171;
  --radius: 16px;
  --mono: "JetBrains Mono", ui-monospace, Consolas, monospace;
  --player-a: #3b82f6;
  --player-b: #22d3ee;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  overflow-x: hidden;
}

a { color: var(--blue-2); text-decoration: none; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.board-note { font-size: 12px; margin: 10px 2px 0; }
.home-board { max-width: 900px; margin: 40px auto 0; }
.last-duel { margin-top: 16px; padding: 16px 18px; text-align: left; display: flex; flex-direction: column; gap: 6px; }
.last-duel-head { display: flex; align-items: center; gap: 8px; }
.last-duel-head .grow { flex: 1; }
.last-duel-score { font-family: var(--mono); font-size: 1.05rem; font-weight: 700; }
.last-duel-links { display: flex; gap: 14px; font-size: 0.85rem; }
.last-duel-title {
  display: flex; align-items: center; gap: 10px;
  font-size: 1.35rem; font-weight: 800; letter-spacing: 0.1em; text-transform: uppercase;
  text-shadow: 0 0 18px rgba(59, 130, 246, 0.6);
}
.last-duel-icon { display: inline-grid; color: var(--blue-2); }
.last-duel-icon svg { width: 22px; height: 22px; }

.result-banner.result-panel {
  --accent: var(--blue-2);
  position: relative; overflow: hidden; padding: 26px 20px 20px;
  font-size: 1rem; font-weight: 400;
  background: radial-gradient(ellipse at 50% -20%, color-mix(in srgb, var(--accent) 22%, transparent), transparent 65%), var(--bg-2);
  border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
  animation: panel-in 0.5s ease-out both;
}
.result-panel.lose { --accent: #7b8db0; }
.result-panel.draw { --accent: #a5b4fc; }
.result-panel.decisive { --accent: #38bdf8; }
.result-panel.crushing { --accent: #64748b; }
.rp-symbol {
  width: 58px; height: 58px; margin: 0 auto 12px; border-radius: 50%;
  display: grid; place-items: center; color: var(--accent);
  border: 1.5px solid color-mix(in srgb, var(--accent) 55%, transparent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  box-shadow: 0 0 24px color-mix(in srgb, var(--accent) 35%, transparent);
}
.rp-symbol svg { width: 28px; height: 28px; }
.rp-title {
  font-size: clamp(1.7rem, 5vw, 2.5rem); line-height: 1.1; font-weight: 900;
  letter-spacing: 0.1em; text-transform: uppercase; color: #f1f6ff;
  text-shadow: 0 0 26px color-mix(in srgb, var(--accent) 70%, transparent);
  animation: title-in 0.9s 0.1s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}
.result-panel.lose .rp-title { color: #cdd6e6; }
.rp-message { margin: 8px auto 0; max-width: 520px; color: var(--muted); font-size: 1rem; }
.rp-score { margin-top: 14px; font-family: var(--mono); font-weight: 700; font-size: 0.95rem; }
@keyframes panel-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes title-in { from { opacity: 0; letter-spacing: 0.4em; } to { opacity: 1; letter-spacing: 0.1em; } }
@media (prefers-reduced-motion: reduce) {
  .result-banner.result-panel, .rp-title { animation: none; }
}
.result-sub { margin-top: 8px; font-size: 0.85rem; color: var(--muted); font-weight: 400; }
.result-sub .icon-btn { margin-left: 6px; }
.mono { font-family: var(--mono); }

/* ---------- Background ---------- */
.bg-grid {
  position: fixed; inset: 0; z-index: -2;
  background-image:
    linear-gradient(rgba(59, 130, 246, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(59, 130, 246, 0.06) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse at 50% 0%, #000 30%, transparent 75%);
}
.bg-glow {
  position: fixed; z-index: -1;
  width: 900px; height: 600px; left: 50%; top: -280px;
  transform: translateX(-50%);
  background: radial-gradient(closest-side, rgba(29, 78, 216, 0.45), transparent);
  filter: blur(40px);
  pointer-events: none;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px clamp(16px, 4vw, 48px);
  border-bottom: 1px solid var(--border);
  background: rgba(4, 6, 11, 0.6);
  backdrop-filter: blur(12px);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 12px; color: var(--text); }
.brand-logo { width: 36px; height: 36px; filter: drop-shadow(0 0 10px rgba(59, 130, 246, 0.5)); }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name { font-weight: 800; font-size: 1.15rem; letter-spacing: 0.08em; text-transform: uppercase; }
.brand-name span { color: var(--blue-2); }
.brand-sub { font-size: 0.7rem; color: var(--muted); letter-spacing: 0.1em; text-transform: uppercase; }
.topbar-right { font-size: 0.85rem; color: var(--muted); }

main {
  flex: 1; width: 100%; max-width: 980px;
  margin: 0 auto;
  padding: clamp(24px, 5vw, 56px) clamp(16px, 4vw, 32px);
}

/* ---------- Cards, buttons, inputs ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  backdrop-filter: blur(14px);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.btn {
  font: inherit; font-weight: 600; font-size: 0.92rem;
  border-radius: 10px; border: 1px solid transparent;
  padding: 9px 16px; cursor: pointer;
  transition: box-shadow 0.2s, background 0.2s, border-color 0.2s;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  white-space: nowrap; color: var(--text); background: transparent;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(135deg, var(--blue), var(--blue-deep));
  color: #fff; box-shadow: 0 6px 24px rgba(37, 99, 235, 0.4);
}
.btn-primary:hover:not(:disabled) { box-shadow: 0 8px 32px rgba(59, 130, 246, 0.6); }
.btn-ghost { border-color: var(--border-strong); }
.btn-ghost:hover:not(:disabled) { background: rgba(59, 130, 246, 0.1); }
.btn-danger { border-color: rgba(248, 113, 113, 0.4); color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: rgba(248, 113, 113, 0.1); }
.btn-lg { padding: 14px 24px; font-size: 1rem; }
.btn-block { width: 100%; }

.field { display: flex; flex-direction: column; gap: 6px; flex: 1; min-width: 0; }
.field-label { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.1em; font-weight: 600; }
.input {
  font: inherit; font-family: var(--mono);
  background: rgba(4, 8, 18, 0.8);
  border: 1px solid var(--border-strong);
  color: var(--text);
  border-radius: 10px; padding: 12px 14px; outline: none; width: 100%;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25); }
.form-error { min-height: 20px; font-size: 0.88rem; color: var(--danger); text-align: center; }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase;
  padding: 4px 10px; border-radius: 999px;
  border: 1px solid var(--border-strong); color: var(--muted);
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.waiting { color: var(--warn); border-color: rgba(251, 191, 36, 0.4); }
.pill.running { color: var(--ok); border-color: rgba(52, 211, 153, 0.4); }
.pill.running::before { animation: pulse 1.6s infinite; box-shadow: 0 0 8px var(--ok); }
.pill.finished { color: var(--muted); }
@keyframes pulse { 50% { opacity: 0.3; } }

/* ---------- Join ---------- */
.join { max-width: 440px; margin: 4vh auto 0; text-align: center; }
.join-logo {
  width: 96px; height: 96px; margin-bottom: 18px;
  filter: drop-shadow(0 0 28px rgba(59, 130, 246, 0.6));
  animation: float 6s ease-in-out infinite;
}
@keyframes float { 50% { transform: translateY(-6px); } }
.event-title {
  font-size: clamp(2.6rem, 8vw, 4rem); font-weight: 800;
  letter-spacing: 0.06em; text-transform: uppercase; line-height: 1;
  background: linear-gradient(180deg, #fff 20%, var(--blue-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.event-sub { margin-top: 10px; color: var(--muted); font-size: 0.8rem; letter-spacing: 0.18em; text-transform: uppercase; }
.join-card { margin-top: 36px; padding: 24px; display: flex; flex-direction: column; gap: 14px; }
.join-card .input {
  text-align: center; font-size: 1.4rem; letter-spacing: 0.3em; text-transform: uppercase; padding: 14px;
}
.register-card { text-align: left; }
.reg-notice { margin-top: 28px; padding: 14px 18px; text-align: left; font-size: 0.92rem; border-color: var(--border-strong); }
.reg-notice:not(.hidden) + .register-card { margin-top: 14px; }
.join-card.register-card .input { text-align: left; font-size: 1rem; letter-spacing: normal; text-transform: none; padding: 12px 14px; }
.register-card .form-error { text-align: left; }
.reg-status-title { font-size: 1.3rem; font-weight: 800; }
.reg-handle { font-family: var(--mono); font-size: 1.05rem; font-weight: 700; }
.register-card .icon-btn { align-self: flex-start; }
.reg-pending { border-color: var(--border-strong); }
.reg-confirmed { border-color: rgba(52, 211, 153, 0.5); }
.reg-confirmed .reg-status-title { color: var(--ok); }
.reg-declined .reg-status-title { color: var(--danger); }

/* ---------- Room ---------- */
.room-bar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 12px; }
.room-code { font-family: var(--mono); color: var(--muted); font-size: 0.9rem; letter-spacing: 0.15em; }
.room-code strong { color: var(--text); }

.duel-head {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  gap: 16px; padding: 22px 26px;
}
.player { display: flex; align-items: center; gap: 14px; min-width: 0; }
.player-right { flex-direction: row-reverse; }
.avatar {
  width: 52px; height: 52px; border-radius: 12px; object-fit: cover; flex-shrink: 0;
  border: 2px solid var(--pc); background: var(--bg-2);
  box-shadow: 0 0 18px color-mix(in srgb, var(--pc) 45%, transparent);
}
.player-handle {
  font-weight: 700; font-size: 1.1rem; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.duel-center { text-align: center; }
.score { font-size: 2.2rem; font-weight: 800; font-family: var(--mono); line-height: 1; }
.score .a { color: var(--player-a); }
.score .b { color: var(--player-b); }
.score .sep { color: var(--muted); margin: 0 6px; }
.timer-label { margin-top: 8px; font-size: 0.65rem; color: var(--muted); letter-spacing: 0.16em; text-transform: uppercase; }
.timer { font-family: var(--mono); font-size: 1.05rem; color: var(--text); }
.timer.low { color: var(--danger); }

.result-banner {
  text-align: center; padding: 16px; border-radius: var(--radius); margin-top: 14px;
  border: 1px solid var(--border-strong);
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.25), rgba(34, 211, 238, 0.12));
  font-size: 1.4rem; font-weight: 800;
}

.problem-list { list-style: none; display: flex; flex-direction: column; gap: 12px; margin-top: 16px; }
.problem {
  display: grid; grid-template-columns: 52px 1fr auto; align-items: center; gap: 18px;
  padding: 16px 20px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  backdrop-filter: blur(14px);
  transition: border-color 0.25s, background 0.4s;
}
.problem:not(.locked):hover { border-color: var(--border-strong); }
.problem-label {
  font-family: var(--mono); font-weight: 700; font-size: 1.3rem;
  width: 52px; height: 52px; display: grid; place-items: center;
  border-radius: 12px; color: var(--blue-2);
  background: rgba(59, 130, 246, 0.1); border: 1px solid var(--border-strong);
}
.problem-name { font-weight: 600; font-size: 1.05rem; color: var(--text); }
.problem-name.placeholder { color: var(--muted); letter-spacing: 0.3em; }
.problem.locked {
  background: linear-gradient(90deg, color-mix(in srgb, var(--sc) 16%, transparent), rgba(10, 15, 28, 0.7) 60%);
  border-color: color-mix(in srgb, var(--sc) 45%, transparent);
}
.problem.locked .problem-label { color: var(--sc); border-color: color-mix(in srgb, var(--sc) 50%, transparent); }
.lock-badge {
  display: inline-flex; align-items: center; gap: 8px;
  font-weight: 700; font-size: 0.9rem; color: var(--sc);
  padding: 8px 14px; border-radius: 10px;
  border: 1px solid color-mix(in srgb, var(--sc) 50%, transparent);
  background: color-mix(in srgb, var(--sc) 10%, transparent);
}
.lock-time { font-family: var(--mono); font-size: 0.75rem; color: var(--muted); text-align: right; margin-top: 4px; }
.problem.just-locked { animation: lockflash 1.2s ease; }
@keyframes lockflash {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--sc) 70%, transparent); }
  100% { box-shadow: 0 0 0 18px transparent; }
}

/* ---------- Admin ---------- */
.admin-grid { display: flex; flex-direction: column; gap: 20px; }
.panel { padding: 22px; }
.panel-title { font-size: 0.78rem; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); margin-bottom: 16px; }
.row { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; }
.row + .row { margin-top: 14px; }
.row .field.sm { flex: 0 0 120px; }
.login { max-width: 360px; margin: 6vh auto 0; display: flex; flex-direction: column; gap: 14px; }

.room-card { padding: 18px 20px; }
.room-card-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.room-card-code {
  font-family: var(--mono); font-weight: 700; font-size: 1.15rem; letter-spacing: 0.15em;
  cursor: pointer; color: var(--text);
}
.room-card-code:hover { color: var(--blue-2); }
.room-card-players { font-weight: 600; }
.room-card-players .vs { color: var(--muted); margin: 0 6px; font-weight: 400; }
.room-card-meta { color: var(--muted); font-size: 0.82rem; font-family: var(--mono); margin-left: auto; }
.room-card-problems { margin-top: 12px; display: flex; flex-direction: column; gap: 4px; font-size: 0.9rem; }
.room-card-problems .lbl { font-family: var(--mono); color: var(--blue-2); margin-right: 8px; font-weight: 700; }
.room-card-problems .solver { margin-left: 8px; font-size: 0.8rem; }
.room-card-actions { margin-top: 14px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.sched { display: inline-flex; gap: 6px; align-items: center; }
.sched-input { width: auto; padding: 8px 10px; font-size: 0.85rem; color-scheme: dark; }
input[type="datetime-local"] { color-scheme: dark; }
.empty { text-align: center; color: var(--muted); padding: 24px; }

/* ---------- Nav, tables ---------- */
.nav { display: flex; gap: 18px; font-size: 0.85rem; }
.nav a { color: var(--muted); }
.nav a:hover { color: var(--text); }
.room-bar-right { display: inline-flex; align-items: center; gap: 12px; }
.problem-main { min-width: 0; }
.problem-points { font-family: var(--mono); font-size: 0.78rem; color: var(--muted); margin-top: 2px; }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.table th {
  text-align: left; font-size: 0.7rem; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--muted); font-weight: 700; padding: 12px 14px; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td { padding: 10px 14px; border-bottom: 1px solid rgba(96, 165, 250, 0.08); white-space: nowrap; }
.table tr:last-child td { border-bottom: none; }
.table tbody tr:hover td { background: rgba(59, 130, 246, 0.04); }
.table .strong { font-weight: 700; color: var(--text); }
.table .empty { text-align: center; color: var(--muted); padding: 20px; }
.table a { color: var(--text); }
.table a:hover { color: var(--blue-2); }
tr.inactive td { opacity: 0.45; }
.v-ok { color: var(--ok); }
.v-bad { color: var(--danger); }
.v-free { color: var(--muted); }

/* ---------- Admin extras ---------- */
.tabs { display: flex; gap: 6px; margin-bottom: 20px; flex-wrap: wrap; }
.tab {
  font: inherit; font-weight: 600; font-size: 0.88rem; cursor: pointer;
  padding: 9px 16px; border-radius: 10px; border: 1px solid var(--border);
  background: transparent; color: var(--muted);
}
.tab.active { color: var(--text); border-color: var(--border-strong); background: rgba(59, 130, 246, 0.12); }
.tab-count {
  display: inline-block; min-width: 20px; margin-left: 4px; padding: 0 6px; border-radius: 999px;
  background: var(--blue); color: #fff; font-size: 0.72rem; font-weight: 700; line-height: 18px; text-align: center;
}
.textarea { min-height: 90px; resize: vertical; font-family: var(--mono); }
.form-info { min-height: 20px; font-size: 0.88rem; color: var(--muted); }
.section-gap { display: flex; flex-direction: column; gap: 20px; }
.inline { display: inline-flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.toggle { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 0.9rem; user-select: none; }
.toggle input { width: 18px; height: 18px; accent-color: var(--blue); }
.points-row { display: flex; gap: 8px; flex-wrap: wrap; }
.points-row .field { flex: 0 0 92px; }
.points-row .input { padding: 9px 10px; }
.sel { padding: 8px 10px; font-size: 0.85rem; width: auto; }
.round-card { padding: 18px 20px; }
.round-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.round-title { font-weight: 800; font-size: 1.1rem; }
.round-meta { color: var(--muted); font-size: 0.82rem; font-family: var(--mono); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 12px 0; }
.btn-sm { padding: 6px 12px; font-size: 0.82rem; }
.error-text { color: var(--danger); font-size: 0.85rem; }
.admin-top { display: flex; align-items: center; gap: 12px; }
.cf-health {
  display: inline-flex; align-items: center; gap: 7px; padding: 5px 11px; border-radius: 999px; white-space: nowrap;
  border: 1px solid var(--border-strong); font: 600 0.76rem/1.2 var(--mono); color: var(--muted);
}
.cf-health::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.cf-health.ok { color: var(--text); }
.cf-health.ok::before { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.cf-health.slow { color: var(--warn); border-color: rgba(251, 191, 36, 0.45); }
.cf-health.slow::before { background: var(--warn); }
.cf-health.down { color: var(--danger); border-color: rgba(248, 113, 113, 0.5); }
.cf-health.down::before { background: var(--danger); box-shadow: 0 0 6px var(--danger); }
.server-notice {
  margin-bottom: 16px; padding: 12px 16px; border-radius: 12px; font-size: 0.9rem;
  border: 1px solid rgba(248, 113, 113, 0.5); background: rgba(248, 113, 113, 0.1); color: var(--text);
}
.solved-row { align-items: center; margin-top: 10px; }
.addtime { width: 70px; }
.pe-row { display: flex; gap: 8px; align-items: center; margin: 6px 0; }
.pe-row select { flex: 1; min-width: 0; }
.pe-row .pe-num { width: 22px; text-align: right; }
.pe-row .pe-warn { color: var(--danger); font-size: 0.8rem; white-space: nowrap; }
.pe-locked { opacity: 0.6; }
.table tr.has-hist td { border-bottom: none; padding-bottom: 4px; }
.table tr.hist-row td { padding-top: 0; white-space: normal; }
.table tbody tr.hist-row:hover td { background: none; }
.hist { display: flex; flex-wrap: wrap; gap: 6px; }
.hist-chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 999px; font: inherit; font-size: 0.8rem;
  color: var(--muted); background: rgba(148, 163, 184, 0.06); border: 1px solid rgba(148, 163, 184, 0.25);
}
button.hist-chip { cursor: pointer; }
button.hist-chip:hover { border-color: var(--blue-2); }
.hist-chip b { font-weight: 700; }
.hist-chip .hist-opp { color: var(--text); }
.hist-chip.win { border-color: rgba(52, 211, 153, 0.45); }
.hist-chip.win b { color: var(--ok); }
.hist-chip.loss { border-color: rgba(248, 113, 113, 0.45); }
.hist-chip.loss b { color: var(--danger); }
.hist-chip.draw b { color: var(--text); }
.hist-chip.bye { border-color: rgba(59, 130, 246, 0.45); }
.hist-chip.bye b { color: var(--blue-2); }
.hist-chip.pending { border-color: rgba(251, 191, 36, 0.45); }
.hist-chip.pending b { color: var(--warn); }
.hist-chip.none { opacity: 0.6; }

.modal {
  position: fixed; inset: 0; z-index: 100; background: rgba(2, 4, 10, 0.75);
  backdrop-filter: blur(6px); display: flex; justify-content: center; align-items: flex-start;
  padding: 4vh 16px; overflow-y: auto;
}
.modal-box { width: 100%; max-width: 980px; padding: 24px; background: var(--bg-2); }
.modal-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.modal-head .grow { flex: 1; }
.sub-title { font-size: 0.72rem; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); margin: 20px 0 10px; }

/* ---------- Footer ---------- */
.footer {
  text-align: center; color: var(--muted); font-size: 0.78rem; letter-spacing: 0.08em;
  padding: 20px 16px; border-top: 1px solid var(--border);
}

.spinner {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.3); border-top-color: #fff;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Alerts, extension ---------- */
.guard-dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-left: 6px; vertical-align: middle;
  background: var(--danger);
}
.guard-dot.on { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.guard-dot.off { background: var(--warn); }
.viewing-tag {
  display: inline-block; margin-left: 6px; padding: 0 7px; border-radius: 999px; vertical-align: middle;
  border: 1px solid var(--border-strong); color: var(--text); font: 600 0.72rem/18px var(--mono); white-space: nowrap;
}
.viewing-tag.away { color: var(--warn); border-color: rgba(245, 158, 11, 0.4); }
.viewing-tag.dim { color: var(--muted); }
.viewing-tag.ai { color: var(--danger); border-color: rgba(248, 113, 113, 0.55); background: rgba(248, 113, 113, 0.1); }
.viewing-tag.ai.live { animation: ai-pulse 1.4s ease-in-out infinite; }
@keyframes ai-pulse { 50% { background: rgba(248, 113, 113, 0.32); } }
.tl-col.ai-flag { border-color: rgba(248, 113, 113, 0.55); }
.ai-total { font-size: 0.86rem; margin-bottom: 6px; }
.viewing-tag .eye { color: var(--ok, #22c55e); margin-right: 4px; font-size: 0.6rem; vertical-align: 1px; }
.timeline { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 8px; }
.tl-col { padding: 10px 12px; max-height: 320px; overflow-y: auto; }
.tl-head { font-weight: 700; margin-bottom: 6px; }
.tl-row { display: flex; gap: 10px; padding: 3px 0; border-bottom: 1px solid var(--border); font-size: 0.86rem; }
.tl-row:last-child { border-bottom: 0; }
.tl-row .mono { min-width: 58px; }
@keyframes sub-flash { from { background: rgba(59, 130, 246, 0.28); } to { background: transparent; } }
tr.sub-new td { animation: sub-flash 3.5s ease-out; }

.toasts { position: fixed; top: 76px; right: 18px; z-index: 50; display: flex; flex-direction: column; gap: 10px; width: 300px; }
.toast {
  padding: 12px 14px; border-radius: 12px; background: rgba(6, 10, 22, 0.96);
  border: 1px solid var(--border-strong); border-left: 4px solid var(--tc, var(--blue));
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.55); animation: toast-in 0.25s ease-out;
}
.toast-title { font-weight: 800; }
.toast-body { font-size: 0.8rem; color: var(--muted); margin-top: 2px; }
@keyframes toast-in { from { transform: translateX(30px); opacity: 0; } }

.icon-btn {
  background: none; border: 1px solid var(--border-strong); color: var(--muted); border-radius: 999px;
  padding: 4px 10px; font: inherit; font-size: 0.72rem; letter-spacing: 0.1em; text-transform: uppercase; cursor: pointer;
}
.icon-btn:hover { color: var(--text); }

.ext { max-width: 560px; margin: 4vh auto 0; }
.ext-card { padding: 24px; }
.ext-steps { margin: 18px 0 0; padding-left: 20px; display: flex; flex-direction: column; gap: 10px; color: var(--muted); }
.ext-steps b, .ext-steps code { color: var(--text); }
.ext-steps code { font-family: var(--mono); background: rgba(59, 130, 246, 0.12); padding: 1px 6px; border-radius: 6px; }
.ext-status { margin-top: 16px; font-size: 0.85rem; }
.gated { display: none !important; }
.ext-gate { text-align: center; padding: 40px 24px; }
.ext-gate-title { font-size: 1.4rem; font-weight: 800; }
.ext-gate p { margin: 8px 0 20px; }

@media (max-width: 720px) {
  .duel-head { grid-template-columns: 1fr; text-align: center; }
  .player, .player-right { justify-content: center; flex-direction: row; }
  .duel-center { order: -1; }
  .problem { grid-template-columns: 52px 1fr; }
  .problem-side { grid-column: 1 / -1; }
  .room-card-meta { margin-left: 0; width: 100%; }
}
