/* CT CRUSH — global layout */
/* Mobile-first, canvas scales to fit, keeps 1:1 aspect ratio */

/* ── Design Tokens (Neon Degen Arcade — Wariant A) ───────────────────────────
   Single source of truth for all colours. No raw hex outside this block.    */
:root {
  /* tła */
  --bg-deep: #0b0714;        /* główne tło (prawie czarny fiolet) */
  --bg-panel: #171028;       /* karty, HUD, menu */
  --bg-board: #1d1433;       /* podkład planszy */
  --bg-cell: #251a40;        /* pusty slot kafla */

  /* akcenty */
  --accent: #a855f7;         /* fiolet — główny */
  --accent-bright: #b975f9;  /* fiolet jaśniejszy — hover primary */
  --accent-2: #22d3ee;       /* cyjan — sekundarny, przyciski secondary */
  --gold: #fbbf24;           /* legendary, gwiazdki, tier 7 */
  --gold-soft: #ffe9a3;      /* jasne złoto — obwódki/tekst legendary */
  --danger: #f43f5e;         /* mało ruchów/czasu */

  /* tekst */
  --text: #f5f3ff;
  --text-dim: #a79cc8;

  /* efekty */
  --glow-accent: 0 0 24px rgba(168, 85, 247, .45);
  --glow-gold:   0 0 32px rgba(251, 191, 36, .55);
  --radius-card: 20px;
  --radius-tile: 22%;        /* zaokrąglenie kafli (procent tileSize) */

  /* layout */
  --board-size: min(calc(100vw - 16px), 60vh, 512px);
}

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

/* ── Root + animated background ─────────────────────────────────────────────── */
html, body {
  width: 100%;
  height: 100%;
  min-height: 100dvh;
  background-color: var(--bg-deep);
  /* Subtle animated gradient — slow 30s loop */
  background-image:
    radial-gradient(ellipse 80% 60% at 20% 30%, rgba(168, 85, 247, 0.12) 0%, transparent 60%),
    radial-gradient(ellipse 60% 80% at 80% 70%, rgba(34, 211, 238, 0.07) 0%, transparent 60%);
  background-size: 200% 200%;
  animation: bg-drift 30s ease-in-out infinite alternate;
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
}

@keyframes bg-drift {
  0%   { background-position: 0% 0%; }
  50%  { background-position: 60% 40%; }
  100% { background-position: 100% 100%; }
}

/* Respect user motion preference — disable animation */
@media (prefers-reduced-motion: reduce) {
  html, body {
    animation: none;
    background-image: none;
  }
}

/* ── Top bar ─────────────────────────────────────────────────────────────────── */
#loading-screen {
  position: fixed;
  inset: 0;
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0b0714;
  opacity: 1;
  transition: opacity 0.28s ease;
}

#loading-screen.loading-screen--hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-card {
  display: flex;
  width: min(280px, 82vw);
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.loading-art {
  width: 132px;
  aspect-ratio: 1;
  border: 1px solid rgba(168, 85, 247, 0.45);
  border-radius: 22px;
  background:
    linear-gradient(140deg, rgba(168, 85, 247, 0.16), rgba(34, 211, 238, 0.12)),
    url("assets/brand/loading.webp") center / cover no-repeat,
    #171028;
  box-shadow: var(--glow-accent), inset 0 0 28px rgba(255, 255, 255, 0.08);
  position: relative;
  animation: loading-pulse 1.6s ease-in-out infinite;
}

.loading-art::before,
.loading-art::after {
  content: '';
  position: absolute;
  display: none;
  border-radius: 14px;
  background: rgba(251, 191, 36, 0.9);
  box-shadow: var(--glow-gold);
}

.loading-art::before {
  width: 34px;
  height: 34px;
  top: 24px;
  left: 26px;
}

.loading-art::after {
  width: 46px;
  height: 46px;
  right: 24px;
  bottom: 22px;
}

.loading-logo {
  width: 150px;
  height: auto;
}

.loading-dots {
  display: flex;
  gap: 8px;
}

