/* Hidden Differences — layout + components.
   The puzzle images are the hero: gameplay chrome stays slim and the stage
   area claims the viewport. One shell owns width; no 100vw anywhere. */

:root {
  --site-header-height: 64px;
  --page-gutter: clamp(12px, 3vw, 28px);
  --hd-cream: #f6fbff;
  --hd-cream-2: #e8f4f2;
  --hd-ink: #0f3d3a;
  --hd-ink-soft: #4e6f6b;
  --hd-teal: #0f766e;
  --hd-teal-soft: #99d5ce;
  --hd-amber: #f59e0b;
  --hd-coral: #fb7185;
  --hd-indigo: #6366f1;
  --hd-radius: 22px;
  --hd-shadow: 0 10px 30px rgba(15, 118, 110, 0.14);
  --hd-focus: 0 0 0 3px #fff, 0 0 0 6px var(--hd-indigo);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

.hd-body {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(1100px 500px at 50% -10%, #d9f2ee 0%, transparent 60%),
    linear-gradient(180deg, var(--hd-cream) 0%, var(--hd-cream-2) 100%);
  color: var(--hd-ink);
  font-family: 'Fredoka', system-ui, -apple-system, 'Segoe UI', sans-serif;
  overflow-x: clip;
  -webkit-tap-highlight-color: transparent;
}

.hd-skip {
  position: fixed;
  top: -80px;
  left: 12px;
  z-index: 100;
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--hd-ink);
  color: #fff;
  text-decoration: none;
}
.hd-skip:focus { top: 12px; }

/* --- shared in-game site header (matches the other games) ---------------- */
.site-game-header {
  display: flex;
  align-items: center;
  min-height: var(--site-header-height);
  padding: max(6px, env(safe-area-inset-top)) max(var(--page-gutter), env(safe-area-inset-right)) 6px max(var(--page-gutter), env(safe-area-inset-left));
  border-bottom: 1px solid rgba(15, 118, 110, 0.14);
  background: rgba(246, 251, 255, 0.94);
}
.site-game-brand { display: inline-flex; align-items: center; color: var(--hd-ink); text-decoration: none; }
.site-game-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--hd-teal);
  color: #fff;
  font-weight: 700;
  font-size: 1.2rem;
}
body.hd-max .site-game-header, :fullscreen .site-game-header { display: none; }

main#app { flex: 1; display: flex; flex-direction: column; min-height: 0; }

#party-canvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 60;
}

/* --- generic screen shells ------------------------------------------------ */
.hd-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: min(100%, 1100px);
  margin: 0 auto;
  padding: 12px var(--page-gutter) 24px;
}
.hd-center { justify-content: center; gap: 16px; text-align: center; }
.hd-loading-note { color: var(--hd-ink-soft); font-size: 1.05rem; text-align: center; }

.hd-screen-head {
  display: grid;
  grid-template-columns: 48px 1fr 60px;
  align-items: center;
  width: 100%;
  gap: 10px;
  margin-bottom: 12px;
}
.hd-screen-head h2 { margin: 0; text-align: center; font-size: clamp(1.2rem, 3.5vw, 1.7rem); }
.hd-total-stars { justify-self: end; font-weight: 600; }

