:root {
    --bg: #fffbf0;
    --bg-soft: #fff5d6;
    --text: #3a2a07;
    --text-muted: #8a7340;
    --accent: #e6a300;
    --accent-soft: #ffe896;
    --border: #f0e0a8;
    --shadow: 0 6px 18px rgba(160, 110, 0, 0.12);
}
[data-theme="dark"] {
    --bg: #1a1408;
    --bg-soft: #251c0e;
    --text: #f5e8c0;
    --text-muted: #a08848;
    --accent: #e6a300;
    --accent-soft: #3d2e00;
    --border: #3c2e12;
    --shadow: 0 6px 18px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }
/* The browser's default `[hidden] { display: none }` has the same
   specificity as any class-based `display:` rule and loses by source
   order, so a `.stat { display: flex }` (or grid/etc.) ends up
   showing tiles that JS marked hidden. Re-assert with !important so
   the HTML `hidden` attribute always wins. */
[hidden] { display: none !important; }

html, body {
    margin: 0; padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter",
                 "Segoe UI", Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.4;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    min-height: 100vh;
    /* No horizontal page scroll — the bowl/page shouldn't slide
       sideways even if a child somehow overflows. */
    overflow-x: hidden;
    /* Disable text selection across the whole UI — it's a game, not
       a document. Inputs/textareas re-enable it explicitly below. */
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}
input, textarea { -webkit-user-select: text; user-select: text; }

.page {
    max-width: 480px;
    margin: 0 auto;
    padding: 20px 18px 40px;
}

/* --- Hero --- */

.hero { text-align: center; margin-bottom: 18px; }
.title {
    margin: 0;
    font-size: 28px;
    font-weight: 800;
    letter-spacing: -0.01em;
}
.tag { margin: 4px 0 0; color: var(--text-muted); font-style: italic; font-size: 14px; }

/* --- Banana card --- */

