:root {
    --bg: #1b1846;
    --ink: #2b2350;
    --muted: #6d6a94;
    --accent: #ff5fa2;
    --accent-2: #ffb42e;
    --gold: #ffc21f;
    --card: #ffffff;
    --line: rgba(43, 35, 80, 0.16);
    --emoji: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
    height: 100%;
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
    overflow: hidden;
    overscroll-behavior: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

#stage {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    touch-action: none;
    cursor: pointer;
}

/* ---------- HUD ---------- */
.hud {
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 5;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 8px;
    padding: calc(10px + env(safe-area-inset-top)) calc(12px + env(safe-area-inset-right)) 0 calc(12px + env(safe-area-inset-left));
    pointer-events: none;
}
.hud-left { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.hud-right { display: flex; justify-content: flex-end; gap: 8px; }

.pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    font-size: 16px;
    font-weight: 900;
    color: var(--ink);
    background: rgba(255, 255, 255, 0.86);
    border-radius: 999px;
    box-shadow: 0 3px 0 rgba(43, 35, 80, 0.14);
    font-variant-numeric: tabular-nums;
}
.pill.big { font-size: 22px; padding: 4px 14px 4px 10px; }
.pill .star { font-family: var(--emoji); font-size: 20px; line-height: 1; }
.pill.big.bump { animation: bump 0.45s ease-out; }
.pill .paw { font-family: var(--emoji); font-size: 15px; line-height: 1; }
@keyframes bump {
    30% { transform: scale(1.35) rotate(-6deg); }
    60% { transform: scale(0.95); }
}