/* --- buttons -------------------------------------------------------------- */
.hd-btn {
  appearance: none;
  border: 2px solid rgba(15, 118, 110, 0.2);
  border-radius: 16px;
  background: #fff;
  color: var(--hd-ink);
  font: inherit;
  font-weight: 600;
  padding: 12px 20px;
  min-height: 48px;
  min-width: 48px;
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(15, 118, 110, 0.15);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}
.hd-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(15, 118, 110, 0.15); }
.hd-btn:focus-visible { outline: none; box-shadow: var(--hd-focus); }
.hd-btn-primary { background: var(--hd-teal); border-color: var(--hd-teal); color: #fff; }
.hd-btn-big { font-size: 1.35rem; padding: 16px 42px; min-height: 64px; border-radius: 22px; }
.hd-btn-ghost { background: transparent; box-shadow: none; border-color: transparent; color: var(--hd-ink-soft); text-decoration: underline; }
.hd-btn-icon { padding: 8px; width: 48px; font-size: 1.25rem; line-height: 1; }

/* --- landing --------------------------------------------------------------- */
.hd-landing { justify-content: center; gap: 14px; text-align: center; }
.hd-title { margin: 0; font-size: clamp(2rem, 7vw, 3.2rem); color: var(--hd-teal); }
.hd-tagline { margin: 0; color: var(--hd-ink-soft); font-size: clamp(1rem, 3vw, 1.2rem); }
.hd-hero { position: relative; }
.hd-hero-pair { display: flex; gap: 10px; }
.hd-hero-card {
  display: grid;
  place-items: center;
  padding: 14px 18px;
  font-size: clamp(1.4rem, 5vw, 2.2rem);
  background: #fff;
  border-radius: var(--hd-radius);
  box-shadow: var(--hd-shadow);
  border: 3px solid var(--hd-teal-soft);
}
.hd-hero-glass {
  position: absolute;
  bottom: -14px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 2rem;
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.2));
}
.hd-howto { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; color: var(--hd-ink-soft); font-weight: 500; }
.hd-modes { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 4px; }
.hd-mode-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 14px;
  min-width: 76px;
  font-size: 1.4rem;
  line-height: 1;
}
.hd-mode-chip span { font-size: 0.78rem; font-weight: 600; }

.hd-landing-controls { display: flex; gap: 12px; margin-top: 6px; }
.hd-grownups {
  margin-top: 10px;
  border: none;
  background: none;
  color: var(--hd-ink-soft);
  font: inherit;
  font-size: 0.9rem;
  text-decoration: underline dotted;
  cursor: pointer;
  padding: 10px;
}
.hd-grownups.is-holding { color: var(--hd-teal); }

