:root {
  --radius: 12px;
  --accent: #ff5a3c;
  --accent-2: #ffb02e;
  --good: #2fbf71;
  --bad: #ff5d6c;
  --warn: #f0a62b;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
:root[data-theme="dark"] {
  --bg: #0e1014; --surface: #161a22; --surface-2: #1e2430; --border: #2a3140;
  --text: #e8ecf3; --muted: #8f9bb0; --link: #ff8a70; --shadow: 0 8px 30px rgba(0,0,0,.35);
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f3f4f8; --surface: #ffffff; --surface-2: #eef0f6; --border: #d9dde8;
  --text: #171b24; --muted: #5d6882; --link: #d4401f; --shadow: 0 8px 30px rgba(30,40,70,.12);
  color-scheme: light;
}

* { box-sizing: border-box; }
html { scroll-padding-top: 80px; }
body {
  margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 var(--font);
  min-height: 100vh; display: flex; flex-direction: column;
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
h1 { font-size: 1.8rem; } h2 { font-size: 1.35rem; } h3 { font-size: 1.05rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- top bar */
.topbar { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); }
.topbar::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2) 60%, transparent); opacity: .8; }
.topbar-inner { max-width: 1280px; margin: 0 auto; padding: 10px 20px; display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.15rem; color: var(--text); letter-spacing: .2px; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 22px; height: 22px; background: linear-gradient(135deg, var(--accent), var(--accent-2));
  transform: rotate(45deg); border-radius: 4px; box-shadow: 0 0 14px color-mix(in srgb, var(--accent) 55%, transparent); }
.nav { display: flex; gap: 4px; flex-wrap: wrap; }
.nav-link { color: var(--muted); padding: 7px 12px; border-radius: 8px; font-weight: 600; }
.nav-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-link[aria-current="page"] { color: var(--text); background: var(--surface-2); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.auth { display: flex; align-items: center; gap: 8px; }
.user-chip { display: flex; align-items: center; gap: 8px; padding: 5px 10px; border-radius: 999px; background: var(--surface-2);
  color: var(--text); font-weight: 600; }
.user-chip:hover { text-decoration: none; background: var(--border); }
.icon-btn { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); width: 36px; height: 36px; border-radius: 10px; cursor: pointer; font-size: 1.05rem; }
.icon-btn:hover { background: var(--border); }

.container { width: 100%; max-width: 1280px; margin: 0 auto; padding: 24px 20px 48px; flex: 1; outline: none; }
.footer { text-align: center; color: var(--muted); font-size: .85rem; padding: 18px; border-top: 1px solid var(--border); }

