/* ── Reset & custom properties ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --green:   #22c55e;
  --red:     #ef4444;
  --blue:    #3b82f6;
  --gold:    #f59e0b;
  --dark:    #111827;
  --card:    #1f2937;
  --border:  #374151;
  --text:    #f9fafb;
  --muted:   #9ca3af;
  --input-bg:#111827;
  --radius:  0.5rem;
  font-size: 16px;
}

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--dark);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

/* ── Layout ────────────────────────────────────────────────────────────── */
.container { max-width: 900px; margin: 0 auto; padding: 0 1rem; }
.wide      { max-width: 1200px; margin: 0 auto; padding: 0 1rem; }

/* ── Nav ───────────────────────────────────────────────────────────────── */
nav {
  background: #0d1117;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
}
nav .nav-inner {
  display: flex; align-items: center; gap: 0.25rem;
  padding: 0 1rem; height: 52px;
  max-width: 1200px; margin: 0 auto;
}
.nav-brand {
  font-weight: 700; font-size: 1.1rem; color: var(--gold);
  text-decoration: none; margin-right: auto;
  display: flex; align-items: center; gap: 0.4rem;
}
nav a {
  color: var(--muted); text-decoration: none;
  padding: 0.35rem 0.6rem; border-radius: var(--radius);
  font-size: 0.9rem; transition: color 0.15s, background 0.15s;
}
nav a:hover, nav a.active { color: var(--text); background: var(--card); }
.nav-user { color: var(--muted); font-size: 0.85rem; padding: 0.35rem 0.6rem; }
.btn-logout {
  background: none; border: 1px solid var(--border);
  color: var(--muted); cursor: pointer; font-size: 0.85rem;
  padding: 0.3rem 0.7rem; border-radius: var(--radius); transition: all 0.15s;
}
.btn-logout:hover { color: var(--red); border-color: var(--red); }

/* ── Admin nav dropdown ─────────────────────────────────────────────────── */
.nav-dropdown {
  position: relative;
}
.nav-dropdown-toggle {
  color: var(--muted); font-size: 0.9rem;
  padding: 0.35rem 0.6rem; border-radius: var(--radius);
  cursor: pointer; transition: color 0.15s, background 0.15s;
  white-space: nowrap; user-select: none;
}
.nav-dropdown:hover .nav-dropdown-toggle,
.nav-dropdown.active .nav-dropdown-toggle {
  color: var(--text); background: var(--card);
}
.nav-dropdown-menu {
  display: none;
  position: absolute; top: calc(100% + 4px); right: 0;
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 0.35rem 0;
  min-width: 140px; z-index: 200;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}
.nav-dropdown:hover .nav-dropdown-menu { display: block; }
.nav-dropdown-menu a {
  display: block; padding: 0.4rem 1rem;
  border-radius: 0; background: none;
}
.nav-dropdown-menu a:hover, .nav-dropdown-menu a.active {
  background: rgba(255,255,255,0.07); color: var(--text);
}

/* ── Cards ─────────────────────────────────────────────────────────────── */
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem;
}
.card-header {
  font-weight: 600; font-size: 0.85rem; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--muted); margin-bottom: 0.75rem;
}

