/* =====================================================================
   Base, components, layouts, pages. All colours come from tokens.css.
   ===================================================================== */

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: var(--lh);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
}
h1, h2, h3, h4 { margin: 0; line-height: var(--lh-tight); font-weight: 600; letter-spacing: -0.02em; }
h1 { font-size: var(--fs-xl); letter-spacing: -0.03em; }
h2 { font-size: var(--fs-lg); }
h3 { font-size: var(--fs-md); }
p { margin: 0 0 var(--s-3); }
a { color: var(--text); text-decoration: underline; text-decoration-color: var(--line-strong); text-underline-offset: 3px; transition: text-decoration-color var(--t-fast), color var(--t-fast); }
a:hover { text-decoration-color: currentColor; }
.prose a, .help a, .foot a, .muted a { color: var(--accent); text-decoration-color: var(--accent-line); }
code, kbd, pre, .mono { font-family: var(--font-mono); }
code { font-size: 0.875em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; border: 1px solid var(--line); }
pre { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-md); padding: var(--s-4); overflow-x: auto; font-size: var(--fs-sm); }
pre code { background: none; border: 0; padding: 0; }
hr { border: 0; border-top: 1px solid var(--line); margin: var(--s-6) 0; }
img, svg { max-width: 100%; }
::selection { background: var(--accent-soft); color: var(--text); }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--r-sm); }
.icon { width: 16px; height: 16px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; vertical-align: -3px; }
.icon.sm { width: 14px; height: 14px; }
.icon.lg { width: 20px; height: 20px; }
.muted { color: var(--text-2); }
.subtle { color: var(--text-3); }
.small { font-size: var(--fs-sm); }
.xs { font-size: var(--fs-xs); }
.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); border: 0; }
.hidden { display: none !important; }
.stack > * + * { margin-top: var(--s-4); }
.stack-sm > * + * { margin-top: var(--s-2); }
.row { display: flex; align-items: center; gap: var(--s-3); }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); flex-wrap: wrap; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.grid { display: grid; gap: var(--s-4); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-sidebar { grid-template-columns: minmax(0, 1fr) 320px; align-items: start; }
.grid > .field + .field { margin-top: 0; }
.grid + .field { margin-top: var(--s-4); }
@media (max-width: 960px) {
  .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-sidebar { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 600px) {
  .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-3); }
}
.prose { max-width: 70ch; line-height: 1.65; }
.prose h2 { font-size: var(--fs-md); margin: var(--s-6) 0 var(--s-2); }
.prose h3 { font-size: var(--fs-base); margin: var(--s-5) 0 var(--s-2); }
.prose ul, .prose ol { padding-left: 1.25em; margin: 0 0 var(--s-3); }
.prose li + li { margin-top: var(--s-1); }
.prose > :first-child { margin-top: 0; }
.prose > :last-child { margin-bottom: 0; }
.prose img { border-radius: var(--r-md); }
.prose table { border-collapse: collapse; margin-bottom: var(--s-3); }
.prose td, .prose th { border: 1px solid var(--line); padding: 4px 10px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; transition-duration: 1ms !important; }
}

