/* Jigsaw Puzzle Adventure — kid-first, bright, rounded. */

:root {
  --purple: #7C5CFC;
  --purple-deep: #5B3DF5;
  --sun: #FFC94D;
  --sun-deep: #FF9A3D;
  --leaf: #3ECF8E;
  --leaf-deep: #1FA870;
  --ink: #2C2450;
  --ink-soft: #5A527E;
  --paper: #FFFFFF;
  --bg-top: #EFEAFF;
  --bg-bottom: #DFF4FF;
  --shadow: 0 10px 24px rgba(44, 36, 80, 0.16);
  --radius: 22px;
  --hud-h: 56px;
  --content-pad: max(16px, calc((100% - 1120px) / 2));
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  overflow: hidden;
  font-family: 'Segoe UI', 'Comic Sans MS', system-ui, sans-serif;
  color: var(--ink);
  background: linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
}

button { font: inherit; color: inherit; cursor: pointer; border: none; background: none; }
button:focus-visible { outline: 3px solid var(--purple); outline-offset: 2px; }

.skip-link {
  position: absolute; top: -100px; left: 16px; z-index: 9999;
  background: var(--sun); color: var(--ink); padding: 12px 20px;
  border-radius: 0 0 12px 12px; font-weight: 700; text-decoration: none;
  transition: top 200ms;
}
.skip-link:focus { top: 0; }

#app { height: 100dvh; display: flex; flex-direction: column; }

.screen { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.screen[hidden] { display: none; }

/* ── Buttons ─────────────────────────────────────────────────────────── */

.big-btn {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  width: 100%; max-width: 340px;
  padding: 16px 24px;
  border-radius: var(--radius);
  font-size: 1.25rem; font-weight: 800; color: #fff;
  box-shadow: var(--shadow);
  transition: transform 120ms ease, box-shadow 120ms ease;
}
.big-btn:active { transform: scale(0.97); }
.big-btn__icon { font-size: 1.5rem; }
.big-btn--primary { background: linear-gradient(135deg, var(--purple), var(--purple-deep)); }
.big-btn--sun     { background: linear-gradient(135deg, var(--sun), var(--sun-deep)); color: #5C3A00; }
.big-btn--leaf    { background: linear-gradient(135deg, var(--leaf), var(--leaf-deep)); }
.big-btn--ghost   { background: #fff; color: var(--ink); border: 2px solid #D9D2F5; box-shadow: none; }

.icon-btn {
  position: relative;
  width: 44px; height: 44px; flex: 0 0 auto;
  display: grid; place-items: center;
  border-radius: 14px; font-size: 1.25rem;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 3px 8px rgba(44, 36, 80, 0.12);
  transition: transform 120ms ease, background 120ms;
}
.icon-btn:active { transform: scale(0.92); }
.icon-btn[aria-pressed="true"] { background: var(--sun); }
.icon-btn .badge {
  position: absolute; top: -6px; right: -6px;
  min-width: 20px; height: 20px; padding: 0 5px;
  border-radius: 10px; background: #3B82F6; color: #fff;
  font-size: 0.72rem; font-weight: 800; line-height: 20px;
}
.icon-btn .badge:empty { display: none; }

/* ── HOME ────────────────────────────────────────────────────────────── */

.screen--home {
  align-items: center; justify-content: center;
  gap: 28px; padding: 24px var(--content-pad);
  text-align: center;
}
.home-hero h1 {
  font-size: clamp(1.8rem, 5vw, 2.6rem);
  line-height: 1.1; letter-spacing: -0.5px;
}
.home-hero h1 span {
  display: block;
  background: linear-gradient(90deg, var(--purple-deep), var(--sun-deep));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.home-logo { animation: bob 3.2s ease-in-out infinite; }
.home-tag { margin-top: 8px; color: var(--ink-soft); font-size: 1.05rem; }
.home-actions { display: flex; flex-direction: column; align-items: center; gap: 14px; width: 100%; }
.home-stats { display: flex; gap: 18px; color: var(--ink-soft); font-weight: 700; }
.home-stats span b { color: var(--ink); }

@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-10px); } }
@media (prefers-reduced-motion: reduce) { .home-logo { animation: none; } }

/* ── Top bar (gallery/setup) ─────────────────────────────────────────── */

.top-bar {
  display: flex; align-items: center; gap: 12px;
  padding: 12px var(--content-pad);
}
.top-bar h2 { font-size: 1.3rem; }
.top-bar__spacer { flex: 1; }

/* ── GALLERY ─────────────────────────────────────────────────────────── */

.cat-chips {
  display: flex; flex-wrap: wrap; align-content: flex-start; gap: 10px;
  max-width: 100%;
  padding: 4px var(--content-pad) 14px;
  overflow: visible; flex: 0 0 auto;
}
.cat-chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 1 auto;
  max-width: 100%;
  white-space: nowrap;
  padding: 9px 16px; border-radius: 999px;
  background: #fff; font-weight: 700; font-size: 0.95rem;
  box-shadow: 0 2px 6px rgba(44, 36, 80, 0.10);
  border: 2px solid transparent;
}
.chip[aria-selected="true"] {
  background: var(--purple); color: #fff; border-color: var(--purple-deep);
}

