* {
    box-sizing: border-box;
}

:root {
    color-scheme: dark;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-synthesis: none;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    --page: #111827;
    --surface: #1b2537;
    --stage: #151f30;
    --text: #f5f7fb;
    --muted: #9aa8bc;
    --accent: #8b7bff;
    --accent-strong: #6654ed;
    --glow: rgb(139 123 255 / 28%);
}

body[data-theme="sunset"] {
    color-scheme: light;
    --page: #fff3e9;
    --surface: #fffaf6;
    --stage: #ffeadb;
    --text: #432b36;
    --muted: #846b70;
    --accent: #ff8568;
    --accent-strong: #ed5c66;
    --glow: rgb(237 92 102 / 25%);
}

body[data-theme="mint"] {
    color-scheme: light;
    --page: #eaf8f1;
    --surface: #f8fffb;
    --stage: #d9f1e5;
    --text: #183c34;
    --muted: #638078;
    --accent: #39bd91;
    --accent-strong: #159b78;
    --glow: rgb(21 155 120 / 25%);
}

body {
    min-width: 320px;
    min-height: 100vh;
    margin: 0;
    padding: 48px 20px;
    background:
        radial-gradient(ellipse at 50% 0%, var(--glow), transparent 55%),
        var(--page);
    color: var(--text);
    transition: background-color 180ms ease, color 180ms ease;
}

.game {
    width: min(100%, 860px);
    margin: 0 auto;
}

.game-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 32px;
}

.eyebrow {
    margin: 0 0 8px;
    color: var(--accent);
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

h1 {
    margin: 0;
    font-size: clamp(2rem, 6vw, 3.25rem);
    letter-spacing: -0.055em;
    line-height: 1;
}

.subtitle {
    max-width: 430px;
    margin: 12px 0 0;
    color: var(--muted);
    line-height: 1.6;
}

.theme-picker {
    display: grid;
    gap: 7px;
    color: var(--muted);
    font-size: 0.8rem;
    font-weight: 700;
}

.theme-picker select {
    min-width: 150px;
    padding: 10px 34px 10px 12px;
    border: 1px solid color-mix(in srgb, var(--muted), transparent 65%);
    border-radius: 12px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    cursor: pointer;
}

.stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

.stat-card {
    display: grid;
    gap: 8px;
    min-height: 100px;
    padding: 18px 22px;
    border: 1px solid color-mix(in srgb, var(--muted), transparent 82%);
    border-radius: 18px;
    background: var(--surface);
}

.stat-label {
    color: var(--muted);
    font-size: 0.8rem;
    font-weight: 700;
}

.stat-card strong {
    font-size: clamp(1.7rem, 5vw, 2.2rem);
    letter-spacing: -0.04em;
    line-height: 1;
}

.level-card {
    gap: 7px;
}

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

.level-count {
    display: grid;
    width: 28px;
    height: 28px;
    place-items: center;
    border-radius: 50%;
    background: var(--accent);
    color: white;
    font-size: 0.85rem;
    font-weight: 900;
}

.level-card .level-name {
    font-size: 1.15rem;
    letter-spacing: -0.02em;
}

.progress-track {
    height: 7px;
    overflow: hidden;
    border-radius: 99px;
    background: color-mix(in srgb, var(--muted), transparent 82%);
}

.progress-track span {
    display: block;
    width: 0;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--accent), var(--accent-strong));
    transition: width 250ms ease;
}

.level-hint {
    color: var(--muted);
    font-size: 0.68rem;
}

.stat-unit {
    color: var(--accent);
    font-size: 0.9rem;
    letter-spacing: 0;
}

.play-area {
    position: relative;
    height: 360px;
    overflow: hidden;
    border: 1px solid color-mix(in srgb, var(--muted), transparent 85%);
    border-radius: 24px;
    background-color: var(--stage);
    background-image: radial-gradient(color-mix(in srgb, var(--muted), transparent 79%) 1px, transparent 1px);
    background-size: 22px 22px;
}

#clickButton {
    position: absolute;
    display: flex;
    inset: 0;
    width: 100%;
    height: 100%;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 12px;
    border: 0;
    border-radius: 23px;
    background: linear-gradient(145deg, var(--accent), var(--accent-strong));
    box-shadow: inset 0 0 0 8px color-mix(in srgb, white, transparent 82%);
    color: white;
    font: inherit;
    font-size: clamp(1.5rem, 5vw, 2.5rem);
    font-weight: 900;
    letter-spacing: 0.08em;
    cursor: pointer;
    user-select: none;
    text-align: center;
    transition: filter 120ms ease, transform 120ms ease;
}

#clickButton:hover {
    filter: brightness(1.08);
}

#clickButton:active {
    filter: brightness(0.94);
    transform: scale(0.992);
}

