@import url('https://fonts.googleapis.com/css2?family=Fredoka:wght@400;600;700&display=swap');

:root {
    --color-sky: #87CEEB;
    --color-coin: #f1c40f;
    --color-coin-shine: #ffe566;
    --color-coin-border: #e67e22;
    --color-accent: #ff5e62;
    --color-accent-dark: #c0392b;
    --color-blue: #3498db;
    --color-blue-dark: #1a5276;
    --color-white: #fff;
    --font-family: 'Fredoka', sans-serif;
    --z-game: 1;
    --z-ui: 10;
    --z-mobile-blocker: 100;

    --title-size: 72px;
    --btn-size: 22px;
    --score-font-size: 30px;
    --coin-icon-size: 28px;
    --screen-padding: 32px;
    --logo-max-width: clamp(270px, 46vw, 380px);
    --logo-max-height: clamp(92px, 17vh, 155px);
}

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

body {
    margin: 0;
    padding: 0;
    overflow: hidden;
    background: var(--color-sky);
    font-family: var(--font-family);
    touch-action: none;
}

body.is-mobile-blocked #game-container,
body.is-mobile-blocked #ui-layer {
    pointer-events: none;
    user-select: none;
}

#game-container {
    position: absolute;
    inset: 0;
    z-index: var(--z-game);
}

#ui-layer {
    position: absolute;
    inset: 0;
    z-index: var(--z-ui);
    pointer-events: none;
}

/* ── HUD ── */
#home-btn-wrap {
    position: absolute;
    top: 0;
    left: 0;
    padding: 14px 16px;
    display: none;
    pointer-events: none;
}

#home-btn-wrap.is-active {
    display: block;
    animation: fade-down 0.35s ease-out;
}

.hud-btn {
    pointer-events: auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    background:
        radial-gradient(circle at 30% 25%, rgba(255, 255, 255, 0.28), rgba(255, 255, 255, 0) 58%),
        linear-gradient(180deg, rgba(75, 115, 255, 0.95), rgba(35, 75, 220, 0.95));
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.26);
    color: var(--color-white);
    font-family: var(--font-family);
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
    cursor: pointer;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
    box-shadow:
        0 6px 0 rgba(8, 18, 80, 0.92),
        0 14px 26px rgba(0, 0, 0, 0.32),
        inset 0 1px 0 rgba(255, 255, 255, 0.22),
        inset 0 -10px 18px rgba(0, 0, 0, 0.18);
    transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
}

.hud-btn:hover {
    transform: translateY(-1px);
    filter: brightness(1.05) saturate(1.08);
    box-shadow:
        0 7px 0 rgba(8, 18, 80, 0.92),
        0 16px 30px rgba(0, 0, 0, 0.34),
        0 0 0 5px rgba(255, 255, 255, 0.08),
        0 0 20px rgba(52, 152, 219, 0.18),
        inset 0 1px 0 rgba(255, 255, 255, 0.22),
        inset 0 -10px 18px rgba(0, 0, 0, 0.16);
}

.hud-btn:active {
    transform: translateY(4px);
    box-shadow:
        0 2px 0 rgba(8, 18, 80, 0.92),
        0 8px 16px rgba(0, 0, 0, 0.30),
        inset 0 1px 0 rgba(255, 255, 255, 0.18),
        inset 0 -10px 18px rgba(0, 0, 0, 0.18);
}

.hud-btn__icon {
    font-size: 18px;
    line-height: 1;
    text-shadow:
        0 2px 0 rgba(8, 18, 80, 0.6),
        0 4px 10px rgba(0, 0, 0, 0.32);
}

#score-display {
    position: absolute;
    top: 0;
    right: 0;
    padding: 14px 16px;
    display: none;
}

#score-display.is-active {
    display: block;
    animation: fade-down 0.35s ease-out;
}

#score-display.score-pop .hud-pill {
    animation: score-pop 0.12s ease;
}