/* --- cards (categories / puzzles) ------------------------------------------ */
.hd-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
  width: 100%;
}
.hd-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px;
  border: 2px solid rgba(15, 118, 110, 0.16);
  border-radius: var(--hd-radius);
  background: #fff;
  box-shadow: var(--hd-shadow);
  cursor: pointer;
  font: inherit;
  color: inherit;
  text-align: left;
}
.hd-card:focus-visible { outline: none; box-shadow: var(--hd-focus); }
.hd-cat-cover, .hd-puzzle-thumb {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: 14px;
  background-size: cover;
  background-position: center;
  background-color: var(--hd-cream-2);
}
/* Shimmer while the cover/thumb image is still loading; fade in when ready. */
.hd-cat-cover.is-loading, .hd-puzzle-thumb.is-loading {
  background-image: linear-gradient(100deg, #e3efed 40%, #f2faf8 50%, #e3efed 60%);
  background-size: 200% 100%;
  animation: hd-shimmer 1.4s linear infinite;
}
.hd-cat-cover.is-loaded, .hd-puzzle-thumb.is-loaded { animation: hd-cover-in 0.35s ease both; }
@keyframes hd-cover-in { from { opacity: 0.3; } to { opacity: 1; } }
.hd-cat-card.is-locked .hd-cat-cover { filter: grayscale(0.7) brightness(0.85); }
.hd-lock {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 2rem;
}
.hd-cat-name, .hd-puzzle-name { font-weight: 600; font-size: 1.05rem; }
.hd-cat-meta { font-size: 0.85rem; color: var(--hd-ink-soft); }
.hd-muted { color: var(--hd-ink-soft); font-weight: 400; }
.hd-puzzle-stars .hd-star { font-size: 1rem; }

.hd-tabs { display: flex; gap: 8px; width: 100%; margin-bottom: 14px; flex-wrap: wrap; }
.hd-tab {
  flex: 1;
  min-width: 110px;
  border: 2px solid rgba(15, 118, 110, 0.16);
  border-radius: 999px;
  padding: 10px 12px;
  background: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  min-height: 48px;
}
.hd-tab.is-active { background: var(--hd-teal); border-color: var(--hd-teal); color: #fff; }
.hd-tab.is-active .hd-muted { color: rgba(255, 255, 255, 0.8); }
.hd-tab:focus-visible { outline: none; box-shadow: var(--hd-focus); }

/* --- gameplay --------------------------------------------------------------- */
.hd-game { padding: 6px var(--page-gutter) 10px; max-width: none; width: 100%; position: relative; }

.hd-hud {
  display: grid;
  grid-template-columns: 48px 1fr auto;
  align-items: center;
  gap: 10px;
  width: min(100%, 1200px);
  margin: 0 auto 8px;
}
.hd-hud-center { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 0; }
.hd-level-title {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--hd-ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.hd-dots { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.hd-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--hd-teal);
  transition: background 0.2s ease, transform 0.2s ease;
}
.hd-dot.is-found { background: var(--hd-amber); border-color: var(--hd-amber); transform: scale(1.15); }
.hd-hud-right { display: flex; align-items: center; gap: 10px; }
.hd-score {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--hd-teal);
  background: #fff;
  border-radius: 999px;
  padding: 6px 14px;
  box-shadow: var(--hd-shadow);
  min-width: 52px;
  text-align: center;
}

/* The stage area: side-by-side on wide screens, stacked on narrow/portrait.
   Each frame keeps a fixed 4:3 box so images never shift the layout. */
.hd-stage-area {
  flex: 1;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  min-height: 0;
}
.hd-stage-area.is-hidden .hd-inner { visibility: hidden; }

.hd-frame {
  position: relative;
  aspect-ratio: 4 / 3;
  /* Wide layout: half the row, capped by available height. */
  width: min(49%, calc((100dvh - var(--site-header-height) - 216px) * 4 / 3));
  border-radius: 18px;
  border: 3px solid #fff;
  box-shadow: var(--hd-shadow);
  overflow: hidden;
  background: var(--hd-cream-2);
  touch-action: none;
  cursor: crosshair;
}
.hd-frame:focus-visible { outline: none; box-shadow: var(--hd-focus); }

@media (max-width: 719px), (orientation: portrait) {
  .hd-stage-area { flex-direction: column; }
  .hd-frame {
    /* Stacked layout: full width, capped so both frames + chrome fit. */
    width: min(100%, calc((100dvh - var(--site-header-height) - 236px) / 2 * 4 / 3));
  }
}

/* Memory Flip: one large centered picture + a big toggle button. */
.hd-flip-area { flex-direction: column; justify-content: center; gap: 14px; }
.hd-flip-area .hd-frame {
  width: min(92%, calc((100dvh - var(--site-header-height) - 266px) * 4 / 3));
}

/* Found-differences strip: fills in each difference as it is identified. */
.hd-found-strip {
  display: flex;
  gap: 8px;
  justify-content: center;
  align-items: center;
  flex-wrap: nowrap;
  width: 100%;
  overflow-x: auto;
  padding: 5px 6px;
  scrollbar-width: thin;
  flex: 0 0 auto;
}
.hd-found-slot {
  position: relative;
  flex: 0 0 auto;
  width: 60px;
  height: 45px;
  border-radius: 10px;
  border: 2px dashed var(--hd-teal-soft);
  background: var(--hd-cream-2);
  display: grid;
  place-items: center;
  color: var(--hd-ink-soft);
  font-weight: 700;
  overflow: hidden;
}
.hd-found-slot.is-filled {
  border-style: solid;
  border-color: var(--hd-amber);
  color: transparent;
  cursor: pointer;
  animation: hd-found-pop 0.32s ease;
}
.hd-found-slot img { position: absolute; max-width: none; pointer-events: none; }
.hd-found-slot:focus-visible { outline: none; box-shadow: var(--hd-focus); }
.hd-found-check {
  position: absolute;
  right: 2px;
  bottom: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--hd-teal);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: grid;
  place-items: center;
}
/* Ends and starts at scale(1) so a stalled/interrupted animation never leaves
   the slot shrunk; a real device sees a brief pop as the difference is added. */