/* ---------- Buttons ---------- */
.btn {
  --btn-bg: var(--surface);
  --btn-fg: var(--text);
  --btn-bd: var(--line-strong);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 var(--s-3);
  font: 500 var(--fs-sm)/1 var(--font-sans);
  color: var(--btn-fg); background: var(--btn-bg);
  border: 1px solid var(--btn-bd); border-radius: var(--r-md);
  box-shadow: var(--shadow-sm);
  cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast);
}
.btn:hover { background: var(--surface-hover); color: var(--btn-fg); text-decoration: none; }
.btn[disabled], .btn.is-loading { opacity: .55; cursor: not-allowed; }
.btn-primary { --btn-bg: var(--primary); --btn-fg: var(--on-primary); --btn-bd: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-ghost { --btn-bg: transparent; --btn-bd: transparent; --btn-fg: var(--text-2); box-shadow: none; }
.btn-ghost:hover { color: var(--text); }
.btn-outline { --btn-bg: transparent; }
.btn-danger { --btn-bg: var(--surface); --btn-fg: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 35%, transparent); }
.btn-sm { height: 28px; padding: 0 10px; font-size: var(--fs-xs); border-radius: var(--r-sm); }
.btn-lg { height: 40px; padding: 0 var(--s-5); font-size: var(--fs-base); }
.btn-block { width: 100%; }
.btn-icon { width: 34px; padding: 0; }
.btn-icon.btn-sm { width: 28px; }
.btn-oauth { width: 100%; height: 40px; font-size: var(--fs-base); }
.btn-oauth svg.brand { width: 16px; height: 16px; }
.link-btn { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; }
.link-btn:hover { text-decoration: underline; }
form.inline { display: inline; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field + .field, .field + .row-between, .row-between + .field { margin-top: var(--s-4); }
.label { font-size: var(--fs-sm); font-weight: 500; color: var(--text); display: flex; justify-content: space-between; gap: var(--s-2); }
.label .subtle { font-weight: 400; }
.input, .select, .textarea {
  width: 100%; height: 36px; padding: 0 var(--s-3);
  font: 400 var(--fs-base)/1.4 var(--font-sans);
  color: var(--text); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: var(--r-md);
  box-shadow: var(--shadow-sm);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.textarea { height: auto; min-height: 120px; padding: var(--s-3); resize: vertical; }
.textarea.code, .input.code { font-family: var(--font-mono); font-size: var(--fs-sm); }
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--text-3); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input[aria-invalid="true"] { border-color: var(--danger); }
.input:disabled { background: var(--surface-2); color: var(--text-3); }
.select { appearance: none; padding-right: 30px; background-image: linear-gradient(45deg, transparent 50%, var(--text-3) 50%), linear-gradient(135deg, var(--text-3) 50%, transparent 50%); background-position: calc(100% - 15px) 15px, calc(100% - 11px) 15px; background-size: 4px 4px; background-repeat: no-repeat; }
.help { font-size: var(--fs-xs); color: var(--text-3); }
.field-error { font-size: var(--fs-xs); color: var(--danger); }
.check { display: inline-flex; align-items: center; gap: var(--s-2); font-size: var(--fs-sm); cursor: pointer; }
.check input { width: 15px; height: 15px; accent-color: var(--accent); }
.input-wrap { position: relative; }
.input-wrap .input { padding-right: 40px; }
.input-wrap .btn-reveal { position: absolute; right: 3px; top: 3px; height: 30px; width: 32px; border: 0; background: none; color: var(--text-3); cursor: pointer; border-radius: var(--r-sm); }
.input-wrap .btn-reveal:hover { color: var(--text); }
.strength { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin-top: 2px; }
.strength span { height: 3px; border-radius: 2px; background: var(--line); transition: background var(--t); }
.strength[data-score="1"] span:nth-child(-n+1) { background: var(--danger); }
.strength[data-score="2"] span:nth-child(-n+2) { background: var(--warning); }
.strength[data-score="3"] span:nth-child(-n+3) { background: var(--accent); }
.strength[data-score="4"] span { background: var(--success); }
.otp { display: flex; gap: var(--s-2); justify-content: space-between; }
.otp input {
  width: 100%; max-width: 50px; height: 52px; text-align: center;
  font: 500 var(--fs-lg) var(--font-mono); color: var(--text);
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--r-md);
  box-shadow: var(--shadow-sm);
}
.otp input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.flag-form { display: flex; gap: var(--s-2); }
.flag-form .input { font-family: var(--font-mono); font-size: var(--fs-sm); }
.flag-form.is-wrong .input { border-color: var(--danger); animation: shake 300ms var(--ease); }
.flag-form.is-right .input { border-color: var(--success); }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
.divider-text { display: flex; align-items: center; gap: var(--s-3); color: var(--text-3); font-size: var(--fs-xs); margin: var(--s-5) 0; }
.divider-text::before, .divider-text::after { content: ""; flex: 1; border-top: 1px solid var(--line); }

