:root {
    --page: #FBF7EE;
    --ink: #33312B;
    --muted: #6E6A5E;
    --card: #FFFFFF;
    --line: rgba(40, 36, 28, 0.12);
    --sky-top: #BFE6F4;
    --sky-bot: #E4F4FA;
    --grass: #7CB24E;
    --soil: #9A6B43;
    --key: #FFFFFF;
    --key-ink: #33312B;
    --accent: #8A4F6E;
    --accent-ink: #FFFFFF;
    --good: #3E7D2E;
    --good-bg: #DDEFCF;
    --bad: #B4452E;
    --bad-bg: #F1D8D1;
    --plaque-bg: rgba(255, 255, 255, 0.82);
}

html.dark {
    --page: #1B1F22;
    --ink: #ECE7DA;
    --muted: #A0A096;
    --card: #262B2E;
    --line: rgba(255, 255, 255, 0.14);
    --sky-top: #1E2C36;
    --sky-bot: #2A3C46;
    --grass: #3E5A28;
    --soil: #5C4026;
    --key: #2D3337;
    --key-ink: #ECE7DA;
    --accent: #C58BA8;
    --accent-ink: #20141B;
    --good: #8FCB6B;
    --good-bg: #2C3B22;
    --bad: #E08C75;
    --bad-bg: #3C241C;
    --plaque-bg: rgba(20, 24, 26, 0.74);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--page);
    color: var(--ink);
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
    -webkit-text-size-adjust: 100%;
}

.cc-game {
    max-width: 420px;
    min-height: 100vh;
    min-height: 100svh;
    min-height: 100dvh;
    margin: 0 auto;
    padding: 10px 14px 14px;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    /* justify-content: center;
    justify-content: safe center; */
    gap: 12px;
}

/* --- scene ---------------------------------------------------------------- */
.cc-scene {
    --climb: 0.25;
    position: relative;
    flex: 1 1 auto;
    min-height: 180px;
    max-height: min(70vh, 540px);
    max-height: min(70svh, 540px);
    width: 100%;
    border-radius: 18px;
    overflow: hidden;
    background: var(--sky-bot);
}

.cc-bg,
.cc-ground,
.cc-tree,
.cc-figs,
.cc-chimp {
    position: absolute;
}

.cc-bg {
    inset: 0;
    background: linear-gradient(var(--sky-top), var(--sky-bot));
}

.cc-ground {
    left: 0;
    right: 0;
    bottom: 0;
    height: 11%;
    z-index: 3;
}

.cc-figs {
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 62%;
    height: 27%;
    z-index: 1;
}

.cc-tree {
    top: 10%;
    bottom: 2%;
    left: 50%;
    transform: translateX(-50%);
    width: 50%;
    z-index: 2;
}

.cc-chimp {
    left: 44%;
    width: 24%;
    height: 24%;
    transform: translateX(-50%);
    bottom: calc(20% + var(--climb) * 52%);
    z-index: 4;
    transition: bottom 0.45s cubic-bezier(0.34, 1.18, 0.64, 1);
}

.cc-scene svg {
    display: block;
    width: 100%;
    height: 100%;
}

/* skin image swap: drawn svg hides, image fills, broken image keeps drawn */
.cc-bg.is-skinned,
.cc-ground.is-skinned,
.cc-figs.is-skinned,
.cc-tree.is-skinned,
.cc-chimp.is-skinned {
    background-image: var(--skin-img);
    background-repeat: no-repeat;
    background-position: center bottom;
    background-size: contain;
}

.cc-bg.is-skinned,
.cc-ground.is-skinned {
    background-size: cover;
}

.cc-figs.is-skinned svg,
.cc-tree.is-skinned svg,
.cc-ground.is-skinned svg,
.cc-chimp.is-skinned svg {
    display: none;
}

.cc-scene.is-won .cc-chimp {
    animation: cc-cheer 0.5s ease;
    left: 66%;
    top: 18%;
}

.cc-scene.is-lost .cc-chimp {
    bottom: calc(20% - 60px);
    left: 40%;
}

@keyframes cc-cheer {
    50% {
        transform: translateX(-50%) translateY(-6px) rotate(-3deg);
    }
}

/* --- plaque overlay (status + word over the scene) ------------------------ */
.cc-plaque {
    position: absolute;
    left: 8px;
    right: 8px;
    bottom: 8px;
    z-index: 5;
    padding: 6px 10px 8px;
    border-radius: 12px;
    background: var(--plaque-bg);
    border: 1px solid var(--line);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.cc-status {
    margin: 0;
    text-align: center;
    font-size: 13px;
    font-weight: 600;
    color: var(--muted);
    min-height: 16px;
}

.cc-word {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: flex-end;
    gap: 5px 5px;
}

.cc-slot {
    width: 22px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-bottom: 3px solid var(--line);
    font-size: 22px;
    font-weight: 600;
    line-height: 1;
}

.cc-slot.is-filled {
    border-bottom-color: var(--accent);
}

.cc-slot.is-missed {
    color: var(--bad);
    border-bottom-color: var(--bad);
}

.cc-gap {
    width: 11px;
}

.cc-punct {
    width: 14px;
    height: 30px;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    font-size: 20px;
    color: var(--muted);
}

/* --- keyboard ------------------------------------------------------------- */
.cc-keys {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 7px;
}

.cc-key {
    min-height: 44px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--key);
    color: var(--key-ink);
    font-size: 18px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.06s ease, background 0.12s ease;
}

.cc-key:hover:not(:disabled) {
    border-color: var(--accent);
}

.cc-key:active:not(:disabled) {
    transform: scale(0.94);
}

.cc-key.is-correct {
    background: var(--good-bg);
    color: var(--good);
    border-color: transparent;
}

.cc-key.is-wrong {
    background: var(--bad-bg);
    color: var(--bad);
    border-color: transparent;
}

.cc-key:disabled {
    cursor: default;
    opacity: 0.65;
}

.cc-key.is-correct:disabled,
.cc-key.is-wrong:disabled {
    opacity: 1;
}

/* --- controls ------------------------------------------------------------- */
.cc-control-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.cc-levels {
    display: inline-flex;
    border: 1px solid var(--line);
    border-radius: 10px;
    overflow: hidden;
}

.cc-levels button {
    border: 0;
    background: transparent;
    color: var(--muted);
    padding: 8px 14px;
    font-size: 14px;
    cursor: pointer;
}

.cc-levels button.is-active {
    background: var(--accent);
    color: var(--accent-ink);
}

.cc-new {
    border: 1px solid var(--accent);
    background: transparent;
    color: var(--accent);
    padding: 9px 18px;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
}

.cc-new:active {
    transform: scale(0.97);
}

.cc-stats {
    width: 100%;
    margin: 0;
    text-align: center;
    font-size: 13px;
    color: var(--muted);
}

/* --- paused --------------------------------------------------------------- */
.cc-game.is-paused .cc-keys {
    pointer-events: none;
    opacity: 0.5;
}

.cc-game.is-paused .cc-scene::after {
    content: "Paused";
    position: absolute;
    inset: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.35);
    color: #fff;
    font-size: 22px;
    font-weight: 600;
}

@media (prefers-reduced-motion: reduce) {
    .cc-chimp {
        transition: none;
    }

    .cc-scene.is-won .cc-chimp {
        animation: none;
    }
}