:root {
  --bg: #0f1115;
  --card: #171a21;
  --border: #2a2e38;
  --text: #e7e9ee;
  --muted: #9aa1ad;
  --accent: #5b8cff;
  --danger: #ff5b6b;
  --gold: #ffc94a;
  --xp: #6ee7a0;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 20px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
}

.brand {
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
  font-size: 1.1rem;
}

.main-nav {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
}

.main-nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.88rem;
}

.main-nav a:hover { color: var(--text); }

.user-nav {
  display: flex;
  align-items: center;
  margin-left: auto;
}

.who { color: var(--muted); margin-right: 12px; }

.level-badge {
  display: inline-block;
  margin-right: 14px;
  padding: 4px 10px;
  border-radius: 999px;
  background: #22262f;
  border: 1px solid var(--border);
  color: var(--gold);
  font-size: 0.82rem;
  font-weight: 600;
  text-decoration: none;
}

.link-btn {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  text-decoration: underline;
  font-size: 0.9rem;
}

.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 32px 20px;
}

.auth-box, .form-box {
  max-width: 380px;
  margin: 40px auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 28px;
}

h1 { margin-top: 0; font-size: 1.4rem; }

label {
  display: block;
  margin-bottom: 14px;
  font-size: 0.9rem;
  color: var(--muted);
}

input, textarea, select {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 9px 10px;
  background: #0f1115;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
}

textarea { resize: vertical; }

button, .btn {
  display: inline-block;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 9px 16px;
  font-size: 0.9rem;
  cursor: pointer;
  text-decoration: none;
}

.btn.small { padding: 6px 10px; font-size: 0.82rem; }
.btn.danger, button.danger { background: var(--danger); }

.muted { color: var(--muted); }
.error {
  background: #3a1720;
  border: 1px solid var(--danger);
  color: #ffb3ba;
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 0.88rem;
}

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

.new-buttons { display: flex; gap: 8px; }

.item-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }

.item-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.item-main { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.item-link { color: var(--accent); word-break: break-all; }
.item-preview { margin: 0; color: var(--muted); font-size: 0.88rem; }
.item-actions { display: flex; gap: 8px; flex-shrink: 0; }

.badge {
  display: inline-block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 8px;
  border-radius: 999px;
  width: fit-content;
  background: #22262f;
  color: var(--muted);
}
.badge-note { color: #8fd0ff; }
.badge-link { color: #a6ff9e; }
.badge-file { color: #ffd98f; }

.form-actions { display: flex; gap: 10px; margin-top: 8px; }

.log-box { max-width: none; margin: 0 0 28px; }

.level-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 24px;
}

.level-card-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 10px;
}

.level-big { font-size: 1.3rem; font-weight: 700; }
.coin-big { color: var(--gold); font-weight: 600; }

.xp-bar {
  height: 10px;
  border-radius: 999px;
  background: #22262f;
  overflow: hidden;
}

.xp-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--xp), var(--accent));
  border-radius: 999px;
  transition: width 0.3s ease;
}

.xp-bar-fill.over { background: linear-gradient(90deg, var(--gold), var(--danger)); }

.xp-label {
  margin-top: 6px;
  font-size: 0.78rem;
  color: var(--muted);
}

.xp-label.eval-good { color: var(--xp); }
.xp-label.eval-over, .xp-label.eval-sugar { color: var(--danger); }
.xp-label.eval-under { color: var(--gold); }

.section-title { font-size: 1.1rem; margin: 24px 0 12px; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 16px 0 24px;
}

.stat-tile {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-num { font-size: 1.4rem; font-weight: 700; }
.stat-label { font-size: 0.75rem; color: var(--muted); }

/* --- goal + streak card --- */
.goal-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
  margin-bottom: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

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

.goal-top {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  margin-bottom: 6px;
}

.goal-bar {
  height: 8px;
  border-radius: 999px;
  background: #22262f;
  overflow: hidden;
}

.goal-bar-fill {
  height: 100%;
  background: var(--xp);
  border-radius: 999px;
  transition: width 0.3s ease;
}

.goal-bar-fill.met { background: var(--gold); }

.streak-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 16px;
  background: #22262f;
  border-radius: 10px;
  min-width: 70px;
}

.streak-num { font-size: 1.3rem; font-weight: 700; }
.streak-label { font-size: 0.7rem; color: var(--muted); }

