:root {
    --olly-green: #A2C559;
    --olly-cream: #FFF3B8;
    --olly-coral: #E76254;
    --olly-brown: #5C4635;
    --olly-mint: #C5E1A5;
    --bg: #EAF5D8;
    --ink: #5C4635;
    --muted: #6c5848;
    --card: #fffef7;
    --sun: #FFF3B8;
    --mint: #C5E1A5;
    --sky: #dcecc3;
    --ok: #6a8f2a;
    --warn: #E76254;
    --ring: #5C4635;
    --radius: 24px;
    --shadow: 0 10px 28px rgba(58, 47, 35, 0.14);
    --hand-font: "Chalkboard SE", "Marker Felt", "Comic Sans MS", "Avenir Next", sans-serif;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    background: radial-gradient(circle at 12% 18%, #faffee, var(--bg));
    color: var(--ink);
    font-family: "Avenir Next", "Nunito", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    min-height: 100%;
    -webkit-text-size-adjust: 100%;
    touch-action: manipulation;
}

button,
a {
    -webkit-tap-highlight-color: transparent;
}

.page-shell {
    max-width: 980px;
    margin: 0 auto;
    padding: 16px 16px calc(20px + env(safe-area-inset-bottom));
    position: relative;
}

.page-shell::before,
.page-shell::after {
    content: "";
    position: fixed;
    width: 90px;
    height: 90px;
    border-radius: 50%;
    z-index: -1;
    opacity: 0.28;
}

.page-shell::before {
    top: 14px;
    right: 10px;
    background: var(--olly-cream);
}

.page-shell::after {
    left: 8px;
    bottom: 12px;
    background: var(--olly-green);
}

.hero-illustration-wrap {
    display: grid;
    place-items: center;
    margin-top: 6px;
}

.hero-illustration {
    width: min(92%, 360px);
    filter: drop-shadow(0 10px 20px rgba(22, 50, 79, 0.15));
    border-radius: 20px;
}

.hero-title {
    margin: 24px 0 6px;
    font-size: clamp(2rem, 7vw, 3.4rem);
    line-height: 1.1;
    text-align: center;
}

.hero-subtitle {
    margin: 0 0 26px;
    text-align: center;
    font-size: clamp(1rem, 3vw, 1.4rem);
    color: var(--muted);
}

.card-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
}

.big-card {
    min-height: 170px;
    padding: 20px;
    border-radius: var(--radius);
    box-shadow: 0 12px 26px rgba(58, 47, 35, 0.14);
    text-decoration: none;
    color: var(--ink);
    display: grid;
    align-content: center;
    justify-items: center;
    text-align: center;
    border: 3px solid #dfd1ab;
}

.big-card__icon {
    font-size: clamp(2.4rem, 7vw, 3.4rem);
    margin-bottom: 6px;
}

.big-card__title {
    font-size: clamp(1.5rem, 5vw, 2.3rem);
    font-weight: 800;
}

.big-card__subtitle {
    font-size: clamp(0.95rem, 2.6vw, 1.25rem);
    color: #2f4f70;
}