/* ---------- Panels ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-sm); }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); padding: var(--s-3) var(--s-5); min-height: 48px; border-bottom: 1px solid var(--line); }
.panel-head h2, .panel-head h3 { font-size: var(--fs-base); font-weight: 600; letter-spacing: -0.01em; }
.panel-head a { font-size: var(--fs-sm); color: var(--text-2); }
.panel-body { padding: var(--s-5); }
.panel-body.flush { padding: 0; }
.panel-foot { padding: var(--s-3) var(--s-5); border-top: 1px solid var(--line); background: color-mix(in srgb, var(--surface-2) 50%, transparent); border-radius: 0 0 var(--r-lg) var(--r-lg); }

/* ---------- Stats ---------- */
.stat { padding: var(--s-4) var(--s-5); }
.stat-label { font-size: var(--fs-sm); color: var(--text-2); margin-top: var(--s-1); }
.stat-value { font: 600 var(--fs-xl)/1.1 var(--font-sans); font-variant-numeric: tabular-nums; letter-spacing: -0.03em; }
.stat-delta { font-size: var(--fs-xs); color: var(--text-3); margin-top: 2px; }
.stat-delta a { color: var(--text-2); }
@media (max-width: 600px) {
  .stat { padding: var(--s-3) var(--s-4); }
  .stat-value { font-size: var(--fs-lg); }
}

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  height: 20px; padding: 0 7px;
  font: 500 var(--fs-xs)/1 var(--font-sans);
  color: var(--text-2); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: var(--r-pill);
  white-space: nowrap; vertical-align: middle;
}
.badge .icon { width: 12px; height: 12px; }
.badge-accent { color: var(--accent); background: var(--accent-soft); border-color: transparent; }
.badge-success { color: var(--success); background: var(--success-soft); border-color: transparent; }
.badge-danger { color: var(--danger); background: var(--danger-soft); border-color: transparent; }
.badge-warning { color: var(--warning); background: var(--warning-soft); border-color: transparent; }
.badge-info { color: var(--info); background: var(--info-soft); border-color: transparent; }
.badge-blood { color: var(--blood); background: color-mix(in srgb, var(--blood) 12%, transparent); border-color: transparent; }
.diff { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-xs); color: var(--text-2); }
.diff::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--d, var(--text-3)); }
.diff-easy { --d: var(--diff-easy); }
.diff-medium { --d: var(--diff-medium); }
.diff-hard { --d: var(--diff-hard); }
.diff-insane { --d: var(--diff-insane); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.table th { text-align: left; font-weight: 500; font-size: var(--fs-xs); color: var(--text-3); padding: 10px var(--s-4); border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 10px var(--s-4); border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: color-mix(in srgb, var(--surface-hover) 60%, transparent); }
.table .r { text-align: right; }
.table a.rowlink { color: var(--text); font-weight: 500; text-decoration: none; }
.table a.rowlink:hover { text-decoration: underline; }

/* ---------- Tabs / segmented ---------- */
.tabs { display: flex; gap: var(--s-1); border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.tabs a, .tabs button {
  display: inline-flex; align-items: center; gap: 6px;
  padding: var(--s-3) var(--s-2); margin-bottom: -1px;
  font: 500 var(--fs-sm) var(--font-sans); color: var(--text-2); text-decoration: none;
  background: none; border: 0; border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap;
}
.tabs a:hover, .tabs button:hover { color: var(--text); }
.tabs .is-active { color: var(--text); border-bottom-color: var(--text); }
.segmented { display: inline-flex; padding: 2px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-md); }
.segmented button, .segmented a { height: 28px; padding: 0 var(--s-3); border: 0; background: none; border-radius: var(--r-sm); color: var(--text-2); font: 500 var(--fs-sm) var(--font-sans); cursor: pointer; display: inline-flex; align-items: center; text-decoration: none; }
.segmented .is-active { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08), 0 0 0 1px var(--line); }

/* ---------- Alerts & toasts ---------- */
.alert { display: flex; gap: var(--s-3); align-items: flex-start; padding: var(--s-3) var(--s-4); border-radius: var(--r-md); font-size: var(--fs-sm); border: 1px solid var(--line); background: var(--surface-2); }
.alert .icon { margin-top: 2px; }
.alert-error { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.alert-success { background: var(--success-soft); border-color: color-mix(in srgb, var(--success) 25%, transparent); }
.alert-info { background: var(--info-soft); border-color: color-mix(in srgb, var(--info) 25%, transparent); }
.alert-warning { background: var(--warning-soft); border-color: color-mix(in srgb, var(--warning) 25%, transparent); }
.toasts { position: fixed; z-index: 100; right: var(--s-4); bottom: var(--s-4); display: flex; flex-direction: column; gap: var(--s-2); width: min(360px, calc(100vw - 32px)); }
.toast {
  display: flex; gap: var(--s-3); align-items: flex-start;
  padding: var(--s-3) var(--s-4); background: var(--bg-raised); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--shadow-pop); font-size: var(--fs-sm);
  animation: toast-in var(--t) var(--ease);
}
.toast > .icon { margin-top: 2px; color: var(--info); }
.toast.success > .icon { color: var(--success); }
.toast.error > .icon { color: var(--danger); }
.toast.warning > .icon { color: var(--warning); }
.toast.blood > .icon { color: var(--blood); }
.toast .grow strong { display: block; font-weight: 600; }
.toast.leaving { opacity: 0; transform: translateY(6px); transition: all var(--t); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px) scale(.98); } }