.goal-edit { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.goal-edit input { width: 60px; margin-top: 0; }
.goal-edit-unit { font-size: 0.8rem; color: var(--muted); margin-right: 4px; }
.goal-edit button { padding: 8px 12px; }

/* --- achievement badge grid --- */
.badge-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
  margin: 16px 0 24px;
}

.badge-tile {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 10px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.badge-tile.locked { opacity: 0.35; }
.badge-tile-icon { font-size: 1.6rem; }
.badge-tile-label { font-size: 0.78rem; font-weight: 600; }
.badge-tile-desc { font-size: 0.68rem; color: var(--muted); }

/* --- leaderboard --- */
.leaderboard-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }

.leaderboard-row {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
}

.leaderboard-row.me { border-color: var(--accent); background: #171f30; }

.lb-rank { width: 28px; text-align: center; font-weight: 700; color: var(--muted); }
.lb-rank.top1 { color: var(--gold); }
.lb-rank.top2 { color: #d9d9d9; }
.lb-rank.top3 { color: #cd8a4e; }
.lb-name { flex: 1; }
.lb-xp { color: var(--xp); font-weight: 600; font-size: 0.9rem; }

/* --- bar chart (stats page) --- */
.chart-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 24px;
}

.chart-bars {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  height: 140px;
  margin-top: 12px;
}

.chart-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
  gap: 6px;
}

.chart-bar-value { font-size: 0.68rem; color: var(--muted); }

.chart-bar {
  width: 100%;
  max-width: 34px;
  background: var(--accent);
  border-radius: 4px 4px 0 0;
  min-height: 2px;
}

.chart-bar.over { background: var(--danger); }

.chart-bar-label {
  font-size: 0.68rem;
  color: var(--muted);
  text-align: center;
}

/* --- rewards --- */
.reward-list { list-style: none; padding: 0; margin: 0 0 24px; display: flex; flex-direction: column; gap: 10px; }

.reward-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.reward-cost { color: var(--gold); font-weight: 600; }

/* --- avatar --- */
.level-badge-avatar { font-size: 1rem; margin-right: 2px; }

.avatar-hero {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 14px;
}

.avatar-hero-icon {
  font-size: 3rem;
  line-height: 1;
}

.avatar-hero-name { font-weight: 700; font-size: 1.1rem; }

/* --- quests --- */
.quest-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 12px; }

.quest-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
}

.quest-card.done { border-color: var(--xp); }

.quest-top {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 10px;
}

.quest-icon { font-size: 1.6rem; }
.quest-info { flex: 1; }
.quest-desc { margin: 2px 0 0; font-size: 0.85rem; }
.quest-reward { color: var(--gold); font-weight: 700; font-size: 0.9rem; white-space: nowrap; }
.quest-progress-label { margin-top: 6px; font-size: 0.75rem; color: var(--muted); text-align: right; }

/* --- celebration popup --- */
.celebration-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 6, 10, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: celebration-fade-in 0.25s ease;
}

.celebration-overlay.closing { animation: celebration-fade-out 0.25s ease forwards; }

.celebration-confetti {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.confetti-piece {
  position: absolute;
  top: -40px;
  font-size: 1.4rem;
  animation-name: confetti-fall;
  animation-timing-function: ease-in;
  animation-fill-mode: forwards;
}

.celebration-card {
  position: relative;
  background: linear-gradient(160deg, #1b1f2b, #12141a);
  border: 1px solid var(--gold);
  box-shadow: 0 0 40px rgba(255, 201, 74, 0.25);
  border-radius: 16px;
  padding: 36px 32px;
  text-align: center;
  max-width: 320px;
  width: 90%;
  animation: celebration-pop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.celebration-close {
  position: absolute;
  top: 10px;
  right: 12px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1rem;
  cursor: pointer;
}

.celebration-icon {
  font-size: 3.5rem;
  line-height: 1;
  margin-bottom: 12px;
  animation: celebration-icon-pulse 1.4s ease-in-out infinite;
}

.celebration-title { color: var(--gold); font-weight: 700; font-size: 1.05rem; margin-bottom: 6px; }
.celebration-subtitle { color: var(--text); font-size: 0.9rem; }
.celebration-count { margin-top: 10px; font-size: 0.72rem; color: var(--muted); }

@keyframes celebration-fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes celebration-fade-out { from { opacity: 1; } to { opacity: 0; } }
@keyframes celebration-pop {
  0% { transform: scale(0.7); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}
@keyframes celebration-icon-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.12); }
}
@keyframes confetti-fall {
  0% { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(100vh) rotate(360deg); opacity: 0; }
}
