/* ============================================================================
  Gamification — HUD, mortgage coins, streak, skill tree, celebrations
   ============================================================================ */

/* ─── HUD (persistent in topbar) ──────────────────────────────────────── */
.hud {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0 var(--space-2);
}

.hud-level {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0.25rem 0.625rem;
  background: var(--level-gradient);
  color: #fff;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 700;
  box-shadow: var(--shadow-sm);
  letter-spacing: -0.01em;
}
.hud-level-crown { font-size: 0.7rem; }

.hud-xp {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 120px;
  max-width: 200px;
  flex: 1;
}
.hud-xp-bar {
  position: relative;
  flex: 1;
  height: 8px;
  background: var(--surface-2);
  border-radius: var(--radius-full);
  overflow: hidden;
}
.hud-xp-fill {
  position: absolute;
  inset: 0 auto 0 0;
  background: linear-gradient(90deg, #fbbf24, #f59e0b, #d97706);
  border-radius: var(--radius-full);
  transition: width var(--dur-slower) var(--ease-spring);
  box-shadow: 0 0 8px rgb(16 185 129 / 0.4);
}
.hud-xp-fill.is-pulsing {
  animation: xp-pulse 600ms var(--ease-out);
}
@keyframes xp-pulse {
  0% { filter: brightness(1) }
  40% { filter: brightness(1.4) drop-shadow(0 0 8px rgb(16 185 129 / 0.8)) }
  100% { filter: brightness(1) }
}
.hud-xp-text {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* ─── Streak flame ─────────────────────────────────────────────────── */
.hud-streak {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-full);
  background: var(--surface-2);
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--dur-fast);
}
.hud-streak.is-active {
  background: rgb(249 115 22 / 0.12);
  color: var(--warn-700);
}
.hud-streak.is-hot {
  background: rgb(239 68 68 / 0.12);
  color: var(--danger-600);
}
.hud-streak.is-rainbow {
  background: linear-gradient(90deg, #ef4444, #f97316, #eab308, #22c55e, #3b82f6, #8b5cf6);
  color: #fff;
}
.hud-streak-flame {
  font-size: 0.875rem;
  animation: flame-flicker 2s ease-in-out infinite alternate;
}
@keyframes flame-flicker {
  0% { transform: scale(1) rotate(-2deg) }
  100% { transform: scale(1.08) rotate(2deg) }
}

/* ─── Daily goal ring ──────────────────────────────────────────────── */
.hud-ring { position: relative; width: 28px; height: 28px; }
.hud-ring svg { transform: rotate(-90deg); }
.hud-ring-track { stroke: var(--border-default); fill: none; stroke-width: 3; }
.hud-ring-fill {
  stroke: var(--accent-500);
  fill: none;
  stroke-width: 3;
  stroke-linecap: round;
  transition: stroke-dashoffset var(--dur-slower) var(--ease-spring);
}
.hud-ring.is-complete .hud-ring-fill { stroke: var(--accent-500); }
.hud-ring.is-complete::after {
  content: '✓';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent-600);
}

/* ─── Mascot ───────────────────────────────────────────────────────── */
.mascot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  background: var(--brand-50);
  flex-shrink: 0;
  cursor: pointer;
  transition: transform var(--dur-fast) var(--ease-spring);
}
.mascot:hover { transform: scale(1.08) rotate(-3deg); }
.mascot-lg { width: 64px; height: 64px; }
.mascot-xl { width: 96px; height: 96px; }
[data-theme="dark"] .mascot { background: rgb(99 102 241 / 0.15); }