/* ---------- Empty, skeleton, avatar ---------- */
.empty { text-align: center; padding: var(--s-12) var(--s-6); color: var(--text-2); }
.empty .icon { width: 20px; height: 20px; color: var(--text-3); margin-bottom: var(--s-3); }
.empty h3 { color: var(--text); margin-bottom: var(--s-2); font-size: var(--fs-base); }
.empty p { max-width: 44ch; margin: 0 auto var(--s-4); font-size: var(--fs-sm); }
.empty p:last-child { margin-bottom: 0; }
.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--surface-hover), var(--surface-2)); background-size: 200% 100%; animation: sk 1.2s linear infinite; border-radius: var(--r-sm); min-height: 14px; }
@keyframes sk { to { background-position: -200% 0; } }
.avatar { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--surface-2); color: var(--text-2); font: 600 11px var(--font-sans); border: 1px solid var(--line); flex: none; }
.avatar.lg { width: 52px; height: 52px; font-size: var(--fs-md); border-radius: var(--r-lg); }

/* ---------- Dialog / drawer ---------- */
dialog { padding: 0; border: 0; background: transparent; color: var(--text); max-width: none; max-height: none; }
dialog::backdrop { background: rgba(0, 0, 0, 0.4); backdrop-filter: blur(2px); }
.drawer[open] { position: fixed; inset: 8px 8px 8px auto; margin: 0; height: calc(100% - 16px); width: min(620px, calc(100vw - 16px)); animation: drawer-in var(--t) var(--ease); }
.drawer-inner { height: 100%; display: flex; flex-direction: column; background: var(--bg-raised); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-pop); overflow: hidden; }
.drawer-body { flex: 1; overflow-y: auto; padding: var(--s-6); }
.drawer-head { padding: var(--s-5) var(--s-6) var(--s-4); border-bottom: 1px solid var(--line); }
.drawer-foot { padding: var(--s-4) var(--s-6); border-top: 1px solid var(--line); }
@keyframes drawer-in { from { transform: translateX(16px); opacity: 0; } }
@media (max-width: 600px) { .drawer[open] { inset: 0; height: 100%; width: 100vw; } .drawer-inner { border-radius: 0; } }

/* ---------- Dropdown (details/summary) ---------- */
.menu { position: relative; }
.menu > summary { list-style: none; cursor: pointer; }
.menu > summary::-webkit-details-marker { display: none; }
.menu-list { position: absolute; right: 0; top: calc(100% + 6px); z-index: 40; min-width: 220px; padding: var(--s-1); background: var(--bg-raised); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-pop); }
.menu-list a, .menu-list button { display: flex; align-items: center; gap: var(--s-2); width: 100%; padding: 7px var(--s-3); color: var(--text); font: 400 var(--fs-sm) var(--font-sans); background: none; border: 0; border-radius: var(--r-sm); cursor: pointer; text-align: left; text-decoration: none; }
.menu-list a:hover, .menu-list button:hover { background: var(--surface-hover); }
.menu-list .sep { height: 1px; background: var(--line); margin: var(--s-1) 0; }
.menu-head { padding: var(--s-2) var(--s-3) var(--s-3); border-bottom: 1px solid var(--line); margin-bottom: var(--s-1); }

/* =====================================================================
   Layouts
   ===================================================================== */

/* ---------- Brand ---------- */
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); font-weight: 600; letter-spacing: -0.02em; white-space: nowrap; text-decoration: none; }
.brand:hover { color: var(--text); }
.brand img { width: 26px; height: 26px; border-radius: 7px; }
.brand small { display: none; }