@keyframes fade-down {
    from { opacity: 0; transform: translateY(-12px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes score-pop {
    50% { transform: scale(1.12); }
}

.hud-pill {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 8px 18px 8px 12px;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 40px;
    border: 2px solid rgba(255, 255, 255, 0.2);
    font-size: var(--score-font-size);
    font-weight: 700;
    color: var(--color-white);
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

.coin-icon {
    width: var(--coin-icon-size);
    height: var(--coin-icon-size);
    background: radial-gradient(circle at 35% 30%, var(--color-coin-shine), var(--color-coin));
    border-radius: 50%;
    border: 3px solid var(--color-coin-border);
    flex-shrink: 0;
}

.coin-icon--lg {
    --coin-icon-size: 44px;
}

/* ── Screen overlay (lets 3D world show through) ── */
.screen {
    position: absolute;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    padding: var(--screen-padding);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.screen.is-active {
    display: flex;
}

.screen-overlay {
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.15) 0%, rgba(0, 0, 0, 0.55) 100%);
    pointer-events: none;
}

.screen-overlay--heavy {
    background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.35) 0%, rgba(0, 0, 0, 0.7) 100%);
}

/* ── Menu content ── */
.menu-content {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    width: 100%;
    max-width: 560px;
}

.screen.is-entering .menu-content {
    animation: menu-in 0.5s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes menu-in {
    from {
        opacity: 0;
        transform: translateY(24px) scale(0.97);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Logo */
.game-logo {
    display: block;
    width: auto;
    height: auto;
    max-width: min(100%, var(--logo-max-width));
    max-height: var(--logo-max-height);
    margin: 0 auto 12px;
    object-fit: contain;
    filter: drop-shadow(0 8px 20px rgba(0, 0, 0, 0.4));
    user-select: none;
    -webkit-user-drag: none;
}

.game-tagline {
    margin: 0 0 24px;
    font-size: 18px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.85);
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
    letter-spacing: 0.5px;
}

/* Controls row */
.controls-row {
    display: flex;
    gap: 12px;
    margin-bottom: 36px;
    padding: 14px 20px;
    background: rgba(0, 0, 0, 0.35);
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    backdrop-filter: blur(8px);
}

.controls-row__item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 0 16px;
    border-right: 1px solid rgba(255, 255, 255, 0.1);
}

.controls-row__item:last-child {
    border-right: none;
}

.controls-row__item span {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: rgba(255, 255, 255, 0.65);
}

.controls-row kbd {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    padding: 0 6px;
    font-family: var(--font-family);
    font-size: 15px;
    font-weight: 700;
    color: #2c3e50;
    background: #ecf0f1;
    border-radius: 8px;
    border: none;
    box-shadow: 0 3px 0 #7f8c8d;
}

.controls-row kbd + kbd {
    margin-left: 4px;
}

/* Play button */
.game-btn {
    min-width: 220px;
    padding: 16px 48px;
    font-family: var(--font-family);
    font-size: var(--btn-size);
    font-weight: 700;
    letter-spacing: 3px;
    text-transform: uppercase;
    color: var(--color-white);
    background: var(--color-accent);
    border: none;
    border-radius: 12px;
    cursor: pointer;
    box-shadow: 0 6px 0 var(--color-accent-dark), 0 12px 28px rgba(0, 0, 0, 0.35);
    transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.game-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 0 var(--color-accent-dark), 0 16px 32px rgba(0, 0, 0, 0.4);
}

.game-btn:active {
    transform: translateY(4px);
    box-shadow: 0 2px 0 var(--color-accent-dark), 0 6px 16px rgba(0, 0, 0, 0.3);
}

.game-btn--blue {
    background: var(--color-blue);
    box-shadow: 0 6px 0 var(--color-blue-dark), 0 12px 28px rgba(0, 0, 0, 0.35);
}

.game-btn--blue:hover {
    box-shadow: 0 8px 0 var(--color-blue-dark), 0 16px 32px rgba(0, 0, 0, 0.4);
}

.game-btn--blue:active {
    box-shadow: 0 2px 0 var(--color-blue-dark), 0 6px 16px rgba(0, 0, 0, 0.3);
}

.game-hint {
    margin: 18px 0 0;
    font-size: 13px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.45);
    letter-spacing: 0.5px;
}

/* ── Game Over ── */
.gameover-eyebrow {
    margin: 0 0 8px;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 3px;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.5);
}

.gameover-title {
    margin: 0 0 32px;
    font-size: calc(var(--title-size) * 0.75);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 3px;
    color: var(--color-accent);
    text-shadow: 0 4px 0 var(--color-accent-dark), 0 8px 20px rgba(0, 0, 0, 0.4);
}