.big-card--sun {
    background: linear-gradient(160deg, #fffdf4, var(--sun));
    border-color: #e2c773;
}
.big-card--mint {
    background: linear-gradient(160deg, #f9ffef, #d7ecb2);
    border-color: #9eba63;
}
.big-card--sky {
    background: linear-gradient(160deg, #fffaf2, #f6e7cc);
    border-color: #d9b592;
}

.game {
    display: grid;
    gap: 14px;
}

.topbar {
    display: grid;
    grid-template-columns: minmax(92px, auto) 1fr auto;
    align-items: center;
    gap: 10px;
}

.topbar__title {
    margin: 0;
    font-size: clamp(1.3rem, 4vw, 2rem);
    text-align: center;
}

.topbar__actions {
    display: flex;
    gap: 8px;
}

.back-btn {
    min-height: 56px;
    min-width: 92px;
    padding: 8px 12px;
    border-radius: 16px;
    text-decoration: none;
    color: var(--ink);
    background: linear-gradient(180deg, #fff9dc, var(--olly-cream));
    border: 3px solid #ead486;
    box-shadow: var(--shadow);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.back-btn__icon {
    font-size: 1.2rem;
    line-height: 1;
}

.back-btn__text {
    font-size: 1rem;
    font-weight: 800;
}

.icon-btn,
.primary-btn,
.choice-card {
    min-height: 56px;
    border-radius: 16px;
    border: 0;
    font-size: 1.1rem;
    font-weight: 700;
}

.icon-btn {
    min-width: 56px;
    background: #fffef7;
    box-shadow: var(--shadow);
}

.primary-btn {
    width: 100%;
    padding: 14px 18px;
    font-size: clamp(1.1rem, 3vw, 1.4rem);
    background: linear-gradient(180deg, #b7d26f, #9fbe56);
    color: #3e3125;
    border: 3px solid #8bab49;
    box-shadow: 0 8px 18px rgba(126, 154, 65, 0.35);
}

.panel {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: clamp(14px, 3vw, 24px);
    border: 3px solid #e3d6b6;
}

.panel__title {
    margin: 0;
    text-align: center;
    font-size: clamp(1.4rem, 4vw, 2rem);
}

.panel__text {
    margin: 8px 0 18px;
    text-align: center;
    color: var(--muted);
    font-size: 1.15rem;
    font-weight: 700;
}

.best-score {
    text-align: center;
    font-size: 1.2rem;
}

.mode-picker {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    margin: 0 0 14px;
}

.mode-card {
    min-height: 76px;
    border: 3px solid #d8cbab;
    border-radius: 14px;
    background: linear-gradient(180deg, #ffffff, #f2f9ff);
    color: var(--olly-brown);
    font-weight: 800;
    font-size: 0.95rem;
    display: grid;
    justify-items: center;
    align-content: center;
    gap: 2px;
    padding: 6px 4px;
}

.mode-card:nth-child(1) { background: linear-gradient(180deg, #fff8d8, #fff0ba); }
.mode-card:nth-child(2) { background: linear-gradient(180deg, #f2f9e2, #e4f1c6); }
.mode-card:nth-child(3) { background: linear-gradient(180deg, #f9f0dd, #f7e3bf); }

.mode-card__icon {
    font-size: 1.8rem;
    line-height: 1;
}

.mode-card__hint {
    font-size: 1rem;
    line-height: 1.1;
    color: #16324f;
    font-weight: 800;
}

.game-buddy {
    width: min(70%, 190px);
    margin: 0 auto 10px;
    display: block;
    filter: drop-shadow(0 8px 16px rgba(22, 50, 79, 0.12));
}

.end-mascot {
    display: block;
    width: min(52vw, 210px);
    margin: 8px auto 6px;
    filter: drop-shadow(0 8px 16px rgba(22, 50, 79, 0.16));
}

.mode-card.is-active {
    border-color: #8fac48;
    box-shadow: 0 0 0 3px rgba(143, 172, 72, 0.22);
    transform: translateY(-1px);
}

.progress {
    height: 14px;
    border-radius: 999px;
    background: #efe3c8;
    overflow: hidden;
    margin-bottom: 14px;
}

.progress__fill {
    height: 100%;
    background: linear-gradient(90deg, var(--olly-green), #c3da7b);
    transition: width 200ms ease;
}

.question-wrap {
    display: grid;
    justify-items: center;
    margin-bottom: 14px;
}

.question-wrap__help {
    margin: 0;
    color: var(--muted);
}

.question-symbol {
    font-size: clamp(4rem, 18vw, 7rem);
    font-weight: 900;
    line-height: 1;
}

.question-symbol--number {
    font-size: clamp(3.6rem, 16vw, 6.4rem);
}

.question-symbol--sequence {
    font-size: clamp(2.2rem, 10vw, 4rem);
    letter-spacing: 0.06em;
}

.choices-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.choice-card {
    width: 100%;
    padding: 14px;
    background: linear-gradient(180deg, #ffffff, #f7fbff);
    border: 3px solid #ddcfad;
    color: var(--ink);
    font-size: clamp(2rem, 8vw, 3rem);
    transition: transform 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
}

.choice-card.choice-card--dots {
    min-height: 108px;
    padding: 10px;
    display: grid;
    place-items: center;
}

.prompt-dots {
    margin-top: 8px;
}

.dot-frames {
    display: grid;
    gap: 8px;
}

.ten-frame {
    display: grid;
    grid-template-columns: repeat(5, 14px);
    gap: 6px;
    padding: 6px;
    border: 2px solid #dbe6f4;
    border-radius: 10px;
    background: #fff;
}

.dot-slot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid #bfd3ea;
    background: #eef5ff;
}

.dot-slot.is-filled {
    border-color: #1b7bff;
    background: #1b7bff;
}

.choice-card.is-correct {
    border-color: #22a763;
    transform: scale(1.03);
    box-shadow: 0 0 0 4px rgba(34, 167, 99, 0.2);
}

.choice-card.is-wrong {
    border-color: #e88952;
    transform: scale(0.98);
}

.draw-board {
    position: relative;
    height: clamp(240px, 42vw, 340px);
    border: 3px solid #dbe6f4;
    border-radius: 20px;
    background: linear-gradient(180deg, #ffffff, #f7fbff);
    overflow: hidden;
}

.draw-board__guide {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    font-size: clamp(8rem, 26vw, 12rem);
    font-weight: 900;
    color: rgba(45, 134, 255, 0.14);
    pointer-events: none;
    user-select: none;
}

.write-symbol,
.write-guide {
    font-family: var(--hand-font);
    font-weight: 800;
}

.draw-board__canvas {
    width: 100%;
    height: 100%;
    display: block;
    touch-action: none;
}

.draw-actions {
    margin-top: 12px;
    display: grid;
    grid-template-columns: 1fr 1.5fr;
    gap: 10px;
}

.draw-btn {
    width: 100%;
}

.feedback {
    min-height: 1.6em;
    text-align: center;
    margin: 12px 0 0;
    font-size: 1.2rem;
    font-weight: 700;
}

.feedback--ok { color: var(--ok); }
.feedback--warn { color: var(--olly-coral); }

.stars {
    text-align: center;
    font-size: 2.3rem;
    margin: 10px 0;
}

.modal[hidden] {
    display: none;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 30;
}

.modal__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(10, 20, 35, 0.5);
}

.modal__panel {
    position: absolute;
    left: 50%;
    top: 50%;
    width: min(92vw, 460px);
    transform: translate(-50%, -50%);
    background: #fff;
    border-radius: 20px;
    box-shadow: var(--shadow);
    padding: 14px;
}

.modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.settings-form fieldset {
    border: 2px solid #e4edf8;
    border-radius: 16px;
    margin: 10px 0;
    padding: 10px;
}

.settings-form label {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 44px;
    font-size: 1.05rem;
}

.confetti-layer {
    pointer-events: none;
    position: fixed;
    inset: 0;
    overflow: hidden;
    z-index: 40;
}

.confetti {
    position: absolute;
    width: 10px;
    height: 14px;
    opacity: 0.95;
    animation: drop 950ms linear forwards;
}

.mascot-popup[hidden] {
    display: none;
}

.mascot-popup {
    position: fixed;
    left: 50%;
    top: 50%;
    z-index: 45;
    transform: translate(-50%, -45%) scale(0.92);
    display: block;
    pointer-events: none;
    opacity: 0;
    transition: opacity 220ms ease, transform 260ms cubic-bezier(0.18, 0.8, 0.3, 1);
}

.mascot-popup.is-visible {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

.mascot-popup.is-hiding {
    opacity: 0;
    transform: translate(-50%, -54%) scale(0.95);
}

.mascot-viewport {
    height: min(54vh, 280px);
    aspect-ratio: 3 / 4;
    width: auto;
    overflow: visible;
    filter: drop-shadow(0 10px 18px rgba(22, 50, 79, 0.2));
}

.mascot-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

@keyframes drop {
    0% { transform: translateY(-10vh) rotate(0deg); }
    100% { transform: translateY(105vh) rotate(520deg); opacity: 0; }
}

:focus-visible {
    outline: 4px solid var(--ring);
    outline-offset: 2px;
}

@media (min-width: 768px) {
    .card-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .mode-picker {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .choices-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 16px;
    }
}

@media (prefers-reduced-motion: reduce) {
    * {
        transition: none !important;
        animation: none !important;
        scroll-behavior: auto !important;
    }
}