.loading-dots span {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--accent-2);
  animation: loading-dot 0.9s ease-in-out infinite;
}

.loading-dots span:nth-child(2) { animation-delay: 0.12s; }
.loading-dots span:nth-child(3) { animation-delay: 0.24s; }

.loading-progress {
  width: 100%;
  height: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
}

.loading-progress span {
  display: block;
  width: 46%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--accent-2), var(--gold));
  animation: loading-progress 1.25s ease-in-out infinite;
}

@keyframes loading-pulse {
  0%, 100% { transform: scale(1); filter: brightness(1); }
  50% { transform: scale(1.04); filter: brightness(1.16); }
}

@keyframes loading-dot {
  0%, 100% { transform: translateY(0); opacity: 0.5; }
  50% { transform: translateY(-5px); opacity: 1; }
}

@keyframes loading-progress {
  0% { transform: translateX(-120%); }
  100% { transform: translateX(235%); }
}

@media (prefers-reduced-motion: reduce) {
  #loading-screen,
  .loading-art,
  .loading-dots span,
  .loading-progress span {
    animation: none;
    transition: none;
  }
}

#top-bar {
  width: var(--board-size);
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 48px;
  padding: 0 4px;
  flex-shrink: 0;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

/* Logo SVG in top bar — small version */
#logo {
  display: block;
  height: 28px;
  width: auto;
}

#mute-toggle,
.top-icon-btn {
  background: transparent;
  border: none;
  font-size: 1.25rem;
  cursor: pointer;
  color: var(--text-dim);
  padding: 8px;
  line-height: 1;
  border-radius: 8px;
  transition: color 0.15s ease;
}
#mute-toggle:hover,
.top-icon-btn:hover { color: var(--text); }

.top-icon-btn {
  font-size: 1.1rem;
}

/* ── Game container ─────────────────────────────────────────────────────────── */
/* Centre the game shell on the page (top-bar + HUD stacked above the board) */
#game-container {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 100dvh;
  padding: 0 8px;
  padding-top: max(8px, env(safe-area-inset-top));
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  position: relative;
}

/* ── HUD bar ─────────────────────────────────────────────────────────────────── */
/* countdown (left) + score (right), aligned to the board width */
#hud {
  width: var(--board-size);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 10px 18px;
  background: rgba(168, 85, 247, 0.08);
  border: 1px solid rgba(168, 85, 247, 0.25);
  border-radius: 12px;
  flex-shrink: 0;
}

.hud-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.hud-group--right {
  align-items: flex-end;
}

.hud-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--text-dim);
}

#time-value,
#score-value {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text);
  font-variant-numeric: tabular-nums; /* digits keep width as values change */
  font-family: 'Sora', system-ui, sans-serif;
}

/* ── Overlay fade transitions (A6) ──────────────────────────────────────────── */
#start-overlay,
#gameover-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(11, 7, 20, 0.85);
  border-radius: 8px;
  /* Fade transition — driven by .fade-in / .fade-out classes from transitions.js */
  opacity: 1;
  transition: opacity 0.2s ease;
}

#start-overlay.hidden,
#gameover-overlay.hidden {
  display: none;
}

#pause-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(11, 7, 20, 0.9);
  opacity: 1;
  transition: opacity 0.2s ease;
}

#pause-overlay.hidden {
  display: none;
}

.pause-kicker {
  margin: 0 0 8px;
  color: var(--accent-2);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.18em;
}

#pause-title {
  margin-bottom: 10px;
  color: var(--text);
  font-family: 'Sora', system-ui, sans-serif;
  font-size: 1.5rem;
  line-height: 1.2;
}

/* Applied by fadeIn() */
.fade-in {
  opacity: 1 !important;
}
/* Applied by fadeOut() — element starts at opacity 0, transitions to fully gone */
.fade-out {
  opacity: 0 !important;
  pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
  #start-overlay,
  #gameover-overlay,
  #pause-overlay {
    transition: none;
  }
}

