:root {
    --bg-void: #050711;
    --bg-panel: rgba(10, 16, 32, 0.72);
    --bg-panel-strong: rgba(14, 22, 44, 0.86);
    --text-primary: #f8fbff;
    --text-muted: #9fb1c7;
    --line-soft: rgba(255, 255, 255, 0.14);
    --line-bright: rgba(113, 245, 255, 0.55);
    --cyan: #67e8f9;
    --lime: #bef264;
    --rose: #fb7185;
    --amber: #fbbf24;
    --shadow-glow: 0 24px 80px rgba(0, 0, 0, 0.55);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html,
body {
    width: 100%;
    height: 100%;
    position: fixed;
    overflow: hidden;
    background-color: #04050c;
    overscroll-behavior: none;
}

body {
    min-height: 100dvh;
    overflow: hidden;
    color: var(--text-primary);
    font-family: "Noto Sans JP", sans-serif;
    background:
        radial-gradient(circle at 16% 14%, rgba(103, 232, 249, 0.2), transparent 26rem),
        radial-gradient(circle at 86% 78%, rgba(251, 113, 133, 0.2), transparent 28rem),
        linear-gradient(135deg, #070816 0%, #0a1228 44%, #04050c 100%);
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px);
    background-size: 42px 42px;
    mask-image: radial-gradient(circle at center, #000 20%, transparent 78%);
}

.ambient {
    position: fixed;
    width: 34vmax;
    aspect-ratio: 1;
    border-radius: 999px;
    pointer-events: none;
    filter: blur(22px);
    opacity: 0.26;
}

.ambient-a {
    top: -12vmax;
    left: -8vmax;
    background: #22d3ee;
}

.ambient-b {
    right: -10vmax;
    bottom: -14vmax;
    background: #fb7185;
}

.app-container {
    position: relative;
    z-index: 1;
    width: 100vw;
    height: 100dvh;
    display: grid;
    place-items: center;
    padding: clamp(12px, 2vw, 28px);
}

.game-shell {
    position: relative;
    width: min(100%, calc((100dvh - 40px) * 16 / 9));
    max-width: none;
    aspect-ratio: 16 / 9;
    padding: 1px;
    border-radius: clamp(18px, 3vw, 34px);
    background:
        linear-gradient(135deg, rgba(103, 232, 249, 0.8), rgba(190, 242, 100, 0.22) 38%, rgba(251, 113, 133, 0.72));
    box-shadow: 0 20px 54px rgba(0, 0, 0, 0.48), 0 0 38px rgba(103, 232, 249, 0.12);
}

.game-shell::after {
    content: "";
    position: absolute;
    inset: 12px;
    border-radius: inherit;
    border: 1px solid rgba(255, 255, 255, 0.12);
    pointer-events: none;
}

.game-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
    border-radius: inherit;
    background: #060915;
}

#gameCanvas {
    width: 100%;
    height: 100%;
    display: block;
}

#webcamVideo {
    position: absolute;
    right: clamp(14px, 2vw, 26px);
    bottom: clamp(14px, 2vw, 26px);
    width: clamp(180px, 18vw, 250px);
    height: clamp(135px, 13.5vw, 187px);
    z-index: 12;
    object-fit: cover;
    transform: scaleX(-1);
    border-radius: 18px;
    border: 1px solid rgba(255, 255, 255, 0.22);
    background: #111827;
    box-shadow: 0 18px 48px rgba(0, 0, 0, 0.42), 0 0 30px rgba(103, 232, 249, 0.16);
}

.hud {
    position: absolute;
    left: clamp(14px, 2vw, 28px);
    right: clamp(14px, 2vw, 28px);
    z-index: 10;
    pointer-events: none;
}

.top-hud {
    top: clamp(14px, 2vw, 26px);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    max-width: 100%;
}

.stat-group {
    display: flex;
    gap: clamp(8px, 1vw, 14px);
}

.score-group {
    flex-grow: 1;
    justify-content: center;
}

