/* Puzzle Canvas — Puzzle Cards web player (staging prototype).
   Tokens mirror the Puzzle Canvas design system (see design handoff README). */

:root {
  --pc-gold: #b68b4b;
  --pc-gold-ink: #fffaf1;
  --pc-gold-deep: #8b6b32;
  --pc-gold-wash: rgba(206, 125, 47, 0.14);
  --pc-screen: #f6f5f2;
  --pc-card: #ffffff;
  --pc-text: #000000;
  --pc-text-secondary: #333333;
  --pc-text-muted: #6b6b6b;
  --pc-divider: #c6c6c8;
  --pc-marketing-bg: #f7efe2;
  --pc-marketing-panel: #e9dbc6;
  --pc-marketing-ink: #090909;
  --pc-marketing-body: #4a463f;
  --pc-marketing-legal: #6b6258;
  --pc-puzzle-screen: #dedad4;
  --pc-board-shell: #eeebe5;
  --pc-board-border: rgba(180, 175, 168, 0.4);
  --pc-glass-fill: rgba(220, 220, 220, 0.5);
  --pc-ease: cubic-bezier(0.22, 0.61, 0.36, 1);
  --pc-font-sans: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
/* Author display values (flex etc.) must never defeat the hidden attribute. */
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--pc-font-sans);
  -webkit-font-smoothing: antialiased;
  color: var(--pc-text);
  background: var(--pc-marketing-bg);
  overscroll-behavior: none;
}

@keyframes pcspin { to { transform: rotate(360deg); } }
@keyframes pcpop {
  0% { transform: scale(0.7); opacity: 0; }
  60% { transform: scale(1.06); }
  100% { transform: scale(1); opacity: 1; }
}
@keyframes pcslideup {
  0% { transform: translateY(18px); opacity: 0; }
  100% { transform: translateY(0); opacity: 1; }
}
@keyframes pcfall {
  0% { transform: translateY(-40px) rotate(0); opacity: 0; }
  12% { opacity: 1; }
  100% { transform: translateY(105vh) rotate(320deg); opacity: 0; }
}

.view {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: max(18px, env(safe-area-inset-top)) 28px max(24px, env(safe-area-inset-bottom));
}
.view[hidden] { display: none; }

.spinner {
  width: 22px;
  height: 22px;
  border: 2.5px solid var(--pc-gold);
  border-top-color: transparent;
  border-radius: 999px;
  animation: pcspin 0.8s linear infinite;
  display: inline-block;
}
.spinner-lg { width: 32px; height: 32px; border-width: 3px; }
.view-loading { justify-content: center; background: var(--pc-marketing-bg); }

.lockup { display: flex; align-items: center; gap: 8px; }
.lockup-left { align-self: flex-start; margin-bottom: 12px; }
.lockup-icon { width: 28px; height: 28px; border-radius: 8px; }
.lockup-name {
  font-size: 11.5px;
  font-weight: 800;
  color: var(--pc-marketing-legal);
  letter-spacing: 1.3px;
  text-transform: uppercase;
}
.lockup-name-small {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--pc-marketing-legal);
  letter-spacing: 0.3px;
}

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  max-width: 420px;
  height: 54px;
  border: none;
  border-radius: 999px;
  font-family: var(--pc-font-sans);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.12s var(--pc-ease);
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--pc-gold); color: var(--pc-gold-ink); }
.btn-secondary { background: var(--pc-gold-wash); color: var(--pc-gold-deep); }
.btn-icon { width: 18px; height: 18px; border-radius: 5px; }

/* ---------- Cover ---------- */
.cover-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
}
.sealed-card {
  position: relative;
  width: min(216px, 60vw);
  aspect-ratio: 216 / 262;
  border-radius: 20px;
  background: #e7dac4;
  box-shadow:
    0 20px 44px -18px rgba(60, 45, 20, 0.55),
    inset 0 0 0 1px rgba(120, 95, 55, 0.2);
  padding: 11px;
  animation: pcpop 0.5s var(--pc-ease);
}
.sealed-grid {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(5, 1fr);
  gap: 6px;
  border-radius: 12px;
  overflow: hidden;
}
.sealed-tile {
  border-radius: 4px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.45),
    inset 0 0 0 1px rgba(120, 95, 55, 0.14);
}
.sealed-glaze {
  position: absolute;
  inset: 11px;
  border-radius: 12px;
  background: linear-gradient(155deg, rgba(255, 251, 244, 0.22), rgba(120, 90, 50, 0.16));
  pointer-events: none;
}
.wax-seal {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 86px;
  height: 86px;
  border-radius: 999px;
  background: var(--pc-gold);
  box-shadow:
    0 8px 18px -4px rgba(120, 90, 40, 0.65),
    inset 0 0 0 3px rgba(255, 250, 241, 0.4);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.wax-initials {
  font-size: 30px;
  font-weight: 900;
  color: var(--pc-gold-ink);
  letter-spacing: -0.5px;
  line-height: 1;
}
.wax-label {
  font-size: 7.5px;
  font-weight: 800;
  letter-spacing: 1.5px;
  color: rgba(255, 250, 241, 0.85);
  text-transform: uppercase;
  margin-top: 2px;
}
.cover-copy { margin-top: 26px; text-align: center; }
.cover-eyebrow {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 1px;
  color: var(--pc-gold-deep);
  text-transform: uppercase;
  margin-bottom: 8px;
}
.cover-title {
  margin: 0 0 8px;
  font-size: 25px;
  font-weight: 800;
  letter-spacing: -0.4px;
  color: var(--pc-marketing-ink);
  line-height: 1.15;
}
.cover-line {
  margin: 0 auto;
  max-width: 280px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--pc-marketing-body);
}