/* ── Menu card (shared by start + game-over) ─────────────────────────────────── */
.menu-card {
  text-align: center;
  padding: 28px 24px;
  width: min(360px, 90%);
  background: var(--bg-panel);
  border: 1px solid rgba(168, 85, 247, 0.4);
  border-radius: var(--radius-card);
  box-shadow: var(--glow-accent);
}

/* Logo SVG on start screen — larger than top-bar version */
.start-logo {
  display: block;
  margin: 0 auto 14px;
  height: 48px;
  width: auto;
  max-width: 100%;
}

.menu-tagline {
  color: var(--text-dim);
  font-weight: 700;
  line-height: 1.3;
  margin-bottom: 20px;
  font-size: 0.92rem;
}

/* ── Game-over card specifics ─────────────────────────────────────────────────── */
#gameover-title {
  font-family: 'Sora', system-ui, sans-serif;
  font-size: 1.5rem;
  color: var(--text);
  margin-bottom: 10px;
  line-height: 1.2;
}

.gameover-sub {
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--text-dim);
  line-height: 1.4;
}

#final-score {
  font-size: 3rem;
  font-weight: 900;
  color: var(--accent);
  margin: 4px 0 20px;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  font-family: 'Sora', system-ui, sans-serif;
}

/* ── Buttons ─────────────────────────────────────────────────────────────────── */
/* Full-width modifier used on start + game-over cards */
.btn-full {
  display: block;
  width: 100%;
}

/* Primary: gradient fiolet→cyjan, thumb-friendly height ≥52px */
.primary-action {
  font-family: 'Sora', system-ui, sans-serif;
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: 0.04em;
  color: var(--text);
  background: linear-gradient(90deg, var(--accent) 0%, var(--accent-2) 100%);
  border: none;
  border-radius: 12px;
  min-height: 52px;
  padding: 14px 28px;
  cursor: pointer;
  transition: filter 0.15s ease, transform 0.1s ease;
  margin-bottom: 10px;
}

.primary-action:hover  { filter: brightness(1.12); }
.primary-action:active { transform: scale(0.97); }

/* Secondary: outline cyjan */
.secondary-action {
  font-family: 'Sora', system-ui, sans-serif;
  font-weight: 700;
  font-size: 0.92rem;
  color: var(--accent-2);
  background: rgba(34, 211, 238, 0.08);
  border: 1px solid rgba(34, 211, 238, 0.45);
  border-radius: 12px;
  min-height: 44px;
  padding: 10px 18px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}

.secondary-action:hover  { background: rgba(34, 211, 238, 0.16); }
.secondary-action:active { transform: scale(0.98); }

/* ── Featuring KOL row (start screen) ───────────────────────────────────────── */
.featuring-row {
  margin-top: 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.featuring-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--text-dim);
}

.kol-avatars {
  display: flex;
  align-items: center;
  /* Negative margin creates the stacked / overlapping look */
}

.kol-avatars canvas {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid var(--bg-panel);
  margin-left: -8px;
  box-shadow: 0 0 8px rgba(168, 85, 247, 0.4);
}

/* First avatar — no negative offset */
.kol-avatars canvas:first-child {
  margin-left: 0;
}

/* ── Responsive: small viewport height ─────────────────────────────────────── */
@media (max-height: 560px) {
  :root {
    --board-size: min(calc(100vw - 16px), calc(100dvh - 92px), 512px);
  }

  #game-container {
    gap: 4px;
    padding-top: max(4px, env(safe-area-inset-top));
  }

  #hud {
    padding: 8px 14px;
  }

  #time-value,
  #score-value {
    font-size: 1.2rem;
  }

  .menu-card {
    padding: 16px 18px;
  }

  .start-logo {
    height: 36px;
    margin-bottom: 10px;
  }

  .primary-action {
    min-height: 44px;
    padding: 10px 20px;
  }
}

/* ── Desktop ≥768px ──────────────────────────────────────────────────────────── */
@media (min-width: 768px) {
  :root {
    --board-size: min(560px, calc(100dvh - 140px));
  }
}