/* ── Match card ─────────────────────────────────────────────────────────── */
.match-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem;
  display: flex; flex-direction: column; gap: 0.5rem;
}
.match-teams {
  display: flex; align-items: center; justify-content: space-between;
  gap: 0.5rem;
}
.team-block { display: flex; align-items: center; gap: 0.4rem; flex: 1; }
.team-block.away { flex-direction: row-reverse; }
.team-flag { font-size: 1.4rem; line-height: 1; }
.team-name { font-weight: 600; font-size: 0.95rem; }
.score-block {
  font-size: 1.6rem; font-weight: 700; min-width: 4rem;
  text-align: center; color: var(--gold);
}
.score-dash { font-size: 1.2rem; color: var(--muted); }
.match-meta { font-size: 0.8rem; color: var(--muted); }
.match-status {
  font-size: 0.75rem; font-weight: 600; text-transform: uppercase;
  padding: 0.1rem 0.4rem; border-radius: 0.25rem;
}
.status-live { background: var(--red); color: #fff; animation: blink 1s infinite; }
.status-finished { background: var(--border); color: var(--muted); }
.status-scheduled { background: transparent; border: 1px solid var(--border); color: var(--muted); }

@keyframes blink { 50% { opacity: 0.5; } }

/* ── Bet bar ────────────────────────────────────────────────────────────── */
.bet-bar { display: flex; height: 6px; border-radius: 3px; overflow: hidden; margin-top: 0.25rem; }
.bet-bar-home { background: var(--blue); }
.bet-bar-draw { background: var(--muted); }
.bet-bar-away { background: var(--red); }
.bet-bar-labels {
  display: flex; justify-content: space-between; font-size: 0.72rem; color: var(--muted);
}

/* ── Bet form (bets page) ───────────────────────────────────────────────── */
.bet-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
}
.bet-row:last-child { border-bottom: none; }
.score-input-pair {
  display: flex; align-items: center; gap: 0.4rem;
}
.score-input {
  width: 3rem; text-align: center;
  background: var(--input-bg); border: 1px solid var(--border);
  color: var(--text); padding: 0.4rem; border-radius: var(--radius);
  font-size: 1.1rem; font-weight: 700;
  -moz-appearance: textfield;
}
.score-input::-webkit-outer-spin-button,
.score-input::-webkit-inner-spin-button { -webkit-appearance: none; }
.score-input:focus { outline: none; border-color: var(--blue); }
.score-input:disabled { opacity: 0.5; cursor: not-allowed; }
.vs-sep { color: var(--muted); font-size: 0.85rem; }
.save-btn {
  background: var(--blue); color: #fff; border: none;
  padding: 0.35rem 0.8rem; border-radius: var(--radius);
  cursor: pointer; font-size: 0.85rem; font-weight: 600;
  transition: background 0.15s;
}
.save-btn:hover { background: #2563eb; }
.save-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.lock-badge {
  font-size: 0.72rem; color: var(--muted); border: 1px solid var(--border);
  padding: 0.2rem 0.5rem; border-radius: 0.25rem;
}
.bet-points {
  font-weight: 700; font-size: 1rem;
  padding: 0.2rem 0.5rem; border-radius: 0.25rem;
}
.pts-15 { color: var(--gold); }
.pts-pos { color: var(--green); }
.pts-zero { color: var(--muted); }

/* ── Group section ──────────────────────────────────────────────────────── */
.group-header {
  font-size: 0.8rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.07em; color: var(--gold);
  padding: 0.75rem 0 0.25rem;
  border-top: 1px solid var(--border); margin-top: 1rem;
}
.group-header:first-child { border-top: none; margin-top: 0; }

/* ── Standings table ────────────────────────────────────────────────────── */
.standings-table { width: 100%; border-collapse: collapse; }
.standings-table th {
  text-align: left; font-size: 0.75rem; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--muted); padding: 0.5rem 0.5rem;
  border-bottom: 1px solid var(--border);
}
.standings-table td { padding: 0.6rem 0.5rem; border-bottom: 1px solid var(--border); }
.standings-table tr:last-child td { border-bottom: none; }
.standings-table tr.me td { background: rgba(59, 130, 246, 0.08); }
.rank-cell { font-weight: 700; color: var(--muted); width: 2.5rem; }
.rank-1 .rank-cell { color: var(--gold); }
.movement { font-size: 0.9rem; }
.movement.up   { color: var(--green); }
.movement.down { color: var(--red); }
.movement.same { color: var(--muted); }
.movement.new  { color: var(--blue); font-size: 0.7rem; font-weight: 700; }
.pts-col { font-weight: 700; text-align: right; }