/* ---------- Play ---------- */
.view-play {
  background: var(--pc-puzzle-screen);
  padding-left: 0;
  padding-right: 0;
  align-items: stretch;
  overflow: hidden;
}
.play-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 16px 8px;
  position: relative;
  z-index: 2;
}
.play-from {
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.from-label { font-size: 12px; font-weight: 600; color: #5a5550; }
.from-name { font-size: 15px; font-weight: 800; color: #1c1a17; letter-spacing: -0.2px; }
/* 40px blur pill buttons, same as the app's pause/heart chrome. */
.round-btn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 999px;
  background: rgba(235, 233, 228, 0.6);
  backdrop-filter: saturate(140%) blur(18px);
  -webkit-backdrop-filter: saturate(140%) blur(18px);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  padding: 0;
}
.round-btn:active { transform: scale(0.92); }
.round-btn-icon { width: 18px; height: 18px; object-fit: contain; }
.round-btn-icon-lg { width: 22px; height: 22px; }
.stage-wrap {
  flex: 1;
  /* Without min-height:0 this flex child refuses to shrink below the sized
     stage, pushing the tray below the fold. */
  min-height: 0;
  position: relative;
  overflow: hidden;
  display: flex;
  justify-content: center;
}
.stage { position: relative; }
/* Board frame: shell padding 4 + 2px border + radius 6, same as the app. */
.board-panel {
  position: absolute;
  left: -6px;
  top: -6px;
  background: var(--pc-board-shell);
  border: 2px solid var(--pc-board-border);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(58, 54, 50, 0.1);
}
.board { position: absolute; left: 0; top: 0; }

/* Tile anatomy mirrors the app's puzzle-tile.tsx: root slot > scale wrap >
   clip (merges into connected neighbors) > image slice, plus half-gap edge
   strips in the shell color and a gold flash overlay. */
.tile {
  position: absolute;
  cursor: grab;
  touch-action: none;
}
.tile-scale {
  position: absolute;
  inset: 0;
}
.tile-clip {
  position: absolute;
  overflow: hidden;
}
.tile-img {
  position: absolute;
  left: 0;
  top: 0;
  background-repeat: no-repeat;
}
/* Gap-strip overlays: static strips above resting tiles (z3), and a
   transform-synced copy for the dragged group above everything (z6). */
.grid-overlay,
.drag-grid-overlay {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
.grid-overlay { z-index: 3; }
.drag-grid-overlay { z-index: 6; }
.grid-strip {
  position: absolute;
}
.tile-active {
  z-index: 5 !important;
  cursor: grabbing;
}
.tile-flashing {
  z-index: 4 !important;
}
.tile-active-shadow {
  filter: drop-shadow(0 8px 14px rgba(45, 27, 9, 0.22));
}
.tile-hovered {
  filter: drop-shadow(0 0 6px rgba(215, 135, 45, 0.4));
}
.tile-flash-overlay {
  position: absolute;
  inset: 0;
  border-style: solid;
  border-width: 0;
  border-color: #ffd700;
  opacity: 0;
  pointer-events: none;
  z-index: 10;
}
@keyframes tileFlashFade {
  0% { opacity: 1; }
  100% { opacity: 0; }
}
.tile-flash-border {
  animation: tileFlashFade 0.6s ease-in-out forwards;
}
@keyframes tileFlashScale {
  0% { transform: scale(1); }
  20% { transform: scale(1.04); }
  60% { transform: scale(1); }
  100% { transform: scale(1); }
}
.tile-flash-scale {
  animation: tileFlashScale 0.6s ease-in-out;
}

/* Background glow circles, straight from the app's puzzle screen. */
.glow-top {
  position: absolute;
  top: -120px;
  right: -40px;
  width: 280px;
  height: 280px;
  border-radius: 140px;
  background: rgba(240, 238, 234, 0.9);
  pointer-events: none;
}
.glow-bottom {
  position: absolute;
  bottom: -80px;
  left: -60px;
  width: 260px;
  height: 260px;
  border-radius: 130px;
  background: rgba(200, 198, 194, 0.16);
  pointer-events: none;
}

/* Pause / Settings modal (mirrors the app's pause sheet). */
.pause-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(28, 28, 30, 0.52);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 80;
  padding: 24px;
}
.pause-card {
  width: 100%;
  max-width: 340px;
  background: #f2f2f7;
  border: 1px solid var(--pc-divider);
  border-radius: 18px;
  padding: 22px 20px 20px;
}
.pause-title {
  margin: 0 0 16px;
  font-size: 19px;
  font-weight: 800;
  color: #1c1c1e;
  text-align: center;
}
.pause-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 2px;
}
.pause-row-label {
  font-size: 15px;
  font-weight: 700;
  color: #1c1c1e;
}
.pause-divider {
  border-bottom: 1px solid var(--pc-divider);
}
.pause-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: #e5e5ea;
  outline: none;
}
.pause-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: #ffffff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
  cursor: pointer;
}
.pause-slider::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 999px;
  background: #ffffff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
  cursor: pointer;
}
.pause-resume {
  margin-top: 18px;
  height: 48px;
}

