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

:root {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --success: #22c55e;
  --warning: #f59e0b;
  --bg: #f8fafc;
  --card-bg: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --highlight: #fef3c7;
}

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

header {
  background: var(--primary);
  color: white;
  padding: 1rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}

header h1 {
  font-size: 1.5rem;
  font-weight: 600;
}

.user-selector {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.user-selector select {
  padding: 0.5rem 1rem;
  border-radius: 6px;
  border: none;
  font-size: 1rem;
  cursor: pointer;
}

main {
  max-width: 1600px;
  margin: 0 auto;
  padding: 2rem;
  display: grid;
  gap: 2rem;
  grid-template-columns: 1fr;
}

@media (min-width: 900px) {
  main {
    grid-template-columns: 300px 1fr;
  }
}

@media (min-width: 1200px) {
  main {
    grid-template-columns: 280px 320px 1fr;
  }
}

section {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

h2 {
  font-size: 1.25rem;
  margin-bottom: 1rem;
  color: var(--text);
}

h3 {
  font-size: 1rem;
  margin-bottom: 0.75rem;
  color: var(--text-muted);
}

/* Leaderboard */
.leaderboard {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.leaderboard-item {
  display: grid;
  grid-template-columns: 30px 1fr auto;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem;
  border-radius: 8px;
  background: var(--bg);
  transition: transform 0.2s;
}

.leaderboard-item.current-user {
  background: var(--highlight);
  border: 2px solid var(--warning);
}

.leaderboard-item.rank-1 .rank {
  color: #fbbf24;
  font-weight: bold;
}

.leaderboard-item.rank-2 .rank {
  color: #94a3b8;
  font-weight: bold;
}

.leaderboard-item.rank-3 .rank {
  color: #cd7f32;
  font-weight: bold;
}

.rank {
  font-size: 1.25rem;
  font-weight: 600;
  text-align: center;
}

.player-info {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.player-name {
  font-weight: 500;
}

.progress-bar-container {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: var(--primary);
  border-radius: 3px;
  transition: width 0.3s ease;
}

.player-xp {
  font-weight: 600;
  color: var(--primary);
  white-space: nowrap;
}

.player-badges {
  display: flex;
  gap: 0.25rem;
  margin-top: 0.25rem;
}

.mini-badge {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  font-size: 0.6rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Badges */
.badges-container {
  margin-bottom: 1.5rem;
}

.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.5rem;
  border-radius: 8px;
  background: var(--bg);
  min-width: 70px;
  text-align: center;
  transition: transform 0.2s;
  cursor: help;
}

.badge.earned {
  background: linear-gradient(135deg, #fef3c7, #fde68a);
  box-shadow: 0 2px 8px rgba(251, 191, 36, 0.3);
}

.badge.locked {
  opacity: 0.5;
  filter: grayscale(1);
}

.badge-icon {
  font-size: 1.25rem;
  margin-bottom: 0.25rem;
}

.badge-name {
  font-size: 0.65rem;
  font-weight: 500;
}

.badge-xp {
  font-size: 0.6rem;
  color: var(--text-muted);
}

/* Day Tabs */
.days-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.day-tab {
  padding: 0.5rem 1rem;
  border: none;
  background: var(--bg);
  border-radius: 6px;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.2s;
}

.day-tab:hover {
  background: var(--border);
}

.day-tab.active {
  background: var(--primary);
  color: white;
}

/* Checkpoints */
.checkpoints {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.checkpoint {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem;
  border-radius: 8px;
  background: var(--bg);
  cursor: pointer;
  transition: all 0.2s;
  border: 2px solid transparent;
}

.checkpoint:hover {
  background: var(--border);
}

.checkpoint.completed {
  background: #dcfce7;
}

.checkpoint.active {
  border-color: var(--primary);
  background: #eef2ff;
}

.checkpoint.active.completed {
  background: #dcfce7;
  border-color: var(--success);
}

.checkpoint input[type="checkbox"] {
  width: 20px;
  height: 20px;
  cursor: pointer;
  accent-color: var(--success);
}

.checkpoint-info {
  flex: 1;
}

.checkpoint-name {
  font-weight: 500;
  font-size: 0.875rem;
}

.checkpoint-level {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.checkpoint-xp {
  font-weight: 600;
  color: var(--primary);
  padding: 0.25rem 0.5rem;
  background: white;
  border-radius: 4px;
  font-size: 0.75rem;
}

/* Task Detail Panel */
.task-detail-section {
  max-height: calc(100vh - 150px);
  overflow-y: auto;
}

.task-detail {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.task-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.nav-btn {
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  background: white;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.2s;
}

.nav-btn:hover:not(:disabled) {
  background: var(--bg);
  border-color: var(--primary);
  color: var(--primary);
}

.nav-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.task-counter {
  font-weight: 600;
  color: var(--text-muted);
}

.task-header {
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.task-title-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 0.5rem;
}

.task-title-row h3 {
  margin: 0;
  color: var(--text);
  font-size: 1.1rem;
}

.task-xp {
  padding: 0.25rem 0.75rem;
  background: var(--primary);
  color: white;
  border-radius: 20px;
  font-weight: 600;
  font-size: 0.875rem;
  white-space: nowrap;
}

.task-xp.completed {
  background: var(--success);
}

.task-meta {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.task-meta span {
  padding: 0.25rem 0.5rem;
  background: var(--bg);
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 500;
}

.task-day {
  color: var(--primary);
}

.task-level {
  color: var(--text-muted);
}

.task-status {
  color: var(--warning);
}

.task-status.completed {
  color: var(--success);
  background: #dcfce7 !important;
}

.task-section h4 {
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--text);
}

.task-section p {
  font-size: 0.875rem;
  color: var(--text-muted);
  line-height: 1.7;
}

.task-description {
  background: var(--bg);
  padding: 1rem;
  border-radius: 8px;
  font-family: inherit;
}

.adr-quote {
  margin-top: 0.75rem;
  padding: 0.75rem 1rem;
  border-left: 3px solid var(--primary);
  background: #eef2ff;
  font-style: italic;
  font-size: 0.8rem;
  color: var(--primary-dark);
}

.references-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.references-list li {
  font-size: 0.875rem;
}

.references-list a {
  color: var(--primary);
  text-decoration: none;
}

.references-list a:hover {
  text-decoration: underline;
}

.completion-criteria {
  background: #fefce8;
  padding: 1rem;
  border-radius: 8px;
  border: 1px solid #fef08a;
}

.mark-complete-btn {
  padding: 1rem 2rem;
  border: none;
  background: var(--primary);
  color: white;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  margin-top: 0.5rem;
}

.mark-complete-btn:hover {
  background: var(--primary-dark);
}

.mark-complete-btn.completed {
  background: var(--success);
}

.mark-complete-btn.completed:hover {
  background: #16a34a;
}

/* Footer */
footer {
  text-align: center;
  padding: 1rem;
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* Loading state */
.loading {
  display: flex;
  justify-content: center;
  padding: 2rem;
  color: var(--text-muted);
}

/* Responsive */
@media (max-width: 600px) {
  header {
    flex-direction: column;
    text-align: center;
  }

  main {
    padding: 1rem;
  }

  .badges {
    justify-content: center;
  }

  .task-title-row {
    flex-direction: column;
  }
}
