
  :root {
    --ink: #3b2855;
    --accent: #ff8fbf;
    --accent-2: #ffd166;
    --shadow: #b8a8d8;
    --card-shadow: #c5b9e3;
  }
  * { box-sizing: border-box; }
  html, body {
    margin: 0;
    padding: 0;
    min-height: 100dvh;
    font-family: "Comic Sans MS", "Chalkboard SE", "Baloo", system-ui, sans-serif;
    color: var(--ink);
    /* Painted cozy-playroom backdrop (Gemini gen, 2026-05-17).
       Pastel-pink gradient is the fallback if the WebP fails. */
    background:
      url('./assets/bg.webp') center/cover no-repeat,
      linear-gradient(180deg, #ffeaf6 0%, #ffd9ec 40%, #fce8ff 100%);
    background-attachment: fixed;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
  }
  header {
    text-align: center;
    padding: 20px 12px 8px;
  }
  h1 {
    margin: 0;
    font-size: clamp(22px, 4.5vw, 36px);
    color: #d660b0;
    text-shadow: 0 2px 0 #fff, 0 4px 0 rgba(0,0,0,0.15);
  }
  #hud {
    display: flex;
    gap: 10px;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    font-size: clamp(14px, 2.2vw, 18px);
    background: rgba(255,255,255,0.85);
    padding: 6px 14px;
    border-radius: 999px;
    width: fit-content;
    margin: 6px auto 0;
    box-shadow: 0 2px 6px rgba(0,0,0,0.1);
  }
  #hud b { color: #d6336c; }
  #hud .pip { opacity: 0.45; }
  #hud .streak {
    background: linear-gradient(135deg, #ffe46b, #ffb547);
    color: #6a3f00;
    padding: 2px 10px;
    border-radius: 999px;
    font-weight: 800;
    box-shadow: 0 0 8px rgba(255, 181, 71, 0.5);
    transition: transform 200ms;
    transform: scale(1);
  }
  #hud .streak.bump { transform: scale(1.18); }

  /* Grid sized per difficulty: --cols and --rows are set from JS so
     each card stays roughly square. */
  #grid {
    display: grid;
    grid-template-columns: repeat(var(--cols, 4), 1fr);
    gap: clamp(5px, 1.4vw, 11px);
    width: min(94vw, calc(var(--cols, 4) * 110px));
    margin: 18px auto;
  }
  .card {
    aspect-ratio: 1;
    perspective: 800px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
  .card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    transition: transform 0.45s ease-out;
  }
  .card.flipped .card-inner,
  .card.matched .card-inner,
  .card.peek    .card-inner { transform: rotateY(180deg); }

  /* Countdown badge during the start-of-game peek. */
  #peekCountdown {
    position: fixed;
    top: 14px; left: 50%;
    transform: translateX(-50%);
    z-index: 50;
    padding: 10px 22px;
    background: linear-gradient(180deg, #fff4b3, #ffb24a);
    color: #4a2410;
    font-family: "Comic Sans MS", "Chalkboard SE", "Baloo", system-ui, sans-serif;
    font-size: clamp(20px, 4vw, 32px);
    font-weight: 800;
    border-radius: 18px;
    border: 3px solid #b97318;
    box-shadow: 0 6px 14px rgba(0,0,0,0.35);
    pointer-events: none;
    user-select: none;
    display: none;
    animation: peekBob 0.5s ease-in-out infinite alternate;
  }
  @keyframes peekBob {
    from { transform: translate(-50%, 0); }
    to   { transform: translate(-50%, -4px); }
  }
  .card-face {
    position: absolute;
    inset: 0;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    border-radius: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 4px solid #fff;
    box-shadow: 0 5px 0 var(--card-shadow), 0 8px 16px rgba(0,0,0,0.15);
  }
  .card-back {
    background:
      radial-gradient(circle at 30% 30%, rgba(255,255,255,0.4) 0 30%, transparent 31%),
      linear-gradient(135deg, #ff8fbf, #b36bff);
    color: #fff;
    font-size: clamp(24px, 5vw, 42px);
    text-shadow: 0 2px 4px rgba(0,0,0,0.25);
    position: relative;
    overflow: hidden;
  }
  /* Subtle shine sweep on the card back so it feels more alive. */
  .card-back::after {
    content: "";
    position: absolute;
    inset: -50% -50% -50% -50%;
    background: linear-gradient(110deg, transparent 40%, rgba(255,255,255,0.18) 50%, transparent 60%);
    animation: backShine 5s linear infinite;
    pointer-events: none;
  }
  @keyframes backShine {
    from { transform: translateX(-50%); }
    to   { transform: translateX(50%); }
  }
  .card-front {
    background: #fff;
    transform: rotateY(180deg);
    font-size: clamp(28px, 7vw, 56px);
    padding: 8%;
  }
  .card-front img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    image-rendering: -webkit-optimize-contrast;
  }
  .card.matched .card-inner {
    animation: matchedPulse 0.7s ease-out;
  }
  .card.matched .card-front {
    background: linear-gradient(135deg, #fff5d4, #ffe8a8);
    border-color: #ffd166;
    box-shadow: 0 0 18px rgba(255, 209, 102, 0.7), 0 5px 0 #c9a55a;
  }
  @keyframes matchedPulse {
    0%, 100% { transform: rotateY(180deg) scale(1); }
    50%      { transform: rotateY(180deg) scale(1.12); }
  }
  /* Hearts shoot off a freshly-matched pair. */
  .heart-burst {
    position: absolute;
    font-size: 22px;
    pointer-events: none;
    animation: heartFly 700ms ease-out forwards;
    z-index: 35;
  }
  @keyframes heartFly {
    0%   { opacity: 1; transform: translate(0,0) scale(0.4); }
    100% { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(1.6) rotate(360deg); }
  }

  #buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin: 14px auto 26px;
    flex-wrap: wrap;
  }
  #buttons button {
    font-family: inherit;
    font-size: 16px;
    padding: 9px 18px;
    border-radius: 999px;
    border: 3px solid var(--accent);
    background: #fff;
    color: var(--accent);
    cursor: pointer;
    box-shadow: 0 3px 0 var(--accent);
    font-weight: bold;
  }
  #buttons button:active { translate: 0 2px; box-shadow: 0 1px 0 var(--accent); }

  #home-btn, #music-btn {
    position: fixed;
    top: 12px;
    font-family: inherit;
    font-size: 15px;
    padding: 7px 12px;
    border-radius: 999px;
    border: 3px solid var(--accent);
    background: #fff;
    color: var(--ink);
    text-decoration: none;
    box-shadow: 0 3px 0 var(--accent);
    z-index: 30;
    cursor: pointer;
  }
  #home-btn  { left: 12px; }
  #music-btn { right: 12px; }
  #home-btn:active, #music-btn:active { translate: 0 2px; box-shadow: 0 1px 0 var(--accent); }
  #music-btn.on {
    background: linear-gradient(135deg, #ff6bb5, #ffd166);
    color: #fff;
  }

  #author {
    position: fixed;
    bottom: 6px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 12px;
    color: rgba(60,40,80,0.55);
    font-style: italic;
    pointer-events: none;
  }

  #winScreen {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.4);
    z-index: 40;
    padding: 12px;
  }
  #winScreen.show { display: flex; }
  #winScreen .panel {
    background: #fff;
    border: 6px solid var(--accent);
    border-radius: 24px;
    padding: 22px 26px;
    text-align: center;
    box-shadow: 0 12px 40px rgba(0,0,0,0.3);
    max-width: 92vw;
    min-width: 280px;
    animation: wiggle 1.2s ease-in-out infinite;
  }
  #winScreen h2 { margin: 0 0 6px; color: var(--accent); font-size: clamp(22px, 5vw, 32px); }
  #winScreen p  { margin: 6px 0; font-size: clamp(15px, 2.6vw, 19px); }
  #winScreen .big-stat { font-size: clamp(32px, 6vw, 50px); color: #d6336c; margin: 4px 0; }
  #winScreen .stars-row {
    font-size: 52px;
    letter-spacing: 6px;
    margin: 6px 0 10px;
    min-height: 60px;
  }
  #winScreen .stars-row .star {
    display: inline-block;
    opacity: 0.25;
    transform: scale(0.7);
    transition: opacity 280ms, transform 360ms cubic-bezier(.4,1.7,.5,1);
  }
  #winScreen .stars-row .star.lit {
    opacity: 1;
    transform: scale(1.15) rotate(8deg);
    filter: drop-shadow(0 0 10px rgba(255, 209, 102, 0.95));
  }
  #winScreen .win-btns { display: flex; gap: 10px; justify-content: center; margin-top: 10px; flex-wrap: wrap; }
  #winScreen button {
    font-family: inherit;
    font-size: 16px;
    padding: 8px 18px;
    border-radius: 999px;
    border: 3px solid var(--accent);
    cursor: pointer;
    box-shadow: 0 3px 0 var(--accent);
    font-weight: bold;
  }
  #winScreen button:active { translate: 0 2px; box-shadow: 0 1px 0 var(--accent); }
  #winScreen #playAgain { background: var(--accent); color: #fff; }
  #winScreen #pickerBtn {
    background: linear-gradient(135deg, #ffd166, #ffb547);
    color: #4a2410;
    border-color: #c98b2a;
    box-shadow: 0 3px 0 #c98b2a;
  }
  #winScreen #menuBtn   {
    background: linear-gradient(135deg, #66a6ff 0%, #4d8fd8 100%);
    color: #fff;
    border-color: #4d8fd8;
    box-shadow: 0 3px 0 #2d6db8;
  }
  @keyframes wiggle {
    0%, 100% { transform: rotate(-1deg); }
    50%      { transform: rotate(1deg); }
  }

  .confetti {
    position: fixed;
    top: -20px;
    font-size: 22px;
    pointer-events: none;
    animation: fall linear forwards;
    z-index: 35;
  }
  @keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

  /* ===== Picker screen (theme + difficulty) ===== */
  #picker {
    position: fixed; inset: 0;
    background: linear-gradient(180deg, #ffeaf6 0%, #ffd9ec 50%, #fce8ff 100%);
    z-index: 60;
    display: none;
    flex-direction: column;
    align-items: center;
    padding: 24px 16px 16px;
    overflow-y: auto;
  }
  #picker.show { display: flex; }
  #picker h2 {
    margin: 4px 0 2px;
    color: #d660b0;
    font-size: clamp(22px, 5vw, 32px);
    text-shadow: 0 2px 0 #fff;
    text-align: center;
  }
  #picker .lead {
    margin: 0 0 14px;
    color: var(--ink);
    font-size: clamp(13px, 2.4vw, 16px);
    text-align: center;
    opacity: 0.85;
  }
  #picker .section-label {
    margin: 14px 0 6px;
    color: var(--ink);
    font-size: clamp(14px, 2.6vw, 18px);
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 1px;
    opacity: 0.85;
  }
  #picker .grid-themes {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 10px;
    width: 100%;
    max-width: 640px;
  }
  #picker .grid-diff {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 10px;
    width: 100%;
    max-width: 640px;
  }
  #picker .opt {
    background: #fff;
    border: 3px solid var(--accent);
    border-radius: 16px;
    padding: 10px 8px;
    text-align: center;
    cursor: pointer;
    box-shadow: 0 4px 0 var(--accent);
    transition: transform 0.1s;
    font-family: inherit;
    color: var(--ink);
    position: relative;
  }
  #picker .opt:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--accent); }
  #picker .opt.sel {
    background: linear-gradient(135deg, #fff4b3, #ffd166);
    border-color: #b97318;
    box-shadow: 0 4px 0 #b97318;
  }
  #picker .opt .ico { font-size: 28px; line-height: 1; display: block; margin-bottom: 4px; }
  #picker .opt .name { font-weight: 800; font-size: 14px; }
  #picker .opt .sub  { font-size: 11px; opacity: 0.7; margin-top: 2px; }
  #picker .opt .stars {
    position: absolute;
    top: 2px; right: 4px;
    font-size: 11px;
    color: #ffb547;
    text-shadow: 0 1px 0 rgba(0,0,0,0.2);
  }
  #picker .go-btn {
    margin: 18px 0 10px;
    padding: 14px 32px;
    font-size: 20px;
    font-weight: 900;
    background: linear-gradient(135deg, #ff6bb5, #ff8fbf);
    color: #fff;
    border: 4px solid #d6336c;
    border-radius: 999px;
    cursor: pointer;
    box-shadow: 0 5px 0 #c2436d, 0 0 20px rgba(255, 143, 191, 0.5);
    font-family: inherit;
  }
  #picker .go-btn:active { transform: translateY(2px); box-shadow: 0 3px 0 #c2436d; }
  #picker .total-stars {
    text-align: center;
    margin-top: 8px;
    font-size: 14px;
    font-weight: 800;
    color: #d660b0;
  }

  /* Princess-Run-style title screen — full-bleed painted hero art that
     doubles as the asset-loading curtain. */
  #title-screen {
    position: fixed; inset: 0;
    z-index: 9000;
    display: grid; place-items: center;
    transition: opacity 0.5s ease;
    background: #0a1a3a;
    overflow: hidden;
  }
  #title-screen.hide { opacity: 0; pointer-events: none; }
  #title-screen #title-art {
    position: absolute; inset: 0;
    width: 100%; height: 100%;
    object-fit: cover; object-position: center;
    z-index: 0; pointer-events: none;
  }
  #title-screen #title-text {
    position: absolute; z-index: 1;
    left: 50%; top: 6vh;
    transform: translateX(-50%);
    text-align: center;
    pointer-events: none; user-select: none;
    line-height: 0.9;
    font-family: "Fredoka", "Comic Sans MS", system-ui, sans-serif;
    font-weight: 800;
    width: max-content;
  }
  #title-screen #title-text .row1,
  #title-screen #title-text .row2 {
    display: block;
    color: #fff7d6;
    letter-spacing: 2px;
    text-shadow:
      -3px 0 0 #1a2440, 3px 0 0 #1a2440,
      0 -3px 0 #1a2440, 0 3px 0 #1a2440,
      -3px -3px 0 #1a2440, 3px 3px 0 #1a2440,
      -3px 3px 0 #1a2440, 3px -3px 0 #1a2440,
      0 6px 0 rgba(0,0,0,0.35),
      0 12px 22px rgba(0,0,0,0.55);
    animation: title-bob 2.4s ease-in-out infinite alternate;
  }
  #title-screen #title-text .row1 {
    font-size: clamp(24px, 6.5vw, 76px);
    color: #ffe18f;
    margin-bottom: 4px;
  }
  #title-screen #title-text .row2 {
    font-size: clamp(40px, 11vw, 132px);
    color: #ffdf63;
    letter-spacing: 4px;
    animation-delay: 0.2s;
  }
  @keyframes title-bob {
    from { transform: translateY(0)    rotate(-1deg); }
    to   { transform: translateY(-6px) rotate(1deg); }
  }
  /* Difficulty picker = stack of three wood buttons in the middle
     of the title screen. Center vertically + horizontally. */
  #title-screen .title-actions {
    position: absolute; z-index: 1;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    display: flex; flex-direction: column;
    align-items: center; gap: 12px;
    padding: 12px 16px;
  }
  #title-screen .wood-btn {
    appearance: none; border: none; cursor: pointer;
    font-family: "Georgia", "Times New Roman", serif;
    font-weight: 900;
    font-size: clamp(18px, 3vw, 28px);
    letter-spacing: 0.04em;
    color: #4a2a14;
    text-shadow: 0 1px 0 rgba(255, 240, 210, 0.7);
    padding: 0.45em 1.2em;
    border-radius: 16px;
    background: linear-gradient(180deg, #fbe6b1 0%, #f1c878 45%, #d99a3f 100%);
    box-shadow:
      0 0 0 4px #4a2a14,
      0 0 0 7px #b6803a,
      inset 0 4px 0 rgba(255, 250, 220, 0.65),
      inset 0 -6px 8px rgba(120, 60, 20, 0.45),
      0 8px 14px rgba(0, 0, 0, 0.45);
    transition: transform 0.12s ease;
    min-width: 220px;
  }
  #title-screen .wood-btn:hover  { transform: translateY(-2px); }
  #title-screen .wood-btn:active { transform: translateY(2px); }
  #title-screen .wood-btn:disabled { cursor: wait; filter: saturate(0.5) brightness(0.85); }
  #title-screen .wood-btn .sub {
    display: block;
    font-size: 0.55em;
    font-weight: 700;
    color: #5a3a18;
    margin-top: 2px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
  }
  #title-screen .wood-btn .stars {
    display: inline-block;
    margin-left: 6px;
    font-size: 0.7em;
    filter: drop-shadow(0 1px 0 rgba(0,0,0,0.3));
  }
  #title-screen .total-stars {
    position: absolute;
    bottom: 4vh; left: 50%;
    transform: translateX(-50%);
    z-index: 1;
    color: #fff7d6;
    font-family: "Comic Sans MS", "Chalkboard SE", "Baloo", system-ui, sans-serif;
    font-weight: 800;
    font-size: clamp(14px, 2.5vw, 18px);
    text-shadow:
      -2px 0 0 #1a2440, 2px 0 0 #1a2440,
      0 -2px 0 #1a2440, 0 2px 0 #1a2440,
      0 4px 12px rgba(0,0,0,0.5);
    pointer-events: none;
  }
