:root {
  --bg: #010a13;
  --bg2: #0a1428;
  --panel: #0f1b2d;
  --panel2: #142338;
  --line: #1e2d40;
  --line2: #2b3e57;
  --text: #e8e4d8;
  --muted: #8d97a5;
  --gold: #c8aa6e;
  --gold2: #f0e6d2;
  --gold-dim: #785a28;
  --teal: #0ac8b9;
  --blue: #0397ab;
  --red: #e84057;
  --green: #3ecf8e;
  --r-silver: #b9c3cf;
  --r-gold: #f2c14e;
  --r-diamond: #6fd3ff;
  --r-gm: #ff5ca8;
  --radius: 10px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: radial-gradient(1200px 600px at 70% -10%, #0d2a3f 0%, transparent 60%),
    radial-gradient(900px 500px at -10% 110%, #1b1530 0%, transparent 60%), var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font: 15px/1.5 Inter, system-ui, sans-serif;
  min-height: 100vh;
}
a { color: var(--teal); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { font-family: Cinzel, Georgia, serif; color: var(--gold2); letter-spacing: 0.02em; margin: 0 0 12px; }
h1 { font-size: 28px; }
h2 { font-size: 20px; }
h3 { font-size: 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.gold { color: var(--gold); }
.pos { color: var(--green); }
.neg { color: var(--red); }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.mono { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

.container { max-width: 1180px; margin: 0 auto; padding: 24px 16px 64px; }

/* Topbar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 18px;
  padding: 10px 20px;
  background: rgba(1, 10, 19, 0.88);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--gold-dim);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--gold2); font-family: Cinzel, serif; font-weight: 800; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 32px; height: 32px; display: grid; place-items: center;
  border: 2px solid var(--gold); transform: rotate(45deg); font-size: 14px;
}
.brand-mark { color: var(--gold); }
.brand-mark > span { transform: rotate(-45deg); }
.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.nav a {
  color: var(--muted); padding: 8px 12px; border-radius: 6px; font-weight: 600; font-size: 14px; white-space: nowrap;
}
.nav a:hover { color: var(--gold2); text-decoration: none; background: rgba(200, 170, 110, 0.08); }
.nav a.active { color: var(--gold2); background: rgba(200, 170, 110, 0.14); box-shadow: inset 0 -2px 0 var(--gold); }
.userbox { display: flex; align-items: center; gap: 8px; }
.userchip { color: var(--gold2); font-weight: 600; font-size: 14px; white-space: nowrap; }

/* Buttons & form */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: 6px; cursor: pointer;
  font: 600 14px Inter, sans-serif; letter-spacing: 0.02em;
  color: var(--bg); background: linear-gradient(180deg, #e2c98f, var(--gold));
  border: 1px solid var(--gold);
  transition: filter 0.15s, transform 0.05s;
}
.btn:hover { filter: brightness(1.1); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; filter: none; }
.btn.ghost { background: transparent; color: var(--gold2); border-color: var(--line2); }
.btn.ghost:hover { border-color: var(--gold); }
.btn.teal { background: linear-gradient(180deg, #2fe0d2, var(--teal)); border-color: var(--teal); }
.btn.danger { background: transparent; color: var(--red); border-color: rgba(232, 64, 87, 0.5); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.block { width: 100%; }

input, select, textarea {
  font: inherit; color: var(--text);
  background: var(--bg2); border: 1px solid var(--line2); border-radius: 6px;
  padding: 8px 10px; min-width: 0;
}
input:focus, select:focus { outline: none; border-color: var(--gold); }
input[type='checkbox'] { width: 16px; height: 16px; accent-color: var(--gold); }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
.field { margin-bottom: 14px; }
.field input, .field select { width: 100%; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1; }
.stack > * + * { margin-top: 16px; }

/* Panels */
.panel {
  background: linear-gradient(180deg, var(--panel), rgba(15, 27, 45, 0.85));
  border: 1px solid var(--line); border-radius: var(--radius); padding: 18px;
}
.panel.gold { border-color: var(--gold-dim); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-team { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: 18px; align-items: start; }
@media (max-width: 900px) {
  .grid2, .grid-team { grid-template-columns: 1fr; }
}

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h1 { margin: 0; }

/* Auth */
.auth-wrap { min-height: 80vh; display: grid; place-items: center; }
.auth-card { width: 100%; max-width: 420px; }
.auth-hero { text-align: center; margin-bottom: 22px; }
.auth-hero h1 { font-size: 34px; margin-bottom: 4px; }
.auth-hero .trophy { font-size: 46px; filter: drop-shadow(0 0 18px rgba(200, 170, 110, 0.5)); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs button {
  background: none; border: none; color: var(--muted); font: 600 14px Inter, sans-serif;
  padding: 10px 14px; cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap;
}
.tabs button.active { color: var(--gold2); border-bottom-color: var(--gold); }

/* Round banner */
.round-banner {
  display: flex; gap: 18px; align-items: center; justify-content: space-between; flex-wrap: wrap;
  padding: 14px 18px; margin-bottom: 18px;
  border: 1px solid var(--gold-dim); border-radius: var(--radius);
  background: linear-gradient(90deg, rgba(200, 170, 110, 0.12), rgba(10, 200, 185, 0.06));
}
.round-banner .title { font-family: Cinzel, serif; color: var(--gold2); font-size: 18px; }
.countdown { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--teal); font-size: 18px; }

/* Budget */
.budget { margin-bottom: 14px; }
.budget-bar { height: 10px; background: var(--bg2); border: 1px solid var(--line2); border-radius: 99px; overflow: hidden; }
.budget-fill { height: 100%; background: linear-gradient(90deg, var(--teal), var(--gold)); transition: width 0.25s; }
.budget-fill.over { background: var(--red); }

/* Lineup */
.slots { display: grid; gap: 10px; }
.slot {
  display: grid; grid-template-columns: 54px minmax(0, 1fr) auto; gap: 12px; align-items: center;
  padding: 10px 12px; border-radius: var(--radius);
  background: var(--panel2); border: 1px solid var(--line); cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.slot:hover { border-color: var(--line2); }
.slot.selected { border-color: var(--gold); background: rgba(200, 170, 110, 0.08); }
.slot.empty .pname { color: var(--muted); font-weight: 500; }
.role-badge {
  width: 54px; height: 54px; display: grid; place-items: center; border-radius: 8px;
  font: 800 12px Inter, sans-serif; letter-spacing: 0.06em; color: var(--gold2);
  background: radial-gradient(circle at 30% 20%, #23395a, #0b1626); border: 1px solid var(--gold-dim);
}
.pname { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.pmeta { font-size: 13px; color: var(--muted); }
.slot-actions { display: flex; gap: 6px; align-items: center; }
.icon-btn {
  width: 34px; height: 34px; display: grid; place-items: center; border-radius: 6px; cursor: pointer;
  background: var(--bg2); border: 1px solid var(--line2); color: var(--muted); font-size: 16px;
}
.icon-btn:hover { border-color: var(--gold); color: var(--gold2); }
.icon-btn.on { border-color: var(--gold); color: var(--bg); background: var(--gold); }
.item-chip {
  display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600;
  padding: 2px 8px; border-radius: 99px; border: 1px solid currentColor; background: rgba(0, 0, 0, 0.25);
  cursor: pointer;
}
.item-chip.add { color: var(--muted); border-style: dashed; }
.tag { display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 4px; background: var(--bg2); border: 1px solid var(--line2); color: var(--muted); }
.tag.cap { color: var(--bg); background: var(--gold); border-color: var(--gold); }
.tag.reward { color: var(--gold); border-color: var(--gold); white-space: normal; text-align: center; line-height: 1.4; }
.tag.elim { color: var(--red); border-color: rgba(232, 64, 87, 0.5); }

.r0 { color: var(--r-silver); }
.r1 { color: var(--r-gold); }
.r2 { color: var(--r-diamond); }
.r3 { color: var(--r-gm); }

.save-bar { display: flex; gap: 10px; align-items: center; margin-top: 14px; flex-wrap: wrap; }
.dirty { color: var(--gold); font-size: 13px; font-weight: 600; }

/* Market */
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.filters input { flex: 1; min-width: 140px; }
.role-tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 10px; }
.role-tabs button {
  background: var(--bg2); border: 1px solid var(--line2); color: var(--muted); border-radius: 6px;
  padding: 5px 10px; font: 700 12px Inter, sans-serif; cursor: pointer;
}
.role-tabs button.active { color: var(--bg); background: var(--gold); border-color: var(--gold); }
.market { max-height: 620px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 700; background: var(--bg2); position: sticky; top: 0; z-index: 1; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: rgba(255, 255, 255, 0.02); }
tr.picked td { background: rgba(10, 200, 185, 0.07); }
tr.me td { background: rgba(200, 170, 110, 0.1); }
tr.clickable { cursor: pointer; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }
.table-wrap th { position: static; }

.rank { font-family: Cinzel, serif; font-weight: 800; width: 40px; }
.rank-1 { color: #ffd76a; }
.rank-2 { color: #d6dde6; }
.rank-3 { color: #d39a63; }

/* F1-style podium: 1st in the middle (tallest), 2nd left, 3rd right */
.podium { display: flex; align-items: flex-end; justify-content: center; gap: 10px; margin: 16px 0 24px; }
.podium-spot {
  flex: 1 1 0; min-width: 0; max-width: 170px; text-align: center; cursor: pointer;
  background: var(--bg2); border: 1px solid var(--line2); border-radius: 10px 10px 4px 4px;
  padding: 14px 8px; display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.podium-spot.place-2 { order: 1; padding-bottom: 6px; }
.podium-spot.place-1 { order: 2; padding: 22px 8px 14px; border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold) inset; }
.podium-spot.place-3 { order: 3; padding-bottom: 2px; }
.pd-medal { font-size: 26px; line-height: 1; }
.podium-spot.place-1 .pd-medal { font-size: 36px; }
.pd-name { font-weight: 700; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pd-user { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pd-pts { font-weight: 800; font-size: 15px; margin-top: 2px; }
.pd-reward { margin-top: 4px; }
@media (max-width: 420px) {
  .podium-spot { padding: 10px 4px; }
  .podium-spot.place-1 { padding: 16px 4px 10px; }
  .pd-medal { font-size: 20px; }
  .podium-spot.place-1 .pd-medal { font-size: 28px; }
  .pd-pts { font-size: 13px; }
}

/* Items */
.items-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.item-card {
  position: relative; padding: 14px; border-radius: var(--radius);
  background: linear-gradient(180deg, var(--panel2), var(--bg2));
  border: 1px solid var(--line2);
  display: flex; flex-direction: column; gap: 6px;
}
.item-card.r1 { border-color: rgba(242, 193, 78, 0.55); }
.item-card.r2 { border-color: rgba(111, 211, 255, 0.6); box-shadow: 0 0 18px rgba(111, 211, 255, 0.12); }
.item-card.r3 { border-color: rgba(255, 92, 168, 0.75); box-shadow: 0 0 24px rgba(255, 92, 168, 0.22); }
.item-icon { font-size: 30px; line-height: 1; }
.item-name { font-weight: 700; color: var(--text); }
.item-rarity { font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.08em; }
.item-desc { font-size: 13px; color: var(--muted); flex: 1; }
.item-count {
  position: absolute; top: 10px; right: 10px; font-weight: 800; font-size: 13px;
  background: var(--bg); border: 1px solid var(--line2); border-radius: 99px; padding: 1px 8px;
}
.item-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.stat-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 18px; }
.tile { padding: 14px 16px; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--line); }
.tile .v { font-size: 26px; font-weight: 800; color: var(--gold2); font-variant-numeric: tabular-nums; }
.tile .l { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; font-weight: 700; }

/* Booster reveal */
.reveal { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 560px) { .reveal { grid-template-columns: 1fr; } }
.reveal .item-card { opacity: 0; transform: translateY(14px) scale(0.96); animation: pop 0.45s forwards; }
.reveal .item-card:nth-child(2) { animation-delay: 0.35s; }
.reveal .item-card:nth-child(3) { animation-delay: 0.7s; }
@keyframes pop { to { opacity: 1; transform: none; } }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, 0.7);
  display: grid; place-items: center; padding: 16px; animation: fade 0.15s;
}
.modal {
  width: 100%; max-width: 620px; max-height: 88vh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--gold-dim); border-radius: 12px; padding: 20px;
  box-shadow: var(--shadow);
}
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.modal-head h2 { margin: 0; }
@keyframes fade { from { opacity: 0; } }

.pick-list { display: grid; gap: 8px; }
.pick {
  display: flex; gap: 12px; align-items: center; padding: 10px 12px; border-radius: 8px; cursor: pointer;
  background: var(--panel2); border: 1px solid var(--line);
}
.pick:hover { border-color: var(--gold); }
.pick.current { border-color: var(--teal); }

/* Toasts */
#toasts { position: fixed; bottom: 16px; right: 16px; left: 16px; z-index: 60; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; pointer-events: none; }
.toast {
  pointer-events: auto; max-width: 420px; padding: 10px 14px; border-radius: 8px; font-weight: 600; font-size: 14px;
  background: var(--panel2); border: 1px solid var(--line2); box-shadow: var(--shadow); animation: fade 0.2s;
}
.toast.ok { border-color: var(--teal); }
.toast.err { border-color: var(--red); color: #ffd0d6; }

/* Results */
.game { margin-bottom: 16px; }
.game-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.vs { font-family: Cinzel, serif; font-size: 18px; color: var(--gold2); }
.vs .w { color: var(--teal); }

.breakdown td, .breakdown th { padding: 6px 8px; font-size: 13px; }
.history-round { margin-bottom: 16px; }

.empty-state { text-align: center; padding: 36px 16px; color: var(--muted); }
.empty-state .big { font-size: 38px; margin-bottom: 8px; }

.code-box {
  font-family: ui-monospace, Consolas, monospace; font-size: 18px; letter-spacing: 0.2em; font-weight: 700;
  color: var(--gold2); background: var(--bg2); border: 1px dashed var(--gold-dim); padding: 4px 10px; border-radius: 6px;
}

.rules p, .rules li { color: #cfd5dd; }
.rules ul { padding-left: 20px; }

/* Admin */
.admin-table input, .admin-table select { padding: 5px 7px; font-size: 13px; }
.admin-table input.num { width: 64px; }
.stats-table input { width: 52px; padding: 4px 5px; font-size: 13px; text-align: center; }
.stats-table td, .stats-table th { padding: 5px 6px; }
.team-blue { color: #5ab0ff; }
.team-red { color: #ff6b7d; }

@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; gap: 8px; padding: 10px 16px; }
  .nav { order: 3; width: 100%; flex: none; }
  .userbox { margin-left: auto; }
  .brand-text { display: none; }
  .container { padding: 16px 16px 48px; }
  h1 { font-size: 22px; }
  .slot { grid-template-columns: 44px minmax(0, 1fr); }
  .role-badge { width: 44px; height: 44px; font-size: 11px; }
  .slot-actions { grid-column: 1 / -1; justify-content: flex-end; }
  .hide-sm { display: none; }
}

/* Photos */
.avatar {
  width: 36px; height: 36px; border-radius: 50%; object-fit: cover; object-position: top;
  background: radial-gradient(circle at 30% 20%, #23395a, #0b1626); border: 1px solid var(--line2); flex: none;
}
.avatar.logo { object-fit: contain; padding: 3px; border-radius: 8px; }
.avatar.lg { width: 84px; height: 84px; }
.avatar.ph { display: grid; place-items: center; font: 800 11px Inter, sans-serif; color: var(--gold2); }
.slot-pic { position: relative; width: 54px; height: 54px; }
.slot-pic .avatar { width: 54px; height: 54px; border-radius: 10px; border-color: var(--gold-dim); }
.slot-pic .role-mini {
  position: absolute; left: 50%; bottom: -6px; transform: translateX(-50%);
  font: 800 9px Inter, sans-serif; letter-spacing: 0.06em; padding: 1px 5px; border-radius: 4px;
  background: var(--bg); border: 1px solid var(--gold-dim); color: var(--gold2); white-space: nowrap;
}
.who { display: flex; align-items: center; gap: 10px; min-width: 0; }
.who b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.linkish { cursor: pointer; }
.linkish:hover b { color: var(--gold2); text-decoration: underline; }

/* Scoring legend & explanations */
.legend {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 12px;
  font-size: 12px; color: var(--muted);
}
.legend .chip { padding: 2px 8px; border-radius: 99px; background: var(--bg2); border: 1px solid var(--line2); color: var(--text); white-space: nowrap; }
.legend .chip b { color: var(--gold); }
.explain td { padding: 5px 8px; font-size: 13px; }
.explain .sub td { border-top: 1px solid var(--line2); font-weight: 700; }
.explain .tot td { border-top: 2px solid var(--gold-dim); font-weight: 800; font-size: 15px; color: var(--gold2); }
.parts { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.parts span { font-size: 11px; padding: 1px 6px; border-radius: 4px; background: var(--bg2); border: 1px solid var(--line); white-space: nowrap; }
.parts .p { color: var(--green); }
.parts .n { color: var(--red); }
.pts-pill { display: inline-block; min-width: 46px; text-align: center; font-weight: 800; padding: 2px 8px; border-radius: 6px; background: rgba(200, 170, 110, 0.14); color: var(--gold2); font-variant-numeric: tabular-nums; }

/* Live */
.live-dot { display: none; width: 8px; height: 8px; border-radius: 50%; background: var(--red); margin-right: 6px; vertical-align: middle; animation: blink 1.2s infinite; }
#nav-live.on .live-dot { display: inline-block; }
@keyframes blink { 50% { opacity: 0.25; } }
.live-badge { display: inline-flex; align-items: center; gap: 6px; font: 800 12px Inter, sans-serif; color: #fff; background: var(--red); padding: 2px 8px; border-radius: 4px; letter-spacing: 0.06em; }
.live-badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: #fff; animation: blink 1.2s infinite; }
.scoreboard { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; margin-bottom: 12px; }
.scoreboard .side { display: flex; align-items: center; gap: 10px; }
.scoreboard .side.red { justify-content: flex-end; text-align: right; }
.scoreboard .kills { font: 800 30px Cinzel, serif; color: var(--gold2); font-variant-numeric: tabular-nums; }
.scoreboard .mid { text-align: center; }
.objs { font-size: 12px; color: var(--muted); }
tr.mine td { background: rgba(200, 170, 110, 0.1); }
tr.mine td:first-child { box-shadow: inset 3px 0 0 var(--gold); }
.champ { font-size: 11px; color: var(--muted); }
.grid-live { grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr); }
@media (max-width: 1150px) { .live-teams { grid-template-columns: 1fr; } }
@media (max-width: 900px) { .grid-live { grid-template-columns: 1fr; } }

/* Schedule */
.sched-day { margin: 14px 0 6px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--gold); }
.sched-row {
  display: grid; grid-template-columns: minmax(0, 1fr) 90px minmax(0, 1fr); align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: 8px; background: var(--panel2); border: 1px solid var(--line); margin-bottom: 6px;
}
.sched-row.done { opacity: 0.7; }
.sched-team { display: flex; align-items: center; gap: 8px; min-width: 0; }
.sched-team.right { justify-content: flex-end; }
.sched-team .avatar { width: 30px; height: 30px; }
.sched-mid { text-align: center; }
.sched-time { font-weight: 800; color: var(--teal); font-variant-numeric: tabular-nums; }
.sched-score { font: 800 16px Cinzel, serif; color: var(--gold2); }
