/* Puzzle Plane — storybook theme (matches Story Road / Word Ladder):
   cream parchment, watercolour art, teal / coral / gold, warm ink outlines. */
:root {
  --cream: #fbf3e2;
  --parch: #f6ead2;
  --parch-dk: #ead8b5;
  --ink: #4a3426;
  --ink-soft: #7a5f4b;
  --teal: #2f9c95;
  --teal-dk: #1f716c;
  --teal-lt: #bfe5dc;
  --coral: #ef7a5f;
  --coral-dk: #c9573f;
  --gold: #f2b84b;
  --gold-dk: #c98a1d;
  --leaf: #7cb36a;
  --shadow: 0 6px 0 rgba(122, 84, 52, .18), 0 14px 28px rgba(122, 84, 52, .16);
  /* names the activities use */
  --line: var(--ink);
  --paper: #fffaf0;
  --pink: var(--coral);
  --pink-soft: #fde3d8;
  --mint: var(--teal-lt);
  --sun: var(--gold);
  --good: #4fae8a;
  --bad: var(--coral);
  --radius: 22px;
  --font: 'Fredoka', 'Trebuchet MS', system-ui, sans-serif;
  --title: 'Cinzel Decorative', Georgia, serif;
  --cell: min(13vw, 64px);
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font); color: var(--ink); overflow-x: hidden;
  background:
    radial-gradient(1200px 600px at 85% -10%, rgba(242,184,75,.35), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(47,156,149,.22), transparent 60%),
    radial-gradient(700px 400px at 100% 100%, rgba(239,122,95,.18), transparent 60%),
    linear-gradient(180deg, #fdf6e7 0%, #f6e7cc 100%);
  background-attachment: fixed;
  -webkit-tap-highlight-color: transparent;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}
body::before { /* paper grain */
  content: ''; position: fixed; inset: 0; pointer-events: none; z-index: 0; opacity: .35;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .45 0 0 0 0 .32 0 0 0 0 .2 0 0 0 .18 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
[hidden] { display: none !important; }
button { font-family: inherit; color: inherit; }

/* soft drifting clouds behind everything */
#sky { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 0; }
.cloud { position: absolute; left: -220px; width: 170px; height: 54px; background: rgba(255,250,240,.75); border-radius: 60px; animation: drift linear infinite; filter: blur(.5px); }
.cloud::before, .cloud::after { content: ''; position: absolute; background: inherit; border-radius: 50%; }
.cloud::before { width: 76px; height: 76px; left: 24px; top: -36px; }
.cloud::after { width: 56px; height: 56px; left: 84px; top: -24px; }
@keyframes drift { to { left: 110vw; } }

#app { position: relative; z-index: 1; max-width: 1040px; margin: 0 auto; padding: 14px 14px 40px; }

/* ---------- home ---------- */
.hero { position: relative; border: 3px solid var(--ink); border-radius: 28px; overflow: hidden; box-shadow: var(--shadow);
  aspect-ratio: 16 / 7.4; min-height: 210px; background: var(--cream) url('../assets/hero.jpg') right center / cover no-repeat; }
.hero::after { content: ''; position: absolute; inset: 0; background: linear-gradient(90deg, rgba(251,243,226,.92) 0%, rgba(251,243,226,.55) 38%, rgba(251,243,226,0) 60%); pointer-events: none; }
.hero-text { position: absolute; z-index: 1; left: 0; top: 0; bottom: 0; display: flex; flex-direction: column; justify-content: center; padding: 0 0 0 clamp(16px, 5vw, 48px); max-width: 58%; }
.kicker { font-weight: 600; font-size: clamp(12px, 2.2vw, 15px); color: var(--coral-dk); letter-spacing: .5px; }
.hero h1 { margin: 4px 0 6px; font-family: var(--title); font-weight: 900; font-size: clamp(34px, 8.4vw, 72px); line-height: .95; color: var(--teal-dk);
  text-shadow: 0 2px 0 #fff8e6, 0 0 18px rgba(255,248,230,.9); }
.sub { margin: 0; font-size: clamp(14px, 2.6vw, 19px); font-weight: 500; color: var(--ink-soft); }
.home-stats { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin: 14px 0 4px; }
.pill { display: inline-flex; align-items: center; gap: 4px; background: var(--cream); border: 2.5px solid var(--ink); border-radius: 999px; padding: 5px 14px; font-weight: 600; font-size: 15px; box-shadow: 0 3px 0 var(--ink); color: var(--ink); }
.btn-pill { cursor: pointer; }
.shelf { margin-top: 26px; }
.shelf-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin: 0 4px 12px; padding-bottom: 6px; border-bottom: 2.5px dashed rgba(74,52,38,.25); }
.shelf h2 { margin: 0; font-family: var(--title); font-weight: 900; font-size: clamp(22px, 4.6vw, 30px); color: var(--ink); }
.shelf h2::before { content: ''; display: inline-block; width: 14px; height: 14px; border-radius: 50%; background: var(--shelf); border: 2.5px solid var(--ink); margin-right: 10px; vertical-align: 2px; }
.shelf-note { color: var(--ink-soft); font-weight: 500; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(176px, 1fr)); gap: 16px; }
.card { text-align: center; background: var(--paper); border: 2.5px solid var(--ink); border-radius: 22px; padding: 10px 10px 12px; cursor: pointer;
  box-shadow: 0 5px 0 var(--ink); transition: transform .12s, box-shadow .12s; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.card:hover { transform: translateY(-3px) rotate(-.6deg); box-shadow: 0 8px 0 var(--ink); }
.card:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--ink); }
/* painted art in a round porthole */
.art { position: relative; border-radius: 50%; overflow: hidden; background: var(--parch); display: flex; align-items: center; justify-content: center;
  box-shadow: 0 0 0 5px var(--cream), 0 0 0 7.5px var(--ink), 0 6px 0 7.5px rgba(74,52,38,.25); }
