/* weightbattle – Mobile-First CSS
   Using CSS Custom Properties throughout */

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-bg);
  min-height: 100vh;
}

a {
  color: var(--color-primary);
  text-decoration: none;
}
a:hover { text-decoration: underline; }

button {
  font: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

img { max-width: 100%; height: auto; }

/* ── CSS Custom Properties ───────────────────────────────────────────────── */
:root {
  /* ── Light Theme Design Tokens ─────────────────────────────────────────── */
  --bg-primary:       #f8fafc;
  --bg-secondary:     #ffffff;
  --bg-card:          #ffffff;
  --text-primary:     #1e293b;
  --text-secondary:   #64748b;
  --accent-primary:   #f97316;
  --accent-blue:      #3b82f6;
  --border:           #e2e8f0;
  --shadow:           0 2px 8px rgba(0,0,0,0.08);
  --nav-bg:           #ffffff;
  --input-bg:         #ffffff;
  --btn-primary-bg:   #f97316;
  --btn-primary-text: #ffffff;
  --glow:             none;

  /* Alpha helper tokens */
  --accent-blue-06:   rgba(59,130,246,0.06);
  --accent-blue-10:   rgba(59,130,246,0.10);
  --accent-blue-12:   rgba(59,130,246,0.12);
  --accent-blue-15:   rgba(59,130,246,0.15);
  --accent-blue-25:   rgba(59,130,246,0.25);
  --positive-04:      var(--positive-04);
  --positive-12:      var(--positive-12);
  --positive-25:      var(--positive-25);
  --positive-30:      rgba(39,174,96,0.30);

  /* ── Legacy variable mappings (used throughout existing CSS) ────────────── */
  --color-primary:      var(--accent-blue);
  --color-primary-dark: #2563eb;
  --color-secondary:    #6C63FF;
  --color-positive:     #27AE60;
  --color-warning:      #F39C12;
  --color-danger:       #E74C3C;

  --color-bg:           var(--bg-primary);
  --color-surface:      var(--bg-card);
  --color-border:       var(--border);
  --color-text:         var(--text-primary);
  --color-text-muted:   var(--text-secondary);

  /* Spacing */
  --space-xs:  0.25rem;
  --space-sm:  0.5rem;
  --space-md:  1rem;
  --space-lg:  1.5rem;
  --space-xl:  2rem;
  --space-2xl: 3rem;

  /* Radius */
  --radius-sm: 0.375rem;
  --radius-md: 0.75rem;
  --radius-lg: 1rem;
  --radius-xl: 1.5rem;

  /* Shadows */
  --shadow-sm: var(--shadow);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.10);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);

  /* Bottom nav height (mobile safe area) */
  --bottom-nav-height: 4rem;
}

/* ── Dark Blue Theme ─────────────────────────────────────────────────────── */
[data-theme="dark"] {
  --bg-primary:       #0d1b2a;
  --bg-secondary:     #1a2744;
  --bg-card:          rgba(255,255,255,0.07);
  --text-primary:     #e8f4fd;
  --text-secondary:   #94b8d4;
  --accent-primary:   #f5a623;
  --accent-blue:      #4fc3f7;
  --border:           rgba(255,255,255,0.12);
  --shadow:           0 8px 32px rgba(0,0,0,0.4), 0 0 0 1px rgba(255,255,255,0.05);
  --nav-bg:           #0a1628;
  --input-bg:         rgba(255,255,255,0.08);
  --btn-primary-bg:   #f5a623;
  --btn-primary-text: #0d1b2a;
  --glow:             0 0 20px rgba(79,195,247,0.2);

  /* Alpha helpers for dark */
  --accent-blue-06:   rgba(79,195,247,0.06);
  --accent-blue-10:   rgba(79,195,247,0.10);
  --accent-blue-12:   rgba(79,195,247,0.12);
  --accent-blue-15:   rgba(79,195,247,0.15);
  --accent-blue-25:   rgba(79,195,247,0.25);
  --positive-04:      rgba(39,174,96,0.06);
  --positive-12:      rgba(39,174,96,0.15);
  --positive-25:      var(--positive-30);
  --positive-30:      rgba(39,174,96,0.35);

  /* Legacy overrides */
  --color-primary-dark: #2ea8e0;
  --shadow-sm:  var(--shadow);
  --shadow-md:  0 8px 32px rgba(0,0,0,0.5);
  --shadow-lg:  0 16px 48px rgba(0,0,0,0.6);
}