/* ---------- Player app: top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 30; background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: saturate(180%) blur(12px); border-bottom: 1px solid var(--line); }
.topbar-inner { max-width: var(--content-w); margin: 0 auto; height: var(--topbar-h); padding: 0 var(--s-6); display: flex; align-items: center; gap: var(--s-6); }
.nav { display: flex; gap: 2px; flex: 1; }
.nav a { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 10px; border-radius: var(--r-md); color: var(--text-2); font-size: var(--fs-sm); font-weight: 500; text-decoration: none; }
.nav a .icon { display: none; }
.nav a:hover { color: var(--text); background: var(--surface-hover); }
.nav a.is-active { color: var(--text); background: var(--surface-2); }
.topbar-actions { display: flex; align-items: center; gap: var(--s-1); }
.topbar-actions .btn-primary, .topbar-actions .btn-ghost:not(.btn-icon) { height: 32px; }
.topbar-actions .menu > summary.btn { padding: 0 4px; }
.bell { position: relative; }
.bell .dot { position: absolute; top: 8px; right: 9px; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 2px var(--bg); }
.event-chip { display: inline-flex; align-items: center; gap: 6px; font: 500 var(--fs-xs) var(--font-sans); color: var(--text-2); padding: 0 10px; height: 26px; border: 1px solid var(--line); border-radius: var(--r-pill); margin-right: var(--s-2); }
.event-chip [data-countdown] { font-family: var(--font-mono); color: var(--text); }
.event-chip .pulse { width: 6px; height: 6px; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 3px var(--success-soft); }
.event-chip.upcoming .pulse { background: var(--info); box-shadow: 0 0 0 3px var(--info-soft); }
.event-chip.ended .pulse, .event-chip.paused .pulse { background: var(--text-3); box-shadow: none; }
.nav-toggle { display: none; }
.page { max-width: var(--content-w); margin: 0 auto; padding: var(--s-10) var(--s-6) var(--s-16); }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s-4); margin-bottom: var(--s-8); flex-wrap: wrap; }
.page-head p { margin: var(--s-2) 0 0; color: var(--text-2); }
.page-head p a { color: var(--text); }
.page-head > div > a.small { color: var(--text-2); text-decoration: none; }
.site-foot { border-top: 1px solid var(--line); }
.site-foot-inner { max-width: var(--content-w); margin: 0 auto; padding: var(--s-6); display: flex; justify-content: space-between; gap: var(--s-4); flex-wrap: wrap; color: var(--text-3); font-size: var(--fs-sm); }
.site-foot a { color: var(--text-3); text-decoration: none; }
.site-foot a:hover { color: var(--text); }
@media (max-width: 860px) {
  .topbar-inner { padding: 0 var(--s-4); gap: var(--s-2); }
  .nav-toggle { display: inline-flex; }
  .nav { display: none; position: absolute; top: var(--topbar-h); left: 0; right: 0; flex-direction: column; padding: var(--s-2); background: var(--bg-raised); border-bottom: 1px solid var(--line); box-shadow: var(--shadow-pop); }
  .nav.is-open { display: flex; }
  .nav a { height: 40px; }
  .nav a .icon { display: inline-block; }
  .event-chip { display: none; }
  .brand { flex: 1; min-width: 0; }
  .brand > span { overflow: hidden; text-overflow: ellipsis; }
  .topbar-actions { flex: none; gap: 2px; }
  .page { padding: var(--s-6) var(--s-4) var(--s-12); }
  .page-head { margin-bottom: var(--s-6); }
}

/* ---------- Auth layout: centred card on a dotted canvas ---------- */
.auth { min-height: 100vh; display: flex; flex-direction: column; align-items: center; padding: var(--s-12) var(--s-4); background-image: radial-gradient(var(--grid-dot) 1px, transparent 1px); background-size: 20px 20px; }
.auth::before { content: ""; position: fixed; inset: 0; pointer-events: none; background: radial-gradient(ellipse 60% 50% at 50% 30%, transparent 0%, var(--bg) 75%); z-index: 0; }
.auth > * { position: relative; z-index: 1; }
.auth-top { margin-bottom: var(--s-8); }
.auth-card { width: 100%; max-width: 400px; padding: var(--s-8); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-pop); }
.auth-card h2 { font-size: var(--fs-lg); letter-spacing: -0.02em; margin-bottom: var(--s-1); }
.auth-card .lead { color: var(--text-2); margin-bottom: var(--s-6); font-size: var(--fs-sm); }
.auth-card .foot { margin-top: var(--s-6); text-align: center; font-size: var(--fs-sm); color: var(--text-2); }
.auth-bottom { margin-top: var(--s-8); font-size: var(--fs-xs); color: var(--text-3); text-align: center; }
.auth-bottom a { color: var(--text-3); }
@media (max-width: 480px) { .auth { padding: var(--s-8) var(--s-3); } .auth-card { padding: var(--s-6) var(--s-5); } }

