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

:root {
  --bg:        #1a1a2e;
  --surface:   #16213e;
  --surface2:  #0f3460;
  --accent:    #e94560;
  --accent2:   #f5a623;
  --text:      #eaeaea;
  --muted:     #888;
  --radius:    14px;
  --pal-h:     110px;
  --hint-h:    32px;
  --hdr-h:     56px;
}

html, body {
  height: 100%;
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  touch-action: none;
}

/* ── Screens ──────────────────────────────────────────────── */
.screen {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  background: var(--bg);
}
.screen.active { display: flex; }

/* ── MENU SCREEN ─────────────────────────────────────────── */
#screen-menu {
  overflow-y: auto;
  padding-bottom: 24px;
  align-items: center;
}

.menu-header {
  text-align: center;
  padding: 48px 24px 28px;
}
.menu-hearts {
  font-size: 52px;
  animation: heartbeat 1.6s ease-in-out infinite;
}
@keyframes heartbeat {
  0%,100% { transform: scale(1); }
  14%      { transform: scale(1.18); }
  28%      { transform: scale(1); }
  42%      { transform: scale(1.12); }
}
.menu-header h1 {
  font-size: clamp(1.6rem, 6vw, 2.4rem);
  font-weight: 800;
  background: linear-gradient(135deg, #f857a6, #ff5858, #f5a623);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin: 12px 0 8px;
}
.menu-subtitle {
  color: var(--muted);
  font-size: 1rem;
}

.puzzle-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  justify-content: center;
  padding: 0 20px;
  width: 100%;
  max-width: 540px;
}

.puzzle-card {
  background: #1e2a4a;
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  width: calc(50% - 9px);
  max-width: 200px;
  box-shadow: 0 4px 20px rgba(0,0,0,.5);
  border: 2px solid rgba(255,255,255,.1);
  transition: transform .18s, border-color .18s, box-shadow .18s;
  user-select: none;
}
.puzzle-card:hover, .puzzle-card:active {
  transform: scale(1.04);
  border-color: var(--accent);
  box-shadow: 0 6px 28px rgba(233,69,96,.35);
}
.puzzle-card-thumb {
  width: 100%;
  aspect-ratio: 1;
  background: #0f2850;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3rem;
  overflow: hidden;
}
.puzzle-card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.puzzle-card-label {
  padding: 10px 12px;
  font-weight: 600;
  font-size: .95rem;
  text-align: center;
}
.puzzle-card-sub {
  padding: 0 12px 10px;
  font-size: .78rem;
  color: var(--muted);
  text-align: center;
}

.menu-footer {
  margin-top: 32px;
  color: var(--muted);
  font-size: .85rem;
}

/* ── LOADING SCREEN ─────────────────────────────────────── */
#screen-loading {
  align-items: center;
  justify-content: center;
}
.loading-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 40px;
  text-align: center;
}
.loading-spinner {
  width: 56px;
  height: 56px;
  border: 5px solid var(--surface2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-bar-track {
  width: 200px;
  height: 8px;
  background: var(--surface2);
  border-radius: 99px;
  overflow: hidden;
}
#loading-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  border-radius: 99px;
  transition: width .3s ease;
}

/* ── GAME SCREEN ─────────────────────────────────────────── */
#screen-game {
  overflow: hidden;
}

#game-header {
  height: var(--hdr-h);
  display: flex;
  align-items: center;
  padding: 0 12px;
  background: var(--surface);
  gap: 10px;
  flex-shrink: 0;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.hdr-btn {
  background: var(--surface2);
  border: none;
  color: var(--text);
  font-size: 1.3rem;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
#puzzle-title-display {
  flex: 1;
  font-weight: 700;
  font-size: 1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#progress-display {
  font-size: .9rem;
  font-weight: 700;
  color: var(--accent2);
  flex-shrink: 0;
}

#canvas-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #111;
  position: relative;
}
#game-canvas {
  display: block;
  cursor: crosshair;
  touch-action: none;
}