/* Dark theme: Glassmorphism cards */
[data-theme="dark"] .card,
[data-theme="dark"] .auth-card,
[data-theme="dark"] .cheer-picker {
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

/* Dark theme: Glow on key numbers */
[data-theme="dark"] .stat-value,
[data-theme="dark"] .weight-display,
[data-theme="dark"] .xp-badge,
[data-theme="dark"] .invite-code-display {
  text-shadow: var(--glow);
}

/* ── Layout ──────────────────────────────────────────────────────────────── */
#app {
  min-height: 100vh;
  padding-bottom: var(--bottom-nav-height);
}

.container {
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
  padding: var(--space-md);
}

/* ── Loading Screen ──────────────────────────────────────────────────────── */
.loading-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.loading-spinner {
  width: 2.5rem;
  height: 2.5rem;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: var(--space-lg);
  margin-bottom: var(--space-md);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-md);
}

.card-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--color-text);
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-xs);
  padding: 0.625rem var(--space-lg);
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: 0.95rem;
  transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
  cursor: pointer;
  border: none;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--btn-primary-bg);
  color: var(--btn-primary-text);
}
.btn-primary:hover { filter: brightness(0.9); }

.btn-secondary {
  background: var(--color-border);
  color: var(--color-text);
}
.btn-secondary:hover { background: #CBD5E0; }

.btn-danger {
  background: var(--color-danger);
  color: white;
}

.btn-full { width: 100%; }

/* ── Forms ───────────────────────────────────────────────────────────────── */
.form-group {
  margin-bottom: var(--space-md);
}

.form-label {
  display: block;
  font-weight: 500;
  margin-bottom: var(--space-xs);
  color: var(--color-text);
  font-size: 0.9rem;
}

.form-input {
  width: 100%;
  padding: 0.625rem var(--space-md);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  font: inherit;
  color: var(--color-text);
  background: var(--input-bg);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--accent-blue-15);
}

.form-input.error {
  border-color: var(--color-danger);
}

.form-error {
  color: var(--color-danger);
  font-size: 0.825rem;
  margin-top: var(--space-xs);
}

.form-hint {
  color: var(--color-text-muted);
  font-size: 0.825rem;
  margin-top: var(--space-xs);
}

/* ── Bottom Navigation (Mobile ≤768px) ───────────────────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--bottom-nav-height);
  background: var(--nav-bg);
  border-top: 1px solid var(--color-border);
  display: flex;
  align-items: stretch;
  z-index: 100;
  box-shadow: 0 -2px 8px rgba(0,0,0,0.08);
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--color-text-muted);
  text-decoration: none;
  font-size: 0.7rem;
  font-weight: 500;
  transition: color 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.nav-item:hover,
.nav-item.active {
  color: var(--color-primary);
  text-decoration: none;
}

.nav-icon { font-size: 1.3rem; line-height: 1; }
.nav-label { font-size: 0.65rem; }

/* ── Desktop Sidebar (>768px) ────────────────────────────────────────────── */
@media (min-width: 769px) {
  #app {
    padding-bottom: 0;
    padding-left: 220px;
  }

  .bottom-nav { display: none !important; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 220px;
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    z-index: 100;
    padding: var(--space-lg) 0;
    box-shadow: var(--shadow-sm);
  }

  .sidebar-logo {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--color-primary);
    padding: 0 var(--space-lg) var(--space-lg);
    border-bottom: 1px solid var(--color-border);
    margin-bottom: var(--space-md);
  }

  .sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 0 var(--space-sm);
  }

  .sidebar-item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-sm);
    color: var(--color-text-muted);
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
    text-decoration: none;
  }

  .sidebar-item:hover {
    background: var(--color-bg);
    color: var(--color-text);
    text-decoration: none;
  }

  .sidebar-item.active {
    background: var(--accent-blue-10);
    color: var(--color-primary);
  }
}

