/* Race to the Moon — game styles. GameKit tokens load first. */

:root {
    --mr-space-top: #241a4d;
    --mr-space-mid: #3a2b6e;
    --mr-space-bot: #5b3f8c;
    --mr-ink: #4A3B5C;
    --mr-glass: rgba(255, 255, 255, 0.9);
}

html, body { overflow: hidden; }
body {
    background: linear-gradient(to bottom, var(--mr-space-top) 0%, var(--mr-space-mid) 55%, var(--mr-space-bot) 100%);
    color: #fff;
}

.screen {
    position: fixed;
    inset: 0;
    z-index: 10;
    display: flex;
    flex-direction: column;
}

/* ═══════════ Starfield backdrop ═══════════ */
#backdrop {
    position: fixed; inset: 0; z-index: 0; overflow: hidden; pointer-events: none;
    background: radial-gradient(120% 80% at 50% -10%, rgba(126, 96, 200, 0.5), transparent 60%);
}
#backdrop .star {
    position: absolute;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 0 4px rgba(255, 255, 255, 0.8);
    animation: mr-twinkle 3.4s ease-in-out infinite;
}
@keyframes mr-twinkle {
    0%, 100% { opacity: 0.9; }
    50%      { opacity: 0.2; }
}

/* ═══════════ TITLE ═══════════ */
.title-inner {
    position: relative; z-index: 1;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    padding: clamp(12px, 3vh, 28px) 16px calc(14px + env(safe-area-inset-bottom));
    gap: 8px;
    text-align: center;
}
.t-top { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.game-title {
    font-size: clamp(2rem, 8vw, 3.4rem);
    line-height: 1.02;
    color: #fff;
    text-shadow: 0 4px 0 #B565D8, 0 8px 22px rgba(0, 0, 0, 0.4);
    letter-spacing: 0.5px;
}
.tagline {
    font-size: clamp(0.85rem, 3.2vw, 1.15rem);
    color: #FFF3B0;
    font-weight: bold;
    max-width: 22ch;
}

.t-scene {
    position: relative;
    width: min(78vw, 340px);
    height: clamp(140px, 26vh, 240px);
    display: flex;
    align-items: center;
    justify-content: center;
}
#title-moon { width: clamp(120px, 30vw, 200px); animation: mr-bob 5s ease-in-out infinite; }
#title-moon svg { width: 100%; height: auto; display: block; overflow: visible; }
.t-rockets {
    position: absolute; inset: 0;
    display: flex; align-items: flex-end; justify-content: center; gap: clamp(20px, 8vw, 60px);
    pointer-events: none;
}
.t-rk { width: clamp(52px, 13vw, 78px); }
.t-rk svg { width: 100%; height: auto; display: block; overflow: visible; }
#title-rk-player { animation: mr-rise 3.2s ease-in-out infinite; }
#title-rk-bolt   { animation: mr-rise 3.2s ease-in-out infinite 0.5s; }
@keyframes mr-rise {
    0%, 100% { transform: translateY(6px) rotate(-3deg); }
    50%      { transform: translateY(-14px) rotate(3deg); }
}
@keyframes mr-bob {
    0%, 100% { transform: translateY(0); }
    50%      { transform: translateY(-10px); }
}

.t-controls { display: flex; flex-direction: column; align-items: center; gap: 12px; width: 100%; }

.start-btn {
    min-height: 68px;
    padding: 14px 48px;
    font-size: clamp(1.3rem, 5vw, 1.7rem);
    font-weight: bold;
    color: #fff;
    background: linear-gradient(135deg, var(--gk-pink) 0%, var(--gk-purple) 100%);
    border: none;
    border-radius: 50px;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(181, 101, 216, 0.55);
    transition: transform 0.18s;
}
.start-btn:active { transform: scale(0.95); }
.btn-pulse { display: inline-block; animation: mr-pulse 1.6s ease-in-out infinite; }
@keyframes mr-pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.06); } }

