/* Purrdle: a cozy cream page, letter tiles that flip, the cats' keyboard. The title screen and the sheets are
   shared/mainmenu.js (menu.css, loaded after this); only their colors are set here (--sg-*). */
:root {
  --bg: #f6e6d0; --bg-hi: #fff6ea; --ink: #4a2f22; --ink-soft: #7b5d4c; --line: rgba(74, 47, 34, 0.2);
  --accent: #2f8f83; --accent-dark: #1f6c62; --sheet: #fff8ee; --card: #fffaf3;
  --hit: #3e9a72; --near: #e39b2d; --miss: #8a7c76;
  --tile: 58px; --gap: 6px; --key-h: 58px;
  color-scheme: light;
}
* { box-sizing: border-box; }
* { touch-action: manipulation; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Baloo 2", ui-rounded, system-ui, sans-serif; color: var(--ink);
  /* A pixel-art study behind the board (Codex, games/art-src/samples-feel/purrdle), washed so the tiles read. */
  background: linear-gradient(rgba(246, 230, 208, .28), rgba(246, 230, 208, .28)), url("assets/play.webp") center top / cover no-repeat, var(--bg);
  overflow: hidden; overscroll-behavior: none;
}
button { font: inherit; color: inherit; }
.app {
  position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center;
  padding: calc(var(--sg-corner-top) - 2px) 8px calc(env(safe-area-inset-bottom, 0px) + 8px);
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}

