:root {
    --bg-deep: #0d0520;
    --bg-mid: #1a0a3d;
    --bg-card: rgba(255,255,255,0.07);
    --gold: #f5c518;
    --gold-dark: #c49a10;
    --green: #2ecc71;
    --red: #e74c3c;
    --white: #f0e8ff;
    --muted: rgba(240,232,255,0.55);
    --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: var(--font);
    background: var(--bg-deep);
    color: var(--white);
}

/* ── Tunnel background ───────────────────────────────── */
#tunnel-bg {
    position: fixed;
    inset: 0;
    z-index: 0;
    background: radial-gradient(ellipse at 50% 42%, #6a1aaa 0%, #2a0a5d 28%, #1a0a3d 55%, var(--bg-deep) 100%);
    overflow: hidden;
}
    /* Central vortex core glow */
    #tunnel-bg::before {
        content: '';
        position: absolute;
        left: 50%;
        top: 44%;
        transform: translate(-50%, -50%);
        width: 140px;
        height: 140px;
        border-radius: 50%;
        background: radial-gradient(circle, rgba(245,197,24,0.65) 0%, rgba(180,60,255,0.45) 38%, transparent 72%);
        animation: core-pulse 2.2s ease-in-out infinite alternate;
    }

@keyframes core-pulse {
    from {
        transform: translate(-50%,-50%) scale(0.65);
        opacity: 0.55;
    }

    to {
        transform: translate(-50%,-50%) scale(1.35);
        opacity: 1;
    }
}

#tunnel-bg::after {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at 50% 44%, rgba(245,197,24,0.2) 0%, rgba(160,80,255,0.12) 28%, transparent 60%);
    animation: bg-breathe 4s ease-in-out infinite alternate;
}

@keyframes bg-breathe {
    from {
        transform: scale(1);
        opacity: 0.45;
    }

    to {
        transform: scale(1.3);
        opacity: 1;
    }
}

.t-ring {
    position: absolute;
    border-radius: 50%;
    border: 3px solid;
    left: 50%;
    top: 44%;
    transform: translate(-50%,-50%);
    animation: ring-out 3s ease-in infinite;
    animation-fill-mode: backwards;
}

#tunnel-bg.rings-paused .t-ring {
    animation-play-state: paused;
    opacity: 0 !important;
}

#tunnel-bg.rings-paused::before {
    animation-play-state: paused;
    opacity: 0;
    transition: opacity 0.6s ease;
}

@keyframes ring-out {
    0% {
        opacity: 0;
        transform: translate(-50%,-50%) scale(0.04);
    }

    12% {
        opacity: 0.65;
    }

    55% {
        opacity: 0.42;
    }

    100% {
        opacity: 0;
        transform: translate(-50%,-50%) scale(1.6);
    }
}

.t-star {
    position: absolute;
    border-radius: 50%;
    background: #fff;
    animation: twinkle 2.2s ease-in-out infinite;
}

@keyframes twinkle {
    0%,100% {
        opacity: 0.12;
    }

    50% {
        opacity: 0.95;
    }
}

/* ── App shell ───────────────────────────────────────── */
#app {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 480px;
    height: 100vh;
    height: 100dvh;
    margin: 0 auto;
    overflow: hidden;
}

/* ── Screens ─────────────────────────────────────────── */
.screen {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 28px 22px 28px;
    overflow-y: auto;
    scrollbar-width: none;
    opacity: 0;
    transform: translateY(18px);
    pointer-events: none;
    transition: opacity 0.28s ease, transform 0.28s ease;
}

    .screen::-webkit-scrollbar {
        display: none;
    }

    .screen.active {
        opacity: 1;
        transform: translateY(0);
        pointer-events: auto;
    }

.screen-center {
    justify-content: center;
}

/* ── Mission badge ───────────────────────────────────── */
.badge {
    display: inline-block;
    background: var(--gold);
    color: var(--bg-deep);
    padding: 5px 16px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.6px;
    text-transform: uppercase;
    margin-bottom: 18px;
}

/* ── Typography ──────────────────────────────────────── */
.title {
    font-size: clamp(28px, 7vw, 44px);
    font-weight: 900;
    text-align: center;
    color: var(--gold);
    text-shadow: 0 0 24px rgba(245,197,24,0.4);
    line-height: 1.1;
    margin-bottom: 6px;
}

.heading {
    font-size: clamp(20px, 5.2vw, 28px);
    font-weight: 800;
    text-align: center;
    line-height: 1.25;
    margin-bottom: 12px;
}

.body-text {
    font-size: clamp(15px, 3.8vw, 19px);
    line-height: 1.55;
    text-align: center;
    margin-bottom: 14px;
}

.muted {
    font-size: 13px;
    color: var(--muted);
    text-align: center;
}