.title-row { display: flex; gap: 12px; align-items: center; }
.star-pill {
    background: rgba(255, 255, 255, 0.16);
    border: 2px solid rgba(255, 255, 255, 0.35);
    color: #FFF3B0;
    font-weight: bold;
    font-size: 1.05rem;
    padding: 6px 16px;
    border-radius: 30px;
}

#level-row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.lvl-btn {
    position: relative;
    width: clamp(88px, 26vw, 118px);
    min-height: 84px;
    padding: 8px 6px;
    border: 3px solid rgba(255, 255, 255, 0.5);
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    transition: transform 0.15s;
}
.lvl-btn:active { transform: scale(0.95); }
.lvl-num {
    font-size: 1.5rem; font-weight: bold; color: #241a4d;
    background: #FCBF49;
    width: 36px; height: 36px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 3px 0 #E8A828;
}
.lvl-name { font-size: 0.82rem; font-weight: bold; }
.lvl-badge {
    font-size: 0.7rem; font-weight: bold;
    background: rgba(0, 0, 0, 0.25);
    padding: 1px 8px; border-radius: 20px;
}
.lvl-lock { display: none; position: absolute; top: -8px; right: -8px; font-size: 1.3rem; }
.lvl-btn.locked { opacity: 0.7; }
.lvl-btn.locked .lvl-lock { display: block; }
.lvl-btn.shake { animation: mr-shake 0.4s; }
@keyframes mr-shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-6px); } 75% { transform: translateX(6px); }
}

/* ═══════════ PLAY ═══════════ */
#screen-play { z-index: 10; padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); }

#turn-banner {
    position: relative; z-index: 2;
    margin: 4px auto 2px;
    display: flex; align-items: center; gap: 10px;
    padding: 6px 22px 6px 10px;
    border-radius: 40px;
    background: rgba(255, 255, 255, 0.95);
    color: var(--mr-ink);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3);
    border: 3px solid var(--gk-pink);
    max-width: 92vw;
}
#turn-banner .tb-rocket { width: 34px; height: 44px; display: block; }
#turn-banner .tb-rocket svg { width: 100%; height: 100%; display: block; overflow: visible; }
#turn-banner .tb-text { font-size: clamp(1.05rem, 4vw, 1.4rem); font-weight: bold; }
#turn-banner.kind-player { border-color: var(--gk-pink); }
#turn-banner.kind-bolt   { border-color: var(--gk-blue); }
#turn-banner.kind-buddy  { border-color: var(--gk-green); }

#board-wrap {
    position: relative; z-index: 1;
    flex: 1;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
}
#board { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; }
.board-svg { width: 100%; height: 100%; max-height: 100%; display: block; overflow: visible; }

.board-moon { animation: mr-moonpulse 3.6s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes mr-moonpulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.05); } }

.rocket {
    transition: transform 0.46s cubic-bezier(0.34, 1.3, 0.5, 1);
    transform-box: fill-box;
    transform-origin: center;
}
.rocket.active { filter: drop-shadow(0 0 8px rgba(255, 243, 176, 0.95)); }
.rocket.blast { transition: transform 1.7s cubic-bezier(0.5, 0, 0.9, 0.4); }
.mr-flame { opacity: 0; transform-origin: center top; }
.rocket.blast .mr-flame { opacity: 1; animation: mr-flicker 0.14s steps(2) infinite; }
@keyframes mr-flicker { 0% { transform: scaleY(1); } 100% { transform: scaleY(0.72); } }

.crater-pop { animation: mr-starpop 0.7s ease-out forwards; transform-box: fill-box; transform-origin: center; pointer-events: none; }
@keyframes mr-starpop {
    0% { transform: scale(0.3); opacity: 1; }
    100% { transform: scale(1.6) translateY(-22px); opacity: 0; }
}