/* ── PALETTE ──────────────────────────────────────────────── */
#palette-wrap {
  height: var(--pal-h);
  background: var(--surface);
  border-top: 1px solid rgba(255,255,255,.06);
  flex-shrink: 0;
  overflow: hidden;
}
#palette-scroll {
  height: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
#palette-scroll::-webkit-scrollbar { display: none; }
#palette {
  display: flex;
  align-items: center;
  height: 100%;
  gap: 10px;
  padding: 0 16px;
  min-width: max-content;
}

.pal-swatch {
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  gap: 5px;
  flex-shrink: 0;
  transition: transform .15s;
  user-select: none;
}
.pal-swatch:active { transform: scale(.92); }

.pal-circle {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 3px solid transparent;
  transition: border-color .15s, transform .15s, box-shadow .15s;
  position: relative;
}
.pal-num {
  font-size: .78rem;
  font-weight: 700;
  color: var(--muted);
  transition: color .15s;
}
.pal-count {
  font-size: .68rem;
  color: var(--muted);
  margin-top: -3px;
}

.pal-swatch.selected .pal-circle {
  border-color: #fff;
  transform: scale(1.18);
  box-shadow: 0 0 0 3px rgba(255,255,255,.25), 0 4px 16px rgba(0,0,0,.4);
}
.pal-swatch.selected .pal-num { color: #fff; }
.pal-swatch.removing {
  overflow: hidden;
  animation: swatch-collapse .35s ease forwards;
}
@keyframes swatch-collapse {
  0%   { opacity: 1; max-width: 80px; margin-right: 0; padding: 0 4px; }
  60%  { opacity: 0; max-width: 80px; }
  100% { opacity: 0; max-width: 0;    margin-right: -10px; padding: 0; }
}

/* ── HINT BAR ────────────────────────────────────────────── */
#hint-bar {
  height: var(--hint-h);
  background: var(--surface);
  border-top: 1px solid rgba(255,255,255,.06);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 16px;
  min-height: 0;
}
#hint-text {
  font-size: .85rem;
  color: var(--accent2);
  font-weight: 500;
  text-align: center;
}

/* ── CELEBRATION SCREEN ───────────────────────────────────── */
#screen-celebration {
  align-items: center;
  justify-content: center;
  position: relative;
}
#confetti-canvas {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
#celebration-box {
  position: relative;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 28px 20px;
  max-width: 420px;
  width: 100%;
  max-height: 100vh;
  overflow-y: auto;
}
#celebration-title {
  text-align: center;
}
#celebration-title h2 {
  font-size: 2rem;
  font-weight: 800;
  background: linear-gradient(135deg, #f857a6, #ff5858, #f5a623);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
#celebration-title p {
  color: var(--muted);
  margin-top: 4px;
}
.cel-stars {
  font-size: 1.4rem;
  margin-bottom: 6px;
  animation: spin 4s linear infinite;
}
#celebration-art-wrap {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 8px 40px rgba(0,0,0,.5);
  max-width: 100%;
  flex-shrink: 0;
}
#celebration-art {
  display: block;
  max-width: 100%;
}
#celebration-video {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
  opacity: 0;
  transition: opacity 0.9s ease;
}
#celebration-video.reveal {
  opacity: 1;
}
#celebration-btns {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}
.cel-btn {
  padding: 14px;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  width: 100%;
  transition: opacity .15s, transform .15s;
}
.cel-btn:active { transform: scale(.97); }
.cel-btn.primary {
  background: linear-gradient(135deg, #f857a6, #ff5858);
  color: #fff;
}
.cel-btn:not(.primary) {
  background: var(--surface2);
  color: var(--text);
}

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

/* ── Debug button ────────────────────────────────────────── */
.debug-btn {
  font-size: .85rem;
  background: rgba(255, 140, 0, 0.25);
  color: #f5a623;
  border: 1px solid rgba(255,140,0,.35);
}


@keyframes pulse-ring {
  0%   { box-shadow: 0 0 0 0 rgba(245,166,35,.5); }
  70%  { box-shadow: 0 0 0 10px rgba(245,166,35,0); }
  100% { box-shadow: 0 0 0 0 rgba(245,166,35,0); }
}