/* ---------- Admin layout: sidebar ---------- */
.admin { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.admin-side { position: sticky; top: 0; height: 100vh; overflow-y: auto; background: var(--bg); border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.admin-side .brand { padding: var(--s-4) var(--s-5); height: var(--topbar-h); }
.side-nav { padding: var(--s-1) var(--s-3); display: flex; flex-direction: column; gap: 1px; flex: 1; }
.side-nav .group { font-size: var(--fs-xs); color: var(--text-3); padding: var(--s-4) var(--s-2) var(--s-1); }
.side-nav a { display: flex; align-items: center; gap: 10px; height: 30px; padding: 0 var(--s-2); border-radius: var(--r-sm); color: var(--text-2); font-size: var(--fs-sm); font-weight: 500; text-decoration: none; }
.side-nav a .icon { color: var(--text-3); }
.side-nav a:hover { color: var(--text); background: var(--surface-hover); }
.side-nav a.is-active { color: var(--text); background: var(--surface-2); }
.side-nav a.is-active .icon { color: var(--text); }
.admin-side-foot { padding: var(--s-4); border-top: 1px solid var(--line); }
.admin-main { min-width: 0; }
.admin-top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: var(--s-2); height: var(--topbar-h); padding: 0 var(--s-8); background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: saturate(180%) blur(12px); border-bottom: 1px solid var(--line); }
.admin-top .crumbs { flex: 1; font-size: var(--fs-sm); color: var(--text-2); }
.admin-top .crumbs a { color: var(--text-2); }
.admin-page { padding: var(--s-8); max-width: 1280px; }
.admin-toggle { display: none; }
@media (max-width: 960px) {
  .admin { grid-template-columns: 1fr; }
  .admin-side { position: fixed; z-index: 50; width: 248px; transform: translateX(-100%); transition: transform var(--t) var(--ease); background: var(--bg-raised); }
  .admin-side.is-open { transform: none; box-shadow: var(--shadow-pop); }
  .admin-toggle { display: inline-flex; }
  .admin-top { padding: 0 var(--s-4); }
  .admin-page { padding: var(--s-5) var(--s-4); }
}

/* =====================================================================
   Pages
   ===================================================================== */

/* ---------- Landing ---------- */
.hero { position: relative; overflow: hidden; border-bottom: 1px solid var(--line); background-image: radial-gradient(var(--grid-dot) 1px, transparent 1px); background-size: 20px 20px; }
.hero::before { content: ""; position: absolute; inset: 0; pointer-events: none; background: radial-gradient(ellipse 70% 80% at 30% 0%, transparent 0%, var(--bg) 80%); }
.hero::after { content: ""; position: absolute; left: 50%; top: -240px; width: 720px; height: 480px; transform: translateX(-50%); pointer-events: none; background: radial-gradient(closest-side, var(--accent-soft), transparent); }
.hero-inner { position: relative; z-index: 1; max-width: var(--content-w); margin: 0 auto; padding: 112px var(--s-6) 96px; display: grid; grid-template-columns: minmax(0, 7fr) minmax(0, 4fr); gap: var(--s-12); align-items: end; }
.hero h1 { font-size: var(--fs-3xl); font-weight: 600; letter-spacing: -0.045em; line-height: 1.02; max-width: 14ch; }
.hero .tagline { font-size: var(--fs-md); color: var(--text-2); max-width: 46ch; margin: var(--s-5) 0 var(--s-8); line-height: 1.6; }
.hero .org { display: inline-flex; align-items: center; gap: var(--s-2); color: var(--text-2); font-size: var(--fs-sm); margin-bottom: var(--s-6); padding: 4px 12px 4px 4px; border: 1px solid var(--line); border-radius: var(--r-pill); background: var(--surface); }
.hero .org img { width: 22px; height: 22px; border-radius: 50%; }
.countdown { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: var(--s-5); box-shadow: var(--shadow-sm); }
.countdown-label { font-size: var(--fs-sm); color: var(--text-2); margin-bottom: var(--s-3); }
.countdown-state { font: 600 var(--fs-xl)/1.1 var(--font-sans); letter-spacing: -0.03em; color: var(--text); display: flex; align-items: center; gap: 10px; }
.countdown-state::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 4px var(--success-soft); }
.countdown-note { margin: var(--s-3) 0 0; font-size: var(--fs-sm); color: var(--text-2); }
.countdown-digits { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--s-2); }
.countdown-digits div { text-align: center; padding: var(--s-3) 0; background: var(--surface-2); border-radius: var(--r-md); }
.countdown-digits b { display: block; font: 600 var(--fs-xl)/1 var(--font-mono); color: var(--text); font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.countdown-digits span { font-size: var(--fs-xs); color: var(--text-3); }
.countdown-when { margin-top: var(--s-4); padding-top: var(--s-4); border-top: 1px solid var(--line); font-size: var(--fs-sm); color: var(--text-2); }
.section { max-width: var(--content-w); margin: 0 auto; padding: var(--s-16) var(--s-6); }
.section-head { margin-bottom: var(--s-8); max-width: 60ch; }
.section-head h2 { font-size: var(--fs-xl); letter-spacing: -0.03em; margin-bottom: var(--s-3); }
.section-head p { color: var(--text-2); line-height: 1.65; }
.cat-strip { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: var(--s-3); }
.cat-strip .panel { padding: var(--s-4); }
.cat-strip .cat-name { font-weight: 600; }
.cat-strip .cat-count { font-size: var(--fs-sm); color: var(--text-3); }
@media (max-width: 860px) {
  .hero-inner { grid-template-columns: 1fr; padding: var(--s-16) var(--s-4) var(--s-12); gap: var(--s-8); }
  .section { padding: var(--s-10) var(--s-4); }
}

/* ---------- Challenge board ---------- */
.board-toolbar { display: flex; gap: var(--s-2); align-items: center; flex-wrap: wrap; margin-bottom: var(--s-6); }
.board-toolbar .search { flex: 1; min-width: 200px; max-width: 320px; position: relative; }
.board-toolbar .search .icon { position: absolute; left: 11px; top: 10px; color: var(--text-3); }
.board-toolbar .search .input { padding-left: 34px; }
.cat-block + .cat-block { margin-top: var(--s-8); }
.cat-title { display: flex; align-items: baseline; gap: var(--s-2); margin-bottom: var(--s-3); }
.cat-title h2 { font-size: var(--fs-base); font-weight: 600; }
.cat-title .progress-text { font: 500 var(--fs-xs) var(--font-mono); color: var(--text-3); }
.chal-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: var(--s-3); }
.chal {
  position: relative; display: flex; flex-direction: column; gap: var(--s-2);
  min-height: 124px; padding: var(--s-4);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  color: var(--text); text-align: left; font: inherit; cursor: pointer;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.chal:hover { border-color: var(--line-strong); box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06); }