.score-box {
    padding: 12px 24px;
    background: rgba(13, 20, 39, 0.88);
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.stat-box,
.modal-content {
    border: 1px solid var(--line-soft);
    background: rgba(13, 20, 39, 0.78);
}

.stat-box {
    min-width: 0;
    padding: 12px 14px;
    border-radius: 18px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.label {
    display: block;
    color: var(--text-muted);
    font-family: "Bricolage Grotesque", "Noto Sans JP", sans-serif;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.value {
    display: block;
    margin-top: 2px;
    font-family: "Bricolage Grotesque", "Noto Sans JP", sans-serif;
    font-size: clamp(1.35rem, 2.1vw, 2rem);
    font-weight: 800;
    line-height: 1;
    color: var(--cyan);
}

.modal {
    position: absolute;
    inset: 0;
    z-index: 100;
    display: flex;
    flex-direction: column;
    padding: 22px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    opacity: 0;
    pointer-events: none;
    transition: opacity 260ms ease;
}

.modal.active {
    opacity: 1;
    pointer-events: auto;
}

.glass-panel {
    background: rgba(3, 6, 18, 0.76);
}

.modal-content {
    margin: auto;
    width: min(94vw, 620px);
    padding: clamp(28px, 5vw, 54px);
    border-radius: 32px;
    text-align: left;
    box-shadow: var(--shadow-glow), inset 0 1px 0 rgba(255, 255, 255, 0.08);
    animation: panelIn 520ms cubic-bezier(.2, .9, .2, 1) both;
}

.modal-content.compact {
    width: min(92vw, 460px);
    text-align: center;
}

.modal-content.compact h1 {
    font-size: clamp(2.5rem, 10vw, 3.8rem);
}

.eyebrow {
    margin-bottom: 12px;
    color: var(--cyan);
    font-family: "Bricolage Grotesque", "Noto Sans JP", sans-serif;
    font-size: 0.76rem;
    font-weight: 800;
    letter-spacing: 0.18em;
    text-transform: uppercase;
}

h1,
h2 {
    font-family: "Bricolage Grotesque", "Noto Sans JP", sans-serif;
    font-weight: 800;
    letter-spacing: -0.05em;
}

h1 {
    margin-bottom: 14px;
    font-size: clamp(3rem, 8vw, 5.8rem);
    line-height: 0.85;
    background: linear-gradient(110deg, #fff 12%, var(--cyan), var(--lime) 78%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

h2 {
    margin-bottom: 24px;
    font-size: clamp(2.4rem, 6vw, 4rem);
}

.subtitle {
    max-width: 38rem;
    margin-bottom: 28px;
    color: #d5e1ef;
    font-size: clamp(1rem, 2vw, 1.18rem);
    line-height: 1.8;
}

.instructions {
    display: grid;
    gap: 10px;
    margin-bottom: 30px;
}

.instructions p {
    display: grid;
    grid-template-columns: 42px 1fr;
    gap: 12px;
    align-items: center;
    min-height: 54px;
    padding: 12px 14px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 18px;
    color: #dbe8f8;
    line-height: 1.6;
    background: rgba(255, 255, 255, 0.045);
}

.step-num {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 999px;
    color: #06111b;
    font-family: "Bricolage Grotesque", sans-serif;
    font-weight: 800;
    background: var(--cyan);
}

.step-copy {
    display: block;
}

.instructions strong {
    color: #fff;
}

.primary-btn {
    width: 100%;
    border: 0;
    border-radius: 18px;
    padding: 17px 24px;
    color: #06111b;
    cursor: pointer;
    font-family: "Noto Sans JP", sans-serif;
    font-size: 1rem;
    font-weight: 900;
    background: linear-gradient(135deg, var(--cyan), var(--lime));
    box-shadow: 0 18px 36px rgba(103, 232, 249, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.48);
    transition: transform 180ms ease, box-shadow 180ms ease, filter 180ms ease;
    pointer-events: auto;
}

.primary-btn:hover {
    transform: translateY(-2px);
    filter: saturate(1.08);
    box-shadow: 0 16px 30px rgba(103, 232, 249, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.58);
}

.primary-btn:active {
    transform: translateY(0);
}

.result-stats {
    margin-bottom: 28px;
}

.stat-item {
    padding: 24px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 22px;
    background: rgba(255, 255, 255, 0.05);
}

.stat-item .value {
    margin-top: 10px;
    color: var(--cyan);
    font-size: clamp(3rem, 8vw, 5rem);
}

.overlay {
    position: absolute;
    inset: 0;
    z-index: 200;
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
}

@keyframes panelIn {
    from {
        opacity: 0;
        transform: translateY(18px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.version-text {
    margin-top: 20px;
    text-align: center;
    color: rgba(255, 255, 255, 0.25);
    font-size: 0.7rem;
    font-family: monospace;
    letter-spacing: 0.1em;
}

@media (max-width: 760px) {
    .app-container {
        padding: 8px;
    }

    .game-shell {
        width: 100%;
        max-height: 100dvh;
        border-radius: 18px;
    }

    .top-hud {
        display: flex;
    }

    .stat-group {
        gap: 6px;
    }

    .stat-box {
        padding: 9px 10px;
        border-radius: 14px;
    }

    .score-box {
        padding: 9px 16px;
    }

    .label {
        font-size: 0.62rem;
    }

    #webcamVideo {
        width: 168px;
        height: 126px;
        border-radius: 14px;
    }

    .instructions p {
        grid-template-columns: 34px 1fr;
        font-size: 0.9rem;
    }
}

@media (max-height: 600px) {
    .modal {
        padding: 8px;
    }

    .modal-content {
        padding: 12px 16px;
        width: min(96vw, 480px);
    }

    h1 {
        font-size: clamp(1.4rem, 5vh, 2rem);
        margin-bottom: 6px;
    }
    
    .eyebrow {
        margin-bottom: 6px;
        font-size: 0.65rem;
    }

    .subtitle {
        margin-bottom: 8px;
        font-size: 0.8rem;
    }

    .instructions {
        margin-bottom: 12px;
        gap: 4px;
    }

    .instructions p {
        min-height: auto;
        padding: 6px 10px;
        font-size: 0.75rem;
    }
    
    .primary-btn {
        padding: 10px 16px;
        font-size: 0.9rem;
    }
    
    .version-text {
        margin-top: 8px;
        font-size: 0.65rem;
    }

    #webcamVideo {
        width: clamp(100px, 25vh, 160px);
        height: clamp(75px, 18.75vh, 120px);
        right: 8px;
        bottom: 8px;
    }

    .top-hud {
        top: 8px;
    }
    
    .value {
        font-size: clamp(1.2rem, 3vh, 1.6rem);
    }
}