/* Die dock */
#dock {
    position: relative; z-index: 2;
    display: flex; align-items: center; justify-content: center; gap: 16px;
    padding: 6px 8px 2px;
    flex-wrap: wrap;
}
#round-stars, .dock-spacer {
    min-width: 68px;
    text-align: center;
    font-weight: bold;
    font-size: 1.15rem;
    color: #FFF3B0;
}
#btn-die {
    width: clamp(84px, 20vw, 118px);
    height: clamp(84px, 20vw, 118px);
    padding: 0;
    border: none;
    border-radius: 24px;
    background: transparent;
    cursor: pointer;
    filter: drop-shadow(0 8px 14px rgba(0, 0, 0, 0.4));
    transition: transform 0.15s;
}
#btn-die #die-face, #btn-die .die-svg { width: 100%; height: 100%; display: block; }
#btn-die.active { animation: mr-diebreathe 1.5s ease-in-out infinite; }
#btn-die.active:active { transform: scale(0.9) rotate(-4deg); animation: none; }
#btn-die:disabled { cursor: default; opacity: 0.72; }
#btn-die.rolling { animation: mr-dieroll 0.28s linear infinite; }
#btn-die.bot-press { animation: mr-botpress 0.24s ease-out; }
@keyframes mr-diebreathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.06); } }
@keyframes mr-dieroll { 0% { transform: rotate(-9deg) scale(1.04); } 50% { transform: rotate(9deg) scale(1.08); } 100% { transform: rotate(-9deg) scale(1.04); } }
@keyframes mr-botpress { 0% { transform: scale(1); } 40% { transform: scale(0.86); } 100% { transform: scale(1); } }

/* ═══════════ Shared bits ═══════════ */
.info-btn {
    position: fixed;
    left: 12px; bottom: 12px;
    z-index: 50;
    width: 52px; height: 52px;
    border: none; border-radius: 50%;
    background: rgba(255, 255, 255, 0.92);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    font-size: 1.5rem; cursor: pointer;
}
.info-btn:active { transform: scale(0.92); }

#ghost-hand {
    position: fixed;
    z-index: 60;
    font-size: 2.4rem;
    pointer-events: none;
    animation: mr-tapbob 1s ease-in-out infinite;
    filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.4));
}
@keyframes mr-tapbob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(10px); } }

/* Overlays */
.overlay {
    position: fixed; inset: 0; z-index: 800;
    display: flex; align-items: center; justify-content: center;
    background: rgba(36, 26, 77, 0.6);
    padding: 20px;
}
.overlay-card { position: relative; max-width: min(92vw, 480px); color: var(--mr-ink); max-height: 90vh; overflow-y: auto; }
.overlay-card h3 { color: var(--gk-purple); margin-bottom: 10px; font-size: 1.35rem; }
.overlay-card p { line-height: 1.5; margin-bottom: 10px; }
.close-btn {
    position: absolute; top: 10px; right: 10px;
    width: 40px; height: 40px; border: none; border-radius: 50%;
    background: var(--gk-cream); color: var(--mr-ink);
    font-size: 1.2rem; cursor: pointer;
}
#info-flow {
    display: flex; align-items: center; justify-content: center; gap: 10px;
    margin: 12px 0; flex-wrap: wrap;
}
#info-flow .flow-die { width: 52px; height: 52px; }
#info-flow .flow-die .die-svg { width: 100%; height: 100%; }
#info-flow .flow-moon { width: 60px; }
#info-flow .flow-moon svg { width: 100%; height: auto; overflow: visible; }
#info-flow .flow-eq { font-weight: bold; color: var(--gk-purple); }
.tip-row { display: flex; gap: 12px; align-items: flex-start; background: var(--gk-cream); border-radius: 16px; padding: 12px 14px; }
.tip-icons { font-size: 1.8rem; }

@media (prefers-reduced-motion: reduce) {
    #backdrop .star, #title-moon, #title-rk-player, #title-rk-bolt,
    .board-moon, .btn-pulse, #btn-die.active, #ghost-hand,
    .rocket.blast .mr-flame { animation: none !important; }
    .rocket { transition: transform 0.25s linear; }
    .rocket.blast { transition: transform 0.8s ease-in; }
}