/* ── Card ────────────────────────────────────────────── */
.card {
    width: 100%;
    background: var(--bg-card);
    border: 1px solid rgba(255,255,255,0.11);
    border-radius: 18px;
    padding: 18px 20px;
    margin-bottom: 18px;
    backdrop-filter: blur(6px);
}
@keyframes clue-pulse {
    0%   { transform: scale(1);     box-shadow: 0 0 0    rgba(245,197,24,0);    border-color: rgba(255,255,255,0.11); }
    25%  { transform: scale(1.07);  box-shadow: 0 0 28px rgba(245,197,24,0.7);  border-color: rgba(245,197,24,0.8); }
    55%  { transform: scale(1.045); box-shadow: 0 0 18px rgba(245,197,24,0.4);  border-color: rgba(245,197,24,0.5); }
    75%  { transform: scale(1.065); box-shadow: 0 0 24px rgba(245,197,24,0.55); border-color: rgba(245,197,24,0.7); }
    100% { transform: scale(1);     box-shadow: 0 0 0    rgba(245,197,24,0);    border-color: rgba(255,255,255,0.11); }
}
.card-pulse {
    animation: clue-pulse 700ms cubic-bezier(0.36,0.07,0.19,0.97) forwards;
}

/* ── Buttons ─────────────────────────────────────────── */
.btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 18px 20px;
    border: none;
    border-radius: 16px;
    font-family: var(--font);
    font-size: clamp(16px, 4vw, 20px);
    font-weight: 700;
    cursor: pointer;
    min-height: 60px;
    transition: transform 0.1s ease, box-shadow 0.1s ease;
    -webkit-appearance: none;
    touch-action: manipulation;
}

    .btn:active {
        transform: scale(0.965);
    }

.btn-primary {
    background: linear-gradient(135deg, var(--gold) 0%, var(--gold-dark) 100%);
    color: var(--bg-deep);
    box-shadow: 0 4px 18px rgba(245,197,24,0.32);
}

    .btn-primary:active {
        box-shadow: 0 2px 8px rgba(245,197,24,0.18);
    }

.btn-secondary {
    background: rgba(255,255,255,0.09);
    color: var(--white);
    border: 1.5px solid rgba(255,255,255,0.22);
}

.btn-answer {
    background: rgba(255,255,255,0.09);
    color: var(--white);
    border: 1.5px solid rgba(255,255,255,0.18);
    margin-bottom: 10px;
    justify-content: flex-start;
    text-align: left;
    border-radius: 14px;
    font-size: clamp(14px, 3.6vw, 18px);
    padding: 16px 18px;
}

    .btn-answer.correct {
        background: rgba(46,204,113,0.25);
        border-color: var(--green);
        color: #8fffd4;
    }

    .btn-answer.wrong {
        background: rgba(231,76,60,0.15);
        border-color: rgba(231,76,60,0.4);
        opacity: 0.6;
    }

    .btn-answer.locked {
        pointer-events: none;
    }

/* ── Feedback banner ─────────────────────────────────── */
.feedback {
    width: 100%;
    padding: 13px 16px;
    border-radius: 13px;
    font-size: clamp(14px, 3.5vw, 16px);
    font-weight: 700;
    text-align: center;
    margin-bottom: 12px;
}

.feedback-ok {
    background: rgba(46,204,113,0.18);
    border: 1.5px solid var(--green);
    color: #8fffd4;
}

.feedback-no {
    background: rgba(231,76,60,0.14);
    border: 1.5px solid rgba(231,76,60,0.55);
    color: #ffb3b3;
}

/* ── Progress dots ───────────────────────────────────── */
.progress-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 14px 0;
}

.pdot {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: rgba(255,255,255,0.18);
    border: 2px solid rgba(255,255,255,0.1);
    transition: background 0.35s, box-shadow 0.35s;
}

    .pdot.lit {
        background: var(--gold);
        border-color: var(--gold-dark);
        box-shadow: 0 0 10px rgba(245,197,24,0.55);
    }

/* ── Token screen ────────────────────────────────────── */
.token-icon {
    width: 88px;
    height: 88px;
    display: block;
    margin: 4px auto 6px;
    animation: token-appear 0.55s cubic-bezier(0.175,0.885,0.32,1.275) both;
}

@keyframes token-appear {
    from {
        transform: scale(0.2) rotate(-15deg);
        opacity: 0;
    }

    to {
        transform: scale(1) rotate(0);
        opacity: 1;
    }
}

.token-count-text {
    font-size: clamp(17px,4.5vw,23px);
    font-weight: 800;
    color: var(--gold);
}

/* ── Completion screen ───────────────────────────────── */
.big-celebrate {
    width: 210px;
    height: 210px;
    display: block;
    margin: 0 auto 6px;
    animation: pop 0.5s cubic-bezier(0.175,0.885,0.32,1.275) both;
}

