/* Puzzle game module - self-contained styles for #puzzleGameRoot.
   All custom properties and classes are scoped/prefixed with "pz-" so this
   file never collides with the host page's own styles. Palette matches the
   app's watercolor blush/dusty-blue theme (see style.css --blush/--accent/--gold). */

#puzzleGameRoot {
  --pz-ice: #eef4f8;
  --pz-ice2: #d6e4ef;
  --pz-accent: #b8cfe0;
  --pz-accent-deep: #6f8caa;
  --pz-blush: #f6dade;
  --pz-blush-deep: #eebfc9;
  --pz-blush-deeper: #dd9aab;
  --pz-ink: #2e3547;
  --pz-muted: #7a8296;
  --pz-card: #fffdfa;
  --pz-gold: #d9b98a;
  --pz-serif: Georgia, "Times New Roman", "Palatino Linotype", serif;
  --pz-shadow: 0 14px 34px rgba(110, 90, 100, 0.18);
  --pz-radius: 20px;

  position: fixed;
  inset: 0;
  z-index: 999999;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-y: auto;
  padding: 24px 16px 40px;
  box-sizing: border-box;
  background: linear-gradient(180deg, var(--pz-ice) 0%, var(--pz-ice2) 100%);
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", sans-serif;
  color: var(--pz-ink);
}

#puzzleGameRoot * { box-sizing: border-box; }

#puzzleGameRoot button {
  font-family: inherit;
}

/* ---------- generic buttons ---------- */
.pz-btn {
  border: none;
  border-radius: 999px;
  padding: 11px 22px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.12s ease, box-shadow 0.12s ease, opacity 0.12s ease;
}
.pz-btn:active { transform: scale(0.96); }
.pz-btn:disabled { opacity: 0.6; cursor: default; transform: none; }

.pz-btn-primary {
  background: linear-gradient(135deg, var(--pz-accent) 0%, var(--pz-accent-deep) 100%);
  color: #fff;
  box-shadow: 0 8px 18px rgba(111, 140, 170, 0.35);
}
.pz-btn-secondary {
  background: linear-gradient(135deg, var(--pz-blush-deep) 0%, var(--pz-blush-deeper) 100%);
  color: #fff;
  box-shadow: 0 8px 18px rgba(221, 154, 171, 0.4);
}
.pz-btn-ghost {
  background: var(--pz-card);
  color: var(--pz-accent-deep);
  border: 1.5px solid var(--pz-ice2);
}

/* ---------- gate card ---------- */
.pz-card {
  background: var(--pz-card);
  border-radius: 24px;
  box-shadow: var(--pz-shadow);
  border: 1px solid rgba(217, 185, 138, 0.35);
  padding: 32px 28px;
  width: 100%;
  max-width: 380px;
  margin: auto 0;
  text-align: center;
}
.pz-gate-icon { font-size: 2.6rem; line-height: 1; margin-bottom: 6px; }
.pz-title { margin: 4px 0 2px; font-size: 1.55rem; color: var(--pz-accent-deep); font-family: var(--pz-serif); }
.pz-sub { margin: 0 0 16px; color: var(--pz-muted); font-style: italic; }

.pz-form { display: flex; flex-direction: column; gap: 10px; }
.pz-input {
  width: 100%;
  padding: 13px 14px;
  border-radius: 999px;
  border: 1.5px solid var(--pz-ice2);
  font-size: 1rem;
  outline: none;
  background: var(--pz-ice);
  transition: border-color 0.15s;
}
.pz-input:focus { border-color: var(--pz-accent-deep); }

.pz-error {
  color: #a3495a;
  background: #fbe9ea;
  border: 1px solid rgba(163,73,90,0.18);
  border-radius: 14px;
  padding: 8px 10px;
  font-size: 0.88rem;
}

.pz-btn-row { display: flex; gap: 10px; justify-content: space-between; margin-top: 4px; }
.pz-btn-row .pz-btn { flex: 1; }

/* ---------- header bar (picker + game screens) ---------- */
.pz-screen {
  width: 100%;
  max-width: 720px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}
