/* ============================================================
   HALL OF FAME — Modern Gaming Theme
   ============================================================ */

:root {
  /* Dark theme (default) */
  --bg: #0b0d12;
  --bg-elevated: #11141a;
  --bg-card: #161a21;
  --bg-card-hover: #1c212b;
  --border: #2a2f3a;
  --border-bright: #3a4152;
  --text: #e8eaed;
  --text-muted: #8b919e;
  --text-dim: #5a6172;
  --accent: #00d4aa;
  --accent-dim: #00d4aa33;
  --accent-strong: #00ffcc;
  --gold: #ffd700;
  --gold-dim: #ffd70033;
  --silver: #c0c0c0;
  --silver-dim: #c0c0c033;
  --bronze: #cd7f32;
  --bronze-dim: #cd7f3233;
  --danger: #ff4757;
  --danger-dim: #ff475733;
  --success: #00d4aa;
  --warning: #ffa502;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.3);
  --shadow-md: 0 8px 24px rgba(0,0,0,0.4);
  --shadow-lg: 0 16px 48px rgba(0,0,0,0.5);
  --shadow-glow: 0 0 24px var(--accent-dim);
  --font-sans: "Inter", "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", "Fira Code", "SF Mono", monospace;
  --transition: 0.2s ease;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f0f2f5;
    --bg-elevated: #ffffff;
    --bg-card: #ffffff;
    --bg-card-hover: #f8fafc;
    --border: #e2e8f0;
    --border-bright: #cbd5e1;
    --text: #1e293b;
    --text-muted: #64748b;
    --text-dim: #94a3b8;
    --accent: #00a88a;
    --accent-dim: #00a88a22;
    --accent-strong: #008f76;
    --gold: #b8860b;
    --gold-dim: #b8860b22;
    --silver: #71797e;
    --silver-dim: #71797e22;
    --bronze: #a0522d;
    --bronze-dim: #a0522d22;
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.08);
    --shadow-md: 0 8px 24px rgba(0,0,0,0.1);
    --shadow-lg: 0 16px 48px rgba(0,0,0,0.12);
    --shadow-glow: 0 0 24px var(--accent-dim);
  }
}

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

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  background-image:
    radial-gradient(ellipse 80% 50% at 50% -20%, var(--accent-dim) 0%, transparent 50%),
    radial-gradient(circle at 100% 100%, var(--gold-dim) 0%, transparent 40%);
  background-attachment: fixed;
}

@media (prefers-color-scheme: light) {
  body {
    background-image:
      radial-gradient(ellipse 80% 50% at 50% -20%, var(--accent-dim) 0%, transparent 50%),
      radial-gradient(circle at 100% 100%, var(--gold-dim) 0%, transparent 40%);
  }
}

/* Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border-bright); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* Selection */
::selection { background: var(--accent-dim); color: var(--text); }

/* ============================================================
   HEADER / NAV
   ============================================================ */
header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 16px 24px;
  background: rgba(11, 13, 18, 0.9);
  backdrop-filter: saturate(180%) blur(16px);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

@media (prefers-color-scheme: light) {
  header { background: rgba(240, 242, 245, 0.9); }
}

header h1 {
  margin: 0;
  font-size: clamp(1.25rem, 3vw, 1.5rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

header h1 a { text-decoration: none; color: inherit; }

header nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.nav-link,
header nav span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
  white-space: nowrap;
}

.nav-link:hover,
header nav a:hover {
  color: var(--text);
  background: var(--bg-card);
  border-color: var(--accent);
  text-decoration: none;
}

.nav-link.active {
  color: var(--accent);
  background: var(--accent-dim);
  border: 1px solid var(--accent);
}

header nav span { color: var(--text); }

/* User badge */
.user-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent);
}

.user-badge::before {
  content: "";
  width: 8px; height: 8px;
  background: var(--accent);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--accent), 0 0 16px var(--accent-dim);
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.5; } }

/* ============================================================
   MAIN CONTENT
   ============================================================ */
main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 20px 60px;
}

.page-title {
  margin: 0 0 8px;
  font-size: clamp(1.5rem, 4vw, 2rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  background: linear-gradient(135deg, var(--text) 0%, var(--text-muted) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.page-subtitle {
  margin: 0 0 32px;
  color: var(--text-muted);
  font-size: 1rem;
}

/* ============================================================
   FLASH MESSAGES
   ============================================================ */
.flash {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 24px;
}

.flash li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

.flash li::before {
  content: "";
  flex-shrink: 0;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--warning);
  box-shadow: 0 0 8px var(--warning);
}

.flash li.success::before { background: var(--success); box-shadow: 0 0 8px var(--success); }
.flash li.error::before { background: var(--danger); box-shadow: 0 0 8px var(--danger); }
.flash li.info::before { background: var(--accent); box-shadow: 0 0 8px var(--accent); }

/* ============================================================
   DEVICE BLOCK / CARDS
   ============================================================ */
.device-block {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-md);
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}

.device-block::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--gold), var(--accent));
  opacity: 0;
  transition: opacity var(--transition);
}

