
  :root {
    --ink: #3b2855;
    --accent: #ff6bb5;
    --accent-2: #ffd166;
  }
  * { box-sizing: border-box; }
  html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    overflow: hidden;
    font-family: "Comic Sans MS", "Chalkboard SE", "Baloo", system-ui, sans-serif;
    color: var(--ink);
    background: linear-gradient(180deg, #ffeaf5, #e0f7ff);
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }

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

  header {
    text-align: center;
    padding: 12px 12px 4px;
    flex-shrink: 0;
  }
  h1 {
    margin: 0;
    font-size: clamp(20px, 4.5vw, 32px);
    color: #d660b0;
    text-shadow: 0 2px 0 #fff, 0 4px 0 rgba(0,0,0,0.15);
  }
  .hint {
    font-size: clamp(12px, 2vw, 14px);
    color: #6d5982;
    margin-top: 2px;
  }

  /* Scene picker chips */
  #scenes {
    display: flex;
    justify-content: center;
    gap: 6px;
    padding: 4px 8px;
    flex-shrink: 0;
  }
  #scenes button {
    font-family: inherit;
    font-size: 22px;
    padding: 4px 10px;
    border-radius: 14px;
    border: 3px solid #fff;
    background: #fff;
    cursor: pointer;
    box-shadow: 0 2px 0 var(--accent);
  }
  #scenes button.active {
    border-color: var(--accent);
    transform: scale(1.1);
    box-shadow: 0 3px 0 var(--accent), 0 0 0 2px var(--accent);
  }
  #scenes button:active { translate: 0 2px; box-shadow: 0 0 0 var(--accent); }

  /* Scene canvas */
  #scene-wrap {
    flex: 1;
    margin: 6px clamp(8px, 2vw, 16px);
    position: relative;
    border-radius: 18px;
    border: 5px solid #fff;
    box-shadow: 0 6px 14px rgba(0,0,0,0.18);
    overflow: hidden;
    min-height: 0;
  }
  #scene {
    position: absolute;
    inset: 0;
    cursor: crosshair;
  }
  #scene.eraser { cursor: not-allowed; }

  /* Background scenes */
  #scene.forest {
    background:
      radial-gradient(ellipse at 20% 100%, #5fa775 0 25%, transparent 26%),
      radial-gradient(ellipse at 80% 100%, #5fa775 0 25%, transparent 26%),
      radial-gradient(circle at 88% 14%, #fff2a0 0 36px, #ffd166 38px 52px, transparent 53px),
      linear-gradient(180deg, #d4f0ff 0%, #e5f7d8 60%, #93d4a4 100%);
  }
  #scene.beach {
    background:
      radial-gradient(circle at 88% 18%, #ffec8c 0 36px, #ffd166 38px 52px, transparent 53px),
      linear-gradient(180deg,
        #b6e3ff 0%,
        #b6e3ff 50%,
        #66c5e8 50.1%,
        #66c5e8 75%,
        #f7e3a8 75.1%,
        #f7e3a8 100%);
  }
  #scene.castle {
    background:
      url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 300 100' preserveAspectRatio='none'><rect x='0' y='62' width='300' height='38' fill='%23b687d8'/><g fill='%23b687d8'><rect x='5' y='28' width='30' height='72'/><rect x='128' y='10' width='44' height='90'/><rect x='265' y='28' width='30' height='72'/></g><g fill='%23905bb5'><polygon points='5,28 20,10 35,28'/><polygon points='128,10 150,-8 172,10'/><polygon points='265,28 280,10 295,28'/></g><circle cx='150' cy='-5' r='3' fill='%23ffd166'/><g fill='%233e2454'><path d='M141 100 L141 78 Q150 68 159 78 L159 100 Z'/><rect x='15' y='50' width='10' height='12'/><rect x='145' y='30' width='10' height='14'/><rect x='275' y='50' width='10' height='12'/></g><g fill='%23b687d8'><rect x='10' y='56' width='10' height='6'/><rect x='30' y='56' width='10' height='6'/><rect x='50' y='56' width='10' height='6'/><rect x='70' y='56' width='10' height='6'/><rect x='90' y='56' width='10' height='6'/><rect x='110' y='56' width='10' height='6'/><rect x='180' y='56' width='10' height='6'/><rect x='200' y='56' width='10' height='6'/><rect x='220' y='56' width='10' height='6'/><rect x='240' y='56' width='10' height='6'/></g></svg>") bottom/100% 70% no-repeat,
      linear-gradient(180deg, #fff5fa 0%, #ffd9ec 40%, #ffc6e3 80%, #ffb3d9 100%);
  }
  #scene.sky {
    background: linear-gradient(180deg,
      #ff8fbf 0%, #ffa94d 25%, #ffd166 50%, #8ec97d 70%, #66d2ff 90%, #b36bff 100%);
  }

  .placed {
    position: absolute;
    transform: translate(-50%, -50%);
    font-size: clamp(40px, 9vw, 60px);
    line-height: 1;
    cursor: pointer;
    filter: drop-shadow(0 3px 4px rgba(0,0,0,0.25));
    animation: appear 240ms ease-out;
    user-select: none;
  }
  @keyframes appear {
    0%   { transform: translate(-50%, -50%) scale(0); }
    70%  { transform: translate(-50%, -50%) scale(1.18); }
    100% { transform: translate(-50%, -50%) scale(1); }
  }

  /* Sticker tray at the bottom — multi-row wrap, vertical scroll if needed */
  #tray {
    background: #fff;
    border-top: 4px solid var(--accent);
    padding: 8px 6px;
    flex-shrink: 0;
    max-height: clamp(120px, 24vh, 200px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  #tray-inner {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 0 6px;
    justify-content: center;
  }
  .sticker {
    flex-shrink: 0;
    font-size: 30px;
    line-height: 1;
    background: #fff5fa;
    border: 3px solid #fce4ec;
    border-radius: 14px;
    padding: 4px;
    cursor: pointer;
    transition: transform 100ms;
    width: 52px;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .sticker img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    pointer-events: none;
  }
  .tray-divider {
    flex-basis: 100%;
    height: 0;
    border-top: 2px dashed #ffc6e3;
    margin: 4px 0;
    opacity: 0.6;
  }
  .placed.placed-img {
    width: clamp(60px, 13vw, 90px);
    height: clamp(60px, 13vw, 90px);
  }
  .placed-img img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    pointer-events: none;
  }
  .sticker.selected {
    background: #ffd9ec;
    border-color: var(--accent);
    transform: scale(1.15) translateY(-4px);
    box-shadow: 0 4px 0 var(--accent);
  }
  .sticker.eraser {
    background: #ffe8a8;
    border-color: #ffd166;
  }
  .sticker.eraser.selected {
    background: #ffd166;
    border-color: #b3841f;
    box-shadow: 0 4px 0 #b3841f;
  }

  #home-btn, #music-btn {
    position: fixed;
    top: 10px;
    font-family: inherit;
    font-size: 14px;
    padding: 6px 11px;
    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: 10px; }
  #music-btn { right: 10px; }
  #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;
  }

  #reset-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    font-family: inherit;
    font-size: 13px;
    padding: 5px 10px;
    border-radius: 999px;
    border: 2px solid #fff;
    background: rgba(255,255,255,0.9);
    color: #b03e7f;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0,0,0,0.15);
    z-index: 5;
  }
  #reset-btn:active { translate: 0 2px; }

  #count {
    position: absolute;
    bottom: 8px;
    right: 12px;
    font-size: 13px;
    color: rgba(60,40,80,0.7);
    background: rgba(255,255,255,0.7);
    padding: 2px 8px;
    border-radius: 999px;
  }
  #rate-btn {
    position: absolute;
    bottom: 8px;
    left: 8px;
    font-family: inherit;
    font-size: 13px;
    padding: 5px 12px;
    border-radius: 999px;
    border: 2px solid #fff;
    background: linear-gradient(135deg, #ffd166, #ff6bb5);
    color: #fff;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0,0,0,0.18);
    z-index: 5;
    font-weight: bold;
  }
  #rate-btn:active { translate: 0 2px; }

  #rate-modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 60;
    padding: 14px;
  }
  #rate-modal.show { display: flex; }
  #rate-modal .panel {
    background: #fff;
    border: 6px solid var(--accent);
    border-radius: 24px;
    padding: 22px 26px;
    text-align: center;
    max-width: 360px;
    box-shadow: 0 12px 36px rgba(0,0,0,0.3);
    animation: pop 320ms ease-out;
  }
  @keyframes pop {
    0%   { transform: scale(0.6); opacity: 0; }
    70%  { transform: scale(1.08); opacity: 1; }
    100% { transform: scale(1); }
  }
  #rate-modal h2 { margin: 0 0 6px; color: #d660b0; font-size: 26px; }
  #rate-modal .score {
    font-size: 64px;
    font-weight: bold;
    line-height: 1;
    margin: 8px 0;
    background: linear-gradient(135deg, #ff6bb5, #ffd166);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    text-shadow: 0 0 0 transparent;
  }
  #rate-modal .out-of { color: #6d5982; font-size: 22px; font-weight: normal; }
  #rate-modal .breakdown {
    font-size: 13px;
    color: #6d5982;
    margin: 8px 0 4px;
    text-align: left;
  }
  #rate-modal .breakdown div { margin: 2px 0; }
  #rate-modal .feedback {
    font-size: 17px;
    color: var(--ink);
    margin: 10px 0;
  }
  #rate-modal .btns {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 14px;
    flex-wrap: wrap;
  }
  #rate-modal button {
    font-family: inherit;
    font-size: 16px;
    padding: 9px 18px;
    border-radius: 999px;
    border: 3px solid var(--accent);
    cursor: pointer;
    box-shadow: 0 3px 0 var(--accent);
    font-weight: bold;
  }
  #rate-modal button:active { translate: 0 2px; box-shadow: 0 1px 0 var(--accent); }
  #keep-drawing { background: var(--accent); color: #fff; }
  #restart-btn  {
    background: linear-gradient(135deg, #66a6ff 0%, #4d8fd8 100%);
    color: #fff;
    border-color: #4d8fd8;
    box-shadow: 0 3px 0 #2d6db8;
  }
  #best-score {
    margin-top: 6px;
    font-size: 12px;
    color: #b03e7f;
  }

  /* 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: #ffe9f0;
    overflow: hidden;
  }
  #title-screen.hide,
  #title-screen.hide * { pointer-events: none; }
  #title-screen.hide { opacity: 0; }
  #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 #6a2b66, 3px 0 0 #6a2b66,
      0 -3px 0 #6a2b66, 0 3px 0 #6a2b66,
      -3px -3px 0 #6a2b66, 3px 3px 0 #6a2b66,
      -3px 3px 0 #6a2b66, 3px -3px 0 #6a2b66,
      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: #ffd1f3;
    margin-bottom: 4px;
  }
  #title-screen #title-text .row2 {
    font-size: clamp(40px, 11vw, 132px);
    color: #ffe18f;
    letter-spacing: 4px;
    animation-delay: 0.2s;
  }
  @keyframes title-bob {
    from { transform: translateY(0)    rotate(-1deg); }
    to   { transform: translateY(-6px) rotate(1deg); }
  }
  #title-screen .title-actions {
    position: absolute; z-index: 1;
    left: 50%; bottom: 10vh;
    transform: translateX(-50%);
    display: flex; flex-direction: column;
    align-items: center; gap: 14px;
  }
  #title-screen .wood-btn {
    appearance: none; border: none; cursor: pointer;
    font-family: "Georgia", "Times New Roman", serif;
    font-weight: 900;
    font-size: clamp(20px, 3.4vw, 34px);
    letter-spacing: 0.06em;
    color: #4a2a14;
    text-shadow: 0 1px 0 rgba(255, 240, 210, 0.7);
    padding: 0.5em 1.6em;
    border-radius: 18px;
    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;
  }
  #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); }