/* Reveal / preview popup (mirrors the app's preview modal). */
.preview-card {
  width: 100%;
  max-width: 420px;
  max-height: 90%;
  background: #f2f2f7;
  border: 1px solid var(--pc-divider);
  border-radius: 16px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}
.preview-heading {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
  color: #1c1c1e;
  text-align: center;
}
.preview-modal-image {
  max-width: 100%;
  min-height: 0;
  flex: 1;
  object-fit: contain;
  border-radius: 8px;
}
.preview-back {
  height: 48px;
  flex: none;
}
.peek-image {
  position: absolute;
  left: 0;
  top: 0;
  object-fit: cover;
  border-radius: 6px;
  z-index: 40;
  pointer-events: none;
}

/* ---------- Finish ---------- */
.view-finish {
  background: var(--pc-marketing-bg);
  padding: 0;
  align-items: stretch;
}
.confetti { position: fixed; inset: 0; overflow: hidden; pointer-events: none; z-index: 8; }
.confetti span {
  position: absolute;
  top: -20px;
  border-radius: 2px;
  animation: pcfall var(--dur) var(--delay) var(--pc-ease) forwards;
}
.finish-hero {
  position: relative;
  height: 56%;
  flex: none;
  overflow: hidden;
}
.finish-hero img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  animation: pcpop 0.6s var(--pc-ease);
}
.finish-hero-fade {
  position: absolute;
  inset: 0;
  /* Fade starts lower so more of the painting stays visible. */
  background: linear-gradient(180deg, rgba(19, 27, 39, 0.12), rgba(233, 219, 198, 0.12) 76%, var(--pc-marketing-bg));
}
.finish-body {
  flex: 1;
  position: relative;
  z-index: 9;
  padding: 22px 28px max(26px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
.finish-title {
  margin: 0;
  font-size: 20px;
  font-weight: 400;
  letter-spacing: -0.2px;
  color: #111111;
  line-height: 1.25;
}
/* The sealed greetings, revealed only after solving — anchored just above
   the actions. */
.message-reveal {
  animation: pcpop 0.5s 0.3s var(--pc-ease) both;
  margin-bottom: 36px;
}
/* Long greetings: claw back 16px above the lockup and 16px below the
   greeting so the text gets the room instead. */
.finish-compact .finish-spacer { min-height: 0; }
.finish-compact .message-reveal { margin-bottom: 20px; }
.message-label {
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.7px;
  color: var(--pc-gold-deep);
  text-transform: uppercase;
  margin-bottom: 6px;
}
.finish-spacer { flex: 1; min-height: 16px; }
.finish-actions { display: flex; flex-direction: column; gap: 10px; align-items: center; }
/* Small CTA label attached to the buttons (14px total below via the
   container's 10px gap; the 36px above comes from .message-reveal). */
.finish-cta-line {
  margin: 0 0 4px;
  font-size: 15px;
  font-weight: 600;
  color: #74695B;
  text-align: center;
}
.finish-actions-row {
  display: flex;
  gap: 10px;
  width: 100%;
  max-width: 420px;
}
.finish-actions-row .btn {
  width: auto;
  flex: 1;
  min-width: 0;
  padding: 0 10px;
  font-size: 15px;
}
.saveimg-card {
  background: var(--pc-marketing-bg);
  border-radius: 18px;
  padding: 18px;
  width: min(340px, 86vw);
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}
.saveimg-hint {
  margin: 0;
  font-size: 14px;
  line-height: 1.45;
  color: var(--pc-marketing-body);
  text-align: center;
}
.saveimg-image {
  width: 100%;
  border-radius: 12px;
  /* Long-press needs the native callout Safari normally suppresses. */
  -webkit-touch-callout: default;
  user-select: auto;
  -webkit-user-select: auto;
}
.saving-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  height: 130px;
}
.saving-label { font-size: 14px; font-weight: 700; color: var(--pc-gold-deep); }

/* ---------- Error ---------- */
.view-error { background: var(--pc-marketing-bg); }
.error-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}
