:root {
    --violet: #6c5ce7;
    --violet-deep: #7c3aed;
    --rose: #ec4899;
    --ink: #2a1848;
    --mint: #159a79;
    --shift-x: 0px;
    --shift-y: 0px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    overflow: hidden;
    background: #ffffff;
    color: var(--ink);
    font-family: "Manrope", "Segoe UI", sans-serif;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    overscroll-behavior: none;
}

button, input { font: inherit; }

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
}

.sky {
    position: fixed;
    inset: 0;
    z-index: 0;
    overflow: hidden;
    pointer-events: none;
    background: #ffffff;
}

.float {
    position: absolute;
    font-size: 26px;
    line-height: 1;
    opacity: 0.2;
    margin-left: var(--shift-x);
    margin-top: var(--shift-y);
    animation: float 18s ease-in-out infinite;
}
.f1 { left: 6%; top: 12%; }
.f2 { right: 7%; top: 16%; animation-duration: 22s; }
.f3 { left: 8%; bottom: 14%; animation-duration: 20s; }
.f4 { right: 9%; bottom: 18%; }
.f5 { left: 18%; top: 38%; animation-duration: 24s; opacity: 0.14; }

.app { position: relative; z-index: 1; height: 100vh; height: 100dvh; }

.loader {
    position: fixed;
    inset: 0;
    z-index: 8;
    display: grid;
    place-items: center;
    background: #ffffff;
    color: var(--violet-deep);
    font-weight: 800;
    transition: opacity 0.3s ease;
}
.loader.is-done { opacity: 0; pointer-events: none; }

.shell {
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 16px 18px 12px;
}

.camera-wrap {
    height: min(calc(100dvh - 112px), calc((100vw - 28px) * 1280 / 720));
    width: auto;
    max-width: calc(100vw - 28px);
    aspect-ratio: 720 / 1280;
    flex: 0 1 auto;
    background: #ffffff;
    border: 0;
    box-shadow: none;
}

.camera {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #ffffff;
    border: 0;
    box-shadow: none;
    border-radius: 0;
    transform: scale(1);
    transform-origin: center 42%;
    transition: transform 1.05s cubic-bezier(.22, .8, .24, 1);
}
.camera.is-close { transform: scale(1.06); }
.camera.is-wide { transform: scale(0.96); }
.camera.is-react { transform: scale(1.03); }

.halo, .floor-shadow { display: none; }
.confetti { position: absolute; inset: 0; z-index: 0; overflow: hidden; display: none; pointer-events: none; }
.confetti-front { z-index: 3; }
.app[data-state="celebrate"] .confetti { display: block; }
.confetti i {
    position: absolute;
    top: -8%;
    width: 8px;
    height: 12px;
    border-radius: 2px;
    animation-name: fall;
    animation-timing-function: linear;
    animation-fill-mode: forwards;
}

.scene-video, .scene-still {
    position: absolute;
    inset: 0;
    z-index: 1;
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #ffffff;
    border: 0;
    opacity: 0;
    pointer-events: none;
}
.scene-video.is-on, .scene-still.is-on { opacity: 1; }
.scene-video.is-on {
    inset: auto;
    left: 50%;
    top: 50%;
    width: 100%;
    height: 100%;
    transform: translate(-50%, -50%) scale(1.04);
}

.ui {
    position: relative;
    z-index: 3;
    order: -1;
    width: min(560px, 100%);
    display: flex;
    flex-direction: column;
    align-items: center;
}

.start-btn, .role-btn, .option, .spin-btn, .claim-btn, .ghost-btn {
    border: 0;
    cursor: pointer;
}
.start-btn, .role-btn, .option, .claim-btn { min-height: 64px; }