.banana-card {
    background: var(--bg-soft);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 24px 18px;
    text-align: center;
    box-shadow: var(--shadow);
    margin-bottom: 18px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.banana-emoji-btn {
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    position: relative;
    width: 140px;
    height: 140px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.banana-emoji-btn:active { transform: scale(0.97); transition: transform 60ms; }

.banana-emoji {
    font-size: 110px;
    line-height: 1;
    display: inline-block;
    animation: breathe 4s ease-in-out infinite;
    transform-origin: 50% 80%;
}

.pats-pill {
    position: absolute;
    top: 0;
    right: 0;
    background: var(--bg);
    color: var(--accent);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 2px 8px;
    font-size: 11px;
    font-weight: 800;
}

/* Bonus composts banked from swatted flies — appears top-left of the
   banana button during the compost stage. */
.swat-pill {
    position: absolute;
    top: 0;
    left: 0;
    background: var(--bg);
    color: #6b4310;
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 2px 8px;
    font-size: 11px;
    font-weight: 800;
}

/* Fly swarm overlay inside the banana button. The container itself
   doesn't intercept clicks; the .fly children re-enable pointer
   events so each one is its own tap target. */
.flies {
    position: absolute;
    inset: 0;
    pointer-events: none;
    overflow: visible;
}
.fly {
    position: absolute;
    pointer-events: auto;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    will-change: transform, opacity;
    /* Outer span: walks from spawn → destination AND fades in/out
       over the full lifetime (set via --life on the element). */
    opacity: 0;
    animation: flyWalk var(--life, 18s) ease-in-out forwards,
               flyFade var(--life, 18s) ease-in-out forwards;
}
.fly-inner {
    display: inline-block;
    font-size: 13px;        /* deliberately small — mosquito-ish */
    line-height: 1;
    /* Inner span: continuous wiggle. Independent of the outer walk
       so they compose cleanly (both touch `transform`). */
    animation: flyWiggle 380ms ease-in-out infinite alternate;
    will-change: transform;
}
.fly.swatted {
    animation: flySwat 260ms ease-out forwards;
    pointer-events: none;
}
.fly.swatted .fly-inner { animation: none; }
@keyframes flyWalk {
    from { transform: translate(0, 0); }
    to   { transform: translate(var(--dx, 0px), var(--dy, 0px)); }
}
@keyframes flyFade {
    0%, 100% { opacity: 0; }
    10%, 85% { opacity: 1; }
}
@keyframes flyWiggle {
    from { transform: rotate(-9deg) translateX(-1px); }
    to   { transform: rotate(9deg)  translateX(1px); }
}
@keyframes flySwat {
    to { transform: scale(0.15) rotate(180deg); opacity: 0; }
}

.hearts {
    position: absolute;
    inset: 0;
    pointer-events: none;
    overflow: visible;
}
.heart {
    position: absolute;
    font-size: 22px;
    animation: floatUp 800ms ease-out forwards;
    pointer-events: none;
}
@keyframes floatUp {
    0%   { transform: translate(-50%, 0) scale(0.6); opacity: 1; }
    100% { transform: translate(-50%, -90px) scale(1.3); opacity: 0; }
}

@keyframes breathe {
    0%, 100% { transform: rotate(-3deg) scale(1.0); }
    50%      { transform: rotate(3deg) scale(1.05); }
}

.banana-status {
    color: var(--text-muted);
    font-size: 14px;
    font-weight: 600;
    min-height: 20px;
}

/* Segmented progress bar — vertical ticks at the stage thresholds
   (4%, 12%, 32%, 60% of total lifetime). The fill is a solid accent
   color now (the rainbow gradient looked janky), and the transition
   is snappy (200ms) so updates don't feel laggy. */
.banana-progress {
    position: relative;
    width: 100%;
    height: 8px;
    background: var(--border);
    border-radius: 999px;
    overflow: hidden;
}
.banana-progress-fill {
    height: 100%;
    background: var(--accent);
    /* 1s linear transition matches the 1Hz extrapolation tick — the
       bar slides smoothly between updates instead of stepping. */
    transition: width 1s linear;
    width: 0%;
    border-radius: 999px;
}
.banana-progress-tick {
    position: absolute;
    top: 0; bottom: 0;
    width: 2px;
    background: var(--bg);
    pointer-events: none;
}
[data-theme="dark"] .banana-progress-tick { background: rgba(0,0,0,0.5); }

/* Bonus floater near a pat: animates up + fades out. */
.pat-bonus-float {
    position: absolute;
    pointer-events: none;
    color: var(--accent);
    font-weight: 800;
    font-size: 14px;
    text-shadow: 0 1px 2px rgba(0,0,0,0.25);
    animation: bonusFloat 850ms ease-out forwards;
}
@keyframes bonusFloat {
    0%   { transform: translate(0, 0) scale(0.9); opacity: 1; }
    100% { transform: translate(8px, -50px) scale(1.1); opacity: 0; }
}

.action-row {
    display: flex;
    flex-direction: column;        /* stack on small screens — readable at 320px */
    gap: 8px;
    width: 100%;
}
@media (min-width: 380px) {
    .action-row { flex-direction: row; }
}

.primary-btn {
    background: var(--accent);
    color: #1f1503;
    border: none;
    border-radius: 14px;
    padding: 14px 18px;
    font-size: 16px;
    font-weight: 800;
    cursor: pointer;
    box-shadow: var(--shadow);
    transition: transform 100ms ease, opacity 100ms ease;
    flex: 1;
    min-width: 0;                  /* allow shrinking inside the row */
}
.primary-btn:active { transform: scale(0.97); }
.primary-btn:disabled { opacity: 0.4; cursor: default; }

.primary-btn-alt {
    background: var(--bg);
    color: var(--accent);
    border: 1px solid var(--accent);
    box-shadow: none;
}

.link-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 13px;
    text-decoration: underline;
    cursor: pointer;
    padding: 4px;
}

/* --- Profile dialog --- */

.dialog {
    border: none;
    border-radius: 18px;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    width: min(92vw, 380px);
    max-height: 84vh;
    overflow: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.25);
}
.dialog::backdrop { background: rgba(0,0,0,0.5); }
.dialog-body {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    position: relative;
}
.dialog-close {
    position: absolute;
    top: 6px; right: 10px;
    background: none;
    border: none;
    font-size: 24px;
    color: var(--text-muted);
    cursor: pointer;
}

.profile-header {
    display: flex;
    align-items: center;
    gap: 14px;
}
.profile-emoji { font-size: 56px; line-height: 1; }
.profile-name { font-size: 20px; font-weight: 800; }
.profile-sub { color: var(--text-muted); font-size: 13px; }

.profile-stats {
    display: flex;
    gap: 8px;
}
.profile-stats > div {
    flex: 1;
    background: var(--bg-soft);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 8px 4px;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: 11px;
    color: var(--text-muted);
}
.profile-stats strong { font-size: 18px; color: var(--text); }

.section-label {
    font-size: 11px;
    font-weight: 800;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-top: 4px;
}

.profile-history {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 13px;
}
.profile-history .row {
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 4px 0;
}
.profile-history .empty { color: var(--text-muted); font-style: italic; padding: 8px 0; }

/* --- Stats --- */