@keyframes hd-found-pop { 0% { transform: scale(1); } 45% { transform: scale(1.16); } 100% { transform: scale(1); } }
.hd-flip-toggle { font-size: 1.15rem; padding: 14px 28px; min-height: 56px; }

.hd-inner {
  position: absolute;
  inset: 0;
  transform-origin: 0 0;
  will-change: transform;
}
.hd-inner img {
  display: block;
  width: 100%;
  height: 100%;
  user-select: none;
  -webkit-user-drag: none;
}
.hd-layer { position: absolute; inset: 0; pointer-events: none; }

/* Found marker: shape + check, never color alone (colorblind-safe). */
.hd-marker {
  position: absolute;
  transform: translate(-50%, -50%);
  aspect-ratio: 1;
  border: 3px solid var(--hd-amber);
  outline: 2px solid #fff;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(245, 158, 11, 0.12);
}
.hd-marker-check {
  position: absolute;
  top: -6px;
  right: -6px;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--hd-amber);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
}

.hd-ripple {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 14%;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 3px solid rgba(99, 102, 241, 0.7);
}

.hd-sparkle {
  position: absolute;
  transform: translate(-50%, -50%);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  font-size: 1.6rem;
}
.hd-hint-pulse {
  position: absolute;
  transform: translate(-50%, -50%);
  aspect-ratio: 1;
  border-radius: 50%;
  border: 4px solid var(--hd-indigo);
}

.hd-cursor {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px dashed var(--hd-indigo);
  background: rgba(99, 102, 241, 0.15);
}

.hd-debug-spot {
  position: absolute;
  transform: translate(-50%, -50%);
  aspect-ratio: 1;
  border-radius: 50%;
  border: 2px dashed rgba(239, 68, 68, 0.8);
}

.hd-caption {
  min-height: 34px;
  margin: 6px auto 0;
  padding: 4px 18px;
  border-radius: 999px;
  background: rgba(15, 118, 110, 0.08);
  color: var(--hd-ink);
  font-weight: 500;
  opacity: 0;
  transition: opacity 0.25s ease;
  max-width: min(92%, 560px);
  text-align: center;
}
.hd-caption.is-visible { opacity: 1; }

.hd-fabs {
  position: fixed;
  right: max(10px, env(safe-area-inset-right));
  bottom: max(12px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 50;
}
.hd-fab {
  position: relative;
  width: 54px;
  height: 54px;
  padding: 0;
  border-radius: 50%;
  font-size: 1.3rem;
}
.hd-fab-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--hd-coral);
  color: #fff;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 1px 6px;
}

/* --- overlays ---------------------------------------------------------------- */
.hd-overlay, .hd-modal {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  background: rgba(15, 61, 58, 0.55);
  backdrop-filter: blur(4px);
  padding: 16px;
}
.hd-overlay[hidden] { display: none; }
.hd-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: min(94vw, 420px);
  max-height: min(90dvh, 640px);
  overflow-y: auto;
  padding: 24px;
  border-radius: var(--hd-radius);
  background: #fff;
  box-shadow: var(--hd-shadow);
  text-align: center;
}
.hd-panel h2 { margin: 0; color: var(--hd-teal); }
.hd-panel .hd-btn { width: 100%; }
.hd-toggle-row { display: flex; gap: 12px; }
.hd-toggle-row .hd-btn { width: 56px; }
.hd-check { display: flex; align-items: center; gap: 10px; text-align: left; font-size: 0.95rem; }
.hd-check input { width: 22px; height: 22px; accent-color: var(--hd-teal); }

