/* =========================
   THEME TOKENS
   ========================= */
:root {
  --bg: #fafafa;
  --panel: #ffffff;
  --ink: #111827;    /* main text */
  --muted: #666666;  /* secondary text */
  --border: #e5e7eb;
  --brand: #4f46e5;
  --shadow: 0 6px 18px rgba(17,24,39,.06);
}

:root[data-theme="dark"] {
  --bg: #0b0f17;
  --panel: #111827;
  --ink: #f3f4f6;     /* brighter for titles/text in dark */
  --muted: #a1a1aa;   /* readable secondary on dark */
  --border: #2a2f3d;
  --brand: #8b9dff;
  --shadow: 0 6px 18px rgba(0,0,0,.45);
}

/* Optional: smooth theme transition (respects reduced motion) */
* { transition: color .15s linear, background-color .15s linear, border-color .15s linear; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* =========================
   BASE LAYOUT
   ========================= */
body {
  font-family: Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  margin: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

main.page {
  flex: 1;
  padding: 32px;
  display: grid;
  place-items: center;
  text-align: center;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  width: min(680px, 92%);
  box-shadow: var(--shadow);
}

/* =========================
   TYPOGRAPHY
   ========================= */
h1 {
  margin: 0 0 8px;
  font-size: 28px;
  color: var(--ink);  /* ensure titles adapt to theme */
}

h2, h3, h4, h5, h6 { color: var(--ink); }

p {
  margin: 0 0 16px;
  color: var(--muted);
}

/* =========================
   BUTTONS
   ========================= */
.btn {
  display: inline-block;
  padding: 10px 14px;
  border-radius: 999px;
  text-decoration: none;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--ink);
  font-weight: 600;
}

.btn.primary {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}

/* Dark-specific lift for neutral buttons (better contrast) */
[data-theme="dark"] .btn {
  background: #1d2330;
  border-color: var(--border);
  color: var(--ink);
}

/* =========================
   TABS (BOTTOM NAV)
   ========================= */
nav.tabs {
  position: sticky;
  bottom: 0;
  background: var(--panel);
  border-top: 1px solid var(--border);
}

nav.tabs .row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  max-width: 720px;
  margin: 0 auto;
}

nav.tabs a {
  display: grid;
  place-items: center;
  gap: 4px;
  padding: 12px 0;
  text-decoration: none;
  color: var(--muted);
  font-size: 14px;
}

nav.tabs a.active {
  color: var(--brand);
  font-weight: 700;
}

.icon { font-size: 18px; }

/* =========================
   DIALOGS & FORMS
   ========================= */
dialog {
  border: none;
  border-radius: 12px;
  width: min(480px, 92%);
  box-shadow: 0 10px 30px rgba(0,0,0,.15);
  background: var(--panel);
  color: var(--ink);
}

dialog::backdrop { background: rgba(0,0,0,.35); }

.form { display: grid; gap: 10px; }
.form label { font-weight: 600; }

.form input,
.form textarea,
.form select {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
}

.row-actions { display: flex; gap: 8px; }
.inline { display: flex; align-items: center; gap: 8px; }
.hint.meta { color: var(--muted); font-size: 12px; }
.section-title { font-size: 16px; margin: 16px 0 8px; }

/* =========================
   DARK THEME TUNING
   ========================= */

/* Make panel headings and list titles dimmer in dark mode for readability */
[data-theme="dark"] .route div[style*="font-weight:700"],
[data-theme="dark"] .leaderboard .name,
[data-theme="dark"] .leaderboard td:first-child {
  color: #d1d5db !important; /* soft neutral, not blinding white */
}

/* Optional: tweak meta text for better contrast */
[data-theme="dark"] .meta2 {
  color: #020406;
}

/* Optional: soften contrast on bright route thumb labels */
[data-theme="dark"] .thumb {
  background: linear-gradient(135deg, #1e293b, #374151);
  color: #c7d2fe; /* pale lavender-blue */
}

/* =========================
   FIX: Leaderboard highlight legibility
   ========================= */

/* Make sure leaderboard text is readable */
.leaderboard th,
.leaderboard td {
  color: var(--ink);
  border-color: var(--border);
}

/* Highlight row for "You" (2nd row or .you class) */
.lb-table tr.you,
.leaderboard tr.you {
  background-color: rgba(79, 70, 229, 0.1) !important;  /* brand color with transparency */
  border-left: 3px solid var(--brand);
}

/* Dark theme version */
[data-theme="dark"] .lb-table tr.you,
[data-theme="dark"] .leaderboard tr.you {
  background-color: rgba(139, 157, 255, 0.15) !important;
  border-left-color: var(--brand);
}

/* Ensure text inside cells stays readable */
.lb-table tr.you td,
.leaderboard tr.you td {
  color: var(--ink) !important;
}


/* ========== Routes ========== */
.route-name { font-weight: 700; color: var(--ink); }
/* A touch darker than pure white in dark mode for easier reading */
[data-theme="dark"] .route-name { color: #0a0b10 !important; }

/* Meta stays clearly secondary in dark mode */
[data-theme="dark"] .meta { color: #e8eaed; }


/* =========================
   HEADER WITH THEME TOGGLE
   ========================= */

.header h1 {
  font-size: 20px;
  margin: 0;
  font-weight: 700;
  text-align: left;
}

.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.back-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--ink);
  text-decoration: none;
  transition: all 0.2s ease;
  margin-right: 12px;
  vertical-align: middle;
}

.back-button:hover {
  background: var(--brand);
  color: white;
  border-color: var(--brand);
  transform: translateX(-2px);
}

.page-title-with-back {
  display: flex;
  align-items: center;
  gap: 0;
  margin: 0 0 8px;
}

.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 18px;
  transition: all 0.2s ease;
  color: var(--ink);
}