.stats {
    /* Grid auto-wraps the stats — at 6+ tiles they stack onto two
       rows instead of forcing a horizontal scroll. */
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(76px, 1fr));
    gap: 8px;
    margin-bottom: 22px;
}
.stat {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 8px;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;          /* allow shrinking inside the grid cell */
}
.stat-emoji { font-size: 16px; }
.stat-num { font-size: 18px; font-weight: 800; }
.stat-label { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
/* Bonus chip — small accent that slides into the compost tile after
   the first compost to show the merged growth multiplier. */
.stat-bonus {
    margin-top: 2px;
    font-size: 10px;
    font-weight: 800;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* --- The bowl --- */

.bowl-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin: 0 4px 10px;
}
.bowl-title { font-size: 16px; font-weight: 800; }
.bowl-count { color: var(--text-muted); font-size: 12px; }

.bowl-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.bowl-row {
    display: grid;
    grid-template-columns: 38px 1fr auto;
    gap: 10px;
    align-items: center;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 8px 12px;
}
.bowl-row.me {
    background: var(--accent-soft);
    border-color: var(--accent);
}
.bowl-row .emoji { font-size: 22px; text-align: center; }
.bowl-row .name { font-weight: 700; }
/* Only the avatar + name open the profile — give them a tap cue. */
.bowl-row .tap-profile { cursor: pointer; }
.bowl-row .name.tap-profile { display: inline-block; }
.bowl-row .tap-profile:active { opacity: 0.55; }
.bowl-row .meta { color: var(--text-muted); font-size: 12px; }
.bowl-row .age { color: var(--text-muted); font-size: 12px; font-variant-numeric: tabular-nums; }

/* Lifetime tally under each bowl row — eaten / baked / composted. */
.bowl-tally {
    display: flex;
    gap: 8px;
    margin-top: 2px;
    color: var(--text-muted);
    font-size: 11px;
    font-variant-numeric: tabular-nums;
}
.bowl-tally span { white-space: nowrap; }
.bowl-tally .bowl-speed {
    color: var(--accent);
    font-weight: 600;
}

/* --- Reactions v2 (feedback #15) ----------------------------------- */

/* Tally chips — read-only counts on every row. */
.bowl-react-summary {
    margin-top: 4px;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}
.bowl-react-tally {
    background: var(--bg-soft);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 2px 8px;
    font-size: 12px;
}

/* Picker chips — only on other people's rows. Bouncy on tap. */
.bowl-react-picker {
    margin-top: 6px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.bowl-react-btn {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 16px;
    cursor: pointer;
    line-height: 1;
    transition: transform 80ms ease, background 120ms ease;
}
.bowl-react-btn:active,
.bowl-react-btn.bowl-react-pop {
    transform: scale(1.25);
    background: var(--accent-soft);
}
/* Combo progress: emoji already tapped on this player in the window. */
.bowl-react-btn.done {
    background: var(--accent);
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-soft);
}
.bowl-combo-count {
    align-self: center;
    font-size: 11px;
    font-weight: 700;
    color: var(--accent);
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--accent-soft);
}
.bowl-combo-count.ready {
    background: var(--accent);
    color: #1a1207;
    animation: comboPulse 700ms ease-in-out infinite;
}
@keyframes comboPulse {
    0%, 100% { transform: scale(1); }
    50%      { transform: scale(1.12); }
}

/* Online dot — who you can earn a combo boost from right now. */
.online-dot {
    display: inline-block;
    width: 8px; height: 8px;
    margin-right: 6px;
    border-radius: 999px;
    background: #3fb950;
    vertical-align: middle;
    box-shadow: 0 0 0 2px rgba(63, 185, 80, 0.25);
}

/* React-combo reward banner — live while the boost is running. */
.boost-banner {
    margin: 14px 0 0;
    padding: 10px 14px;
    border-radius: 12px;
    background: var(--accent);
    color: #1a1207;
    font-weight: 800;
    font-size: 14px;
    text-align: center;
    box-shadow: var(--shadow);
    animation: comboPulse 1600ms ease-in-out infinite;
}

/* --- BIG splash for incoming reactions (receiver side) ------------- */
.react-splash {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    z-index: 1000;
    animation: reactSplashIn 250ms ease-out,
               reactSplashOut 400ms ease-in 1600ms forwards;
}
.react-splash-name {
    background: var(--accent);
    color: #1a1207;
    font-weight: 800;
    font-size: 18px;
    padding: 8px 22px;
    border-radius: 999px;
    box-shadow: 0 6px 24px rgba(0,0,0,0.35);
    margin-bottom: 18px;
}
.react-splash-emojis {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 16px;
    max-width: 88vw;
}
.react-splash-emoji {
    font-size: 84px;
    line-height: 1;
    filter: drop-shadow(0 8px 16px rgba(0,0,0,0.35));
    animation: reactEmojiPop 800ms cubic-bezier(0.34, 1.56, 0.64, 1) backwards;
}
@keyframes reactSplashIn {
    from { opacity: 0; transform: scale(0.92); }
    to   { opacity: 1; transform: scale(1); }
}
@keyframes reactSplashOut {
    from { opacity: 1; }
    to   { opacity: 0; transform: scale(0.96); }
}
@keyframes reactEmojiPop {
    0%   { opacity: 0; transform: scale(0) rotate(-15deg); }
    60%  { opacity: 1; transform: scale(1.25) rotate(5deg); }
    100% { opacity: 1; transform: scale(1) rotate(0); }
}

.history { margin-top: 24px; }
/* Native <details> collapse: hide the default disclosure triangle and
   use our own chevron that rotates 90° when open. */