/* ── Mobile only: hide sidebar ───────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { display: none !important; }
}

/* ── Toast Notifications ─────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  top: var(--space-md);
  right: var(--space-md);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  max-width: 320px;
}

.toast {
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: var(--space-md);
  display: flex;
  align-items: flex-start;
  gap: var(--space-sm);
  animation: toast-in 0.3s ease;
  border-left: 4px solid var(--color-primary);
}

.toast.success { border-left-color: var(--color-positive); }
.toast.error   { border-left-color: var(--color-danger); }
.toast.warning { border-left-color: var(--color-warning); }

@keyframes toast-in {
  from { transform: translateX(120%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

@keyframes toast-out {
  from { transform: translateX(0);    opacity: 1; }
  to   { transform: translateX(120%); opacity: 0; }
}

.toast.hiding { animation: toast-out 0.3s ease forwards; }

/* ── Auth Views (Login / Register) ───────────────────────────────────────── */
.auth-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: var(--space-lg);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: var(--space-xl);
}

.auth-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--color-primary);
  text-align: center;
  margin-bottom: var(--space-xs);
}

.auth-subtitle {
  color: var(--color-text-muted);
  text-align: center;
  margin-bottom: var(--space-xl);
  font-size: 0.9rem;
}

/* ── Error View ──────────────────────────────────────────────────────────── */
.error-view {
  padding: var(--space-xl);
  text-align: center;
}

.error-view h2 {
  color: var(--color-danger);
  margin-bottom: var(--space-md);
}

/* ── Utility Classes ─────────────────────────────────────────────────────── */
.text-muted  { color: var(--color-text-muted); }
.text-sm     { font-size: 0.875rem; }
.text-center { text-align: center; }
.mt-sm       { margin-top: var(--space-sm); }
.mt-md       { margin-top: var(--space-md); }
.mt-lg       { margin-top: var(--space-lg); }
.mb-sm       { margin-bottom: var(--space-sm); }
.mb-md       { margin-bottom: var(--space-md); }
.hidden      { display: none !important; }

/* ── Page Title ──────────────────────────────────────────────────────────── */
.page-title {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: var(--space-lg);
  color: var(--color-text);
}

/* ── Badge / Achievement chip ────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  padding: 2px var(--space-sm);
  border-radius: var(--radius-xl);
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--accent-blue-12);
  color: var(--color-primary);
}

.badge-success { background: var(--positive-12); color: var(--color-positive); }
.badge-warning { background: rgba(243, 156, 18, 0.12); color: var(--color-warning); }

/* ── Profile View ─────────────────────────────────────────────────────────── */
.profile-avatar-row {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
}

.profile-avatar {
  width: 4rem;
  height: 4rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
  text-transform: uppercase;
}

.profile-display-name {
  font-size: 1.2rem;
  font-weight: 600;
}

.profile-stats {
  display: flex;
  gap: var(--space-xl);
  padding-top: var(--space-md);
  border-top: 1px solid var(--color-border);
}

.stat-item { text-align: center; }
.stat-value { font-size: 1.5rem; font-weight: 700; color: var(--color-primary); }
.stat-label { font-size: 0.75rem; color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.05em; }

/* Color Picker */
.color-picker {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
  margin-top: var(--space-xs);
}

.color-swatch {
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  transition: transform 0.1s, border-color 0.1s;
}
.color-swatch:hover  { transform: scale(1.15); }
.color-swatch.selected { border-color: var(--color-text); }

/* Unit Toggle */
.unit-toggle {
  display: flex;
  gap: 0;
  margin-top: var(--space-xs);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  width: fit-content;
}