.theme-toggle:hover {
  background: var(--bg);
  transform: scale(1.05);
}

.theme-toggle:active {
  transform: scale(0.95);
}

/* =========================
   HOME PAGE STYLES
   ========================= */
.home-card {
  max-width: 600px;
}

.hero-section {
  text-align: center;
  margin-bottom: 32px;
  padding-bottom: 24px;
  border-bottom: 2px solid var(--border);
}

.gradient-text {
  color: var(--brand);
  font-size: 42px;
  font-weight: 800;
  margin-bottom: 8px;
}

.subtitle {
  font-size: 16px;
  color: var(--muted);
  margin: 0;
}

.status-card {
  margin: 24px 0;
  padding: 16px;
  border-radius: 12px;
  background: rgba(79, 70, 229, 0.1);
  border: 1px solid rgba(79, 70, 229, 0.2);
}

[data-theme="dark"] .status-card {
  background: rgba(139, 157, 255, 0.1);
  border-color: rgba(139, 157, 255, 0.2);
}

.action-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-top: 24px;
}

.action-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 20px 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel);
  text-decoration: none;
  color: var(--ink);
  transition: all 0.2s ease;
  cursor: pointer;
}

.action-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  border-color: var(--brand);
}

.action-card.primary {
  background: var(--brand);
  color: white;
  border-color: var(--brand);
}

.action-card.sync-card {
  background: var(--brand);
  color: white;
  border: none;
  opacity: 0.9;
}

.action-card.sync-card:hover {
  opacity: 1;
}

.action-icon {
  font-size: 32px;
  margin-bottom: 4px;
}

.action-text {
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.action-text strong {
  font-size: 14px;
  font-weight: 600;
}

.action-text span {
  font-size: 11px;
  opacity: 0.8;
}

/* =========================
   PROFILE PAGE STYLES
   ========================= */
.profile-card {
  max-width: 600px;
}

.profile-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding-bottom: 24px;
  border-bottom: 2px solid var(--border);
  margin-bottom: 24px;
}

.avatar-container {
  position: relative;
}

.avatar-large {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: 3px solid var(--brand);
  object-fit: cover;
}

.avatar-badge {
  position: absolute;
  bottom: -4px;
  right: -4px;
  background: var(--brand);
  border-radius: 50%;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  border: 2px solid var(--panel);
}

.profile-info {
  flex: 1;
  text-align: left;
}

.profile-info h1 {
  margin: 0 0 4px;
  font-size: 24px;
}

.profile-meta {
  color: var(--muted);
  font-size: 14px;
  margin: 0;
}

.warning-banner {
  padding: 12px 16px;
  margin: 16px 0;
  background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
  border: 1px solid #fbbf24;
  border-radius: 10px;
  text-align: center;
  font-size: 14px;
}

[data-theme="dark"] .warning-banner {
  background: linear-gradient(135deg, #78350f 0%, #92400e 100%);
  border-color: #f59e0b;
  color: #fef3c7;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: 12px;
  margin: 24px 0;
}

.stat-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  text-align: center;
  transition: all 0.2s ease;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.stat-card.highlight {
  background: linear-gradient(135deg, rgba(79, 70, 229, 0.15) 0%, rgba(99, 102, 241, 0.2) 100%);
  border-color: var(--brand);
}

.stat-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--brand);
  margin-bottom: 4px;
}

.stat-label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.profile-actions {
  display: flex;
  gap: 12px;
  margin-top: 24px;
  flex-wrap: wrap;
}

.pill-btn {
  flex: 1;
  min-width: 140px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel);
  color: var(--ink);
  text-decoration: none;
  font-weight: 600;
  transition: all 0.2s ease;
}

.pill-btn:hover {
  background: var(--brand);
  color: white;
  border-color: var(--brand);
  transform: translateY(-1px);
}

/* =========================
   ACCESSIBILITY
   ========================= */
:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: 8px;
}