/* ── Forms ──────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 0.3rem; }
.form-control {
  width: 100%; padding: 0.5rem 0.75rem;
  background: var(--input-bg); border: 1px solid var(--border);
  color: var(--text); border-radius: var(--radius); font-size: 0.95rem;
}
.form-control:focus { outline: none; border-color: var(--blue); }
.btn {
  display: inline-block; padding: 0.5rem 1.25rem;
  border: none; border-radius: var(--radius); cursor: pointer;
  font-size: 0.9rem; font-weight: 600; text-decoration: none; transition: opacity 0.15s;
}
.btn:hover { opacity: 0.85; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-danger  { background: var(--red); color: #fff; }
.btn-sm      { padding: 0.3rem 0.7rem; font-size: 0.8rem; }
.btn-outline  { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-paid     { background: rgba(34,197,94,0.15); border: 1px solid #22c55e; color: #22c55e; }
.btn-unpaid   { background: rgba(239,68,68,0.1);  border: 1px solid var(--border); color: var(--muted); }

/* ── Alerts ─────────────────────────────────────────────────────────────── */
.alert { padding: 0.75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: 0.9rem; }
.alert-error { background: rgba(239,68,68,0.15); border: 1px solid var(--red); color: #fca5a5; }
.alert-success { background: rgba(34,197,94,0.15); border: 1px solid var(--green); color: #86efac; }
.alert-info { background: rgba(59,130,246,0.15); border: 1px solid var(--blue); color: #93c5fd; }

/* ── Page sections ──────────────────────────────────────────────────────── */
.page-title { font-size: 1.5rem; font-weight: 700; margin-bottom: 1.5rem; }
.section-title { font-size: 1.1rem; font-weight: 700; margin: 1.5rem 0 0.75rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.text-muted { color: var(--muted); font-size: 0.85rem; }
.text-center { text-align: center; }
.font-bold { font-weight: 700; }

/* ── Login page ─────────────────────────────────────────────────────────── */
.login-wrap {
  min-height: calc(100vh - 52px); display: flex;
  align-items: center; justify-content: center; padding: 2rem 1rem;
}
.login-card { width: 100%; max-width: 360px; }
.login-logo { text-align: center; font-size: 2rem; margin-bottom: 1rem; }

/* ── Admin table ────────────────────────────────────────────────────────── */
.admin-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.admin-table th { text-align: left; padding: 0.5rem; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); border-bottom: 1px solid var(--border); }
.admin-table td { padding: 0.6rem 0.5rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.admin-table tr:last-child td { border-bottom: none; }

/* ── Badge ──────────────────────────────────────────────────────────────── */
.badge { display: inline-block; padding: 0.1rem 0.45rem; border-radius: 999px; font-size: 0.72rem; font-weight: 600; }
.badge-admin  { background: var(--gold); color: #000; }
.badge-manual { background: var(--blue); color: #fff; }
.badge-paid   { background: rgba(34,197,94,0.15); border: 1px solid #22c55e; color: #22c55e; }
.badge-unpaid { background: rgba(239,68,68,0.1);  border: 1px solid var(--border); color: var(--muted); }

/* ── Stat box ───────────────────────────────────────────────────────────── */
.stat-box { text-align: center; }
.stat-box .stat-num { font-size: 2rem; font-weight: 700; color: var(--gold); }
.stat-box .stat-label { font-size: 0.8rem; color: var(--muted); text-transform: uppercase; }

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .hide-mobile { display: none; }
  nav a { font-size: 0.8rem; padding: 0.3rem 0.4rem; }
  .team-name { font-size: 0.82rem; }
  .standings-table th:nth-child(4),
  .standings-table td:nth-child(4),
  .standings-table th:nth-child(5),
  .standings-table td:nth-child(5) { display: none; }
}

/* ── Race bar ───────────────────────────────────────────────────────────── */
#race-bar {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: 80px;
  background: #0d1117;
  border-top: 2px solid var(--border);
  z-index: 200;
  overflow: visible;
}
.race-bar-header {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0 0.75rem; height: 16px;
  border-bottom: 1px solid var(--border);
}
.race-bar-title {
  font-size: 0.65rem; font-weight: 700; color: var(--gold);
  text-transform: uppercase; letter-spacing: 0.07em;
}
.race-bar-start {
  font-size: 0.6rem; color: var(--muted);
}
.race-bar-end { margin-left: auto; font-size: 0.9rem; }
#race-track {
  position: relative; height: 64px;
  /* subtle ground line */
  background: linear-gradient(to bottom, transparent 85%, rgba(255,255,255,0.04) 86%, transparent 87%);
}
.race-finish-flag {
  position: absolute; right: 6px;
  top: 50%; transform: translateY(-50%);
  font-size: 1.3rem; z-index: 1; line-height: 1;
}

/* Token (avatar circle) */
.race-horse-wrap {
  position: absolute;
  top: 50%; transform: translateY(-50%);
  transition: left 1.4s cubic-bezier(0.25, 1, 0.5, 1);
  z-index: 10; cursor: pointer;
}
.race-horse-wrap:hover { z-index: 50; }
.race-token {
  position: relative;
  width: 48px; height: 48px;
}
.race-token-face {
  width: 48px; height: 48px;
  border-radius: 50%;
  border: 3px solid var(--token-color);
  overflow: hidden;
  background: var(--card);
  box-shadow: 0 0 0 1px rgba(0,0,0,0.4), 0 2px 8px rgba(0,0,0,0.5);
  /* gentle bob animation */
  animation: token-bob 1.6s ease-in-out infinite;
}
.race-token-face svg { display: block; width: 100%; height: 100%; }

/* Stagger the bob so players don't all move in sync */
.race-horse-wrap:nth-child(2)  .race-token-face { animation-delay: -0.2s; }
.race-horse-wrap:nth-child(3)  .race-token-face { animation-delay: -0.4s; }
.race-horse-wrap:nth-child(4)  .race-token-face { animation-delay: -0.6s; }
.race-horse-wrap:nth-child(5)  .race-token-face { animation-delay: -0.8s; }
.race-horse-wrap:nth-child(6)  .race-token-face { animation-delay: -1.0s; }
.race-horse-wrap:nth-child(7)  .race-token-face { animation-delay: -1.2s; }
.race-horse-wrap:nth-child(8)  .race-token-face { animation-delay: -0.3s; }
.race-horse-wrap:nth-child(9)  .race-token-face { animation-delay: -0.7s; }
.race-horse-wrap:nth-child(10) .race-token-face { animation-delay: -1.1s; }

@keyframes token-bob {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-4px); }
}

.race-token-rank {
  position: absolute; bottom: -2px; right: -2px;
  background: #0d1117; border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.6rem; font-weight: 700; color: var(--gold);
  padding: 0 4px; line-height: 1.5;
  white-space: nowrap;
}

/* Tooltip */
.race-tip {
  display: none;
  position: absolute;
  bottom: calc(100% + 10px);
  left: 50%; transform: translateX(-50%);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.65rem 0.8rem;
  min-width: 168px;
  gap: 0.65rem;
  z-index: 400;
  box-shadow: 0 6px 24px rgba(0,0,0,0.6);
  pointer-events: none;
}
.race-horse-wrap:hover .race-tip { display: flex; align-items: flex-start; }
.race-tip-face { flex-shrink: 0; border-radius: 50%; overflow: hidden; width: 44px; height: 44px; }
.race-tip-face svg { display: block; }
.race-tip-name  { font-weight: 700; font-size: 0.88rem; margin-bottom: 0.15rem; }
.race-tip-pts   { font-size: 0.75rem; color: var(--gold); margin-bottom: 0.3rem; }
.race-tip-row   { font-size: 0.75rem; color: var(--muted); margin-bottom: 0.1rem; }
.race-tip-row strong { color: var(--text); }

/* ── Avatar builder (profile page) ─────────────────────────────────────── */
.av-section { margin-bottom: 1.1rem; }
.av-label {
  font-size: 0.78rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--muted); margin-bottom: 0.5rem;
}
.av-swatches { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.swatch-btn {
  cursor: pointer; border: 2px solid transparent;
  border-radius: 999px; padding: 2px; transition: border-color 0.15s;
}
.swatch-btn input { display: none; }
.swatch-btn.active, .swatch-btn:hover { border-color: var(--blue); }
.swatch-circle { display: block; width: 28px; height: 28px; border-radius: 50%; }
.av-pills { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.pill-btn {
  cursor: pointer; padding: 0.3rem 0.75rem;
  border: 1px solid var(--border); border-radius: 999px;
  font-size: 0.82rem; transition: all 0.15s; color: var(--muted);
}
.pill-btn input { display: none; }
.pill-btn.active { border-color: var(--blue); color: var(--text); background: rgba(59,130,246,0.15); }
.pill-btn:hover:not(.active) { border-color: var(--muted); color: var(--text); }

/* Flag pattern grid */
.pattern-grid {
  display: flex; gap: 0.5rem; flex-wrap: wrap;
}
.pattern-btn {
  cursor: pointer; background: var(--card);
  border: 2px solid var(--border); border-radius: var(--radius);
  padding: 0.35rem 0.5rem; display: flex; flex-direction: column;
  align-items: center; gap: 0.3rem;
  transition: border-color 0.15s; min-width: 52px;
}
.pattern-btn:hover { border-color: var(--muted); }
.pattern-btn.active { border-color: var(--blue); background: rgba(59,130,246,0.1); }
.pattern-mini { display: block; line-height: 0; border-radius: 2px; overflow: hidden; }
.pattern-name { font-size: 0.65rem; color: var(--muted); white-space: nowrap; }

/* Prize pool card */
.prize-pool { display: flex; gap: 1rem; flex-wrap: wrap; margin-top: 1.25rem; }
.prize-item {
  flex: 1; min-width: 130px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 0.75rem 1rem; text-align: center;
}
.prize-medal { font-size: 1.5rem; display: block; margin-bottom: 0.25rem; }
.prize-amount { font-size: 1.2rem; font-weight: 700; color: var(--gold); }
.prize-pct { font-size: 0.75rem; color: var(--muted); }

/* ── HTMX loading indicator ─────────────────────────────────────────────── */
.htmx-request .spinner { display: inline-block; }
.spinner { display: none; width: 14px; height: 14px; border: 2px solid var(--border); border-top-color: var(--blue); border-radius: 50%; animation: spin 0.6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Points bar (stats) ──────────────────────────────────────────────────── */
.pts-bar-row { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.3rem; font-size: 0.85rem; }
.pts-bar-label { width: 3rem; text-align: right; color: var(--muted); }
.pts-bar-fill { height: 14px; background: var(--blue); border-radius: 3px; min-width: 2px; }
.pts-bar-count { color: var(--muted); }

/* ── Chat widget ─────────────────────────────────────────────────────────── */
.chat-feed {
  height: 260px; overflow-y: auto; padding: 0.5rem 1rem;
  display: flex; flex-direction: column; gap: 0.5rem;
  border-bottom: 1px solid var(--border);
}
.chat-form {
  display: flex; gap: 0.5rem; padding: 0.65rem 1rem; align-items: center;
}
.chat-form .form-control { flex: 1; }
.chat-msg {
  display: flex; gap: 0.5rem; align-items: flex-start;
}
.chat-msg-avatar {
  flex-shrink: 0; width: 28px; height: 28px;
  border-radius: 50%; overflow: hidden;
}
.chat-msg-avatar svg { display: block; }
.chat-msg-body { flex: 1; min-width: 0; }
.chat-msg-meta {
  display: flex; gap: 0.5rem; align-items: baseline; margin-bottom: 0.1rem;
}
.chat-msg-name { font-weight: 600; font-size: 0.82rem; }
.chat-msg-time { font-size: 0.72rem; color: var(--muted); }
.chat-msg-text {
  font-size: 0.87rem; word-break: break-word; line-height: 1.4;
}