details.history > summary { cursor: pointer; list-style: none; user-select: none; }
details.history > summary::-webkit-details-marker { display: none; }
details.history > summary::marker { content: ""; }
.history-chevron {
    margin-left: 8px;
    color: var(--text-muted);
    font-size: 14px;
    transition: transform 200ms ease;
    display: inline-block;
    transform-origin: 50% 55%;
}
details.history[open] .history-chevron { transform: rotate(90deg); }
.history-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.history-row {
    display: grid;
    grid-template-columns: 28px 1fr auto;
    gap: 10px;
    align-items: center;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 6px 12px;
    font-size: 13px;
}
.history-row .end-emoji { font-size: 18px; text-align: center; }
.history-row .meta { color: var(--text-muted); font-size: 11px; }
.history-row .age { color: var(--text-muted); font-size: 11px; }

.empty { color: var(--text-muted); text-align: center; font-style: italic; padding: 16px; }

/* --- Footer --- */

.footer {
    text-align: center;
    padding: 18px 0 4px;
    color: var(--text-muted);
    font-size: 11px;
    opacity: 0.6;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
}
.footer-btn {
    background: none;
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 3px 11px;
    color: var(--text-muted);
    font: inherit;
    font-size: 11px;
    cursor: pointer;
    touch-action: manipulation;
}
.footer-btn:active { transform: scale(0.95); }

/* --- Toast --- */

.toast {
    position: fixed;
    bottom: calc(20px + env(safe-area-inset-bottom));
    left: 50%;
    transform: translateX(-50%);
    background: var(--text);
    color: var(--bg);
    border-radius: 999px;
    padding: 10px 18px;
    font-size: 13px;
    font-weight: 700;
    box-shadow: var(--shadow);
    z-index: 1000;
    pointer-events: none;
}

/* Stage tints over the banana */
.stage-green   .banana-emoji { filter: hue-rotate(50deg) saturate(0.85); }
.stage-yellow  .banana-emoji { /* default */ }
.stage-spotted .banana-emoji { filter: brightness(0.92) saturate(1.05); }
.stage-brown   .banana-emoji { filter: brightness(0.55) saturate(0.6) sepia(0.5); }
.stage-compost .banana-emoji { filter: grayscale(0.7) brightness(0.8); animation-duration: 8s; }
/* Rotten — even more grey, slower wobble, slight tilt to feel sad. */
.stage-rotten  .banana-emoji {
    filter: grayscale(0.95) brightness(0.55) contrast(0.85);
    animation-duration: 12s;
}
.stage-rotten.banana-card { border-color: rgba(120, 90, 70, 0.5); }

/* --- Monkey card ---------------------------------------------------- */

