:root {
    --ink: #2d3350;
    --ink-soft: #6a6f8e;
    --paper: #fffdf7;
    --leaf: #4cc27a;
    --leaf-dark: #2f9a5a;
    --sky: #4aa8f0;
    --sky-dark: #2a82c8;
    --sun: #ffc93c;
    --sun-dark: #e0a400;
    --coral: #ff7a6b;
    --pink: #ff6fa8;
    --pink-dark: #d94a85;
    --grey: #e6e8f2;
    --grey-dark: #b9bdd3;
    --good: #2fbf71;
    --shadow: 0 6px 0 rgba(0, 0, 0, .07), 0 12px 26px rgba(50, 80, 110, .14);
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { min-height: 100%; }

body {
    font-family: 'Baloo 2', 'Trebuchet MS', sans-serif;
    color: var(--ink);
    background: linear-gradient(175deg, #d9f1ff 0%, #effaff 45%, #f3fbe9 100%);
    padding: 64px 14px 60px;
    overflow-x: hidden;
}

.grass {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: 120px;
    pointer-events: none;
    z-index: 0;
    background:
        radial-gradient(120% 100% at 20% 100%, #c6efb4 0 55%, transparent 56%),
        radial-gradient(110% 100% at 85% 100%, #b2e59c 0 50%, transparent 51%);
    opacity: .85;
}

/* ---------- top bar ---------- */
.topbar {
    position: fixed;
    top: 10px;
    left: 0;
    right: 0;
    display: flex;
    gap: 8px;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    z-index: 40;
}

.chip {
    font-family: inherit;
    font-size: .95rem;
    font-weight: 700;
    color: var(--ink);
    background: rgba(255, 255, 255, .92);
    border: 2px solid #fff;
    border-radius: 999px;
    padding: .35rem .85rem;
    cursor: pointer;
    box-shadow: 0 3px 10px rgba(50, 80, 110, .13);
    transition: transform .12s;
}

.chip:hover { transform: translateY(-2px); }
.chip.starcount { cursor: default; }
.chip .s { color: var(--sun); margin-right: .3rem; }
.home-link { text-decoration: none; white-space: nowrap; }
body.at-start .topbar > :not(.home-link) { display: none; }

/* ---------- screens and cards ---------- */
.screen {
    display: none;
    position: relative;
    z-index: 1;
    max-width: 760px;
    margin: 0 auto;
}

.screen.active { display: block; animation: rise .35s ease-out; }

@keyframes rise { from { opacity: 0; transform: translateY(14px); } }

.card {
    background: var(--paper);
    border-radius: 28px;
    box-shadow: var(--shadow);
    border: 4px solid #fff;
    padding: 1.4rem 1.4rem 1.6rem;
}

.start-card { text-align: center; }

.game-title {
    font-family: 'Fredoka One', 'Baloo 2', sans-serif;
    font-size: clamp(2.2rem, 7vw, 3.2rem);
    line-height: 1.05;
    color: var(--sky-dark);
    margin-top: .4rem;
    text-shadow: 0 3px 0 rgba(0, 0, 0, .06);
}

.game-title span { color: var(--pink); }

.tagline { color: var(--ink-soft); font-size: 1.1rem; margin: .4rem 0 1rem; }
.tagline b { color: var(--ink); }

.how-to { display: grid; gap: .6rem; text-align: left; margin-bottom: 1.2rem; }

.how-step {
    display: flex;
    align-items: center;
    gap: .8rem;
    background: #f1f8ff;
    border-radius: 18px;
    padding: .55rem .9rem;
}

.how-num {
    flex: 0 0 42px;
    height: 42px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: var(--sky);
    color: #fff;
    font: 1.2rem 'Fredoka One', sans-serif;
    box-shadow: 0 3px 0 var(--sky-dark);
}

.how-num.star { background: var(--sun); box-shadow: 0 3px 0 var(--sun-dark); }

.pick-title { font: 1.4rem 'Fredoka One', sans-serif; color: var(--ink); margin-bottom: .6rem; }

.levels {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: .7rem;
}

.level {
    font-family: inherit;
    text-align: left;
    background: #fff;
    border: 3px solid var(--grey);
    border-radius: 20px;
    padding: .7rem .9rem .8rem;
    cursor: pointer;
    transition: transform .12s, border-color .12s;
    color: var(--ink);
}

.level:hover { transform: translateY(-3px); border-color: var(--lc, var(--sky)); }
.level .lname { font: 1.25rem 'Fredoka One', sans-serif; color: var(--lc, var(--sky-dark)); }
.level .ldesc { font-size: .92rem; color: var(--ink-soft); line-height: 1.3; }
.level .lstars { color: var(--sun); font-size: 1.1rem; letter-spacing: 2px; margin-top: .2rem; }
.level .lstars .off { color: var(--grey-dark); }

/* ---------- playing ---------- */
.progress {
    display: flex;
    gap: 6px;
    justify-content: center;
    margin-bottom: .8rem;
}

.progress i {
    width: 34px;
    height: 34px;
    border-radius: 42%;
    background: var(--grey);
    display: grid;
    place-items: center;
    font: .95rem 'Fredoka One', sans-serif;
    color: #fff;
    font-style: normal;
}

.progress i.now { background: var(--sky); box-shadow: 0 0 0 4px rgba(74, 168, 240, .25); }
.progress i.good { background: var(--leaf); }
.progress i.tried { background: var(--sun); }

.problem-top { display: flex; align-items: center; gap: .7rem; }
.emoji { font-size: 2.2rem; line-height: 1; }
.pnum { font: 1.05rem 'Fredoka One', sans-serif; color: var(--ink-soft); }

.story { font-size: 1.35rem; line-height: 1.5; margin: .5rem 0 1rem; }
.story b { color: var(--sky-dark); }

.ask { font-weight: 700; color: var(--ink-soft); margin-bottom: .35rem; }

.answer-row { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; }

.answer {
    font: 2rem 'Fredoka One', sans-serif;
    width: 140px;
    padding: .2rem .7rem;
    border: 3px solid var(--grey-dark);
    border-radius: 16px;
    color: var(--ink);
    background: #fff;
    text-align: center;
    outline: none;
}

.answer:focus { border-color: var(--sky); }
.answer.right { border-color: var(--good); background: #eafbf1; }
.answer.wrong { border-color: var(--coral); animation: shake .4s; }

@keyframes shake {
    20% { transform: translateX(-7px); }
    40% { transform: translateX(6px); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(2px); }
}

.btn {
    font: 1.1rem 'Fredoka One', sans-serif;
    border: 0;
    border-radius: 16px;
    padding: .6rem 1.1rem;
    cursor: pointer;
    color: #fff;
    transition: transform .1s;
}

.btn:active { transform: translateY(2px); }
.btn.go { background: var(--leaf); box-shadow: 0 4px 0 var(--leaf-dark); }
.btn.soft { background: var(--sun); color: #5a4300; box-shadow: 0 4px 0 var(--sun-dark); }
.btn.blue { background: var(--sky); box-shadow: 0 4px 0 var(--sky-dark); }
.btn.big { font-size: 1.3rem; padding: .7rem 1.6rem; }
.btn:disabled { opacity: .45; cursor: default; }

.feedback { min-height: 1.6rem; margin-top: .6rem; font-size: 1.1rem; line-height: 1.4; }
.feedback.good { color: var(--leaf-dark); font-weight: 700; }
.feedback.bad { color: #c94a3d; }
.feedback .work {
    display: block;
    margin-top: .3rem;
    padding: .45rem .7rem;
    border-radius: 12px;
    background: #f1f8ff;
    color: var(--ink);
    font-weight: 600;
}

.step + .step { margin-top: 1.1rem; padding-top: 1rem; border-top: 2px dashed var(--grey); }

/* sentence builder */
.sentence {
    min-height: 54px;
    display: flex;
    flex-wrap: wrap;
    gap: .4rem;
    align-items: center;
    padding: .45rem .6rem;
    border-bottom: 3px solid var(--grey-dark);
    margin-bottom: .7rem;
}

.tiles { display: flex; flex-wrap: wrap; gap: .45rem; }

.word {
    font: 700 1.15rem 'Baloo 2', sans-serif;
    padding: .25rem .8rem;
    border-radius: 12px;
    border: 2px solid var(--grey-dark);
    background: #fff;
    color: var(--ink);
    cursor: pointer;
    box-shadow: 0 3px 0 var(--grey-dark);
}

.word { touch-action: none; user-select: none; -webkit-user-select: none; }
.word.used { visibility: hidden; }
.word.lifted { opacity: .35; }
.word.ghost { position: fixed; z-index: 100; pointer-events: none; transform: rotate(-3deg) scale(1.06); box-shadow: 0 10px 22px rgba(50, 80, 110, .28); border-color: var(--sky); }
.word.ph { border: 2px dashed var(--sky); background: #eef7ff; color: transparent; box-shadow: none; }
.sentence .word { border-color: var(--sky); box-shadow: 0 3px 0 var(--sky-dark); }
.sentence.done .word { border-color: var(--leaf); box-shadow: 0 3px 0 var(--leaf-dark); cursor: default; }

.next-row { margin-top: 1.2rem; text-align: right; }

/* result */
.result-card { text-align: center; }
.result-card h2 { font: 2.2rem 'Fredoka One', sans-serif; color: var(--sky-dark); margin-top: .4rem; }
.big-stars { font-size: 3rem; letter-spacing: 6px; color: var(--sun); margin: .3rem 0; }
.big-stars .off { color: var(--grey); }
.result-card p { font-size: 1.15rem; color: var(--ink-soft); margin-bottom: 1rem; }
.result-btns { display: flex; gap: .7rem; justify-content: center; flex-wrap: wrap; }



/* ============================================================
   Fair Share
   ============================================================ */
.game-title span { color: var(--coral); }
.hero { margin: 0 auto .4rem; max-width: 380px; }
.hero .table { --is: 22px !important; padding: 6px 8px 8px !important; }
.hero .top-row { min-height: 60px; }
.hero .jar { min-height: 46px; }
.hero .spot .who { font-size: 30px; }

/* answer buttons */
.choices { display: flex; gap: .7rem; flex-wrap: wrap; margin-top: .3rem; }
.choice {
    font: 1.9rem 'Fredoka One', sans-serif;
    min-width: 88px;
    padding: .3rem 1rem;
    border: 0;
    border-radius: 18px;
    background: #fff;
    color: var(--ink);
    box-shadow: 0 5px 0 var(--grey-dark), 0 8px 18px rgba(50, 80, 110, .12);
    cursor: pointer;
    touch-action: manipulation;
}
.choice:active { transform: translateY(2px); }
.choice.right { background: var(--leaf); color: #fff; box-shadow: 0 5px 0 var(--leaf-dark); }
.choice.wrong { background: #ffe7e2; color: var(--ink-soft); box-shadow: none; opacity: .7; }
.choice.pulse { animation: pulse 1s ease-in-out infinite; box-shadow: 0 0 0 4px var(--sun), 0 5px 0 var(--grey-dark); }
@keyframes pulse { 50% { transform: scale(1.08); } }

/* the table: jar or pile, then plates or bags, and the puppy */
.table {
    position: relative;
    background: linear-gradient(#fff7ea, #fdebcf);
    border: 3px solid #f6dcb0;
    border-radius: 24px;
    padding: 14px 14px 18px;
    margin: .2rem 0 .9rem;
}
.top-row { display: flex; align-items: center; justify-content: center; gap: 18px; min-height: 92px; }
.jar {
    position: relative;
    min-width: 120px;
    max-width: 330px;
    padding: 10px 12px;
    border-radius: 20px 20px 26px 26px;
    background: rgba(255, 255, 255, .75);
    border: 3px solid #cfe5f5;
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    justify-content: center;
    align-content: center;
    min-height: 70px;
}
.jar-label { position: absolute; top: -12px; left: 50%; transform: translateX(-50%); background: #fff; border-radius: 99px; padding: 0 .6rem; font: .9rem 'Fredoka One', sans-serif; color: var(--sky-dark); border: 2px solid #cfe5f5; white-space: nowrap; }
.item { font-size: var(--is, 26px); line-height: 1.1; display: inline-block; }
.item.pop { animation: pop .3s cubic-bezier(.3, 1.6, .5, 1) backwards; }
.flyer { position: fixed; z-index: 60; pointer-events: none; transition: transform .45s cubic-bezier(.4, -.3, .5, 1.3); }
@keyframes pop { from { transform: scale(0); } }

.puppy { text-align: center; font: .85rem 'Fredoka One', sans-serif; color: var(--ink-soft); }
.puppy .face { font-size: 54px; line-height: 1; display: inline-block; transition: transform .2s; }
.puppy .tummy { display: flex; flex-wrap: wrap; justify-content: center; max-width: 90px; min-height: 26px; }
.puppy.eat .face { animation: chomp .5s ease-in-out 2; }
@keyframes chomp { 30% { transform: scale(1.2) rotate(-8deg); } 60% { transform: scale(.95) rotate(6deg); } }

.spots { display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; margin-top: 16px; }
.spot { display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 84px; }
.spot .who { font-size: 40px; line-height: 1; }
.spot .who.happy { animation: chomp .5s ease-in-out; }
.plate {
    min-width: 84px;
    min-height: 64px;
    padding: 8px;
    border-radius: 50%;
    background: radial-gradient(circle, #fff 55%, #e9eef7 56%, #fff 70%);
    border: 3px solid #dde4f1;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-content: center;
    gap: 1px;
    max-width: 120px;
}
.bag {
    min-width: 78px;
    min-height: 74px;
    padding: 18px 8px 8px;
    border-radius: 12px 12px 22px 22px;
    background: #f7e2bd;
    border: 3px solid #e2bf86;
    position: relative;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-content: center;
    gap: 1px;
    max-width: 112px;
    animation: pop .3s cubic-bezier(.3, 1.6, .5, 1) backwards;
}
.bag::before { content: ''; position: absolute; top: -10px; left: 50%; width: 30px; height: 16px; transform: translateX(-50%); border: 3px solid #e2bf86; border-bottom: 0; border-radius: 16px 16px 0 0; }
.count-tag { font: 1.05rem 'Fredoka One', sans-serif; color: var(--sky-dark); min-height: 1.3em; }

.deal-row { display: flex; gap: .6rem; flex-wrap: wrap; justify-content: center; margin-top: 12px; }
.say { text-align: center; font-size: 1.15rem; min-height: 1.6em; margin-top: 10px; }
.say b { color: var(--coral); }

.eqn {
    font: 2.1rem 'Fredoka One', sans-serif;
    text-align: center;
    margin: .3rem 0 .2rem;
    animation: rise .4s ease-out;
}
.eqn b { color: var(--leaf-dark); }
.eqn small { display: block; font: 600 1rem 'Baloo 2', sans-serif; color: var(--ink-soft); }

/* level 4: the fact triangle */
.tri-wrap { display: flex; align-items: center; justify-content: center; gap: 24px; flex-wrap: wrap; }
.tri { width: 220px; height: 190px; }
.tri text { font-family: 'Fredoka One', sans-serif; text-anchor: middle; dominant-baseline: central; }
.tri-facts { font: 1.45rem 'Fredoka One', sans-serif; line-height: 1.6; }
.tri-facts .x { color: var(--sky-dark); }
.tri-facts .d { color: var(--coral); }
.hint { margin-top: .6rem; padding: .5rem .8rem; border-radius: 14px; background: #f1f8ff; font-size: 1.1rem; }

@media (max-width: 560px) {
    body { padding: 58px 8px 50px; }
    .card { border-radius: 22px; padding: 1.1rem 1rem 1.3rem; }
    .story { font-size: 1.2rem; }
    .btn { font-size: 1rem; padding: .55rem .9rem; }
    .spot { min-width: 64px; }
    .plate, .bag { min-width: 64px; max-width: 96px; }
    .spot .who { font-size: 32px; }
    .choice { font-size: 1.6rem; min-width: 74px; }
    .eqn { font-size: 1.7rem; }
}
.big-hug { font-size: 4.5rem; display: inline-block; animation: wiggle 1.4s ease-in-out infinite; }
@keyframes wiggle { 50% { transform: translateY(-6px) rotate(6deg); } }
.hero .table { margin: 0; }
.hero .spots { margin-top: 8px; }
.hero .plate { min-height: 50px; }
.hint-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.hint-chips span { font: 1.2rem 'Fredoka One', sans-serif; background: #fff; border: 2px solid #cfe5f5; color: var(--sky-dark); border-radius: 12px; padding: 0 .6rem; animation: pop .3s cubic-bezier(.3, 1.6, .5, 1) backwards; }
.hint-chips span:nth-child(2) { animation-delay: .15s; } .hint-chips span:nth-child(3) { animation-delay: .3s; }
.hint-chips span:nth-child(4) { animation-delay: .45s; } .hint-chips span:nth-child(5) { animation-delay: .6s; }
.hint-chips span:nth-child(6) { animation-delay: .75s; } .hint-chips span:nth-child(7) { animation-delay: .9s; }
.hint-chips span:nth-child(8) { animation-delay: 1.05s; } .hint-chips span:nth-child(9) { animation-delay: 1.2s; }
.hint-chips span:nth-child(10) { animation-delay: 1.35s; }