/* ten little dots: the monster's tummy filling up */
.dots { display: flex; gap: 5px; padding: 7px 10px; background: rgba(255, 255, 255, 0.55); border-radius: 999px; }
.dots span {
    width: clamp(9px, 2.6vw, 15px);
    height: clamp(9px, 2.6vw, 15px);
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.8);
    box-shadow: inset 0 0 0 1.5px rgba(43, 35, 80, 0.2);
    transition: transform 0.18s, background 0.18s;
}
.dots span.on {
    background: radial-gradient(circle at 32% 30%, #fff 0 16%, #ffd0e6 34%, var(--accent));
    box-shadow: inset 0 0 0 1.5px rgba(190, 30, 100, 0.65);
    transform: scale(1.22);
}

.tool {
    pointer-events: auto;
    position: relative;
    width: 42px; height: 42px;
    display: grid; place-items: center;
    padding: 0;
    color: var(--ink);
    background: rgba(255, 255, 255, 0.86);
    border: 0;
    border-radius: 50%;
    box-shadow: 0 3px 0 rgba(43, 35, 80, 0.14);
    cursor: pointer;
    touch-action: none;
}
.tool svg { width: 22px; height: 22px; fill: currentColor; overflow: visible; }
.tool .cross { display: none; }
.tool.muted .wave { display: none; }
.tool.muted .cross { display: inline; }
.tool:active { transform: scale(0.94); }

/* the home button fills a ring while it is held (so little fingers cannot end the game by accident) */
.tool.hold svg { width: 42px; height: 42px; }
.tool.hold svg path { transform: scale(0.56); transform-origin: 12px 12px; }
.tool.hold .ring {
    stroke: var(--accent);
    stroke-linecap: round;
    stroke-dasharray: 69.2;
    stroke-dashoffset: 69.2;
    transform: rotate(-90deg);
    transform-origin: 12px 12px;
    transition: stroke-dashoffset 0.15s linear;
}
.tool.hold.holding .ring { stroke-dashoffset: 0; transition-duration: 0.8s; }

/* ---------- transient messages ---------- */
.banner {
    position: fixed;
    top: calc(84px + env(safe-area-inset-top));
    left: 0; right: 0;
    z-index: 4;
    text-align: center;
    font-family: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, sans-serif, var(--emoji);
    font-size: clamp(30px, 9vw, 56px);
    font-weight: 900;
    color: #fff;
    text-shadow: 0 3px 0 rgba(43, 35, 80, 0.35), 0 0 22px rgba(255, 95, 162, 0.8);
    opacity: 0;
    pointer-events: none;
}
.banner.show { animation: banner 1.9s ease-out; }
@keyframes banner {
    0% { opacity: 0; transform: scale(0.5) rotate(-6deg); }
    14% { opacity: 1; transform: scale(1.18) rotate(3deg); }
    26% { transform: scale(1) rotate(0); }
    78% { opacity: 1; transform: scale(1); }
    100% { opacity: 0; transform: scale(1.08); }
}

.hint {
    position: fixed;
    left: 16px; right: 16px;
    top: calc(108px + env(safe-area-inset-top));
    z-index: 4;
    width: fit-content;
    max-width: calc(100% - 32px);
    margin: 0 auto;
    padding: 7px 14px;
    text-align: center;
    font-size: 13px;
    font-weight: 700;
    color: var(--ink);
    background: rgba(255, 255, 255, 0.82);
    border-radius: 999px;
    pointer-events: none;
}

/* ---------- screens ---------- */
.screen {
    position: fixed;
    inset: 0;
    z-index: 10;
    display: flex;
    padding: 16px;
    background: rgba(10, 8, 40, 0.35);
    -webkit-backdrop-filter: blur(3px);
    backdrop-filter: blur(3px);
    overflow-y: auto;
}
.card {
    width: min(420px, 100%);
    margin: auto;
    padding: 22px 22px 18px;
    text-align: center;
    background: var(--card);
    border-radius: 28px;
    box-shadow: 0 10px 0 rgba(43, 35, 80, 0.16), 0 24px 60px rgba(43, 35, 80, 0.3);
}

h1, h2 { margin: 0; font-weight: 900; letter-spacing: 0.01em; }
h1 {
    font-size: clamp(27px, 8.2vw, 38px);
    line-height: 1.05;
    background: linear-gradient(90deg, #ffb42e, #ff5fa2 50%, #7d5cff);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}
h2 { font-size: 28px; margin-bottom: 10px; }

.tagline { margin: 6px 0 14px; color: var(--muted); font-size: 16px; font-weight: 700; }

.logo { display: block; width: 200px; height: 104px; margin: 0 auto 6px; border-radius: 18px; }

.howto {
    list-style: none;
    margin: 0 0 6px;
    padding: 0;
    text-align: left;
    font-size: 14px;
    line-height: 1.4;
    color: #4a4570;
}
.howto li { display: flex; gap: 10px; align-items: flex-start; padding: 4px 0; }
.howto strong { color: var(--ink); }
.dot { flex: none; width: 14px; height: 14px; margin-top: 3px; border-radius: 50%; }
.dot-pop { background: radial-gradient(circle at 35% 30%, #fff, #6fcbff 55%, #2f9cf0); }
.dot-ten { background: var(--gold); clip-path: polygon(50% 0, 62% 35%, 100% 38%, 70% 60%, 80% 100%, 50% 76%, 20% 100%, 30% 60%, 0 38%, 38% 35%); border-radius: 0; }

/* the album: one row for every place, filled in as animals are found (kept on this device) */
.album { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; margin: 14px 0 4px; }
.album span {
    display: grid;
    place-items: center;
    aspect-ratio: 1.3;
    font-family: var(--emoji);
    font-size: clamp(19px, 6vw, 26px);
    line-height: 1;
    background: #fff3c9;
    border-radius: 12px;
    box-shadow: inset 0 0 0 2px #ffd35c;
}
.album span canvas { width: 88%; height: 88%; }
.album span.sky { background: #221d58; box-shadow: inset 0 0 0 2px #4b3a8f; }
.album span.locked {
    font-family: inherit;
    font-size: 16px;
    font-weight: 900;
    color: #b9b6d3;
    background: #f1f0f8;
    box-shadow: inset 0 0 0 2px #e2e0f0;
}

.keys { margin: 12px 0 0; font-size: 12px; font-weight: 700; letter-spacing: 0.06em; color: var(--muted); }

.btn {
    display: block;
    width: 100%;
    margin-top: 10px;
    padding: 14px 16px;
    font: inherit;
    font-size: 18px;
    font-weight: 900;
    color: var(--ink);
    background: #f1f0f8;
    border: 0;
    border-radius: 18px;
    box-shadow: 0 4px 0 #d8d5ea;
    cursor: pointer;
    transition: transform 0.08s, filter 0.15s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #d8d5ea; }
.btn:hover { filter: brightness(1.04); }
.btn:focus-visible, .tool:focus-visible, input:focus-visible { outline: 3px solid #2f9cf0; outline-offset: 2px; }
.btn.primary {
    padding: 16px;
    font-size: 22px;
    color: #fff;
    background: linear-gradient(180deg, #ff7fb6, #ff4f98);
    box-shadow: 0 5px 0 #cf2c74;
    text-shadow: 0 2px 0 rgba(140, 20, 80, 0.35);
}
.btn.primary:active { box-shadow: 0 2px 0 #cf2c74; }
.btn.small { width: auto; margin: 0; padding: 0 16px; font-size: 14px; white-space: nowrap; background: #ffe7a3; box-shadow: 0 3px 0 #f0c64a; }
.btn:disabled { opacity: 0.5; cursor: default; }

/* ---------- finish screen ---------- */
.newbest {
    display: inline-block;
    margin-bottom: 6px;
    padding: 4px 12px;
    font-size: 12px;
    font-weight: 900;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: #4a3200;
    background: var(--gold);
    border-radius: 999px;
}
.final {
    font-size: clamp(54px, 17vw, 76px);
    font-weight: 900;
    line-height: 1;
    color: var(--accent);
    font-variant-numeric: tabular-nums;
    text-shadow: 0 4px 0 rgba(255, 95, 162, 0.2);
}
.unit { margin: 2px 0 0; font-size: 14px; font-weight: 800; color: var(--muted); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0; }
.stats div { padding: 10px 4px; background: #f6f5fb; border-radius: 16px; }
.stats b { display: block; font-size: 20px; }
.stats span { font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }

.save { display: flex; gap: 8px; }
.save input {
    flex: 1;
    min-width: 0;
    height: 46px;
    padding: 0 14px;
    font: inherit;
    font-size: 16px;
    font-weight: 700;
    color: var(--ink);
    background: #fff;
    border: 2px solid #d8d5ea;
    border-radius: 14px;
    -webkit-user-select: text;
    user-select: text;
}
.save .btn { height: 43px; }

.note { min-height: 18px; margin: 10px 0 6px; font-size: 13px; font-weight: 600; color: var(--muted); }

.board { list-style: none; margin: 0 0 6px; padding: 0; text-align: left; font-size: 14px; font-weight: 700; }
.board li {
    display: grid;
    grid-template-columns: 30px 1fr auto;
    gap: 8px;
    align-items: center;
    padding: 7px 10px;
    border-radius: 12px;
    font-variant-numeric: tabular-nums;
}
.board li:nth-child(odd) { background: #f6f5fb; }
.board li.me { background: #fff0c2; outline: 2px solid var(--gold); }
.board .rank { font-weight: 900; color: var(--muted); }
.board li:nth-child(1) .rank { color: #e08a00; }
.board .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board .pts { font-weight: 900; }
.board li.empty { display: block; text-align: center; color: var(--muted); background: none; }

@media (max-height: 620px) {
    .card { padding: 14px 18px; }
    .logo { display: none; }
    .howto { font-size: 13px; margin-bottom: 8px; }
    .howto li { padding: 2px 0; }
    .album span { border-radius: 9px; aspect-ratio: 1.5; font-size: 18px; }
    .btn { padding: 10px 14px; margin-top: 8px; }
    .btn.primary { padding: 12px; font-size: 20px; }
    .stats { margin: 10px 0; }
}
@media (max-height: 620px) and (min-width: 520px) {
    .album { grid-template-columns: repeat(8, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
    .pill.big.bump { animation: none; }
}