/* ── Canvas wrapper ──────────────────────────────────────────────────────────── */
/* Wrapper keeps canvas + overlay stacked perfectly */
#canvas-wrapper {
  position: relative;
  /* JavaScript sets explicit pixel size; CSS keeps it centered */
  display: inline-block;
  line-height: 0; /* remove phantom gap below canvas */
}

canvas#game-canvas {
  display: block;
  /* Display size scales with viewport but stays square (1:1).
     Internal resolution stays 512px (set in JS) for crisp rendering.
     PFPs are photos → smooth scaling (browser default), NOT pixelated. */
  width: var(--board-size);
  height: var(--board-size);
  touch-action: none; /* prevent touch gestures from scrolling during play */
}

/* ── Reaction overlay ────────────────────────────────────────────────────────── */
/* Overlay for reaction pop-ups — sits directly on top of canvas */
#reaction-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none; /* clicks pass through to canvas */
  overflow: hidden;
}

/* ── Combo badge (T6.x) ──────────────────────────────────────────────────────── */
#combo-badge {
  position: absolute;
  left: 50%;
  top: 10%;
  transform: translateX(-50%);
  z-index: 2;
  pointer-events: none;
  min-width: 138px;
  padding: 10px 18px;
  text-align: center;
  font-weight: 900;
  font-size: 1.35rem;
  line-height: 1;
  color: var(--bg-deep);
  background: var(--gold);
  border: 2px solid var(--gold-soft);
  border-radius: 8px;
  box-shadow: 0 0 24px rgba(251, 191, 36, 0.6), 0 6px 20px rgba(0, 0, 0, 0.35);
  text-transform: uppercase;
  font-variant-numeric: tabular-nums;
}

#combo-badge.hidden {
  display: none;
}

#combo-badge.combo-pop {
  animation: combo-pop 0.74s cubic-bezier(0.22, 1, 0.36, 1);
}

/* Escalating combo badge colors: default gold is overridden by tier classes */
#combo-badge.combo--accent {
  background: var(--accent);
  border-color: var(--accent-bright);
  box-shadow: 0 0 24px rgba(168, 85, 247, 0.6), 0 6px 20px rgba(0, 0, 0, 0.35);
  color: #fff;
}

#combo-badge.combo--accent-2 {
  background: var(--accent-2);
  border-color: #67e8f9;
  box-shadow: 0 0 24px rgba(34, 211, 238, 0.6), 0 6px 20px rgba(0, 0, 0, 0.35);
  color: var(--bg-deep);
}

#combo-badge.combo--gold {
  background: var(--gold);
  border-color: var(--gold-soft);
  box-shadow: 0 0 32px rgba(251, 191, 36, 0.8), 0 6px 20px rgba(0, 0, 0, 0.35);
  color: var(--bg-deep);
}

@keyframes combo-pop {
  0%   { transform: translateX(-50%) scale(0.65); opacity: 0; }
  18%  { transform: translateX(-50%) scale(1.12); opacity: 1; }
  70%  { transform: translateX(-50%) scale(1); opacity: 1; }
  100% { transform: translateX(-50%) scale(0.94); opacity: 0; }
}

/* ── Reaction cards (T6.x) ───────────────────────────────────────────────────── */
.reaction-card {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transform: translate(-50%, -50%) scale(var(--tier-scale, 1));
  transform-origin: center center;
  pointer-events: none;
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  filter: drop-shadow(0 4px 14px rgba(168, 85, 247, 0.55));
  will-change: transform, opacity;
}

.reaction-face {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  overflow: hidden;
  border: 3px solid var(--accent);
  background: rgba(13, 13, 26, 0.6);
  box-shadow: 0 0 18px rgba(168, 85, 247, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
}

.reaction-face canvas,
.reaction-face .reaction-real {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.reaction-label {
  font-weight: 900;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--text);
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.7), 0 0 12px rgba(168, 85, 247, 0.9);
}

.reaction-name {
  font-weight: 700;
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
  white-space: nowrap;
}