.final-score {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 36px;
    padding: 16px 32px;
    background: rgba(0, 0, 0, 0.35);
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.final-score__num {
    font-size: 56px;
    font-weight: 700;
    line-height: 1;
    color: var(--color-coin);
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.final-score__label {
    font-size: 18px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.6);
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* ── Mobile blocker ── */
.mobile-blocker {
    position: fixed;
    inset: 0;
    z-index: var(--z-mobile-blocker);
    display: none;
    align-items: center;
    justify-content: center;
    padding: var(--screen-padding);
    background: #1a252f;
}

.mobile-blocker.is-active {
    display: flex;
}

.mobile-blocker__card {
    width: 100%;
    max-width: 380px;
    padding: 40px 32px;
    text-align: center;
    background: #243447;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.5);
}

.mobile-blocker__icon {
    font-size: 48px;
    margin-bottom: 20px;
    line-height: 1;
}

.mobile-blocker h1 {
    margin: 0 0 12px;
    font-size: 26px;
    font-weight: 700;
    color: var(--color-white);
    letter-spacing: 1px;
}

.mobile-blocker p {
    margin: 0 0 20px;
    font-size: 16px;
    font-weight: 600;
    line-height: 1.5;
    color: rgba(255, 255, 255, 0.65);
}

.mobile-blocker__note {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.35);
    padding-top: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

/* ── Tablet Landscape (769px – 1024px) ── */
@media (max-width: 1024px) and (min-width: 769px) {
    :root {
        --title-size: 60px;
        --btn-size: 20px;
        --score-font-size: 26px;
        --screen-padding: 24px;
        --logo-max-width: clamp(250px, 52vw, 340px);
        --logo-max-height: clamp(86px, 16vh, 140px);
    }
}

/* ── Tablet Portrait (641px – 768px) ── */
@media (max-width: 768px) and (min-width: 641px) {
    :root {
        --title-size: 52px;
        --btn-size: 19px;
        --score-font-size: 24px;
        --screen-padding: 20px;
        --logo-max-width: clamp(225px, 64vw, 315px);
        --logo-max-height: clamp(78px, 14vh, 122px);
    }

    .controls-row {
        gap: 8px;
        padding: 12px 14px;
    }

    .controls-row__item {
        padding: 0 10px;
    }

    .game-tagline {
        font-size: 16px;
        margin-bottom: 20px;
    }
}

/* ── Short / embedded viewports ── */
@media (max-height: 720px) {
    :root {
        --logo-max-width: clamp(250px, 44vw, 340px);
        --logo-max-height: clamp(86px, 15vh, 132px);
        --screen-padding: 20px;
    }

    .game-tagline {
        margin-bottom: 16px;
        font-size: 16px;
    }

    .controls-row {
        margin-bottom: 24px;
    }
}

/* ── Desktop embed (portal iframe size like 900×640) ── */
@media (min-width: 700px) and (max-height: 820px) {
    :root {
        --logo-max-width: clamp(320px, 56vw, 450px);
        --logo-max-height: clamp(112px, 21vh, 185px);
    }
}

/* ── Mobile (≤640px) ── */
@media (max-width: 640px) {
    .mobile-blocker {
        display: flex;
    }

    :root {
        --screen-padding: 20px;
    }
}

/* ── Small Mobile (≤480px) ── */
@media (max-width: 480px) {
    :root {
        --title-size: 40px;
        --btn-size: 17px;
        --screen-padding: 16px;
        --logo-max-width: clamp(190px, 74vw, 275px);
        --logo-max-height: clamp(62px, 12vh, 100px);
    }

    .controls-row {
        flex-direction: column;
        gap: 0;
        width: 100%;
        max-width: 260px;
        padding: 8px 0;
    }

    .controls-row__item {
        flex-direction: row;
        justify-content: center;
        gap: 12px;
        padding: 10px 16px;
        border-right: none;
        border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    }

    .controls-row__item:last-child {
        border-bottom: none;
    }

    .game-btn {
        min-width: 180px;
        padding: 14px 36px;
    }

    .final-score__num {
        font-size: 44px;
    }

    .mobile-blocker__card {
        padding: 32px 24px;
    }

    .mobile-blocker h1 {
        font-size: 22px;
    }
}

/* ── Landscape Mobile ── */
@media (orientation: landscape) and (max-height: 500px) {
    .mobile-blocker {
        display: flex;
    }

    .screen {
        align-items: flex-start;
        padding-top: 16px;
        overflow-y: auto;
    }

    :root {
        --title-size: 38px;
        --btn-size: 16px;
        --score-font-size: 22px;
        --screen-padding: 16px;
        --logo-max-width: clamp(200px, 38vw, 275px);
        --logo-max-height: clamp(64px, 23vh, 96px);
    }

    .game-tagline {
        font-size: 14px;
        margin-bottom: 14px;
    }

    .game-logo {
        margin-bottom: 8px;
    }

    .controls-row {
        margin-bottom: 20px;
        padding: 10px 14px;
    }

    .controls-row__item {
        padding: 0 10px;
    }

    .controls-row kbd {
        min-width: 30px;
        height: 30px;
        font-size: 13px;
    }

    .game-btn {
        min-width: 160px;
        padding: 12px 32px;
    }

    .game-hint {
        margin-top: 12px;
    }

    .gameover-title {
        margin-bottom: 20px;
    }

    .final-score {
        margin-bottom: 20px;
        padding: 12px 24px;
    }

    .final-score__num {
        font-size: 36px;
    }

    .mobile-blocker__card {
        max-width: 420px;
        padding: 24px 28px;
    }

    .mobile-blocker__icon {
        font-size: 36px;
        margin-bottom: 12px;
    }

    .mobile-blocker h1 {
        font-size: 20px;
    }

    .mobile-blocker p {
        font-size: 14px;
        margin-bottom: 14px;
    }
}

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