#clickButton.clicked {
    animation: click-pop 180ms ease-out;
}

@keyframes click-pop {
    50% {
        filter: brightness(1.2);
    }
}

#clickButton:focus-visible,
.theme-picker select:focus-visible {
    outline: 3px solid var(--text);
    outline-offset: 4px;
}

.button-icon {
    font-size: clamp(2.5rem, 8vw, 4rem);
    line-height: 1;
}

.click-value {
    font-size: 0.9rem;
    font-weight: 600;
    letter-spacing: 0;
    opacity: 0.8;
}

.achievement-section {
    margin-top: 34px;
}

.section-heading {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    margin-bottom: 14px;
}

.section-heading .eyebrow {
    margin-bottom: 5px;
}

.section-heading h2 {
    margin: 0;
    font-size: 1.6rem;
    letter-spacing: -0.04em;
}

.achievement-count {
    padding: 7px 11px;
    border: 1px solid color-mix(in srgb, var(--muted), transparent 78%);
    border-radius: 99px;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 800;
}

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

.achievement-card {
    display: grid;
    grid-template-columns: 40px minmax(0, 1fr) auto;
    min-width: 0;
    align-items: center;
    gap: 10px 12px;
    padding: 14px;
    border: 1px solid color-mix(in srgb, var(--muted), transparent 84%);
    border-radius: 15px;
    background: color-mix(in srgb, var(--surface), transparent 12%);
    opacity: 0.68;
    transition: border-color 180ms ease, opacity 180ms ease, transform 180ms ease;
}

.achievement-card.unlocked {
    border-color: color-mix(in srgb, var(--accent), transparent 48%);
    opacity: 1;
}

.achievement-card.unlocked .achievement-icon {
    background: var(--glow);
}

.achievement-icon {
    display: grid;
    width: 40px;
    height: 40px;
    flex: 0 0 40px;
    place-items: center;
    border-radius: 12px;
    background: color-mix(in srgb, var(--muted), transparent 90%);
    font-size: 1.25rem;
}

.achievement-details {
    display: grid;
    min-width: 0;
    gap: 4px;
}

.achievement-details strong {
    overflow: hidden;
    font-size: 0.83rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.achievement-details span {
    color: var(--muted);
    font-size: 0.7rem;
    line-height: 1.35;
}

.achievement-status {
    color: var(--muted);
    font-size: 0.62rem;
    font-weight: 800;
    white-space: nowrap;
}

.achievement-card.unlocked .achievement-status {
    color: var(--accent);
}

.achievement-progress {
    grid-column: 2 / -1;
    height: 4px;
    overflow: hidden;
    border-radius: 99px;
    background: color-mix(in srgb, var(--muted), transparent 84%);
}

.achievement-progress span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: var(--accent);
    transition: width 180ms ease;
}

.toast {
    position: fixed;
    z-index: 2;
    right: 20px;
    bottom: 20px;
    max-width: min(360px, calc(100vw - 40px));
    margin: 0;
    padding: 14px 18px;
    border: 1px solid color-mix(in srgb, var(--accent), transparent 40%);
    border-radius: 14px;
    background: var(--surface);
    box-shadow: 0 12px 40px rgb(0 0 0 / 22%);
    color: var(--text);
    font-size: 0.9rem;
    font-weight: 700;
    opacity: 0;
    pointer-events: none;
    transform: translateY(10px);
    transition: opacity 180ms ease, transform 180ms ease;
}

.toast.visible {
    opacity: 1;
    transform: translateY(0);
}

.reset-button {
    display: block;
    margin: 24px auto 0;
    padding: 9px 12px;
    border: 0;
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-size: 0.76rem;
    cursor: pointer;
}

.reset-button:hover {
    color: var(--text);
}

#clickButton:focus-visible,
.theme-picker select:focus-visible,
.reset-button:focus-visible {
    outline: 3px solid var(--text);
    outline-offset: 4px;
}

@media (max-width: 560px) {
    body {
        padding: 32px 16px;
    }

    .game-header {
        flex-direction: column;
        margin-bottom: 24px;
    }

    .theme-picker {
        grid-template-columns: auto 1fr;
        align-items: center;
    }

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

    .level-card {
        grid-column: 1 / -1;
    }

    .stat-card {
        min-height: 88px;
        padding: 12px;
    }

    .stat-label {
        font-size: 0.72rem;
    }

    .level-card .level-name {
        font-size: 0.95rem;
    }

    .level-hint {
        font-size: 0.6rem;
    }

    .play-area {
        height: 320px;
    }

    #clickButton {
        font-size: clamp(1.1rem, 5vw, 1.6rem);
    }

    .achievements {
        grid-template-columns: 1fr;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        transition-duration: 0.01ms !important;
    }
}