.app[data-state="idle"] .ui { order: 2; }
.start-btn {
    min-width: min(420px, 92vw);
    padding: 16px 22px;
    border-radius: 16px;
    background: #24143f;
    color: #fff;
    font-weight: 800;
    font-size: clamp(1rem, 2vw, 1.15rem);
    box-shadow: none;
    animation: none;
}
.start-btn.is-leaving, .app[data-state="greeting"] .start-btn,
.app[data-state="role_selection"] .start-btn,
.app[data-state="quiz"] .start-btn,
.app[data-state="roulette"] .start-btn,
.app[data-state="celebrate"] .start-btn,
.app[data-state="prize"] .start-btn,
.app[data-state="confirm"] .start-btn { display: none; }

.panel { display: none; width: 100%; text-align: center; }
.panel.is-open, .app[data-state="role_selection"] #panel-roles,
.app[data-state="quiz"] #panel-quiz,
.app[data-state="roulette"] #panel-roulette { display: block; animation: rise 0.45s ease both; }

.badge, .subtitle, .roulette-title, .fact, .streak { margin: 0; }
.badge {
    display: inline-flex;
    align-items: center;
    min-height: 48px;
    padding: 10px 18px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.92);
    color: var(--violet-deep);
    font-weight: 800;
    box-shadow: 0 10px 28px rgba(108, 92, 231, 0.12);
}
.subtitle, .roulette-title { margin-top: 10px; color: #5b4b72; font-weight: 700; }
.roulette-note { margin: 8px auto 0; max-width: 34rem; color: #5b4b72; font-weight: 700; }
.quiz-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.quiz-progress, .streak { color: var(--violet); font-weight: 800; }
.timer {
    width: 54px;
    height: 54px;
    border-radius: 50%;
    background: conic-gradient(var(--tone, var(--mint)) calc(var(--p, 1) * 360deg), rgba(108, 92, 231, 0.15) 0);
}
.timer[data-tone="ok"] { --tone: var(--mint); }
.timer[data-tone="warn"] { --tone: #f5b942; }
.timer[data-tone="late"] { --tone: #e11d48; }
.question { margin: 8px 0 0; font-size: clamp(1.2rem, 2.2vw, 1.6rem); line-height: 1.25; }
.reaction { min-height: 1.4rem; margin: 6px 0 0; font-size: 1.4rem; }
.roles, .options { display: grid; gap: 12px; margin-top: 16px; }
.role-btn, .option {
    padding: 16px 18px;
    border-radius: 22px;
    background: rgba(255, 255, 255, 0.94);
    color: var(--ink);
    font-weight: 800;
    font-size: 1.08rem;
    box-shadow: 0 12px 30px rgba(108, 92, 231, 0.1);
}
.option.is-correct { background: var(--mint); color: #fff; }
.option.is-wrong { background: #fb7185; color: #fff; }
.option.is-chosen { background: #efe9ff; color: var(--violet-deep); }
.fact { min-height: 1.4rem; margin-top: 12px; color: #5b4b72; font-weight: 700; }

.roulette-stage { position: relative; width: min(440px, 88vw, 54dvh); aspect-ratio: 1; margin: 12px auto 0; }
.wheel-spin {
    position: relative;
    z-index: 1;
    width: 100%;
    height: 100%;
    transition: none;
    filter: drop-shadow(0 16px 24px rgba(108, 92, 231, 0.25));
}
.wheel-svg { width: 100%; height: 100%; }
.wheel-label { fill: #fff; font-weight: 800; font-family: Manrope, sans-serif; }
.wheel-label.is-exclusive { fill: #2a1848; }
.pointer {
    position: absolute;
    left: 50%;
    top: -8px;
    z-index: 2;
    width: 0;
    height: 0;
    translate: -50% 0;
    border-left: 14px solid transparent;
    border-right: 14px solid transparent;
    border-top: 28px solid var(--ink);
    transform-origin: 50% 0;
}
.pointer.is-flick { animation: flick 0.12s ease; }
.wheel-spin { position: relative; z-index: 1; }
.leds { position: absolute; inset: 0; z-index: 2; pointer-events: none; }
.leds i {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 8px;
    height: 8px;
    margin: -4px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 0 8px #fff;
    opacity: 0.45;
    animation: led 0.6s linear infinite;
    animation-delay: calc(var(--led, 0) * -20ms);
}
.spin-btn {
    position: absolute;
    left: 50%;
    top: 50%;
    z-index: 3;
    width: 112px;
    height: 112px;
    translate: -50% -50%;
    border-radius: 50%;
    background: #fff;
    color: var(--violet-deep);
    font-weight: 800;
    box-shadow: 0 8px 18px rgba(42, 24, 72, 0.16);
}

.celebrate-card, .admin-panel {
    display: none;
    position: absolute;
    z-index: 5;
    left: 50%;
    bottom: max(16px, env(safe-area-inset-bottom));
    width: min(520px, calc(100% - 28px));
    translate: -50% 0;
}
.app[data-state="prize"] .celebrate-card,
.app[data-state="confirm"] .celebrate-card { display: block; animation: rise 0.4s ease both; }
.prize-card, .admin-panel {
    max-height: min(72dvh, 680px);
    overflow: auto;
    padding: 22px 20px 18px;
    border-radius: 28px;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 18px 50px rgba(108, 92, 231, 0.16);
    text-align: center;
}
.prize-kicker {
    display: inline-flex;
    margin: 0 0 4px;
    padding: 4px 10px;
    border-radius: 999px;
    background: #efe9ff;
    color: var(--violet-deep);
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}
.prize-kicker.is-exclusive { background: #fff4d6; color: #9a3412; }
.prize-note { margin-top: 8px; font-size: 0.92rem; }
.prize-icon { margin: 0; font-size: 2rem; }
.prize-card h2 { margin: 6px 0; font-size: clamp(1.25rem, 2.4vw, 1.7rem); }
.prize-card p { margin: 0; color: #5b4b72; }
.fields { display: grid; gap: 10px; margin-top: 14px; text-align: left; }
.fields label, .consent { display: grid; gap: 4px; font-size: 0.82rem; font-weight: 800; color: var(--violet); }
.fields input, .fields select, .fields textarea, .phone input {
    min-height: 52px;
    padding: 12px 14px;
    border: 1px solid rgba(108, 92, 231, 0.28);
    border-radius: 14px;
    background: #fff;
    color: var(--ink);
    font-size: 16px;
}
.fields textarea { min-height: 76px; resize: vertical; }
.fields select { width: 100%; }
.consent a { color: var(--violet-deep); }
.phone { display: grid; grid-template-columns: 88px 1fr; gap: 8px; }
.consent { grid-template-columns: 28px 1fr; align-items: center; color: var(--ink); font-size: 0.95rem; }
.form-error { min-height: 1.2rem; color: #be123c; font-weight: 700; }
.claim-btn, .ghost-btn {
    width: 100%;
    margin-top: 12px;
    border-radius: 999px;
    background: var(--violet);
    color: #fff;
    font-weight: 800;
}
.ghost-btn { min-height: 52px; background: #efe9ff; color: var(--violet-deep); }
.confirm-copy, .code { display: none; }
.app[data-state="confirm"] .win-ask { display: none; }
.app[data-state="prize"] .ui,
.app[data-state="confirm"] .ui { display: none; }
input, textarea { user-select: text; -webkit-user-select: text; }
.app[data-state="confirm"] .fields,
.app[data-state="confirm"] .claim-btn,
.app[data-state="confirm"] .consent,
.app[data-state="confirm"] .form-error,
.app[data-state="prize"] .confirm-copy,
.app[data-state="prize"] .code { display: none; }
.app[data-state="confirm"] .confirm-copy,
.app[data-state="confirm"] .code { display: block; }
.code { margin-top: 8px; font-size: 1.4rem; letter-spacing: 0.08em; }

.app[data-state="celebrate"] .ui { display: none; }
.app[data-state="celebrate"] .camera-wrap {
    position: relative;
    z-index: 2;
    width: auto;
    height: min(88dvh, calc((100vw - 24px) * 1280 / 720));
    max-width: calc(100vw - 24px);
    aspect-ratio: 720 / 1280;
    background: #ffffff;
    border: 0;
    box-shadow: none;
}
.app[data-state="celebrate"] .scene-video.is-on {
    inset: auto;
    left: 50%;
    top: 50%;
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #ffffff;
    transform: translate(-50%, -50%) scale(1.02);
}
.app[data-state="role_selection"] .camera-wrap,
.app[data-state="quiz"] .camera-wrap,
.app[data-state="roulette"] .camera-wrap {
    height: min(42dvh, calc((100vw - 28px) * 1280 / 720));
}
.app[data-state="prize"] .camera-wrap,
.app[data-state="confirm"] .camera-wrap { display: none; }
.app[data-state="prize"] .celebrate-card,
.app[data-state="confirm"] .celebrate-card {
    position: relative;
    left: auto;
    bottom: auto;
    translate: none;
    width: min(720px, calc(100% - 20px));
    margin: 10px auto;
}
.app[data-state="prize"] .prize-card,
.app[data-state="confirm"] .prize-card {
    max-height: calc(100dvh - 20px);
}
.tally-wrap { margin-top: 14px; }
.tally-wrap iframe {
    display: block;
    width: 100%;
    min-height: 720px;
    border: 0;
    background: transparent;
}
.app[data-state="role_selection"] .ui,
.app[data-state="quiz"] .ui,
.app[data-state="roulette"] .ui {
    order: 2;
    width: min(640px, 100%);
    max-height: 56dvh;
    overflow: auto;
}

.sync {
    position: fixed;
    z-index: 6;
    top: 8px;
    right: 10px;
    margin: 0;
    font-size: 12px;
    opacity: 0.75;
}
.admin-hot {
    position: fixed;
    z-index: 6;
    left: 0;
    bottom: 0;
    width: 72px;
    height: 72px;
    background: transparent;
    border: 0;
}
.admin-panel { display: block; }
.admin-panel[hidden] { display: none; }

@media (orientation: landscape) {
    .app[data-state="role_selection"] .shell,
    .app[data-state="quiz"] .shell,
    .app[data-state="roulette"] .shell,
    .app[data-state="prize"] .shell,
    .app[data-state="confirm"] .shell {
        display: grid;
        grid-template-columns: auto minmax(300px, 540px);
        justify-content: center;
        align-items: center;
        column-gap: 28px;
    }
    .app[data-state="role_selection"] .camera-wrap,
    .app[data-state="quiz"] .camera-wrap,
    .app[data-state="roulette"] .camera-wrap,
    .app[data-state="prize"] .camera-wrap,
    .app[data-state="confirm"] .camera-wrap {
        height: min(86dvh, calc(32vw * 1280 / 720));
        max-width: 32vw;
    }
    .app[data-state="role_selection"] .ui,
    .app[data-state="quiz"] .ui,
    .app[data-state="roulette"] .ui {
        order: 0;
        width: 100%;
        max-height: none;
        overflow: visible;
    }
    .app[data-state="prize"] .shell,
    .app[data-state="confirm"] .shell {
        display: flex;
        grid-template-columns: none;
    }
    .app[data-state="prize"] .celebrate-card,
    .app[data-state="confirm"] .celebrate-card {
        position: relative;
        left: auto;
        bottom: auto;
        translate: none;
        width: min(760px, calc(100% - 24px));
    }
}

@keyframes float { 50% { transform: translate3d(0, -14px, 0); } }
@keyframes fall { to { transform: translateY(105vh) rotate(160deg); } }
@keyframes pulse { 70% { box-shadow: 0 0 0 16px rgba(108, 92, 231, 0); } }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes flick { 50% { transform: rotate(-16deg); } }
@keyframes led { 50% { opacity: 1; } }

body.festive .float { animation-duration: 4s; opacity: 0.28; }

@media (prefers-reduced-motion: reduce) {
    .sky, .float, .start-btn, .leds i, .camera, .confetti i { animation: none; transition: none; }
}