.chal:focus-visible { box-shadow: var(--focus); }
.chal-top { display: flex; justify-content: space-between; align-items: center; gap: var(--s-2); }
.chal-id { font: 500 var(--fs-xs) var(--font-mono); color: var(--text-3); }
.chal-title { font-weight: 600; font-size: var(--fs-base); line-height: 1.35; letter-spacing: -0.01em; }
.chal-meta { margin-top: auto; display: flex; justify-content: space-between; align-items: center; gap: var(--s-2); }
.chal-points { font: 600 var(--fs-md) var(--font-mono); color: var(--text); font-variant-numeric: tabular-nums; }
.chal-points::after { content: " pts"; font: 400 var(--fs-xs) var(--font-sans); color: var(--text-3); }
.chal-solves { font-size: var(--fs-xs); color: var(--text-3); display: inline-flex; gap: 4px; align-items: center; }
.chal.is-solved { background: color-mix(in srgb, var(--success) 4%, var(--surface)); border-color: color-mix(in srgb, var(--success) 30%, var(--line)); }
.chal.is-locked { cursor: not-allowed; opacity: .5; }
.chal-status { position: absolute; right: var(--s-4); bottom: var(--s-4); }
.chal.is-solved .chal-solves { display: none; }
.chal-detail .chal-desc { margin-top: var(--s-5); }
.chal-facts { display: flex; flex-wrap: wrap; gap: 6px; }
.conn { display: flex; align-items: center; gap: var(--s-2); padding: 6px 6px 6px var(--s-3); background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-md); font: var(--fs-sm) var(--font-mono); }
.conn code { background: none; border: 0; padding: 0; flex: 1; overflow-x: auto; white-space: nowrap; }
.file-list { display: flex; flex-direction: column; gap: var(--s-2); }
.file { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-2) var(--s-3); border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); color: var(--text); text-decoration: none; }
.file:hover { border-color: var(--line-strong); background: var(--surface-hover); color: var(--text); }
.file .grow { font-size: var(--fs-sm); }
.file .hash { font: var(--fs-xs) var(--font-mono); color: var(--text-3); }
.hint { border: 1px dashed var(--line-strong); border-radius: var(--r-md); padding: var(--s-3) var(--s-4); }
.hint.is-open { border-style: solid; background: var(--surface-2); }
.chal-detail .detail-section { margin-top: var(--s-6); }
.detail-section > h3 { font-size: var(--fs-xs); color: var(--text-3); font-weight: 500; margin-bottom: var(--s-2); }
.solver-list { padding: 0; margin: 0; display: flex; flex-direction: column; }
.solver-list li { display: flex; justify-content: space-between; gap: var(--s-3); padding: var(--s-2) 0; border-bottom: 1px solid var(--line); font-size: var(--fs-sm); list-style: none; }
.solver-list li:last-child { border-bottom: 0; }