.unit-btn {
  padding: var(--space-xs) var(--space-lg);
  background: var(--color-surface);
  color: var(--color-text-muted);
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.unit-btn.active { background: var(--color-primary); color: white; }

/* ── Badges extra ────────────────────────────────────────────────────────── */
.badge-muted  { background: rgba(113,128,150,0.12); color: var(--color-text-muted); }
.badge-danger { background: rgba(231,76,60,0.12);   color: var(--color-danger); }

/* ── % display ───────────────────────────────────────────────────────────── */
.pct-positive { color: var(--color-positive); font-weight: 600; }
.pct-negative { color: var(--color-danger);   font-weight: 600; }

/* ── Error / Success / Warning messages ─────────────────────────────────── */
.error-msg    { color: var(--color-danger);   font-size: 0.875rem; padding: var(--space-sm) 0; }
.success-msg  { color: var(--color-positive); font-size: 0.875rem; padding: var(--space-sm) 0; }
.health-warning {
  background: rgba(243,156,18,0.1);
  border-left: 3px solid var(--color-warning);
  border-radius: var(--radius-sm);
  padding: var(--space-sm) var(--space-md);
  color: var(--color-warning);
  font-size: 0.875rem;
  margin-bottom: var(--space-md);
}

/* ── Section title ───────────────────────────────────────────────────────── */
.section-title { font-size: 1.05rem; font-weight: 600; margin-bottom: var(--space-md); }
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-md);
}
.section-header .section-title { margin-bottom: 0; }

/* ── Buttons extra ───────────────────────────────────────────────────────── */
.btn-sm  { padding: 0.4rem 0.875rem; font-size: 0.85rem; }
.btn-lg  { padding: 0.875rem var(--space-lg); font-size: 1.05rem; }
.btn-outline { background: transparent; border: 1.5px solid currentColor; }
.btn-back { color: var(--color-primary); font-size: 0.9rem; display: inline-block; margin-bottom: var(--space-sm); }

/* ── Avatar ──────────────────────────────────────────────────────────────── */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
  text-transform: uppercase;
  width: 2.25rem;
  height: 2.25rem;
  font-size: 1rem;
}
.avatar--sm { width: 1.75rem; height: 1.75rem; font-size: 0.8rem; }
.avatar--lg { width: 3.25rem; height: 3.25rem; font-size: 1.4rem; }

/* ── Form extras ─────────────────────────────────────────────────────────── */
.form-control {
  width: 100%;
  padding: 0.625rem var(--space-md);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  font: inherit;
  color: var(--color-text);
  background: var(--input-bg);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.form-control:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--accent-blue-15);
}
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-md);
}
@media (max-width: 480px) { .form-row { grid-template-columns: 1fr; } }
label { display: block; font-weight: 500; font-size: 0.9rem; margin-bottom: var(--space-xs); }

/* ── Battle list cards ───────────────────────────────────────────────────── */
.battle-header-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-sm);
  margin-bottom: var(--space-sm);
}
.battle-desc  { color: var(--color-text-muted); font-size: 0.9rem; margin-bottom: var(--space-sm); }
.battle-meta  { display: flex; flex-wrap: wrap; gap: var(--space-md); font-size: 0.85rem; color: var(--color-text-muted); margin-top: var(--space-sm); }
.battle-actions { display: flex; gap: var(--space-sm); flex-wrap: wrap; margin-top: var(--space-md); }

/* ── Participant list ────────────────────────────────────────────────────── */
.participant-list { list-style: none; display: flex; flex-direction: column; gap: var(--space-xs); }
.participant-item {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-xs) 0;
  font-size: 0.9rem;
}
.participant-me { font-weight: 600; color: var(--color-primary); }
.you-tag { font-size: 0.8rem; color: var(--color-primary); }

/* ── Invite card ─────────────────────────────────────────────────────────── */
.invite-code-display {
  font-size: 1.8rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-align: center;
  color: var(--color-primary);
  font-family: monospace;
  margin-bottom: var(--space-sm);
}
.invite-url-row { display: flex; gap: var(--space-sm); }
.invite-url-row .form-control { flex: 1; font-size: 0.85rem; }