/* ---- tile colors: the theme picked in the sticker book; contrast mode overrides hit and near ---- */
.app[data-theme="tabby"] { --hit: #2f8f83; --near: #e8873a; --miss: #8b7766; }
.app[data-theme="garden"] { --hit: #5a9a3c; --near: #d9a520; --miss: #7d8477; }
.app[data-theme="ocean"] { --hit: #2b84b5; --near: #e0a43a; --miss: #78838e; }
.app[data-theme="berry"] { --hit: #8d4fb8; --near: #e3895e; --miss: #857781; }
.app[data-theme="midnight"] { --hit: #3f7fd8; --near: #d8a23a; --miss: #5b6075; }
.app[data-theme="gold"] { --hit: #b8862b; --near: #4f9aa0; --miss: #857b70; }
.app.contrast, .contrast-demo { --hit: #e66100 !important; --near: #3d8fd1 !important; --miss: #6f6762 !important; }

/* ---- top bar ---- */
.bar { width: 100%; max-width: 520px; display: grid; grid-template-columns: 48px 1fr 48px; align-items: center; gap: 8px; }
.icon-btn {
  width: 48px; height: 48px; display: grid; place-items: center; border: 0; border-radius: 16px;
  background: rgba(255, 255, 255, 0.7); box-shadow: 0 2px 0 rgba(74, 47, 34, 0.12); cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn svg { width: 24px; height: 24px; fill: none; stroke: var(--ink); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:active { transform: scale(0.94); }
.switch {
  justify-self: center; display: flex; padding: 4px; gap: 4px; border-radius: 999px;
  background: rgba(74, 47, 34, 0.1); min-width: 0;
}
.sw {
  min-height: 44px; min-width: 92px; padding: 2px 14px 0; border: 0; border-radius: 999px; background: transparent;
  font-weight: 800; font-size: 17px; line-height: 1; color: var(--ink-soft); cursor: pointer; position: relative;
  -webkit-tap-highlight-color: transparent; white-space: nowrap;
}
.sw[aria-selected="true"] { background: #fff; color: var(--ink); box-shadow: 0 2px 0 rgba(74, 47, 34, 0.14); }
.sw .dot { position: absolute; top: 5px; right: 8px; width: 9px; height: 9px; border-radius: 50%; background: var(--hit); box-shadow: 0 0 0 2px #fff; }
.sw .dot.x { background: var(--miss); }

/* ---- the line under the bar, and the cat in the corner ---- */
.info { width: 100%; max-width: 520px; display: flex; align-items: flex-end; justify-content: space-between; gap: 8px; min-height: 80px; padding: 0 4px; }
.sub { margin: 0 0 6px; font-weight: 800; font-size: 16px; line-height: 1.2; color: var(--ink-soft); min-width: 0; }
.sub b { color: var(--ink); }
.sub .tag { display: inline-block; margin-left: 6px; padding: 1px 8px 0; border-radius: 999px; background: #e9d3f2; color: #5c2f7a; font-size: 13px; }
.buddy { position: relative; display: flex; align-items: flex-end; gap: 6px; flex: none; }
.buddy-cat { width: 80px; height: 92px; margin-bottom: -6px; transform-origin: 50% 100%; }
.buddy-cat svg { width: 100%; height: 100%; display: block; }
.bubble {
  position: absolute; right: calc(100% + 2px); top: 2px; z-index: 2; width: max-content; max-width: min(230px, calc(100vw - 120px));
  margin: 0; padding: 6px 11px 4px; border-radius: 14px;
  background: #fff; color: var(--ink); font-weight: 700; font-size: 14px; line-height: 1.2;
  box-shadow: 0 3px 10px -4px rgba(74, 47, 34, 0.4); opacity: 0; transform: translateY(6px) scale(0.9);
  transition: opacity 0.18s, transform 0.18s; pointer-events: none;
}
.bubble::after { content: ""; position: absolute; right: -6px; top: 12px; border: 7px solid transparent; border-left-color: #fff; border-right: 0; }
.bubble.on { opacity: 1; transform: none; }
.buddy-cat.hop { animation: hop 0.5s ease-out; }
.buddy-cat.wiggle { animation: wiggle 0.45s ease-in-out; }
.buddy-cat.cheer { animation: cheer 0.9s ease-out 2; }
.buddy-cat.sad { animation: sad 0.8s ease-out forwards; }
.buddy-cat.leap { animation: leap 1.1s cubic-bezier(.3,.7,.3,1); }
.buddy-cat.phew { animation: phew 1.2s ease-in-out; }
.buddy-cat.sad-still { transform: rotate(-8deg) translateY(4px); filter: saturate(0.6); }
@keyframes hop { 0%, 100% { transform: none; } 35% { transform: translateY(-12px) scale(1.04, 0.96); } 60% { transform: translateY(0) scale(1.05, 0.95); } }
@keyframes wiggle { 0%, 100% { transform: none; } 25% { transform: rotate(-9deg); } 75% { transform: rotate(9deg); } }
@keyframes cheer { 0%, 100% { transform: none; } 30% { transform: translateY(-18px) rotate(-6deg); } 60% { transform: translateY(-6px) rotate(6deg); } }
@keyframes leap { 0%, 100% { transform: none; } 18% { transform: translateY(4px) scale(1.08, 0.9); } 45% { transform: translateY(-26px) rotate(-8deg) scale(0.96, 1.06); } 70% { transform: translateY(0) scale(1.07, 0.93); } 85% { transform: translateY(-6px); } }
@keyframes phew { 0%, 100% { transform: none; } 30% { transform: rotate(-7deg) translateY(3px); } 55% { transform: rotate(5deg); } 75% { transform: translateY(-8px); } }
@keyframes sad { to { transform: rotate(-8deg) translateY(4px); filter: saturate(0.6); } }

/* ---- the board ---- */
.stage { flex: 1; min-height: 0; width: 100%; display: flex; align-items: center; justify-content: center; }
.board { display: grid; gap: var(--gap); }
.row { display: grid; grid-auto-flow: column; grid-auto-columns: var(--tile); gap: var(--gap); }
.tile {
  position: relative; width: var(--tile); height: var(--tile); display: grid; place-items: center;
  border-radius: calc(var(--tile) * 0.2); border: 2.5px solid rgba(74, 47, 34, 0.16); background: rgba(255, 255, 255, 0.55);
  font-weight: 800; font-size: calc(var(--tile) * 0.56); line-height: 1; text-transform: uppercase; color: var(--ink);
  padding-top: calc(var(--tile) * 0.08);
}
.tile.full { border-color: rgba(74, 47, 34, 0.45); background: #fff; animation: pop 0.1s ease-out; }
.tile.hit, .tile.near, .tile.miss { border-color: transparent; color: #fff; text-shadow: 0 1px 0 rgba(0, 0, 0, 0.16); }
.tile.hit { background: var(--hit); }
.tile.near { background: var(--near); }
.tile.miss { background: var(--miss); }
.tile.flip { animation: flip 0.46s ease-in-out both; }
/* contrast mode also marks the tiles: a corner for right spot, a dot for in the word */
.contrast .tile.hit::after, .contrast-demo .tile.hit::after { content: ""; position: absolute; top: 4px; right: 4px; border: calc(var(--tile) * 0.12) solid #fff; border-bottom-color: transparent; border-left-color: transparent; border-radius: 0 6px 0 0; opacity: 0.9; }
.contrast .tile.near::after, .contrast-demo .tile.near::after { content: ""; position: absolute; top: 6px; right: 6px; width: calc(var(--tile) * 0.14); height: calc(var(--tile) * 0.14); border-radius: 50%; background: #fff; opacity: 0.9; }
.row.shake { animation: shake 0.42s ease-in-out; }
.row.bounce .tile { animation: bounce 0.5s ease-out both; }
@keyframes pop { 0% { transform: scale(0.86); } 60% { transform: scale(1.08); } 100% { transform: none; } }
@keyframes flip { 0% { transform: rotateX(0); } 50% { transform: rotateX(90deg); } 100% { transform: rotateX(0); } }
@keyframes shake { 0%, 100% { transform: none; } 20% { transform: translateX(-8px); } 40% { transform: translateX(8px); } 60% { transform: translateX(-6px); } 80% { transform: translateX(5px); } }
@keyframes bounce { 0%, 100% { transform: none; } 40% { transform: translateY(-14px); } 70% { transform: translateY(2px); } }

/* ---- messages ---- */
.toast {
  position: fixed; left: 50%; top: calc(env(safe-area-inset-top, 0px) + 128px); z-index: 5; margin: 0; max-width: calc(100% - 32px);
  padding: 9px 16px 7px; border-radius: 14px; background: var(--ink); color: #fff; font-weight: 800; font-size: 16px; line-height: 1.2;
  text-align: center; transform: translate(-50%, -8px); opacity: 0; pointer-events: none; transition: opacity 0.15s, transform 0.15s;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }

/* ---- the finished puzzle: result and countdown, in the keyboard's place ---- */
.done {
  width: 100%; max-width: 520px; flex: none; display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 12px 12px 6px; border-radius: 22px; background: rgba(255, 255, 255, 0.8); box-shadow: 0 6px 18px -12px rgba(74, 47, 34, 0.55);
}
.done[hidden] { display: none; }
.done-title { margin: 0; font-weight: 800; font-size: 22px; line-height: 1.15; text-align: center; }
.done-next { margin: 0; font-weight: 700; font-size: 16px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.done-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; width: 100%; padding: 4px 0 2px; }
.pill {
  min-height: 48px; padding: 4px 18px 0; border: 0; border-radius: 16px; background: rgba(74, 47, 34, 0.1);
  font-weight: 800; font-size: 17px; cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.pill.primary { background: var(--accent); color: #fff; }
.pill:active { transform: scale(0.97); }
.pill[hidden] { display: none; }

/* ---- the keyboard: each key's button fills its whole cell (no dead gaps); the cap inside is what you see ---- */
.keys { width: calc(100% + 12px); margin: 0 -6px; max-width: 532px; flex: none; display: flex; flex-direction: column; padding-top: 4px; }
.keys[hidden] { display: none; }
.krow { display: flex; justify-content: center; }
.key {
  flex: 0 0 auto; width: calc(100% / 10); height: var(--key-h); padding: 3px 2px; border: 0; background: transparent;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.key.wide { width: calc(100% * 1.5 / 10); }
.key .cap {
  display: grid; place-items: center; width: 100%; height: 100%; border-radius: 10px;
  background: #fffaf3; box-shadow: 0 2px 0 rgba(74, 47, 34, 0.22); color: var(--ink);
  font-weight: 800; font-size: 20px; line-height: 1; text-transform: uppercase; padding-top: 2px;
}
.key.wide .cap { font-size: 14px; letter-spacing: 0.02em; }
.key .cap svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.key.down .cap { transform: translateY(2px) scale(1.1); box-shadow: none; filter: brightness(0.94); }
.key .cap { transition: transform 0.09s ease-out; }
.key.hit .cap { background: var(--hit); color: #fff; }
.key.near .cap { background: var(--near); color: #fff; }
.key.miss .cap { background: var(--miss); color: #fff; opacity: 0.85; }
.krow .half { flex: 0 0 auto; width: calc(100% / 20); }

/* ---- sheets (stats, archive, sticker book, results) ---- */
.pd-tabs { display: flex; gap: 6px; padding: 4px; border-radius: 999px; background: rgba(74, 47, 34, 0.09); margin: 0 0 6px; }
.pd-tabs button { flex: 1; min-height: 44px; border: 0; border-radius: 999px; background: transparent; font-weight: 800; font-size: 16px; cursor: pointer; color: var(--ink-soft); }
.pd-tabs button[aria-selected="true"] { background: #fff; color: var(--ink); box-shadow: 0 2px 0 rgba(74, 47, 34, 0.14); }
.pd-nums { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 4px 0 6px; }
.pd-num { text-align: center; }
.pd-num b { display: block; font-size: 30px; line-height: 1.05; }
.pd-num span { display: block; font-size: 13px; font-weight: 700; line-height: 1.15; color: var(--ink-soft); }
.pd-h { margin: 8px 0 2px; font-weight: 800; font-size: 17px; }
.pd-dist { display: grid; gap: 5px; }
.pd-bar { display: grid; grid-template-columns: 22px 1fr; align-items: center; gap: 6px; font-weight: 800; font-size: 15px; }
.pd-bar i {
  display: block; min-width: 28px; padding: 2px 8px 0; border-radius: 6px; background: var(--miss); color: #fff; text-align: right;
  font-style: normal; line-height: 22px; transition: width 0.4s;
}
.pd-bar.me i { background: var(--hit); }
.pd-note { margin: 6px 0 0; font-weight: 700; font-size: 15px; line-height: 1.35; color: var(--ink-soft); }
.pd-next { margin: 10px 0 0; text-align: center; font-weight: 800; font-size: 17px; font-variant-numeric: tabular-nums; }
.pd-share { width: 100%; min-height: 50px; margin-top: 8px; border: 0; border-radius: 16px; background: var(--accent); color: #fff; font-weight: 800; font-size: 18px; cursor: pointer; }
.pd-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.pd-day {
  width: 100%; min-height: 52px; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 14px 4px;
  border: 1px solid var(--line); border-radius: 14px; background: #fff; text-align: left; cursor: pointer; font-weight: 800; font-size: 16px;
}
.pd-day small { display: block; font-weight: 700; font-size: 13px; color: var(--ink-soft); }
.pd-day .chip { flex: none; padding: 3px 10px 1px; border-radius: 999px; font-size: 14px; background: rgba(74, 47, 34, 0.08); }
.pd-day .chip.win { background: var(--hit); color: #fff; }
.pd-day .chip.lose { background: var(--miss); color: #fff; }
.pd-day .chip.go { background: var(--accent); color: #fff; }
.pd-day .pd-word { margin-left: 8px; letter-spacing: 0.08em; }
.pd-nums.two { grid-template-columns: repeat(2, 1fr); }
.pd-mini { display: grid; gap: 5px; justify-content: center; margin: 10px 0 4px; --tile: 44px; }
.pd-mini .row { display: flex; gap: 5px; }
.pd-mini .tile { font-size: 24px; }
.pd-day:disabled { cursor: default; background: rgba(255, 255, 255, 0.5); }
.pd-more { min-height: 48px; border: 0; border-radius: 14px; background: rgba(74, 47, 34, 0.09); font-weight: 800; font-size: 16px; cursor: pointer; }
.pd-stickers { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 8px; }
.pd-sticker {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 104px; padding: 4px;
  border: 2px solid transparent; border-radius: 16px; background: rgba(255, 255, 255, 0.7); cursor: pointer;
}
.pd-sticker svg { width: 84px; height: auto; display: block; }
.pd-sticker small { font-weight: 700; font-size: 12px; line-height: 1.1; color: var(--ink-soft); text-align: center; }
.pd-sticker[aria-pressed="true"] { border-color: var(--accent); background: #fff; }
.pd-sticker.locked { cursor: default; background: rgba(74, 47, 34, 0.06); }
.pd-sticker.locked .q { width: 54px; height: 54px; display: grid; place-items: center; border-radius: 50%; border: 2px dashed rgba(74, 47, 34, 0.3); font-weight: 800; font-size: 26px; color: rgba(74, 47, 34, 0.4); }
.pd-themes { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.pd-theme { min-height: 64px; display: grid; gap: 4px; justify-items: center; padding: 8px 4px 4px; border: 2px solid transparent; border-radius: 14px; background: rgba(255, 255, 255, 0.7); cursor: pointer; font-weight: 800; font-size: 14px; }
.pd-theme .sw3 { display: flex; gap: 3px; }
.pd-theme .sw3 i { width: 20px; height: 20px; border-radius: 6px; }
.pd-theme[aria-pressed="true"] { border-color: var(--accent); background: #fff; }
.pd-theme:disabled { cursor: default; opacity: 0.55; }
.pd-paws { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-weight: 800; }
.pd-example { display: flex; gap: 5px; margin: 4px 0 2px; --tile: 40px; }
.pd-example .tile { font-size: 22px; }
.pd-ach { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.pd-ach li { display: flex; gap: 10px; align-items: center; padding: 8px 12px 6px; border-radius: 14px; background: rgba(255, 255, 255, 0.7); font-weight: 700; font-size: 15px; line-height: 1.25; }
.pd-ach li b { display: block; font-size: 16px; }
.pd-ach li.no { opacity: 0.55; }
.pd-ach .medal { flex: none; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: #f4c44e; color: #6b4a0c; font-weight: 800; }
.pd-ach li.no .medal { background: rgba(74, 47, 34, 0.14); color: transparent; }

/* ---- the title screen's colors (the layout is shared/mainmenu.js) ---- */
#mm {
  --sg-bg: radial-gradient(ellipse 100% 70% at 50% 25%, var(--bg-hi), transparent 75%), var(--bg);
  --sg-ink: var(--ink); --sg-ink-soft: var(--ink-soft);
  --sg-title: var(--accent-dark); --sg-title-shadow: 0 2px 0 #fff;
  --sg-accent: var(--accent); --sg-accent-ink: #fff;
  --sg-card: #fff; --sg-card-ink: var(--ink); --sg-line: rgba(74, 47, 34, 0.18);
}
#mm .pd-title-art { width: 167px; height: 150px; }
#mm .pd-title-art svg { display: block; width: 100%; height: 100%; }
.sg-sheet { --sg-sheet-bg: var(--sheet); --sg-sheet-ink: var(--ink); --sg-accent: var(--accent); --sg-accent-ink: #fff; --sg-ink-soft: var(--ink-soft); }

@media (prefers-reduced-motion: reduce) {
  .key .cap { transition: none; }
  .key.down .cap { transform: none; }
  .tile.full, .tile.flip, .row.bounce .tile, .buddy-cat.hop, .buddy-cat.wiggle, .buddy-cat.cheer, .buddy-cat.leap, .buddy-cat.phew { animation: none; }
  .tile.flip { animation: fadein 0.2s ease-out both; }
  .row.shake { animation: none; box-shadow: 0 0 0 3px rgba(214, 69, 58, 0.55); border-radius: 12px; }
  .buddy-cat.sad { animation: none; transform: rotate(-4deg); }
  .bubble, .toast, .pd-bar i { transition: none; }
  @keyframes fadein { from { opacity: 0.4; } to { opacity: 1; } }
}