.pz-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: rgba(255, 253, 250, 0.75);
  border-radius: 18px;
  padding: 10px 16px;
  box-shadow: var(--pz-shadow);
}
.pz-header-title {
  font-weight: 700;
  color: var(--pz-accent-deep);
  font-family: var(--pz-serif);
  font-size: 1.1rem;
  white-space: nowrap;
}
.pz-header-spacer { width: 1px; }
.pz-back-btn { white-space: nowrap; }

.pz-body {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

/* ---------- picker ---------- */
.pz-loading, .pz-empty {
  background: var(--pz-card);
  border-radius: var(--pz-radius);
  box-shadow: var(--pz-shadow);
  padding: 22px;
  text-align: center;
  color: var(--pz-muted);
  width: 100%;
  max-width: 460px;
  font-style: italic;
}

.pz-grid {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 12px;
}
.pz-thumb {
  position: relative;
  border: none;
  background: var(--pz-card);
  border-radius: 16px;
  padding: 0;
  overflow: hidden;
  box-shadow: var(--pz-shadow);
  cursor: pointer;
  aspect-ratio: 1 / 1;
  display: block;
}
.pz-thumb:active { transform: scale(0.97); }
.pz-thumb-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.pz-thumb-caption {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  background: linear-gradient(0deg, rgba(46,53,71,0.75), rgba(46,53,71,0));
  color: #fff;
  font-size: 0.75rem;
  padding: 10px 8px 6px;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pz-thumb-broken { display: flex; align-items: center; justify-content: center; }
.pz-thumb-fallback { color: var(--pz-muted); font-size: 0.8rem; padding: 8px; }

/* ---------- jigsaw board + tray ---------- */
.pz-stage {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}
.pz-board-wrap {
  width: min(92vw, 460px);
  display: flex;
  justify-content: center;
}
.pz-board {
  position: relative;
  width: min(92vw, 460px);
  background: var(--pz-card);
  border-radius: 14px;
  box-shadow: var(--pz-shadow);
  border: 3px solid var(--pz-card);
  outline: 2px dashed var(--pz-ice2);
  outline-offset: -2px;
}
.pz-slot {
  position: absolute;
  border: 1px dashed rgba(111, 140, 170, 0.4);
  background: rgba(184, 207, 224, 0.08);
  box-sizing: border-box;
}
.pz-tray-label {
  margin: 0;
  color: var(--pz-muted);
  font-size: 0.9rem;
}
.pz-tray {
  width: min(92vw, 460px);
  min-height: 90px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  align-content: flex-start;
  background: rgba(255, 253, 250, 0.55);
  border-radius: 16px;
  border: 2px dashed var(--pz-ice2);
  padding: 10px;
}
.pz-piece {
  background-repeat: no-repeat;
  border-radius: 4px;
  border: 1px solid rgba(255, 253, 250, 0.9);
  box-shadow: 0 3px 8px rgba(110, 90, 100, 0.28);
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.pz-piece.pz-dragging {
  cursor: grabbing;
  box-shadow: 0 10px 24px rgba(110, 90, 100, 0.45);
  opacity: 0.95;
}
.pz-piece.pz-locked {
  cursor: default;
  border: none;
  box-shadow: none;
  animation: pz-pop 0.25s ease;
}
@keyframes pz-pop {
  0% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

/* ---------- celebration ---------- */
.pz-celebrate {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: rgba(238, 244, 248, 0.88);
  border-radius: 14px;
  overflow: hidden;
  animation: pz-fade-in 0.3s ease;
  z-index: 10;
}
@keyframes pz-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
.pz-celebrate-text {
  font-size: 1.85rem;
  font-weight: 800;
  color: var(--pz-accent-deep);
  font-family: var(--pz-serif);
  text-shadow: 0 2px 10px rgba(238, 191, 201, 0.55);
}
.pz-confetti-piece {
  position: absolute;
  top: -10%;
  pointer-events: none;
  animation-name: pz-fall;
  animation-timing-function: ease-in;
  animation-fill-mode: forwards;
}
@keyframes pz-fall {
  0% { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(420px) rotate(200deg); opacity: 0; }
}

/* ---------- responsive ---------- */
@media (max-width: 480px) {
  #puzzleGameRoot { padding: 14px 10px 28px; }
  .pz-card { padding: 24px 18px; }
  .pz-header-title { font-size: 1rem; }
  .pz-grid { grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); }
}