@keyframes pop {
    from {
        transform: scale(0) rotate(-12deg);
    }

    to {
        transform: scale(1) rotate(0);
    }
}

.reward-code {
    font-size: clamp(32px,8.5vw,50px);
    font-weight: 900;
    color: var(--gold);
    background: rgba(245,197,24,0.1);
    border: 2.5px solid var(--gold);
    border-radius: 16px;
    padding: 16px 32px;
    margin: 12px 0;
    letter-spacing: 6px;
    text-shadow: 0 0 18px rgba(245,197,24,0.5);
}


/* ── Gremlin ─────────────────────────────────────────── */
.gremlin {
    width: 256px;
    height: 214px;
    display: block;
    margin: 0 auto;
    animation: gremlin-bounce 2.2s ease-in-out infinite;
}

@keyframes gremlin-bounce {
    0%,100% {
        transform: translateY(0) rotate(-4deg);
    }

    50% {
        transform: translateY(-10px) rotate(4deg);
    }
}

/* ── Phase 6: iOS safe areas ────────────────────────── */
#app {
    padding-bottom: max(16px, env(safe-area-inset-bottom, 16px));
}

.screen {
    padding-top: max(28px, env(safe-area-inset-top, 28px));
}

/* ── Phase 6: Persistent progress header ────────────── */
#prog-hdr {
    position: absolute;
    top: max(8px, env(safe-area-inset-top, 8px));
    left: 0;
    right: 0;
    height: 28px;
    z-index: 20;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 9px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
}
/* Gameplay screens need extra top room for the header */
.screen-game {
    padding-top: max(52px, calc(env(safe-area-inset-top, 0px) + 52px));
}

/* ── Mission photo ───────────────────────────────────── */
@keyframes photo-glow {
    from { box-shadow: 0 0 4px  rgba(245,197,24,0.10), 0 6px 28px rgba(0,0,0,0.65); }
    to   { box-shadow: 0 0 32px rgba(245,197,24,0.80), 0 0 60px rgba(245,197,24,0.30), 0 6px 28px rgba(0,0,0,0.65); }
}
.mission-photo-wrap {
    position: relative;
    width: 100%;
    margin-bottom: 16px;
    border-radius: 16px;
    overflow: hidden;
    border: 2px solid var(--gold-dark);
    animation: photo-glow 2.2s ease-in-out infinite alternate;
}
.mission-photo-wrap img {
    width: 100%;
    max-height: 180px;
    object-fit: cover;
    display: block;
    filter: sepia(0.65) contrast(1.1) brightness(0.85);
}
.mission-photo-wrap .vignette {
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse at center, transparent 50%, rgba(0,0,0,0.55) 100%);
    pointer-events: none;
}

/* ── Phase 6: Completion token pop ───────────────────── */
@keyframes token-pop {
    0% {
        transform: scale(0) rotate(-15deg);
        opacity: 0;
    }

    75% {
        transform: scale(1.18) rotate(5deg);
        opacity: 1;
    }

    100% {
        transform: scale(1) rotate(0deg);
        opacity: 1;
    }
}

/* ── Loading screen ──────────────────────────────────── */
#load-bar-wrap {
    width: 220px;
    height: 8px;
    background: rgba(255,255,255,0.12);
    border-radius: 4px;
    overflow: hidden;
}

#load-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--gold-dark), var(--gold));
    border-radius: 4px;
    transition: width 0.2s ease;
}

/* ── Tap-the-Past pop effect ─────────────────────────── */
@keyframes tt-pop {
    0% {
        transform: translate(-50%,-50%) scale(0.5);
        opacity: 1;
    }

    100% {
        transform: translate(-50%,-50%) scale(2.2);
        opacity: 0;
    }
}

@keyframes tt-wrong {
    0% {
        filter: brightness(1) saturate(1) hue-rotate(0deg);
        transform: translateX(0);
    }

    20% {
        filter: brightness(2.2) saturate(0.3) hue-rotate(310deg);
        transform: translateX(-8px);
    }

    45% {
        filter: brightness(2) saturate(0.3) hue-rotate(310deg);
        transform: translateX(7px);
    }

    70% {
        filter: brightness(1.8) saturate(0.3) hue-rotate(310deg);
        transform: translateX(-5px);
    }

    100% {
        filter: brightness(1) saturate(1) hue-rotate(0deg);
        transform: translateX(0);
        opacity: 0;
    }
}

/* ── Utilities ───────────────────────────────────────── */
.hidden {
    display: none !important;
}

.w-full {
    width: 100%;
}

.mt-8 {
    margin-top: 8px;
}

.mt-12 {
    margin-top: 12px;
}

.mt-16 {
    margin-top: 16px;
}

.mt-20 {
    margin-top: 20px;
}

.divider {
    width: 100%;
    height: 1px;
    background: rgba(255,255,255,0.1);
    margin: 14px 0;
}

.center {
    text-align: center;
}