/* ── Leaderboard ─────────────────────────────────────────────────────────── */
.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.leaderboard-table th {
  text-align: left;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  padding-bottom: var(--space-sm);
  border-bottom: 1px solid var(--color-border);
}
.leaderboard-row td {
  padding: var(--space-sm) var(--space-xs);
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}
.leaderboard-row:last-child td { border-bottom: none; }
.leaderboard-row--me { background: var(--accent-blue-06); }
.leaderboard-row--me td:first-child { border-left: 3px solid var(--color-primary); }
.col-rank   { width: 2.5rem; font-size: 1.1rem; text-align: center; }
.col-name   { display: flex; align-items: center; gap: var(--space-sm); }
.col-pct    { text-align: right; min-width: 5rem; }
.col-cheers { text-align: right; min-width: 5rem; white-space: nowrap; }

/* Cheer button */
.btn-cheer {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem; height: 2rem;
  border-radius: 50%;
  background: var(--accent-blue-10);
  color: var(--color-primary);
  font-size: 1rem;
  border: none;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  margin-left: var(--space-xs);
}
.btn-cheer:hover { background: var(--accent-blue-25); transform: scale(1.1); }
.btn-cheer--sent { background: var(--positive-12); color: var(--color-positive); cursor: default; }
.cheer-count { font-size: 0.8rem; color: var(--color-text-muted); }
.cheer-picker {
  position: fixed;
  background: var(--color-surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: var(--space-sm);
  display: flex;
  gap: var(--space-xs);
  z-index: 300;
  border: 1px solid var(--color-border);
}
.cheer-emoji-btn {
  font-size: 1.4rem;
  padding: var(--space-xs);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: transform 0.1s, background 0.1s;
  border: none;
  background: none;
}
.cheer-emoji-btn:hover { transform: scale(1.2); background: var(--color-bg); }

/* ── Weight Entry View ───────────────────────────────────────────────────── */
.entry-view      { max-width: 420px; }
.entry-card      { text-align: center; }
.entry-battle-name { margin-top: -0.75rem; margin-bottom: var(--space-lg); }
.weight-display  {
  font-size: 3.5rem;
  font-weight: 700;
  color: var(--color-primary);
  line-height: 1;
  margin-bottom: var(--space-md);
}
.weight-unit { font-size: 1.5rem; color: var(--color-text-muted); margin-left: var(--space-xs); }
.weight-nudge-row { display: flex; justify-content: center; gap: var(--space-md); margin-bottom: var(--space-lg); }
.btn-nudge {
  padding: var(--space-sm) var(--space-xl);
  background: var(--color-bg);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-nudge:hover { background: var(--color-border); }
.weight-input-field {
  font-size: 1.5rem;
  text-align: center;
  font-weight: 600;
  letter-spacing: 0.05em;
}
.entry-progress-card { text-align: center; }

/* ── History View ────────────────────────────────────────────────────────── */
.history-battle-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: var(--space-sm);
}
.history-battle-meta { display: flex; gap: var(--space-sm); align-items: center; }
.history-battle-actions { display: flex; gap: var(--space-sm); margin-top: var(--space-md); }
.pct-badge {
  display: inline-flex;
  padding: 2px var(--space-sm);
  border-radius: var(--radius-xl);
  font-size: 0.8rem;
  font-weight: 700;
}
.chart-wrapper { position: relative; }
.chart-empty   { text-align: center; padding: var(--space-xl); color: var(--color-text-muted); }
.entries-details { margin-top: var(--space-md); }
.entries-summary {
  cursor: pointer;
  font-size: 0.875rem;
  color: var(--color-primary);
  user-select: none;
}
.entries-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  margin-top: var(--space-sm);
}
.entries-table th, .entries-table td {
  padding: var(--space-xs) var(--space-sm);
  border-bottom: 1px solid var(--color-border);
  text-align: left;
}
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
  gap: var(--space-md);
  text-align: center;
}