.device-block:hover {
  border-color: var(--border-bright);
  box-shadow: var(--shadow-lg), var(--shadow-glow);
  transform: translateY(-2px);
}

.device-block:hover::before { opacity: 1; }

.device-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.device-id {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.125rem;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text);
}

.device-id::before {
  content: "";
  width: 12px; height: 12px;
  background: var(--accent);
  border-radius: 3px;
  box-shadow: 0 0 12px var(--accent), 0 0 24px var(--accent-dim);
  animation: blink 1.5s ease-in-out infinite;
}

@keyframes blink { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }

.device-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  font-size: 0.8rem;
  color: var(--text-dim);
  font-family: var(--font-mono);
}

.device-meta span {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

/* ============================================================
   BOARDS GRID
   ============================================================ */
.boards-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
}

@media (max-width: 980px) {
  .boards-row { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 640px) {
  .boards-row { grid-template-columns: 1fr; }
}

.board {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
  transition: all var(--transition);
  display: flex;
  flex-direction: column;
}

.board:hover {
  border-color: var(--border-bright);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.board-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.board-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

.board-type {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-radius: 999px;
  font-family: var(--font-mono);
}

.board-type.higher { background: var(--success-dim); color: var(--success); border: 1px solid var(--success); }
.board-type.lower { background: var(--warning-dim); color: var(--warning); border: 1px solid var(--warning); }

.board-hint {
  margin: 0 0 16px;
  font-size: 0.75rem;
  color: var(--text-dim);
  line-height: 1.5;
}

/* ============================================================
   LEADERBOARD TABLE
   ============================================================ */
.table-wrapper { overflow-x: auto; }

.leaderboard {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.leaderboard thead {
  background: var(--bg-card);
  border-bottom: 2px solid var(--border);
}

.leaderboard th {
  padding: 12px 16px;
  text-align: left;
  font-weight: 600;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  font-family: var(--font-mono);
  white-space: nowrap;
}

.leaderboard td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
  vertical-align: middle;
}

.leaderboard tbody tr {
  transition: all var(--transition);
}

.leaderboard tbody tr:last-child td { border-bottom: none; }

.leaderboard tbody tr:hover td {
  background: var(--bg-card-hover);
}

/* Rank column */
.rank-cell {
  width: 56px;
  text-align: center;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 1rem;
}

/* Medal styles */
.rank-1 { color: var(--gold); }
.rank-2 { color: var(--silver); }
.rank-3 { color: var(--bronze); }
.rank-other { color: var(--text-muted); }

.rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px; height: 32px;
  border-radius: 50%;
  font-size: 0.75rem;
  font-weight: 800;
  font-family: var(--font-mono);
}

.rank-1 .rank-badge { background: var(--gold-dim); border: 2px solid var(--gold); box-shadow: 0 0 12px var(--gold-dim); }
.rank-2 .rank-badge { background: var(--silver-dim); border: 2px solid var(--silver); box-shadow: 0 0 12px var(--silver-dim); }
.rank-3 .rank-badge { background: var(--bronze-dim); border: 2px solid var(--bronze); box-shadow: 0 0 12px var(--bronze-dim); }
.rank-other .rank-badge { background: var(--bg-card); border: 2px solid var(--border); color: var(--text-muted); }

/* Player name */
.player-cell {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 140px;
}

.player-avatar {
  flex-shrink: 0;
  width: 36px; height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.875rem;
  color: var(--bg);
  box-shadow: 0 0 16px var(--accent-dim);
}

.player-name {
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-name.you {
  color: var(--accent);
}

/* Score cell */
.score-cell {
  text-align: right;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 1.125rem;
  color: var(--text);
  white-space: nowrap;
}

.score-unit {
  display: inline-block;
  margin-left: 4px;
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-dim);
}

.empty-state svg { width: 48px; height: 48px; margin-bottom: 12px; opacity: 0.4; }

/* ============================================================
   FORMS (Login / Register / Profile)
   ============================================================ */
.form-card {
  max-width: 420px;
  margin: 0 auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px;
  box-shadow: var(--shadow-lg);
}

.form-title {
  margin: 0 0 8px;
  font-size: 1.5rem;
  font-weight: 700;
  text-align: center;
}

.form-subtitle {
  margin: 0 0 28px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.form-group { margin-bottom: 20px; }

.form-label {
  display: block;
  margin-bottom: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.form-input {
  width: 100%;
  padding: 14px 16px;
  font-family: var(--font-sans);
  font-size: 1rem;
  color: var(--text);
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}

.form-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
  background: var(--bg-card);
}

.form-input::placeholder { color: var(--text-dim); }

.form-input.error { border-color: var(--danger); }
.form-input.error:focus { box-shadow: 0 0 0 3px var(--danger-dim); }

.form-btn {
  width: 100%;
  padding: 14px 24px;
  margin-top: 8px;
  font-family: var(--font-sans);
  font-size: 1rem;
  font-weight: 600;
  color: var(--bg);
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  box-shadow: 0 4px 16px var(--accent-dim);
}

.form-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 24px var(--accent-dim);
}

.form-btn:active { transform: translateY(0); }

.form-footer {
  margin-top: 24px;
  text-align: center;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.form-footer a { color: var(--accent); text-decoration: none; font-weight: 500; }
.form-footer a:hover { text-decoration: underline; }

/* ============================================================
   PROFILE PAGE
   ============================================================ */
.profile-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 24px;
  margin-bottom: 32px;
  padding: 24px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}

.profile-avatar {
  flex-shrink: 0;
  width: 80px; height: 80px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 2rem;
  color: var(--bg);
  box-shadow: 0 0 32px var(--accent-dim);
}

.profile-info { flex: 1; min-width: 200px; }

.profile-name {
  margin: 0 0 4px;
  font-size: 1.5rem;
  font-weight: 700;
}

.profile-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-top: 12px;
}