.art img { position: absolute; inset: -6%; width: 112%; height: 112%; object-fit: cover; }
.art-emoji { font-size: 48px; }
.art.has-img .art-emoji { display: none; }
.card-art { width: min(138px, 70%); aspect-ratio: 1; margin: 8px 0 8px; }
.card-title { font-weight: 700; font-size: 18px; }
.card-blurb { font-size: 13px; color: var(--ink-soft); line-height: 1.3; min-height: 34px; }
.card-stars { font-size: 13px; font-weight: 600; background: var(--teal-lt); border-radius: 99px; padding: 1px 12px; border: 2px solid var(--ink); }
.card-stars.new { background: #ffe4a8; }
.foot { text-align: center; margin-top: 30px; color: var(--ink-soft); font-weight: 500; }

/* ---------- buttons ---------- */
.pp-btn { font-weight: 600; font-size: 18px; background: var(--teal); color: #fff; border: 2.5px solid var(--ink); border-radius: 16px; padding: 10px 22px; cursor: pointer;
  box-shadow: 0 4px 0 var(--ink); text-shadow: 0 1px 0 rgba(31,113,108,.6); transition: transform .08s, box-shadow .08s; }
.pp-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.pp-btn.ghost { background: var(--cream); color: var(--ink); text-shadow: none; }
.pp-btn.mint { background: var(--leaf); }
.pp-btn.small { font-size: 15px; padding: 6px 14px; }

/* ---------- modal + toast ---------- */
#modal { position: fixed; inset: 0; z-index: 50; background: rgba(74,52,38,.38); display: flex; align-items: center; justify-content: center; padding: 16px; backdrop-filter: blur(2px); }
.modal-card { background: var(--cream); border: 3px solid var(--ink); border-radius: 26px; box-shadow: var(--shadow); padding: 22px; max-width: 520px; width: 100%; max-height: 90vh; overflow: auto; text-align: center; animation: pop .3s cubic-bezier(.3,1.5,.6,1); }
@keyframes pop { from { transform: scale(.7); opacity: 0; } }
.modal-card h2 { margin: 10px 0 6px; font-family: var(--title); font-weight: 900; font-size: 26px; color: var(--teal-dk); }
.modal-art { width: 150px; aspect-ratio: 1; margin: 6px auto 10px; }
.modal-art.small { width: 110px; }
.win-art img { width: min(240px, 70%); border-radius: 50%; border: 3px solid var(--ink); box-shadow: 0 0 0 6px var(--cream), 0 0 0 9px var(--gold); animation: bounce 2s ease-in-out infinite; }
.big-emoji { font-size: 64px; line-height: 1.1; }
.bounce { animation: bounce 1s ease-in-out infinite; }
@keyframes bounce { 50% { transform: translateY(-8px) scale(1.03); } }
.level-row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin: 14px 0 10px; }
.level-btn { display: flex; flex-direction: column; align-items: center; min-width: 110px; }
.level-row .level-btn:nth-child(2) { background: var(--gold); color: var(--ink); text-shadow: none; }
.level-row .level-btn:nth-child(3) { background: var(--coral); }
.level-btn small { font-size: 12px; opacity: .9; font-weight: 500; }
.lvl-emoji { font-size: 28px; }
.howto-text { text-align: left; font-size: 17px; line-height: 1.45; background: var(--paper); border: 2.5px solid var(--ink); border-radius: 18px; padding: 10px 14px; margin: 8px 0 14px; }
.howto-text p { margin: 6px 0; }
#toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 60; background: var(--cream); border: 2.5px solid var(--ink); border-radius: 16px; box-shadow: 0 4px 0 var(--ink); padding: 8px 18px; font-weight: 600; font-size: 17px; max-width: 92vw; text-align: center; }
#toast.in { animation: toastin .3s cubic-bezier(.3,1.6,.6,1); }
@keyframes toastin { from { transform: translate(-50%, 30px); opacity: 0; } }