/* ── Achievements View ───────────────────────────────────────────────────── */
.achievement-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: var(--space-sm);
}
.achievement-card {
  display: flex;
  align-items: flex-start;
  gap: var(--space-md);
  padding: var(--space-md);
  border-radius: var(--radius-md);
  border: 1.5px solid var(--color-border);
  transition: box-shadow 0.15s;
}
.achievement-earned {
  border-color: var(--positive-30);
  background: var(--positive-04);
}
.achievement-locked { opacity: 0.55; }
.achievement-icon  { font-size: 1.8rem; flex-shrink: 0; }
.achievement-name  { font-weight: 600; font-size: 0.9rem; }
.achievement-desc  { margin-top: 2px; }
.achievement-date  { margin-top: 4px; }
.achievement-progress-bar {
  height: 6px;
  background: var(--color-border);
  border-radius: var(--radius-xl);
  overflow: hidden;
  margin-top: var(--space-md);
}
.achievement-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--color-primary), var(--color-positive));
  border-radius: var(--radius-xl);
  transition: width 0.6s ease;
}
.achievements-summary .stats-grid { margin-bottom: var(--space-md); }
.achievement-section { margin-bottom: var(--space-lg); }

/* ── Dashboard ───────────────────────────────────────────────────────────── */
.dashboard-greeting {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}
.dashboard-user-row { display: flex; align-items: center; gap: var(--space-md); }
.dashboard-welcome  { font-size: 1.2rem; font-weight: 700; }
.dashboard-streak   { font-size: 0.9rem; color: var(--color-text-muted); }
.dashboard-xp-row   { display: flex; align-items: center; gap: var(--space-md); }
.xp-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px var(--space-sm);
  background: rgba(108,99,255,0.1);
  color: var(--color-secondary);
  border-radius: var(--radius-xl);
  font-size: 0.85rem;
  font-weight: 600;
}
.dashboard-section     { margin-bottom: var(--space-lg); }
.dashboard-battle-card { padding: var(--space-md) var(--space-lg); }
.dashboard-battle-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  margin-bottom: var(--space-xs);
}
.dashboard-battle-name { font-weight: 600; color: var(--color-text); }
.dashboard-battle-name:hover { color: var(--color-primary); }
.dashboard-battle-meta { margin-bottom: var(--space-sm); }
.dashboard-battle-card--pending { opacity: 0.75; }
.entry-status       { font-size: 0.875rem; padding: var(--space-xs) 0; }
.entry-done         { color: var(--color-positive); font-weight: 500; }
.dashboard-entry-btn { display: inline-flex; width: auto; margin-top: var(--space-xs); }
.dashboard-empty    { text-align: center; padding: var(--space-xl); }
.dashboard-empty p  { margin-bottom: var(--space-md); }
.dashboard-quicklinks {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-sm);
  margin-top: var(--space-md);
}
.quicklink-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-md);
  text-align: center;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--color-text);
  text-decoration: none;
  transition: box-shadow 0.15s, transform 0.1s;
}
.quicklink-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); text-decoration: none; }
.quicklink-card span:first-child { font-size: 1.6rem; }

/* Recent achievements in dashboard */
.recent-achievements { display: flex; flex-direction: column; gap: var(--space-sm); }
.recent-achievement-item {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}
.achievement-icon-sm { font-size: 1.3rem; flex-shrink: 0; }
.mb-0 { margin-bottom: 0; }

/* ── Join View ───────────────────────────────────────────────────────────── */
.join-card   { max-width: 420px; margin: var(--space-xl) auto; }
.battle-info-preview { margin-bottom: var(--space-lg); }
.battle-info-preview h2 { font-size: 1.2rem; font-weight: 700; margin-bottom: var(--space-xs); }

/* ── Confetti ─────────────────────────────────────────────────────────────── */
.confetti-container {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 100vh;
  pointer-events: none;
  z-index: 999;
  overflow: hidden;
}
.confetti-particle {
  position: absolute;
  top: -10px;
  animation: confetti-fall linear forwards;
}
@keyframes confetti-fall {
  0%   { transform: translateY(0) rotate(0deg);    opacity: 1; }
  80%  { opacity: 1; }
  100% { transform: translateY(105vh) rotate(720deg); opacity: 0; }
}