/* Tier-driven scale */
.reaction-card.tier-3 { --tier-scale: 0.85; }
.reaction-card.tier-4 { --tier-scale: 1.0; }
.reaction-card.tier-5 { --tier-scale: 1.2; }
.reaction-card.tier-6 { --tier-scale: 1.45; }
.reaction-card.tier-7 { --tier-scale: 1.8; }

/* Legendary (tier 7): gold + violet, stronger glow. */
.reaction-card.legendary .reaction-face {
  border-color: var(--gold);
  box-shadow: 0 0 26px rgba(251, 191, 36, 0.85), 0 0 40px rgba(168, 85, 247, 0.6);
}

.reaction-card.legendary .reaction-label {
  color: var(--gold);
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.7), 0 0 16px rgba(251, 191, 36, 0.95);
}

.reaction-card.legendary .reaction-name {
  color: var(--gold-soft);
  font-weight: 900;
  letter-spacing: 0.08em;
}

/* ── Screen shake (T6B) ──────────────────────────────────────────────────────── */
@keyframes ct-shake {
  0%   { transform: translate(0, 0); }
  15%  { transform: translate(-5px, 3px); }
  30%  { transform: translate(5px, -4px); }
  45%  { transform: translate(-5px, -3px); }
  60%  { transform: translate(4px, 4px); }
  75%  { transform: translate(-3px, 2px); }
  90%  { transform: translate(3px, -2px); }
  100% { transform: translate(0, 0); }
}

.shake {
  animation: ct-shake 0.42s ease-in-out;
  /* Promote to a compositor layer for the duration of the animation.
     Without this some GPUs (notably Windows Chrome) can leave a stale
     "ghost" copy of the board offset to the side after the keyframes. */
  will-change: transform;
  backface-visibility: hidden;
}

/* ── Objectives bar (Levels mode) ───────────────────────────────────────────── */
#objectives-bar {
  width: var(--board-size);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 8px 14px;
  background: rgba(34, 211, 238, 0.06);
  border: 1px solid rgba(34, 211, 238, 0.2);
  border-radius: 12px;
  flex-shrink: 0;
}

.obj-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  background: var(--bg-panel);
  border: 1px solid rgba(168, 85, 247, 0.3);
  border-radius: 8px;
  font-family: 'Sora', system-ui, sans-serif;
  font-size: 0.82rem;
  color: var(--text);
  transition: border-color 0.2s ease, opacity 0.2s ease;
}

.obj-chip.done {
  border-color: rgba(34, 211, 238, 0.7);
  opacity: 0.7;
  text-decoration: line-through;
  color: var(--text-dim);
}

.obj-chip--timer {
  border-color: rgba(250, 204, 21, 0.5);
  color: #fde68a;
}

.obj-chip--timer.danger {
  border-color: rgba(248, 113, 113, 0.8);
  color: var(--danger);
}

.obj-chip__icon {
  font-size: 1rem;
  line-height: 1;
}

.obj-chip__avatar {
  display: inline-flex;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  background: var(--kol-color, var(--bg-panel));
  box-shadow: 0 0 0 1.5px var(--kol-color, transparent);
}

.obj-chip__avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.obj-chip__progress {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.obj-chip__sep {
  color: var(--text-dim);
  font-weight: 400;
}

/* ── Stars row (Levels win overlay) ─────────────────────────────────────────── */
.stars-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 4px;
}

.star {
  font-size: 2.4rem;
  line-height: 1;
  color: var(--bg-cell);           /* empty = dark */
  transition: color 0.3s ease, transform 0.3s ease, text-shadow 0.3s ease;
  display: inline-block;
}

.star.lit {
  color: var(--gold);
  text-shadow: var(--glow-gold);
  transform: scale(1.18);
}

/* ── Level map overlay (C3) ─────────────────────────────────────────────────── */
#map-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: stretch;
  justify-content: center;
  background: rgba(11, 7, 20, 0.92);
  border-radius: 8px;
  opacity: 1;
  transition: opacity 0.2s ease;
  z-index: 10;
  overflow: hidden;
}