/* ---------- puzzle screen ---------- */
.toolbar { display: flex; align-items: center; gap: 8px; background: var(--cream); border: 2.5px solid var(--ink); border-radius: 20px; padding: 6px 8px; box-shadow: 0 4px 0 var(--ink); position: sticky; top: 6px; z-index: 5; }
.tool { display: flex; flex-direction: column; align-items: center; font-size: 22px; background: none; border: 0; cursor: pointer; padding: 2px 6px; border-radius: 12px; min-width: 52px; }
.tool span { font-size: 12px; font-weight: 600; }
.tool:active { background: var(--parch-dk); }
.tool-title { flex: 1; display: flex; align-items: center; gap: 8px; min-width: 0; }
.tool-title > div { min-width: 0; }
.tool-title b { display: block; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tool-title small { color: var(--ink-soft); font-weight: 600; }
.tt-emoji { font-size: 30px; }
.tt-art { width: 42px; height: 42px; flex: none; box-shadow: 0 0 0 2.5px var(--ink); }
.tt-art .art-emoji { font-size: 24px; }
.status { text-align: center; font-weight: 600; font-size: 17px; min-height: 26px; margin: 12px 0 6px; color: var(--ink-soft); }
.area { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.oops { font-size: 20px; text-align: center; }
.panel { background: var(--paper); border: 2.5px solid var(--ink); border-radius: 22px; box-shadow: var(--shadow); padding: 14px; max-width: 100%; }

/* shared grid */
.pp-grid { display: grid; gap: 0; border: 3px solid var(--ink); border-radius: 14px; background: #fffdf7; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; }
.pp-cell { width: var(--cell); height: var(--cell); border-right: 1.5px solid #eadfc8; border-bottom: 1.5px solid #eadfc8; display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: calc(var(--cell) * 0.42); position: relative; }
.pp-cell.given { color: var(--ink); }
.pp-cell.sel { background: #ffe9a8; }
.pp-cell.bad { background: #fbd3c6; }
.pp-cell.good { background: #d6efdf; }

/* number / letter keypad */
.pp-pad { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; max-width: 520px; }
.pp-key { min-width: 50px; height: 50px; font-size: 22px; font-weight: 700; background: var(--cream); border: 2.5px solid var(--ink); border-radius: 14px; box-shadow: 0 3px 0 var(--ink); cursor: pointer; padding: 0 8px; }
.pp-key:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.pp-key.used { opacity: .3; }
.pp-key.erase { background: var(--pink-soft); }

.pp-svg { width: 100%; height: auto; touch-action: none; user-select: none; -webkit-user-select: none; display: block; }

/* confetti */
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 70; overflow: hidden; }
.confetti i { position: absolute; top: -20px; width: 10px; height: 14px; border-radius: 3px; animation: fall linear forwards; }
@keyframes fall { to { top: 105vh; transform: rotate(720deg) translateX(40px); } }

@media (max-width: 520px) {
  .hero { aspect-ratio: auto; height: 230px; background-position: 70% center; }
  .hero::after { background: linear-gradient(90deg, rgba(251,243,226,.95) 0%, rgba(251,243,226,.6) 55%, rgba(251,243,226,0) 80%); }
  .hero-text { max-width: 62%; }
  .hero .sub { font-size: 13px; background: rgba(251,243,226,.8); border-radius: 10px; padding: 2px 6px; margin-left: -6px; }
  .cards { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .card-blurb { display: none; }
  .tool { min-width: 42px; padding: 2px 3px; }
  .tool span { display: none; }
  .tool-title b { font-size: 16px; }
}

/* ---------- Number Path ---------- */
.np-grid .pp-cell.mine { color: #d9558a; }
.np-grid .pp-cell.given { background: #fff7d6; }

/* ---------- Word Search ---------- */
.ws-theme { font-size: 22px; font-weight: 700; background: #fff; border: 3px solid var(--line); border-radius: 99px; padding: 2px 18px; box-shadow: 0 3px 0 var(--line); }
.ws-grid .pp-cell { font-size: calc(var(--cell) * 0.5); }
.ws-grid .pp-cell.sel { background: #fff3b0 !important; }
.ws-grid .pp-cell.ws-hint { animation: glow .5s ease-in-out 4 alternate; }
@keyframes glow { to { background: #ffd36e; transform: scale(1.12); } }
.ws-list { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; max-width: 560px; }
.ws-word { font-weight: 700; background: #fff; border: 2.5px solid var(--line); border-radius: 99px; padding: 2px 12px; }
.ws-word.done { text-decoration: line-through; opacity: .45; background: #dff7d8; }