.hd-star { font-size: 2.2rem; color: #d6dee0; }
.hd-star.is-on { color: var(--hd-amber); }
.hd-star-row { display: flex; gap: 8px; }
.hd-result-score { margin: 0; font-size: 1.5rem; font-weight: 700; color: var(--hd-teal); }
.hd-result-stats { display: flex; gap: 16px; color: var(--hd-ink-soft); font-weight: 500; }
.hd-cat-done { margin: 0; font-weight: 600; color: var(--hd-amber); }
.hd-complete-actions { display: flex; gap: 8px; width: 100%; }
.hd-complete-actions .hd-btn { flex: 1; padding-inline: 8px; }

/* --- bonus timer chip ---------------------------------------------------------- */
.hd-timer {
  font-weight: 700;
  font-size: 1rem;
  color: var(--hd-teal);
  background: #fff;
  border-radius: 999px;
  padding: 6px 12px;
  box-shadow: var(--hd-shadow);
  font-variant-numeric: tabular-nums;
}
.hd-timer.is-low { color: var(--hd-amber); }
.hd-timer.is-out { color: var(--hd-ink-soft); }

.hd-newbest {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--hd-amber);
  color: #fff;
  font-size: 0.85rem;
  vertical-align: middle;
}

/* --- "What changed?" review strip ---------------------------------------------- */
.hd-review { width: 100%; }
.hd-review-title { margin: 4px 0; font-weight: 600; font-size: 0.95rem; }
.hd-review-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 2px 8px;
  scrollbar-width: thin;
}
.hd-review-thumb {
  position: relative;
  flex: 0 0 auto;
  width: 76px;
  aspect-ratio: 4 / 3;
  padding: 0;
  border: 3px solid var(--hd-amber);
  border-radius: 12px;
  overflow: hidden;
  background: var(--hd-cream-2);
  cursor: pointer;
}
.hd-review-thumb:focus-visible { outline: none; box-shadow: var(--hd-focus); }
.hd-review-thumb img {
  position: absolute;
  max-width: none;
  pointer-events: none;
}

/* --- badges ------------------------------------------------------------------- */
.hd-badge-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  width: 100%;
}
.hd-badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 12px 8px;
  border-radius: 16px;
  background: var(--hd-cream);
  border: 2px solid rgba(15, 118, 110, 0.14);
  text-align: center;
}
.hd-badge.is-locked { opacity: 0.6; }
.hd-badge.is-earned { border-color: var(--hd-amber); background: #fffaf0; }
.hd-badge-icon { font-size: 1.9rem; }
.hd-badge-name { font-weight: 600; font-size: 0.9rem; }
.hd-badge-desc { font-size: 0.72rem; color: var(--hd-ink-soft); }

/* --- achievement toast --------------------------------------------------------- */
.hd-toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 140%);
  z-index: 80;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  border-radius: 16px;
  background: var(--hd-ink);
  color: #fff;
  box-shadow: var(--hd-shadow);
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  max-width: 90vw;
}
.hd-toast.is-in { transform: translate(-50%, 0); }
.hd-toast-icon { font-size: 1.8rem; }
body.hd-reduced .hd-toast { transition: opacity 0.3s ease; transform: translate(-50%, 0); opacity: 0; }
body.hd-reduced .hd-toast.is-in { opacity: 1; }

/* --- loading skeleton ---------------------------------------------------------- */
.hd-skeleton-pair { display: flex; gap: 10px; width: min(90%, 700px); }
.hd-skeleton-pair span {
  flex: 1;
  aspect-ratio: 4 / 3;
  border-radius: 18px;
  background: linear-gradient(100deg, #e3efed 40%, #f2faf8 50%, #e3efed 60%);
  background-size: 200% 100%;
}

/* --- accessibility modes --------------------------------------------------------- */
body.hd-contrast .hd-frame { border-color: var(--hd-ink); }
body.hd-contrast .hd-marker { border-width: 5px; }
body.hd-contrast .hd-btn { border-color: var(--hd-ink); }