/* ── Achievement unlock pulse ─────────────────────────────────────────────── */
@keyframes achievement-pulse {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.08); box-shadow: 0 0 0 6px var(--positive-25); }
  100% { transform: scale(1); }
}
.achievement-earned.just-unlocked {
  animation: achievement-pulse 0.6s ease 3;
}

/* ── Toast achievement ───────────────────────────────────────────────────── */
.toast-achievement { border-left-color: var(--color-positive); min-width: 260px; }
.toast-achievement-inner { display: flex; align-items: flex-start; gap: var(--space-sm); }
.toast-achievement-icon  { font-size: 2rem; line-height: 1; flex-shrink: 0; }
.toast-achievement-title { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--color-positive); font-weight: 700; }
.toast-achievement-name  { font-weight: 600; font-size: 0.95rem; }
.toast-achievement-desc  { color: var(--color-text-muted); }

/* ── Focus visible (Accessibility) ──────────────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* ── Skip to main content (Accessibility) ───────────────────────────────── */
.skip-link {
  position: absolute;
  top: -100%;
  left: var(--space-md);
  background: var(--color-primary);
  color: white;
  padding: var(--space-sm) var(--space-md);
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  z-index: 1000;
  font-weight: 600;
  transition: top 0.1s;
}
.skip-link:focus { top: 0; }

/* ── Footer ──────────────────────────────────────────────────────────────── */
.app-footer {
  text-align: center;
  padding: var(--space-xl) var(--space-md);
  font-size: 0.8rem;
  color: var(--color-text-muted);
  border-top: 1px solid var(--color-border);
  margin-top: var(--space-2xl);
}
.app-footer a { color: var(--color-text-muted); }
.app-footer a:hover { color: var(--color-primary); }

/* ── Responsive tweaks ───────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .achievement-grid { grid-template-columns: 1fr; }
  .dashboard-quicklinks { grid-template-columns: 1fr 1fr; }
  .leaderboard-table { font-size: 0.82rem; }
  .col-cheers { display: none; } /* hide on very small screens */
}
@media (min-width: 769px) {
  .col-cheers { display: table-cell; }
  .container  { max-width: 720px; }
}

/* Logout Button in Navigation */
.nav-logout {
  background: none;
  border: none;
  cursor: pointer;
  color: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.5rem 0.75rem;
  font-size: inherit;
  opacity: 0.8;
}
.nav-logout:hover { opacity: 1; color: var(--danger, #e74c3c); }

/* ── Theme Switcher ───────────────────────────────────────────────────────── */
.theme-switcher { margin-bottom: 2rem; }
.theme-options {
  display: flex;
  gap: 1rem;
  margin-top: 0.75rem;
  flex-wrap: wrap;
}
.theme-btn {
  padding: 0.75rem 1.5rem;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: var(--bg-card);
  color: var(--text-primary);
  cursor: pointer;
  font-size: 1rem;
  transition: all 0.2s;
}
.theme-btn:hover { border-color: var(--accent-primary); }
.theme-btn.active {
  border-color: var(--accent-primary);
  background: var(--accent-primary);
  color: var(--btn-primary-text);
}

/* ── Invite Management ────────────────────────────────────────────────────── */
.invite-mgmt-card { margin-top: 1rem; }
.invite-create-row { display: flex; gap: 0.75rem; margin-bottom: 1rem; align-items: center; }
.invite-create-row .form-control { flex: 1; }
.invite-list-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.invite-list-table th { text-align: left; padding: 0.5rem; border-bottom: 2px solid var(--border); color: var(--text-secondary); }
.invite-list-table td { padding: 0.5rem; border-bottom: 1px solid var(--border); }
.invite-list-table tr:last-child td { border-bottom: none; }
.invite-status-used { color: var(--color-positive); font-weight: 600; }
.invite-status-open { color: var(--accent-blue); }
.invite-status-revoked { color: var(--color-danger); text-decoration: line-through; }
.invite-code-chip { font-family: monospace; background: var(--bg-primary); padding: 0.2rem 0.5rem; border-radius: 4px; font-size: 0.85rem; }
.btn-sm { padding: 0.2rem 0.5rem; font-size: 0.8rem; }