#map-overlay.hidden {
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  #map-overlay { transition: none; }
}

/* Map card: fills the overlay, scrollable inner area */
.map-card {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-height: 100%;
  padding: 0;
  border-radius: 8px;
  overflow: hidden;
}

/* Map header: title + close button */
.map-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 12px;
  flex-shrink: 0;
  border-bottom: 1px solid rgba(168, 85, 247, 0.2);
}

.map-title {
  font-family: 'Sora', system-ui, sans-serif;
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--text);
  letter-spacing: 0.05em;
}

.map-close-btn {
  background: transparent;
  border: 1px solid rgba(168, 85, 247, 0.3);
  color: var(--text-dim);
  font-size: 1rem;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s ease, border-color 0.15s ease;
  flex-shrink: 0;
}
.map-close-btn:hover {
  color: var(--text);
  border-color: rgba(168, 85, 247, 0.6);
}

/* Scrollable map area — fills remaining height */
.map-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 24px 0 32px;
  /* Custom scrollbar for style */
  scrollbar-width: thin;
  scrollbar-color: rgba(168, 85, 247, 0.4) transparent;
}
.map-scroll::-webkit-scrollbar { width: 4px; }
.map-scroll::-webkit-scrollbar-track { background: transparent; }
.map-scroll::-webkit-scrollbar-thumb {
  background: rgba(168, 85, 247, 0.4);
  border-radius: 2px;
}

/* Map path: flex column-reverse so level 1 is at the visual bottom */
.map-path {
  display: flex;
  flex-direction: column-reverse;
  align-items: center;
  position: relative;
  gap: 0;
  padding: 8px 0;
}

/* SVG connector lines — absolute, sits behind nodes */
.map-connector-svg {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
  overflow: visible;
}

.map-connector-line {
  fill: none;
  stroke: rgba(168, 85, 247, 0.3);
  stroke-width: 3;
  stroke-dasharray: 6 6;
  stroke-linecap: round;
}

/* Node wrapper: controls horizontal zigzag offset */
.map-node-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  margin: 20px 0;
  position: relative;
}

.map-node--right { margin-right: -60px; }
.map-node--left  { margin-left:  -60px; }

/* Base node button */
.map-node {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-family: 'Sora', system-ui, sans-serif;
  font-weight: 800;
  font-size: 1.05rem;
  color: var(--text);
  cursor: pointer;
  border: 3px solid rgba(168, 85, 247, 0.5);
  background: var(--bg-panel);
  transition: transform 0.15s ease, filter 0.15s ease;
  overflow: hidden;
  padding: 0;
}
.map-node:hover:not(:disabled) {
  transform: scale(1.08);
  filter: brightness(1.15);
}
.map-node:active:not(:disabled) {
  transform: scale(0.96);
}

/* Completed node — accent color */
.map-node--completed {
  border-color: var(--accent);
  background: rgba(168, 85, 247, 0.18);
  color: var(--accent);
  box-shadow: 0 0 12px rgba(168, 85, 247, 0.35);
}

/* Current node — glow + pulse animation */
.map-node--current {
  border-color: var(--accent-bright);
  background: rgba(168, 85, 247, 0.25);
  color: var(--text);
  box-shadow: var(--glow-accent), 0 0 0 4px rgba(168, 85, 247, 0.15);
  animation: map-node-pulse 2s ease-in-out infinite;
}

@keyframes map-node-pulse {
  0%, 100% { box-shadow: var(--glow-accent), 0 0 0 4px rgba(168, 85, 247, 0.15); }
  50%       { box-shadow: 0 0 32px rgba(168, 85, 247, 0.75), 0 0 0 8px rgba(168, 85, 247, 0.1); }
}

@media (prefers-reduced-motion: reduce) {
  .map-node--current { animation: none; }
}

/* Locked node — muted, not clickable */
.map-node--locked {
  border-color: rgba(167, 156, 200, 0.2);
  background: rgba(37, 26, 64, 0.5);
  color: var(--text-dim);
  cursor: default;
  opacity: 0.55;
}
.map-node--locked:disabled { pointer-events: none; }