/* ---------- Scoreboard ---------- */
.rank { display: inline-grid; place-items: center; min-width: 24px; height: 22px; padding: 0 6px; font: 600 var(--fs-xs) var(--font-mono); color: var(--text-2); border-radius: var(--r-sm); background: var(--surface-2); }
.rank-1 { color: #92400E; background: #FEF3C7; }
.rank-2 { color: #3F3F46; background: #E4E4E7; }
.rank-3 { color: #9A3412; background: #FFEDD5; }
:root[data-theme="dark"] .rank-1 { color: #FCD34D; background: rgba(252, 211, 77, 0.14); }
:root[data-theme="dark"] .rank-2 { color: #D4D4D8; background: rgba(212, 212, 216, 0.12); }
:root[data-theme="dark"] .rank-3 { color: #FDBA74; background: rgba(253, 186, 116, 0.13); }
tr.is-me td { background: var(--accent-soft) !important; }
.score { font: 600 var(--fs-base) var(--font-mono); font-variant-numeric: tabular-nums; }
.chart-box { position: relative; height: 300px; }
.chart-box.sm { height: 210px; }
.freeze-banner { display: flex; gap: var(--s-3); align-items: center; padding: var(--s-3) var(--s-4); margin-bottom: var(--s-5); border-radius: var(--r-md); background: var(--info-soft); color: var(--text); font-size: var(--fs-sm); }

/* ---------- Feed ---------- */
.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: flex; gap: var(--s-3); align-items: flex-start; padding: var(--s-3) var(--s-5); border-bottom: 1px solid var(--line); font-size: var(--fs-sm); }
.feed li:last-child { border-bottom: 0; }
.feed li a { color: var(--text); text-decoration: none; }
.feed li a:hover { text-decoration: underline; }
.feed .feed-icon { width: 26px; height: 26px; display: grid; place-items: center; border-radius: 50%; background: var(--surface-2); color: var(--text-2); flex: none; }
.feed .feed-icon.blood { background: color-mix(in srgb, var(--blood) 12%, transparent); color: var(--blood); }
.feed .feed-icon.award { background: var(--accent-soft); color: var(--accent); }
.feed .feed-icon.solve { background: var(--success-soft); color: var(--success); }
.feed time { color: var(--text-3); font-size: var(--fs-xs); }
.announcement { padding: var(--s-4) var(--s-5); border-bottom: 1px solid var(--line); }
.announcement:last-child { border-bottom: 0; }
.announcement h3 { font-size: var(--fs-base); margin-bottom: var(--s-1); display: flex; gap: var(--s-2); align-items: center; flex-wrap: wrap; }

/* ---------- Team ---------- */
.team-hero { display: flex; gap: var(--s-4); align-items: center; flex-wrap: wrap; }
.invite-code { display: inline-flex; align-items: center; gap: var(--s-2); font: 600 var(--fs-md) var(--font-mono); letter-spacing: .14em; padding: 6px var(--s-3); background: var(--surface); border: 1px dashed var(--line-strong); border-radius: var(--r-md); color: var(--text); }
.choice-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-4); }
@media (max-width: 700px) { .choice-grid { grid-template-columns: 1fr; } }
.bar { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 3px; }

/* ---------- Admin specifics ---------- */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: var(--s-2) var(--s-5); font-size: var(--fs-sm); margin: 0; }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; }
.repeat-row { display: grid; gap: var(--s-2); align-items: start; padding: var(--s-3); border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface-2); }
.repeat-row + .repeat-row { margin-top: var(--s-2); }
.flag-row { grid-template-columns: 110px minmax(0, 1fr) auto auto; align-items: center; }
.hint-row { grid-template-columns: minmax(0, 1fr) 96px auto; }
@media (max-width: 700px) { .flag-row, .hint-row { grid-template-columns: 1fr; } }
.md-split { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: var(--s-3); }
.md-split .preview { border: 1px solid var(--line); border-radius: var(--r-md); padding: var(--s-3) var(--s-4); background: var(--surface-2); min-height: 220px; max-height: 480px; overflow-y: auto; }
.dropzone { display: flex; flex-direction: column; align-items: center; gap: var(--s-2); padding: var(--s-6); border: 1px dashed var(--line-strong); border-radius: var(--r-md); color: var(--text-2); text-align: center; cursor: pointer; transition: border-color var(--t-fast), background var(--t-fast); }
.dropzone.is-over, .dropzone:hover { border-color: var(--accent); background: var(--accent-soft); }
.heatmap { display: grid; grid-template-columns: 32px repeat(24, minmax(0, 1fr)); gap: 2px; font: 10px var(--font-mono); color: var(--text-3); }
.heatmap .cell { aspect-ratio: 1; border-radius: 2px; background: var(--surface-2); }
.pagination { display: flex; gap: var(--s-2); justify-content: flex-end; align-items: center; padding: var(--s-3) var(--s-4); border-top: 1px solid var(--line); font-size: var(--fs-sm); color: var(--text-2); }
.filters { display: flex; gap: var(--s-2); flex-wrap: wrap; align-items: center; }
.filters .input, .filters .select { height: 32px; width: auto; font-size: var(--fs-sm); }
.error-page { text-align: center; padding: var(--s-16) var(--s-4); }
.error-page .code { font: 600 64px/1 var(--font-mono); color: var(--text-3); letter-spacing: -0.04em; }