/* ---------- generic components */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; }
.card.narrow { max-width: 480px; margin-left: auto; margin-right: auto; }
.card.medium { max-width: 720px; margin-left: auto; margin-right: auto; }
.page-title { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-title p { margin: 0; color: var(--muted); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 16px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; }
.btn:hover { background: var(--border); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: linear-gradient(135deg, var(--accent), #ff7a45); border-color: transparent; color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.good { background: var(--good); border-color: transparent; color: #04200f; }
.btn.danger { background: transparent; color: var(--bad); border-color: color-mix(in srgb, var(--bad) 55%, transparent); }
.btn.danger:hover { background: color-mix(in srgb, var(--bad) 14%, transparent); }
.btn.small { padding: 5px 10px; font-size: .85rem; border-radius: 8px; }
.btn.block { width: 100%; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.field > span { font-weight: 600; font-size: .9rem; }
.field .hint { font-weight: 400; color: var(--muted); font-size: .82rem; }
input, select, textarea { width: 100%; background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; font: inherit; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 70%, transparent); border-color: var(--accent); }
textarea { resize: vertical; min-height: 80px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 0 14px; }
.form-error { color: var(--bad); background: color-mix(in srgb, var(--bad) 12%, transparent); border: 1px solid color-mix(in srgb, var(--bad) 40%, transparent);
  padding: 9px 12px; border-radius: 10px; margin-bottom: 14px; }
.form-ok { color: var(--good); background: color-mix(in srgb, var(--good) 12%, transparent); border: 1px solid color-mix(in srgb, var(--good) 40%, transparent);
  padding: 9px 12px; border-radius: 10px; margin-bottom: 14px; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .75rem; font-weight: 700; letter-spacing: .3px;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.badge.pending { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 50%, transparent); background: color-mix(in srgb, var(--warn) 12%, transparent); }
.badge.approved { color: var(--good); border-color: color-mix(in srgb, var(--good) 50%, transparent); background: color-mix(in srgb, var(--good) 12%, transparent); }
.badge.rejected { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 50%, transparent); background: color-mix(in srgb, var(--bad) 12%, transparent); }
.badge.main { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 50%, transparent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.badge.extended { color: var(--accent-2); border-color: color-mix(in srgb, var(--accent-2) 50%, transparent); background: color-mix(in srgb, var(--accent-2) 12%, transparent); }
.badge.role-admin { color: #fff; background: var(--accent); border-color: transparent; }
.badge.role-moderator { color: var(--accent-2); border-color: color-mix(in srgb, var(--accent-2) 50%, transparent); }

.flag { width: 24px; height: 18px; border-radius: 3px; object-fit: cover; vertical-align: -3px; box-shadow: 0 0 0 1px var(--border); }
.flag-code { display: inline-block; min-width: 24px; text-align: center; font: 700 .7rem var(--mono); color: var(--muted); }
.flag-none { display: inline-block; width: 24px; height: 18px; }

table.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .6px; font-weight: 700; }
.table tbody tr:hover { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }
.rank { font: 700 .95rem var(--mono); color: var(--muted); }
.rank.top { color: var(--accent-2); }
.empty { text-align: center; color: var(--muted); padding: 32px 12px; }
.player { display: inline-flex; align-items: center; gap: 8px; color: var(--text); font-weight: 600; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; flex-wrap: wrap; }
.tab { padding: 9px 16px; color: var(--muted); font-weight: 700; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab:hover { color: var(--text); text-decoration: none; }
.tab[aria-current="page"] { color: var(--text); border-bottom-color: var(--accent); }
.tab .count { margin-left: 6px; background: var(--accent); color: #fff; border-radius: 999px; padding: 1px 7px; font-size: .72rem; }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar > * { width: auto; }
.toolbar input[type="search"] { min-width: 220px; }

.stat-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 18px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.tile .v { font: 800 1.6rem var(--font); }
.tile .k { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .6px; font-weight: 700; }

/* ---------- list page */
.list-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(360px, 460px); gap: 22px; align-items: start; }
.list-col h3.section { margin: 22px 0 8px; display: flex; align-items: baseline; gap: 10px; color: var(--muted);
  text-transform: uppercase; letter-spacing: .8px; font-size: .82rem; }
.list-col h3.section:first-of-type { margin-top: 6px; }
.list-search { margin-bottom: 6px; }
.level-card { display: flex; align-items: center; gap: 14px; padding: 8px 14px 8px 8px; margin-bottom: 8px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); transition: border-color .12s, transform .12s; }
.level-card:hover { text-decoration: none; border-color: color-mix(in srgb, var(--accent) 60%, var(--border)); transform: translateX(2px); }
.level-card.active { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 9%, var(--surface)); }
.level-card .pos { font: 800 1.15rem var(--mono); width: 3.1ch; text-align: center; color: var(--muted); flex: none; }
.level-card.top3 .pos { color: var(--accent-2); }
.level-card .thumb { width: 120px; height: 68px; object-fit: cover; border-radius: 8px; background: var(--surface-2); flex: none; }
.lc-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.lc-name { font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lc-by { color: var(--muted); font-size: .88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lc-pts { color: var(--muted); font: 600 .85rem var(--mono); white-space: nowrap; }

.detail-col { position: sticky; top: 84px; max-height: calc(100vh - 100px); overflow-y: auto; }
.detail { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.detail .back { display: none; margin-bottom: 10px; }
.detail h2 { margin-bottom: 2px; }
.detail .by { color: var(--muted); margin-bottom: 12px; }
.video { position: relative; aspect-ratio: 16 / 9; background: #000; border-radius: 10px; overflow: hidden; margin-bottom: 14px; }
.video iframe, .video-play, .video-play img { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.video-play { padding: 0; background: #000; cursor: pointer; border: 0; }
.video-play img { object-fit: cover; opacity: .85; transition: opacity .15s; }
.video-play:hover img { opacity: 1; }
.play-icon { position: absolute; inset: 0; margin: auto; width: 64px; height: 64px; border-radius: 50%; background: rgba(255,90,60,.92); color: #fff;
  display: grid; place-items: center; font-size: 1.5rem; padding-left: 4px; box-shadow: 0 6px 24px rgba(0,0,0,.45); }
.stats-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 16px; }
.stat { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
.stat .k { color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .6px; font-weight: 700; }
.stat .v { font-weight: 700; word-break: break-word; }
.mono { font-family: var(--mono); }
.records-title { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin: 6px 0 4px; }

/* ---------- admin / records */
.rec-card { display: grid; grid-template-columns: 160px minmax(0, 1fr) auto; gap: 16px; padding: 14px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 12px; align-items: start; }
.rec-card img.thumb { width: 160px; height: 90px; object-fit: cover; border-radius: 8px; background: var(--surface-2); display: block; }
.rec-title { font-weight: 800; font-size: 1.05rem; }
.rec-meta { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; color: var(--muted); font-size: .9rem; margin: 4px 0; }
.rec-note { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; margin-top: 8px; white-space: pre-wrap; word-break: break-word; font-size: .9rem; }
.rec-actions { display: flex; flex-direction: column; gap: 8px; min-width: 120px; }
.reject-box { display: flex; gap: 8px; margin-top: 8px; }
details.card > summary { cursor: pointer; font-weight: 700; }
details.card[open] > summary { margin-bottom: 14px; }

dialog { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 22px; width: min(560px, calc(100vw - 32px)); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(0,0,0,.6); }
.pw-reveal { font: 700 1.2rem var(--mono); background: var(--bg); border: 1px dashed var(--accent); padding: 12px; border-radius: 10px;
  text-align: center; user-select: all; word-break: break-all; margin: 14px 0; }

.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast { background: var(--surface-2); border: 1px solid var(--border); border-left: 4px solid var(--good); padding: 10px 14px;
  border-radius: 10px; box-shadow: var(--shadow); max-width: 360px; animation: pop .18s ease-out; }
.toast.error { border-left-color: var(--bad); }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- responsive */
@media (max-width: 960px) {
  .list-layout { grid-template-columns: minmax(0, 1fr); }
  .detail-col { position: static; max-height: none; overflow: visible; }
  .list-layout:not(.has-selection) .detail-col { display: none; }
  .list-layout.has-selection .list-col { display: none; }
  .detail .back { display: inline-block; }
  .rec-card { grid-template-columns: 1fr; }
  .rec-card img.thumb { width: 100%; height: auto; aspect-ratio: 16/9; }
  .rec-actions { flex-direction: row; flex-wrap: wrap; }
}
@media (max-width: 560px) {
  .container { padding: 16px 12px 40px; }
  .topbar-inner { padding: 8px 12px; gap: 10px; }
  .level-card .thumb { width: 84px; height: 48px; }
  .lc-pts { display: none; }
  .card { padding: 16px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