/* Milestone node — slightly larger, bolder border */
.map-node--milestone {
  border-width: 4px;
  border-color: var(--gold);
  box-shadow: 0 0 16px rgba(251, 191, 36, 0.3);
}
.map-node--milestone.map-node--locked {
  border-color: rgba(251, 191, 36, 0.2);
  box-shadow: none;
}
.map-node--milestone.map-node--current {
  box-shadow: var(--glow-gold), 0 0 0 5px rgba(251, 191, 36, 0.12);
  animation: map-milestone-pulse 2s ease-in-out infinite;
}

@keyframes map-milestone-pulse {
  0%, 100% { box-shadow: var(--glow-gold), 0 0 0 5px rgba(251, 191, 36, 0.12); }
  50%       { box-shadow: 0 0 40px rgba(251, 191, 36, 0.8), 0 0 0 10px rgba(251, 191, 36, 0.08); }
}

@media (prefers-reduced-motion: reduce) {
  .map-node--milestone.map-node--current { animation: none; }
}

/* Avatar canvas inside milestone node */
.map-node__avatar {
  width: 100%;
  height: 100%;
  display: block;
}

/* Stars below completed node */
.map-node__stars {
  display: flex;
  gap: 1px;
  justify-content: center;
}

.map-node__star {
  font-size: 0.72rem;
  line-height: 1;
  color: var(--bg-cell);
}

.map-node__star--lit {
  color: var(--gold);
  text-shadow: 0 0 6px rgba(251, 191, 36, 0.7);
}

/* Map button on win/lose overlay */
.btn-map {
  font-family: 'Sora', system-ui, sans-serif;
  font-weight: 700;
  font-size: 0.92rem;
  color: var(--accent-2);
  background: rgba(34, 211, 238, 0.08);
  border: 1px solid rgba(34, 211, 238, 0.45);
  border-radius: 12px;
  min-height: 44px;
  padding: 10px 18px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
  width: 100%;
  display: block;
}
.btn-map:hover  { background: rgba(34, 211, 238, 0.16); }
.btn-map:active { transform: scale(0.98); }

/* ── Share-card preview modal ──────────────────────────────────────────────── */
.share-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.share-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
}

.share-modal__card {
  position: relative;
  z-index: 1;
  width: min(92vw, 440px);
  max-height: 90vh;
  overflow-y: auto;
  background: var(--bg-panel, #171226);
  border: 1px solid rgba(168, 85, 247, 0.35);
  border-radius: 18px;
  padding: 20px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.5);
  font-family: 'Sora', system-ui, sans-serif;
  text-align: center;
}

.share-modal__close {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: var(--text-dim, #99a);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  border-radius: 8px;
}

.share-modal__close:hover {
  color: var(--text, #fff);
  background: rgba(255, 255, 255, 0.06);
}

.share-modal__title {
  margin: 0 0 14px;
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--text, #fff);
}

.share-modal__preview {
  width: min(80vw, 340px);
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  display: block;
  margin: 0 auto 12px;
}

.share-modal__help {
  margin: 0 0 16px;
  font-size: 0.8rem;
  color: var(--text-dim, #99a);
}

.share-modal__actions {
  display: flex;
  gap: 10px;
}

.share-modal__btn {
  flex: 1;
  padding: 12px 14px;
  border-radius: 12px;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s ease, filter 0.15s ease;
}

.share-modal__btn:active {
  transform: scale(0.97);
}

.share-modal__btn--secondary {
  background: transparent;
  color: var(--text, #fff);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.share-modal__btn--secondary:hover {
  background: rgba(255, 255, 255, 0.06);
}

.share-modal__btn--primary {
  background: linear-gradient(135deg, #a855f7, #22d3ee);
  color: #fff;
  border: none;
}

.share-modal__btn--primary:hover {
  filter: brightness(1.08);
}

/* ── Utility ─────────────────────────────────────────────────────────────────── */
.hidden {
  display: none !important;
}