.img-grid {
  flex: 1; overflow-y: auto;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  grid-auto-rows: min-content;
  gap: 14px; padding: 4px var(--content-pad) 24px;
}
.img-card {
  border-radius: 18px; overflow: hidden; background: #fff;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  transition: transform 140ms ease;
  padding: 0;
}
.img-card:hover { transform: translateY(-3px) scale(1.02); }
.img-card img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; }
.img-card figcaption {
  padding: 8px 10px; font-weight: 700; font-size: 0.92rem; text-align: left;
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
}
.img-card .done { color: var(--sun-deep); font-size: 0.85rem; }

/* ── SETUP ───────────────────────────────────────────────────────────── */

.setup-body {
  flex: 1; overflow-y: auto;
  display: flex; flex-wrap: wrap; gap: 24px;
  padding: 8px var(--content-pad) 28px; justify-content: center; align-content: flex-start;
}
.setup-preview { text-align: center; }
.setup-preview img {
  width: min(260px, 70vw); aspect-ratio: 1; object-fit: cover;
  border-radius: 20px; box-shadow: var(--shadow); background: #fff;
}
.setup-preview p { margin-top: 10px; font-weight: 800; font-size: 1.05rem; }
.setup-controls { min-width: min(340px, 90vw); max-width: 420px; }
.setup-controls h3 { margin: 14px 0 8px; font-size: 1rem; color: var(--ink-soft); }
.pill-row { display: flex; flex-wrap: wrap; gap: 8px; }
.pill {
  padding: 10px 16px; border-radius: 14px; min-width: 56px;
  background: #fff; font-weight: 800; font-size: 1rem;
  box-shadow: 0 2px 6px rgba(44, 36, 80, 0.10);
  border: 2px solid transparent;
}
.pill[aria-checked="true"] { background: var(--purple); color: #fff; }
.pill--mode { display: flex; flex-direction: column; align-items: flex-start; min-width: 100%; text-align: left; }
.pill--mode small { font-weight: 600; opacity: 0.75; }
.big-btn--start { margin-top: 22px; }

/* ── PLAY ────────────────────────────────────────────────────────────── */

.screen--play { position: relative; }
.hud {
  height: var(--hud-h); flex: 0 0 auto;
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px;
  background: rgba(255, 255, 255, 0.75);
  backdrop-filter: blur(8px);
  box-shadow: 0 2px 12px rgba(44, 36, 80, 0.10);
  z-index: 5;
}
.hud-stat {
  display: flex; align-items: center; gap: 5px;
  font-size: 0.95rem; font-weight: 700; color: var(--ink-soft);
  padding: 6px 10px; border-radius: 12px; background: rgba(255,255,255,0.9);
}
.hud-stat b { color: var(--ink); font-variant-numeric: tabular-nums; }

.stage {
  position: relative; flex: 1; min-height: 0;
  overflow: hidden;
  touch-action: none; /* we handle all gestures */
  background:
    radial-gradient(1200px 500px at 50% -10%, rgba(255, 255, 255, 0.5), transparent),
    linear-gradient(180deg, #8a5a37, #6e4527);
}
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
#canvas-fx { pointer-events: none; }
#canvas-float { cursor: grab; }
#canvas-float.dragging { cursor: grabbing; }

.sr-status {
  position: absolute; width: 1px; height: 1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

/* ── WIN ─────────────────────────────────────────────────────────────── */

.screen--win { align-items: center; justify-content: center; padding: 20px; }
.win-card {
  width: min(440px, 94vw);
  background: #fff; border-radius: 28px; box-shadow: var(--shadow);
  padding: 26px 24px 28px; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  animation: pop-in 380ms cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes pop-in { from { transform: scale(0.7); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .win-card { animation: none; } }
.win-stars { font-size: 2.2rem; letter-spacing: 6px; min-height: 1.2em; }
.win-stars .dim { opacity: 0.25; }
.win-card h2 { font-size: 1.6rem; }
.win-image {
  width: min(240px, 60vw); aspect-ratio: 1; object-fit: cover;
  border-radius: 18px; box-shadow: var(--shadow);
}
.win-meta { color: var(--ink-soft); font-weight: 700; }
.win-actions { display: flex; flex-direction: column; gap: 10px; width: 100%; align-items: center; }

/* ── Compact HUD on narrow screens ───────────────────────────────────── */
@media (max-width: 560px) {
  .hud { gap: 4px; padding: 6px 6px; }
  .icon-btn { width: 38px; height: 38px; font-size: 1.05rem; border-radius: 12px; }
  .hud-stat { font-size: 0.8rem; padding: 5px 7px; gap: 3px; }
  .icon-btn .badge { min-width: 17px; height: 17px; line-height: 17px; font-size: 0.66rem; }
}
@media (max-width: 420px) {
  .hud { gap: 3px; padding: 5px 4px; }
  .icon-btn { width: 35px; height: 35px; font-size: 1rem; }
  .hud-stat { font-size: 0.74rem; padding: 4px 5px; }
}

/* ── Toast ───────────────────────────────────────────────────────────── */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px);
  background: var(--ink); color: #fff;
  padding: 12px 22px; border-radius: 16px;
  font-weight: 700; box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; z-index: 999;
  transition: opacity 220ms, transform 220ms;
  max-width: 90vw; text-align: center;
}
.toast--show { opacity: 1; transform: translate(-50%, 0); }

/* ── High contrast ───────────────────────────────────────────────────── */
@media (prefers-contrast: more) {
  :root { --ink: #14102b; --ink-soft: #3a3363; }
  .icon-btn, .chip, .pill { border: 2px solid var(--ink); }
}