/* ─── Mortgage coin toast ──────────────────────────────────────────── */
.xp-toast-host {
  position: fixed;
  top: calc(var(--topbar-h) + var(--space-2));
  right: var(--space-6);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  pointer-events: none;
}
.xp-toast {
  background: linear-gradient(135deg, #fffbeb, #fef3c7 36%, #fbbf24 100%);
  color: #78350f;
  font-family: var(--font-display);
  font-weight: 850;
  font-size: 0.8125rem;
  padding: 0.3125rem 0.75rem 0.3125rem 0.375rem;
  border-radius: var(--radius-full);
  border: 1px solid rgb(217 119 6 / 0.28);
  box-shadow: 0 12px 28px rgb(217 119 6 / 0.24), inset 0 1px 0 rgb(255 255 255 / 0.75);
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  animation: xp-toast-rise 1800ms var(--ease-out) forwards;
}
.xp-toast .coin-icon { width: 24px; height: 24px; }
@keyframes xp-toast-rise {
  0% { opacity: 0; transform: translateY(12px) scale(0.8) }
  15% { opacity: 1; transform: translateY(0) scale(1.05) }
  25% { transform: translateY(-2px) scale(1) }
  80% { opacity: 1; transform: translateY(-6px) }
  100% { opacity: 0; transform: translateY(-28px) }
}

/* ─── Celebration modal pieces ─────────────────────────────────────── */
.celebrate-panel {
  background: var(--surface-1);
  border-radius: var(--radius-2xl);
  box-shadow: var(--shadow-2xl);
  max-width: 560px;
  width: 100%;
  overflow: hidden;
  border: 1px solid var(--border-subtle);
}
.celebrate-hero {
  padding: var(--space-8) var(--space-6) var(--space-6);
  text-align: center;
  background: linear-gradient(180deg, var(--accent-50), var(--surface-1));
  position: relative;
}
[data-theme="dark"] .celebrate-hero {
  background: linear-gradient(180deg, rgb(16 185 129 / 0.15), var(--surface-1));
}
.celebrate-title {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-top: var(--space-4);
}
.celebrate-xp {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0.5rem 1rem;
  background: linear-gradient(135deg, #fef3c7, #fbbf24, #f59e0b);
  color: #78350f;
  border-radius: var(--radius-full);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.125rem;
  margin-top: var(--space-3);
  box-shadow: var(--shadow-md);
}

.coin-burst {
  position: fixed;
  width: 24px;
  height: 24px;
  pointer-events: none;
  z-index: calc(var(--z-toast) + 1);
  animation: coin-burst-fly 920ms cubic-bezier(.22, 1, .36, 1) forwards;
  filter: drop-shadow(0 6px 8px rgb(120 53 15 / 0.24));
}
@keyframes coin-burst-fly {
  0% { opacity: 0; transform: translate(0, 12px) scale(0.55) rotate(0deg); }
  16% { opacity: 1; }
  68% { opacity: 1; transform: translate(var(--coin-x, 0), var(--coin-y, -52px)) scale(1.08) rotate(var(--coin-r, 90deg)); }
  100% { opacity: 0; transform: translate(calc(var(--coin-x, 0) * 1.2), calc(var(--coin-y, -52px) - 28px)) scale(0.82) rotate(calc(var(--coin-r, 90deg) + 90deg)); }
}

/* ─── Skill tree hex ───────────────────────────────────────────────── */
.skill-node {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  cursor: pointer;
  transition: transform var(--dur-fast) var(--ease-spring);
}
.skill-node:hover { transform: translateY(-2px); }
.skill-hex {
  width: 72px;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.skill-hex-bg {
  position: absolute;
  inset: 0;
  clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
  background: var(--surface-2);
  border: 2px solid var(--border-default);
}
.skill-hex[data-crown="5"] .skill-hex-bg { background: var(--level-gradient); border-color: transparent; }
.skill-hex[data-crown="4"] .skill-hex-bg { background: linear-gradient(135deg, var(--accent-400), var(--accent-600)); border-color: transparent; }
.skill-hex[data-crown="3"] .skill-hex-bg { background: linear-gradient(135deg, var(--brand-300), var(--brand-500)); border-color: transparent; }
.skill-hex[data-crown="2"] .skill-hex-bg { background: var(--brand-100); border-color: var(--brand-400); }
.skill-hex[data-crown="1"] .skill-hex-bg { background: var(--accent-50); border-color: var(--accent-400); }
.skill-hex-icon {
  position: relative;
  z-index: 1;
  font-size: 1.25rem;
  color: var(--text-primary);
}
.skill-hex[data-crown="5"] .skill-hex-icon,
.skill-hex[data-crown="4"] .skill-hex-icon,
.skill-hex[data-crown="3"] .skill-hex-icon { color: #fff; }

.skill-label {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-align: center;
  max-width: 84px;
}
.skill-crowns {
  display: flex;
  gap: 2px;
}
.skill-crown-dot {
  width: 5px;
  height: 5px;
  border-radius: var(--radius-full);
  background: var(--border-default);
}
.skill-crown-dot.is-earned { background: var(--warn-500); }

/* ─── Badge card ───────────────────────────────────────────────────── */
.badge-card {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-4);
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: all var(--dur-fast) var(--ease-out);
}
.badge-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--brand-400);
}
.badge-card.is-locked {
  opacity: 0.5;
  filter: grayscale(1);
}
.badge-icon {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-full);
  background: var(--level-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1.5rem;
  box-shadow: var(--shadow-sm);
}
.badge-card.is-locked .badge-icon { background: var(--surface-3); color: var(--text-tertiary); }
.badge-name {
  font-size: 0.75rem;
  font-weight: 600;
  text-align: center;
  color: var(--text-primary);
}

/* ─── Quest card ───────────────────────────────────────────────────── */
.quest {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  transition: all var(--dur-fast);
}
.quest:hover { border-color: var(--brand-400); }
.quest.is-done {
  background: var(--accent-50);
  border-color: var(--accent-300);
}
[data-theme="dark"] .quest.is-done {
  background: rgb(16 185 129 / 0.1);
  border-color: rgb(16 185 129 / 0.3);
}
.quest-icon {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: var(--radius-md);
  background: var(--brand-50);
  color: var(--brand-600);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.quest.is-done .quest-icon { background: var(--accent-500); color: #fff; }
.quest-body { flex: 1; min-width: 0; }
.quest-title { font-size: 0.875rem; font-weight: 600; color: var(--text-primary); }
.quest-progress-bar {
  margin-top: 0.25rem;
  height: 4px;
  background: var(--surface-2);
  border-radius: var(--radius-full);
  overflow: hidden;
}
.quest-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #fbbf24, #f59e0b, #d97706);
  border-radius: var(--radius-full);
  transition: width var(--dur-slow) var(--ease-out);
}
.quest-reward {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem 0.5rem;
  background: #fffbeb;
  color: #92400e;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 700;
  white-space: nowrap;
}
[data-theme="dark"] .quest-reward { background: rgb(16 185 129 / 0.15); color: var(--accent-300); }

/* ─── Pipeline funnel ──────────────────────────────────────────────── */
.funnel {
  display: flex;
  gap: 4px;
  align-items: stretch;
  height: 64px;
  border-radius: var(--radius-md);
  overflow: hidden;
}
.funnel-seg {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: var(--space-2) var(--space-3);
  color: #fff;
  min-width: 48px;
  cursor: pointer;
  transition: filter var(--dur-fast);
  position: relative;
}
.funnel-seg:hover { filter: brightness(1.1); }
.funnel-seg-label {
  font-size: 0.625rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  opacity: 0.85;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.funnel-seg-count {
  font-family: var(--font-display);
  font-size: 1.125rem;
  font-weight: 700;
  line-height: 1;
}

/* ─── Call readiness meter ─────────────────────────────────────────── */
.readiness {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.readiness-bar {
  display: flex;
  gap: 2px;
}
.readiness-seg {
  width: 16px;
  height: 6px;
  border-radius: var(--radius-sm);
  background: var(--border-default);
}
.readiness[data-level="hot"] .readiness-seg:nth-child(-n+3) { background: var(--danger-500); }
.readiness[data-level="warm"] .readiness-seg:nth-child(-n+2) { background: var(--warn-500); }
.readiness[data-level="cool"] .readiness-seg:nth-child(1) { background: var(--accent-500); }
.readiness-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
}