.stat-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.stat-value { font-family: var(--font-mono); font-weight: 700; font-size: 1.125rem; color: var(--accent); }
.stat-label { font-size: 0.7rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em; }

/* Stats grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
  margin-bottom: 32px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
  transition: all var(--transition);
}

.stat-card:hover { border-color: var(--border-bright); box-shadow: var(--shadow-md); }

.stat-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.stat-game-name { margin: 0; font-size: 1rem; font-weight: 700; }
.stat-game-type {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-radius: 999px;
  font-family: var(--font-mono);
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.stat-row:last-child { border-bottom: none; }

.stat-row-label { font-size: 0.875rem; color: var(--text-muted); }
.stat-row-value { font-family: var(--font-mono); font-weight: 600; color: var(--text); }

/* Recent games */
.recent-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
}

.recent-title { margin: 0 0 20px; font-size: 1.125rem; font-weight: 700; }

.recent-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }

.recent-table th,
.recent-table td { padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--border); }

.recent-table th { font-weight: 600; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-dim); font-family: var(--font-mono); }

.recent-table tbody tr:hover td { background: var(--bg-card-hover); }

.recent-table td:first-child { font-family: var(--font-mono); font-weight: 600; color: var(--accent); }

/* ============================================================
   MAP PAGE
   ============================================================ */
.map-container {
  aspect-ratio: 16/9;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-md);
}

.map-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-dim);
  text-align: center;
  padding: 40px;
}

.map-placeholder svg { width: 64px; height: 64px; margin-bottom: 16px; opacity: 0.3; }

/* ============================================================
   GAME VIEW PAGE
   ============================================================ */
.game-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  padding: 20px 24px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.game-title { margin: 0; font-size: 1.25rem; font-weight: 700; }

.game-meta { display: flex; flex-wrap: wrap; gap: 12px; }

.game-type-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-radius: 999px;
  font-family: var(--font-mono);
}

.game-type-badge.higher { background: var(--success-dim); color: var(--success); border: 1px solid var(--success); }
.game-type-badge.lower { background: var(--warning-dim); color: var(--warning); border: 1px solid var(--warning); }

/* ============================================================
   DEVICE STATS PAGE
   ============================================================ */
.device-stats-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  padding: 24px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.device-stats-title { margin: 0; font-size: 1.25rem; font-weight: 700; }

.device-stats-meta { display: flex; flex-wrap: wrap; gap: 12px; font-size: 0.8rem; color: var(--text-dim); font-family: var(--font-mono); }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 640px) {
  header { padding: 12px 16px; }
  main { padding: 20px 16px 40px; }
  .device-block { padding: 16px; }
  .board { padding: 16px; }
  .form-card { padding: 24px 16px; }
  .leaderboard th, .leaderboard td { padding: 10px 12px; }
  .profile-header { flex-direction: column; text-align: center; }
  .profile-stats { justify-content: center; }
}

/* ============================================================
   REDUCED MOTION
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ============================================================
   PRINT
   ============================================================ */
@media print {
  header, .form-btn, .nav-link { display: none !important; }
  body { background: white; color: black; }
  .device-block, .board, .form-card, .stat-card { break-inside: avoid; box-shadow: none; border: 1px solid #ccc; }
}