.monkey-card {
    background: var(--bg-soft);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 16px;
    margin-bottom: 18px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.monkey-main, .monkey-locked {
    display: flex;
    align-items: center;
    gap: 14px;
}
.monkey-emoji { font-size: 46px; line-height: 1; flex: none; }
.monkey-emoji.dim { filter: grayscale(1); opacity: 0.45; }

.monkey-info { flex: 1; min-width: 0; }
.monkey-level {
    font-weight: 800;
    font-size: 16px;
    text-transform: capitalize;
}
.monkey-meta {
    color: var(--text-muted);
    font-size: 12px;
    margin-top: 2px;
}
.monkey-hungry  { color: #e5484d; font-weight: 700; }
.monkey-content { color: #3fa860; font-weight: 700; }

.monkey-xpbar {
    height: 7px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 999px;
    overflow: hidden;
    margin: 5px 0;
}
.monkey-xpfill {
    height: 100%;
    background: var(--accent);
    border-radius: 999px;
    transition: width 300ms ease;
}

.monkey-feed-btn {
    width: 100%;
    background: var(--accent);
    color: #1a1207;
    border: none;
    border-radius: 12px;
    padding: 12px;
    font-size: 15px;
    font-weight: 800;
    cursor: pointer;
}
.monkey-feed-btn:active { transform: scale(0.98); }
.monkey-feed-btn:disabled {
    background: var(--bg);
    color: var(--text-muted);
    border: 1px solid var(--border);
    cursor: default;
}
.monkey-hint, .monkey-raidline {
    font-size: 12px;
    color: var(--text-muted);
    text-align: center;
}
.monkey-raidline { font-weight: 600; }

/* Monkey badge on bowl rows + the raid button. */
.bowl-monkey { margin-left: 5px; font-size: 13px; }
.bowl-raid-btn {
    margin-top: 6px;
    background: var(--bg);
    border: 1px solid var(--accent);
    color: var(--accent);
    border-radius: 999px;
    padding: 5px 12px;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
}
.bowl-raid-btn:active { transform: scale(0.96); }
.bowl-raid-btn:disabled { opacity: 0.5; cursor: default; }

/* --- Incoming raid alert ------------------------------------------- */

.raid-alert {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    top: calc(12px + env(safe-area-inset-top, 0px));
    z-index: 1200;
    width: min(440px, calc(100vw - 24px));
    background: #e5484d;
    color: #fff;
    border-radius: 14px;
    padding: 12px 16px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
    text-align: center;
    animation: raidPulse 900ms ease-in-out infinite;
}
@keyframes raidPulse {
    0%, 100% { transform: translateX(-50%) scale(1); }
    50%      { transform: translateX(-50%) scale(1.025); }
}
.raid-alert-text { font-size: 14px; font-weight: 700; }
.raid-alert-count {
    font-size: 12px;
    opacity: 0.9;
    margin: 3px 0 8px;
    font-variant-numeric: tabular-nums;
}
.raid-alert-btn {
    background: #fff;
    color: #c0322f;
    border: none;
    border-radius: 999px;
    padding: 9px 22px;
    font-size: 14px;
    font-weight: 800;
    cursor: pointer;
}
.raid-alert-btn:active { transform: scale(0.96); }

/* The tap-frenzy shoo mini-game inside the raid alert. */
.raid-monkey {
    display: inline-block;
    background: rgba(255, 255, 255, 0.12);
    border: none;
    border-radius: 999px;
    padding: 10px 22px;
    margin: 8px auto 6px;
    cursor: pointer;
    font-size: 56px;
    line-height: 1;
    animation: raidMonkeyWiggle 520ms ease-in-out infinite;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.18) inset;
    -webkit-tap-highlight-color: transparent;
    /* Disable double-tap-zoom heuristics on the tap target so rapid
       taps fire without the browser stalling. */
    touch-action: manipulation;
    user-select: none;
}
.raid-monkey:active { background: rgba(255, 255, 255, 0.2); }
.raid-monkey-inner {
    display: inline-block;
    transform-origin: center;
}
.raid-monkey.tap-bounce .raid-monkey-inner {
    animation: raidMonkeyTap 220ms ease-out;
}
.raid-monkey.flee {
    animation: raidMonkeyFlee 360ms cubic-bezier(0.3, 0, 0.7, 0.2) forwards;
    pointer-events: none;
}
@keyframes raidMonkeyWiggle {
    0%, 100% { transform: rotate(-6deg) translateY(0); }
    50%      { transform: rotate(6deg)  translateY(-2px); }
}
@keyframes raidMonkeyTap {
    0%   { transform: scale(1.4); }
    100% { transform: scale(1); }
}
@keyframes raidMonkeyFlee {
    to { transform: translate(160px, -240px) rotate(540deg) scale(0.35); opacity: 0; }
}

.raid-meter {
    height: 10px;
    width: min(260px, 80%);
    margin: 4px auto 6px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 999px;
    overflow: hidden;
}
.raid-meter-fill {
    height: 100%;
    width: 100%;
    /* Animate transform (GPU-composited) instead of width — width
       changes trigger layout on every frame, which the WebView paints
       in chunks and looks jumpy. transform: scaleX glides smoothly. */
    transform: scaleX(0);
    transform-origin: left center;
    background: linear-gradient(90deg, #fff5d6, #fff);
    transition: transform 140ms linear;
    will-change: transform;
}
.raid-hint {
    font-size: 12px;
    opacity: 0.85;
    font-weight: 700;
}

/* --- Teen monkey joke bubble --------------------------------------- */

.monkey-joke {
    background: var(--bg);
    border: 1px dashed var(--accent);
    border-radius: 12px;
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: flex-start;
}
.monkey-joke-text { font-size: 13px; font-style: italic; line-height: 1.4; }
.monkey-joke-btn {
    align-self: flex-end;
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    border-radius: 999px;
    padding: 3px 12px;
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
}
.monkey-joke-btn:active { transform: scale(0.95); }

/* --- Achievements grid --------------------------------------------- */

.achievements { margin-bottom: 18px; }
.achievements-list {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}
.achievement {
    background: var(--bg-soft);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 6px;
    text-align: center;
}
.achievement.locked { opacity: 0.45; filter: grayscale(1); }
.achievement.earned {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent) inset;
}
.achievement-emoji { font-size: 26px; line-height: 1; }
.achievement-name {
    font-size: 11px;
    font-weight: 800;
    margin-top: 4px;
}
.achievement-desc {
    font-size: 9px;
    color: var(--text-muted);
    margin-top: 2px;
    line-height: 1.3;
}

/* --- Flashy achievement-unlock splash ------------------------------ */

.ach-splash {
    position: fixed;
    left: 50%; top: 40%;
    /* Keep the card centred during the gap between achPop (ends ~380ms)
       and achOut (starts at 1850ms). Without a base transform the card
       reverted to its top-left at (50%, 40%) — visibly offset. */
    transform: translate(-50%, -50%);
    z-index: 1500;
    width: min(290px, 80vw);
    padding: 22px 20px;
    border-radius: 20px;
    text-align: center;
    color: #3a2a07;
    background: linear-gradient(160deg, #ffe27a 0%, #f0a800 100%);
    box-shadow: 0 14px 44px rgba(0, 0, 0, 0.45),
                inset 0 0 0 4px rgba(255, 255, 255, 0.45);
    pointer-events: none;
    animation: achPop 380ms cubic-bezier(0.2, 1.5, 0.3, 1),
               achOut 420ms ease-in 1850ms forwards;
}
@keyframes achPop {
    from { transform: translate(-50%, -50%) scale(0.3); opacity: 0; }
    to   { transform: translate(-50%, -50%) scale(1);   opacity: 1; }
}
@keyframes achOut {
    from { transform: translate(-50%, -50%) scale(1);    opacity: 1; }
    to   { transform: translate(-50%, -50%) scale(0.8);  opacity: 0; }
}
.ach-splash-badge {
    font-size: 62px;
    line-height: 1;
    animation: achBadge 700ms ease-out;
}
@keyframes achBadge {
    0%   { transform: rotate(-30deg) scale(0.2); }
    70%  { transform: rotate(12deg)  scale(1.15); }
    100% { transform: rotate(0)      scale(1); }
}
.ach-splash-label {
    font-weight: 800;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    margin-top: 8px;
}
.ach-splash-name { font-weight: 900; font-size: 22px; margin-top: 4px; }
.ach-splash-desc { font-size: 12px; opacity: 0.78; margin-top: 3px; }

.ach-confetti {
    position: fixed;
    top: -8%;
    z-index: 1499;
    font-size: 18px;
    pointer-events: none;
    animation: achConfetti 2s ease-in forwards;
}
@keyframes achConfetti {
    0%   { transform: translateY(0) rotate(0); opacity: 1; }
    100% { transform: translateY(108vh) rotate(540deg); opacity: 0; }
}

/* --- Baker card ---------------------------------------------------- */

.baker-card {
    background: var(--bg-soft);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 14px 16px;
    margin-bottom: 18px;
    box-shadow: var(--shadow);
}
.baker-main {
    display: flex;
    align-items: center;
    gap: 14px;
}
.baker-emoji { font-size: 40px; line-height: 1; flex: none; }
.baker-info { flex: 1; min-width: 0; }
.baker-title { font-weight: 800; font-size: 15px; }
.baker-quote {
    color: var(--text-muted);
    font-size: 12px;
    font-style: italic;
    margin-top: 2px;
}
.baker-stash {
    margin-top: 6px;
    font-weight: 700;
    font-size: 14px;
    color: var(--accent);
}
.baker-stash-hint {
    color: var(--text-muted);
    font-weight: 500;
    font-size: 11px;
}
.baker-progress {
    height: 6px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 999px;
    overflow: hidden;
    margin: 5px 0;
}
.baker-progress-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 999px;
    transition: width 300ms ease;
}
.baker-meta { color: var(--text-muted); font-size: 11px; }

/* --- Baker intro splash (first encounter) -------------------------- */

.baker-splash {
    position: fixed;
    left: 50%; top: 38%;
    transform: translate(-50%, -50%);
    z-index: 1600;
    width: min(320px, 86vw);
    padding: 26px 22px 18px;
    border-radius: 22px;
    text-align: center;
    color: #2a1a05;
    background: linear-gradient(165deg, #fff2c2 0%, #f7c469 100%);
    box-shadow: 0 18px 48px rgba(0, 0, 0, 0.5),
                inset 0 0 0 3px rgba(255, 255, 255, 0.4);
    pointer-events: auto;
    cursor: pointer;
    animation: bakerPop 420ms cubic-bezier(0.2, 1.4, 0.3, 1);
}
@keyframes bakerPop {
    from { transform: translate(-50%, -52%) scale(0.5); opacity: 0; }
    to   { transform: translate(-50%, -50%) scale(1);   opacity: 1; }
}
.baker-splash-emoji {
    font-size: 64px;
    line-height: 1;
    animation: bakerWave 1.4s ease-in-out infinite;
    transform-origin: 50% 80%;
}
@keyframes bakerWave {
    0%, 100% { transform: rotate(-6deg); }
    50%      { transform: rotate(6deg); }
}
.baker-splash-label {
    margin-top: 8px;
    font-weight: 700;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    opacity: 0.75;
}
.baker-splash-name { font-weight: 900; font-size: 22px; margin-top: 2px; }
.baker-splash-quote {
    margin-top: 10px;
    font-size: 14px;
    line-height: 1.4;
    font-style: italic;
}
.baker-splash-tap {
    margin-top: 14px;
    font-size: 10px;
    opacity: 0.6;
    text-transform: uppercase;
    letter-spacing: 0.07em;
}

/* --- Newspaper popups (what's-new) --------------------------------- */

.newspaper {
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%) rotate(-1.2deg);
    z-index: 1800;
    width: min(320px, 86vw);
    background: #f6efd7;
    color: #2a1f0a;
    border: 2px solid #1a1207;
    border-radius: 4px;
    padding: 18px 20px 14px;
    text-align: center;
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55),
                inset 0 0 0 4px #f6efd7,
                inset 0 0 0 5px #1a1207,
                4px 4px 0 0 rgba(0, 0, 0, 0.25);
    font-family: Georgia, "Times New Roman", "Iowan Old Style", serif;
    cursor: pointer;
    animation: newspaperIn 360ms cubic-bezier(0.2, 1.4, 0.4, 1);
}
.newspaper.newspaper-dismissing {
    animation: newspaperOut 260ms ease-in forwards;
}
@keyframes newspaperIn {
    from { transform: translate(-50%, -65%) rotate(-6deg) scale(0.6); opacity: 0; }
    to   { transform: translate(-50%, -50%) rotate(-1.2deg) scale(1);  opacity: 1; }
}
@keyframes newspaperOut {
    to { transform: translate(-50%, -50%) rotate(-1.2deg) scale(0.9); opacity: 0; }
}
.newspaper-masthead {
    font-weight: 900;
    font-size: 14px;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}
.newspaper-date {
    font-size: 10px;
    letter-spacing: 0.15em;
    margin-top: 2px;
    opacity: 0.7;
    font-style: italic;
}
.newspaper-rule {
    border: none;
    height: 0;
    border-top: 1px solid #1a1207;
    border-bottom: 1px solid #1a1207;
    margin: 8px 0 10px;
    padding-top: 1px;
}
.newspaper-emoji { font-size: 44px; line-height: 1; margin-bottom: 4px; }
.newspaper-headline {
    margin: 6px 0 8px;
    font-size: 22px;
    font-weight: 900;
    line-height: 1.1;
    text-transform: uppercase;
    letter-spacing: 0.01em;
}
.newspaper-body {
    font-size: 14px;
    line-height: 1.45;
    text-align: left;
    margin-bottom: 14px;
}
.newspaper-tap {
    font-size: 11px;
    font-style: italic;
    opacity: 0.6;
    letter-spacing: 0.05em;
}

/* --- News archive dialog ------------------------------------------ */

.news-archive-title {
    margin: 0 0 14px;
    font-size: 18px;
    font-weight: 800;
}
.news-archive-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-height: 60vh;
    overflow-y: auto;
}
.news-archive-item {
    background: var(--bg-soft);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 14px;
}
.news-archive-meta {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.07em;
}
.news-archive-headline {
    font-weight: 800;
    font-size: 14px;
    margin: 4px 0 4px;
}
.news-archive-body {
    font-size: 13px;
    color: var(--text);
    line-height: 1.4;
}

/* --- Re-read chip (top-right of each character card) -------------- */

.baker-card,
.chocolatier-card,
.monkey-card,
.grove-card {
    position: relative;
}
.card-replay {
    position: absolute;
    top: 8px;
    right: 10px;
    z-index: 2;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    padding: 4px 6px;
    line-height: 1;
    opacity: 0.55;
    transition: opacity 120ms ease;
}
.card-replay:hover,
.card-replay:active { opacity: 1; }

/* --- Monkey intro splash (mirrors baker/chocolatier) -------------- */

.monkey-splash {
    position: fixed;
    left: 50%; top: 38%;
    transform: translate(-50%, -50%);
    z-index: 1600;
    width: min(320px, 86vw);
    padding: 26px 22px 18px;
    border-radius: 22px;
    text-align: center;
    color: #1a1a1a;
    background: linear-gradient(165deg, #d8c89a 0%, #6b5a2e 100%);
    box-shadow: 0 18px 48px rgba(0, 0, 0, 0.5),
                inset 0 0 0 3px rgba(255, 255, 255, 0.3);
    pointer-events: auto;
    cursor: pointer;
    animation: chocolatierPop 420ms cubic-bezier(0.2, 1.4, 0.3, 1);
}
.monkey-splash-emoji { font-size: 60px; line-height: 1; }
.monkey-splash-label {
    margin-top: 8px;
    font-weight: 700;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    opacity: 0.75;
}
.monkey-splash-name { font-weight: 900; font-size: 22px; margin-top: 2px; }
.monkey-splash-quote {
    margin-top: 10px;
    font-size: 14px;
    line-height: 1.4;
    font-style: italic;
}
.monkey-splash-tap {
    margin-top: 14px;
    font-size: 10px;
    opacity: 0.7;
    text-transform: uppercase;
    letter-spacing: 0.07em;
}

/* --- Beta cheat menu ---------------------------------------------- */

.cheat-dialog {
    border: 1px solid var(--border);
    border-radius: 18px;
    background: var(--bg-soft);
    color: var(--text);
    padding: 18px;
    max-width: 360px;
    width: 88vw;
}
.cheat-dialog::backdrop { background: rgba(0,0,0,0.7); }
.cheat-title { margin: 0 0 4px; font-size: 16px; font-weight: 900; }
.cheat-sub {
    margin: 0 0 12px;
    color: var(--text-muted);
    font-size: 12px;
}
.cheat-presets {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 10px;
}
.cheat-preset-btn {
    display: grid;
    grid-template-columns: 28px 1fr;
    grid-template-rows: auto auto;
    column-gap: 10px;
    align-items: center;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 8px 10px;
    color: var(--text);
    text-align: left;
    cursor: pointer;
    font: inherit;
}
.cheat-preset-btn:active { transform: scale(0.99); }
.cheat-preset-icon { grid-row: 1 / 3; font-size: 22px; text-align: center; }
.cheat-preset-name { font-weight: 800; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
.cheat-preset-desc { font-size: 11px; color: var(--text-muted); line-height: 1.3; }
.cheat-wipe, .cheat-close {
    width: 100%;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 8px;
    margin-top: 6px;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}
.cheat-wipe { color: #c45a47; }

/* --- Cocoa grove --------------------------------------------------- */

.grove-card {
    background: var(--bg-soft);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 14px 16px;
    margin-bottom: 18px;
    box-shadow: var(--shadow);
}
.grove-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 8px;
}
.grove-title { font-weight: 800; font-size: 14px; }
.grove-stash {
    color: var(--accent);
    font-weight: 700;
    font-size: 13px;
}
.grove-empty {
    color: var(--text-muted);
    font-size: 12px;
    font-style: italic;
    margin: 4px 0 8px;
}
.palm-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 4px 0 10px;
}
.palm {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 6px 10px;
    font-size: 14px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.palm.ripe { border-color: var(--accent); }
.palm-ready {
    background: var(--accent);
    color: #1a1207;
    font-size: 11px;
    font-weight: 800;
    padding: 1px 7px;
    border-radius: 999px;
}
.palm-pending {
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 600;
}
.grove-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
.grove-btn {
    flex: 1 1 0;
    min-width: 100px;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 10px;
    padding: 8px 12px;
    font: inherit;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
}
.grove-btn.primary {
    background: var(--accent);
    color: #1a1207;
    border-color: var(--accent);
}
.grove-btn:active { transform: scale(0.98); }
.grove-btn:disabled {
    color: var(--text-muted);
    cursor: default;
    opacity: 0.55;
}

/* --- Chocolatier card --------------------------------------------- */

.chocolatier-card {
    background: var(--bg-soft);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 14px 16px;
    margin-bottom: 18px;
    box-shadow: var(--shadow);
}
.chocolatier-head {
    display: flex;
    align-items: center;
    gap: 12px;
}
.chocolatier-emoji { font-size: 36px; line-height: 1; }
.chocolatier-info { flex: 1; }
.chocolatier-name { font-weight: 800; font-size: 14px; }
.chocolatier-quote {
    color: var(--text-muted);
    font-size: 12px;
    font-style: italic;
    margin-top: 2px;
}
.chocolatier-stash {
    margin: 8px 0;
    font-weight: 700;
    font-size: 13px;
    color: var(--accent);
}
.chocolatier-craft-btn {
    width: 100%;
    background: var(--accent);
    color: #1a1207;
    border: none;
    border-radius: 12px;
    padding: 10px;
    font: inherit;
    font-size: 14px;
    font-weight: 800;
    cursor: pointer;
}
.chocolatier-craft-btn:active { transform: scale(0.98); }
.chocolatier-craft-btn:disabled {
    background: var(--bg);
    color: var(--text-muted);
    border: 1px solid var(--border);
    cursor: default;
}

/* --- Chocolatier intro splash ------------------------------------- */

.chocolatier-splash {
    position: fixed;
    left: 50%; top: 38%;
    transform: translate(-50%, -50%);
    z-index: 1600;
    width: min(320px, 86vw);
    padding: 26px 22px 18px;
    border-radius: 22px;
    text-align: center;
    color: #2a0a05;
    background: linear-gradient(165deg, #c79a7a 0%, #5a2f1c 100%);
    box-shadow: 0 18px 48px rgba(0, 0, 0, 0.55),
                inset 0 0 0 3px rgba(255, 255, 255, 0.25);
    pointer-events: auto;
    cursor: pointer;
    animation: chocolatierPop 420ms cubic-bezier(0.2, 1.4, 0.3, 1);
    color: #fff5e8;
}
@keyframes chocolatierPop {
    from { transform: translate(-50%, -52%) scale(0.5); opacity: 0; }
    to   { transform: translate(-50%, -50%) scale(1);   opacity: 1; }
}
.chocolatier-splash-emoji {
    font-size: 60px;
    line-height: 1;
}
.chocolatier-splash-label {
    margin-top: 8px;
    font-weight: 700;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    opacity: 0.75;
}
.chocolatier-splash-name { font-weight: 900; font-size: 22px; margin-top: 2px; }
.chocolatier-splash-quote {
    margin-top: 10px;
    font-size: 14px;
    line-height: 1.4;
    font-style: italic;
}
.chocolatier-splash-tap {
    margin-top: 14px;
    font-size: 10px;
    opacity: 0.7;
    text-transform: uppercase;
    letter-spacing: 0.07em;
}
