@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');

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

:root {
    --bg: #0a0a0a;
    --green: #33ff33;
    --red: #ff0044;
    --white: #f0f0f0;
    --yellow: #ffff00;
    --cyan: #00ffff;
    --magenta: #ff00ff;
    --dim: #555;
}

body {
    font-family: 'Press Start 2P', monospace;
    background: var(--bg);
    color: var(--green);
    overflow: hidden;
    image-rendering: pixelated;
}

/* CRT */
.crt-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(0, 0, 0, 0.08) 2px, rgba(0, 0, 0, 0.08) 4px);
    pointer-events: none;
    z-index: 9999;
}

.screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    overflow-y: auto;
}

.screen.active {
    display: flex;
}

.container {
    text-align: center;
    padding: 1.2rem;
    max-width: 700px;
    width: 100%;
}

/* 타이틀 */
.neon-title {
    font-size: 2.5rem;
    color: var(--cyan);
    text-shadow: 0 0 10px var(--cyan), 0 0 30px var(--cyan), 0 0 60px #0066ff;
    margin-bottom: 0.6rem;
    letter-spacing: 4px;
    animation: titlePulse 2s ease-in-out infinite;
}

@keyframes titlePulse {

    0%,
    100% {
        text-shadow: 0 0 10px var(--cyan), 0 0 30px var(--cyan)
    }

    50% {
        text-shadow: 0 0 20px var(--cyan), 0 0 50px var(--cyan), 0 0 80px #0066ff
    }
}

.blink-text {
    font-size: 0.65rem;
    color: var(--yellow);
    animation: blink 1s step-end infinite;
    margin-bottom: 1rem;
}

@keyframes blink {
    50% {
        opacity: 0
    }
}

/* 규칙 */
.rules-box {
    border: 2px solid var(--green);
    padding: 0.6rem 1rem;
    margin-bottom: 1rem;
    display: inline-block;
    text-align: left;
    position: relative;
}

.rule {
    font-size: 0.5rem;
    margin: 0.3rem 0;
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--dim);
}

.dot-icon {
    width: 10px;
    height: 10px;
    display: inline-block;
    flex-shrink: 0;
}

.dot-icon.red {
    background: var(--red);
    box-shadow: 0 0 4px var(--red);
}

.dot-icon.white {
    background: var(--white);
}

.dot-icon.green {
    background: var(--green);
    box-shadow: 0 0 4px var(--green);
}

.rules-detail-btn {
    font-family: 'Press Start 2P', monospace;
    font-size: 0.4rem;
    background: transparent;
    color: var(--cyan);
    border: 1px solid var(--cyan);
    padding: 0.3rem 0.5rem;
    cursor: pointer;
    margin-top: 0.5rem;
    transition: all 0.2s;
}

.rules-detail-btn:hover {
    background: var(--cyan);
    color: var(--bg);
}

/* 모달 */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.85);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-box {
    border: 3px solid var(--green);
    background: #111;
    padding: 1.5rem;
    max-width: 500px;
    width: 90%;
    text-align: left;
}

.modal-box h3 {
    font-size: 0.8rem;
    color: var(--yellow);
    margin-bottom: 1rem;
    text-align: center;
}

.modal-rules {
    text-align: center;
}

.modal-rules p {
    font-size: 0.45rem;
    color: var(--white);
    margin: 0.5rem 0;
    line-height: 1.6;
}

.modal-rules b {
    color: var(--yellow);
}

/* 모드 */
.mode-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.8rem;
    margin-bottom: 1rem;
}

.mode-card {
    border: 2px solid var(--green);
    padding: 1rem 0.4rem;
    cursor: pointer;
    transition: all 0.2s;
}

.mode-card:hover {
    border-color: var(--cyan);
    transform: scale(1.05);
    box-shadow: 0 0 15px var(--cyan);
}

.mode-name {
    font-size: 0.9rem;
    margin-bottom: 0.4rem;
}

.diff-bar {
    display: flex;
    gap: 3px;
    justify-content: center;
    margin-bottom: 0.4rem;
}

.diff-bar span {
    width: 20px;
    height: 10px;
    border: 2px solid var(--yellow);
}

.bar-fill {
    background: var(--yellow);
    box-shadow: 0 0 4px var(--yellow);
}

.bar-empty {
    background: transparent;
}

.mode-tag {
    font-size: 0.45rem;
    padding: 0.2rem 0.5rem;
    display: inline-block;
}

.mode-tag.free {
    color: var(--green);
    border: 1px solid var(--green);
}

.mode-tag.locked {
    color: var(--red);
    border: 1px solid var(--red);
}

.mode-tag.unlocked {
    color: var(--yellow);
    border: 1px solid var(--yellow);
}

/* 리더보드 */
.lb-box {
    border: 2px solid var(--dim);
    padding: 0.6rem;
    max-width: 420px;
    margin: 0 auto 0.8rem;
}

.lb-title {
    font-size: 0.55rem;
    color: var(--yellow);
    margin-bottom: 0.5rem;
}

.lb-list {
    font-size: 0.4rem;
    color: var(--dim);
}

.lb-row {
    display: grid;
    grid-template-columns: 1fr 3fr 2fr 2fr 2fr;
    gap: 0.3rem;
    padding: 0.2rem 0;
    border-bottom: 1px solid #222;
    text-align: center;
}

.lb-row.header {
    color: var(--green);
    border-bottom: 1px solid var(--green);
    font-size: 0.35rem;
}

.lb-empty {
    color: #333;
    font-size: 0.4rem;
    padding: 0.4rem;
}

/* 공유 */
.share-btn {
    font-family: 'Press Start 2P', monospace;
    font-size: 0.5rem;
    background: transparent;
    color: var(--magenta);
    border: 1px solid var(--magenta);
    padding: 0.5rem 1rem;
    cursor: pointer;
    margin: 0.5rem 0;
    transition: all 0.2s;
}

.share-btn:hover {
    background: var(--magenta);
    color: var(--bg);
}

/* 카운트다운 */
.countdown-text {
    font-size: 6rem;
    color: var(--yellow);
    text-shadow: 0 0 30px var(--yellow), 0 0 60px var(--yellow);
    animation: countPop 0.5s ease;
}

@keyframes countPop {
    0% {
        transform: scale(2);
        opacity: 0
    }

    60% {
        transform: scale(0.9)
    }

    100% {
        transform: scale(1);
        opacity: 1
    }
}

/* 게임 HUD */
#gameHUD {
    --hud-h: 82px;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--hud-h);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 10px;
    background: rgba(0, 0, 0, 0.9);
    border: none;
    overflow: visible;
    z-index: 100;
}

.hud-center {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 3rem;
    align-items: center;
}

/* 녹색 선을 HUD 하단 내부에 배치 (전체 높이 82px에 포함) */
#gameHUD::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 2px;
    background: var(--green);
}

.hud-item {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.hud-label {
    font-size: 0.45rem;
    color: var(--dim);
    margin-bottom: 0.2rem;
}

.hud-val {
    font-size: 1.1rem;
    color: var(--green);
}

/* 게임 내 좌측 홈 / 우측 재시작 버튼 — 녹색 직사각형 텍스트 버튼 */
.game-top-btn {
    height: 40px;
    min-width: 80px;
    padding: 0 16px;
    background: var(--green);
    color: #000;
    border: none;
    border-radius: 8px;
    font-family: 'Press Start 2P', monospace;
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    cursor: pointer;
    transition: all 0.2s;
}

.game-top-btn:hover {
    background: #fff;
    color: #000;
}

/* 일시정지 팝업 */
.pause-popup {
    max-width: 400px;
}

/* PayPal 화면 BACK 하단 배치 */
.paypal-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 80vh;
    justify-content: center;
}

.paypal-back-btn {
    margin-top: auto;
    padding-top: 1.5rem;
}

/* 등록 완료 팝업 */
.register-popup {
    max-width: 520px;
}

.reg-rank-box {
    text-align: center;
    margin: 0.6rem 0;
}

.reg-rank {
    font-size: 0.6rem;
    color: var(--cyan);
    text-shadow: 0 0 10px var(--cyan);
}

.reg-btn-row {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    margin-top: 1rem;
}

.reg-btn-row .retro-btn {
    flex: 1;
}

#gameArea {
    width: 100vw;
    height: 100vh;
    position: relative;
    cursor: crosshair;
}

/* 점 스타일 */
.dot {
    position: absolute;
    width: 32px;
    height: 32px;
    cursor: pointer;
    transition: transform 0.1s;
    animation: pixelIn 0.3s ease;
    z-index: 10;
    border: 3px solid;
}

.dot:hover {
    transform: scale(1.3);
    z-index: 20;
}

.dot.clicked {
    animation: pixelOut 0.25s ease forwards;
    pointer-events: none;
}

.dot-red {
    background: var(--red);
    border-color: #cc0033;
    box-shadow: 0 0 8px var(--red), 0 0 16px rgba(255, 0, 68, 0.4);
}

.dot-white {
    background: var(--white);
    border-color: #ccc;
    box-shadow: 0 0 6px rgba(240, 240, 240, 0.5);
}

.dot-green {
    background: var(--green);
    border-color: #22cc22;
    box-shadow: 0 0 8px var(--green), 0 0 16px rgba(51, 255, 51, 0.4);
}

.dot-blink {
    animation: dangerBlink 0.2s step-end infinite !important;
}

@keyframes dangerBlink {
    50% {
        opacity: 0.2
    }
}

.dot-converted {
    animation: convertFlash 0.4s ease !important;
}

@keyframes convertFlash {
    0% {
        filter: brightness(3);
        transform: scale(1.4)
    }

    100% {
        filter: brightness(1);
        transform: scale(1)
    }
}

.dot-moving {
    animation: drift 3s ease-in-out infinite alternate;
}

@keyframes drift {
    to {
        transform: translate(var(--mx, 0), var(--my, 0));
    }
}

@keyframes pixelIn {
    0% {
        transform: scale(0);
        opacity: 0
    }

    60% {
        transform: scale(1.2)
    }

    100% {
        transform: scale(1);
        opacity: 1
    }
}

@keyframes pixelOut {
    0% {
        transform: scale(1);
        opacity: 1;
        filter: brightness(1)
    }

    40% {
        transform: scale(1.5);
        filter: brightness(2)
    }

    100% {
        transform: scale(0);
        opacity: 0
    }
}

.combo-popup {
    position: absolute;
    font-family: 'Press Start 2P', monospace;
    font-size: 0.7rem;
    color: var(--yellow);
    pointer-events: none;
    text-shadow: 0 0 8px var(--yellow);
    animation: floatUp 0.8s ease-out forwards;
    z-index: 200;
}

@keyframes floatUp {
    0% {
        opacity: 1;
        transform: translateY(0)
    }

    100% {
        opacity: 0;
        transform: translateY(-50px)
    }
}

/* 게임 오버 — 해골 */
.go-container {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.skull-art {
    color: var(--white);
    margin-bottom: 0.5rem;
}

.skull-head {
    font-size: 0.7rem;
    line-height: 1.3;
}

.skull-jaw {
    font-size: 0.7rem;
    line-height: 1.3;
    animation: jawMove 0.4s ease-in-out infinite;
}

@keyframes jawMove {

    0%,
    100% {
        transform: translateY(0)
    }

    50% {
        transform: translateY(6px)
    }
}

.go-title {
    font-size: 2rem;
    color: var(--red);
    text-shadow: 0 0 20px var(--red), 0 0 40px var(--red);
    animation: goFlicker 0.5s step-end infinite;
    margin-bottom: 0.5rem;
}

@keyframes goFlicker {
    33% {
        opacity: 0.8
    }

    66% {
        opacity: 1
    }
}

.go-laugh {
    font-size: 0.6rem;
    color: var(--yellow);
    animation: blink 0.3s step-end infinite;
    margin-bottom: 1.5rem;
}

/* 클리어 */
.result-box {
    border: 3px solid var(--yellow);
    padding: 1.5rem;
    max-width: 500px;
    margin: 0 auto;
}

.clear-title {
    font-size: 1.8rem;
    color: var(--yellow);
    text-shadow: 0 0 15px var(--yellow), 0 0 30px var(--yellow);
    margin-bottom: 1rem;
    animation: titlePulse 1.5s ease-in-out infinite;
}

.result-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.8rem;
    margin-bottom: 1rem;
}

.r-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3rem;
}

.r-label {
    font-size: 0.35rem;
    color: var(--dim);
}

.r-val {
    font-size: 0.9rem;
    color: var(--green);
}

.score-text {
    color: var(--yellow) !important;
}

.new-record {
    font-size: 0.6rem;
    color: var(--magenta);
    margin-bottom: 0.8rem;
    text-shadow: 0 0 10px var(--magenta);
    animation: blink 0.5s step-end infinite;
}

/* 닉네임 입력 */
.nickname-box {
    margin: 1rem 0;
}

.nick-label {
    font-size: 0.4rem;
    color: var(--dim);
    display: block;
    margin-bottom: 0.4rem;
}

.nick-input {
    font-family: 'Press Start 2P', monospace;
    font-size: 0.55rem;
    background: #111;
    color: var(--green);
    border: 2px solid var(--green);
    padding: 0.5rem;
    width: 100%;
    max-width: 280px;
    outline: none;
    text-align: center;
}

.nick-input:focus {
    border-color: var(--cyan);
    box-shadow: 0 0 10px var(--cyan);
}

.submit-msg {
    font-size: 0.45rem;
    margin: 0.5rem 0;
}

/* 버튼 */
.retro-btn {
    font-family: 'Press Start 2P', monospace;
    font-size: 0.65rem;
    padding: 0.7rem 1.3rem;
    background: transparent;
    color: var(--green);
    border: 2px solid var(--green);
    cursor: pointer;
    transition: all 0.2s;
    margin-top: 0.4rem;
}

.retro-btn:hover {
    background: var(--green);
    color: var(--bg);
    box-shadow: 0 0 15px var(--green);
}

.retro-btn.small {
    font-size: 0.45rem;
    padding: 0.4rem 0.8rem;
}

.pay-title {
    font-size: 1rem;
    color: var(--yellow);
    margin-bottom: 0.8rem;
}

.pay-desc {
    font-size: 0.5rem;
    color: var(--dim);
    margin-bottom: 1.5rem;
}

#paypal-button-container {
    max-width: 350px;
    margin: 0 auto;
}

/* 반응형 */
@media (max-width:600px) {
    .neon-title {
        font-size: 1.5rem;
    }

    .mode-grid {
        gap: 0.4rem;
    }

    .mode-name {
        font-size: 0.6rem;
    }

    .mode-card {
        padding: 0.7rem 0.2rem;
    }

    .dot {
        width: 28px;
        height: 28px;
    }

    /* 모바일 HUD 최적화 — 겹침 방지 */
    #gameHUD {
        --hud-h: 56px;
        height: var(--hud-h);
        padding: 0 6px;
        gap: 0;
    }

    .game-top-btn {
        height: 30px;
        min-width: 52px;
        padding: 0 8px;
        font-size: 0.4rem;
        border-radius: 5px;
        flex-shrink: 0;
    }

    .hud-center {
        position: relative;
        left: auto;
        transform: none;
        gap: 0.8rem;
        flex: 1;
        justify-content: center;
        min-width: 0;
    }

    .hud-label {
        font-size: 0.3rem;
        margin-bottom: 0.1rem;
    }

    .hud-val {
        font-size: 0.55rem;
    }

    .result-grid {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }

    .go-title {
        font-size: 1.5rem;
    }

    .skull-head,
    .skull-jaw {
        font-size: 0.5rem;
    }

    .lb-row {
        grid-template-columns: 1.2rem 4rem 3rem 3rem 2.5rem;
        font-size: 0.35rem;
    }

    /* 모바일 결과 화면 최적화 */
    .result-actions {
        gap: 8px;
    }

    .action-btn {
        padding: 8px 6px;
        font-size: 0.5rem;
    }

    .clear-title {
        font-size: 1.2rem;
    }

    .score-diff-msg {
        font-size: 0.7rem;
        padding: 0.6rem 0.8rem;
    }
}

/* 리더보드 결과 화면 스타일 */
#leaderboardScreen .lb-container {
    width: 100%;
    max-width: 600px;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 80px;
}

.score-diff-msg {
    font-size: 1.2rem;
    color: #fff;
    margin-bottom: 1.5rem;
    padding: 1rem 1.5rem;
    border: 2px solid var(--green);
    background: rgba(0, 255, 51, 0.1);
    text-align: center;
    border-radius: 8px;
    width: 100%;
}

.lb-btn-row {
    width: 100%;
    display: flex;
    justify-content: space-between;
    margin-top: 1.5rem;
    gap: 20px;
}

#screenLeaderboard {
    width: 100%;
    border: 2px solid var(--green);
    background: rgba(0, 0, 0, 0.8);
    padding: 10px;
    min-height: 200px;
}

/* Toast Notification */
#toast {
    visibility: hidden;
    min-width: 250px;
    margin-left: -125px;
    background-color: var(--dim);
    color: #fff;
    text-align: center;
    border-radius: 8px;
    padding: 16px;
    position: fixed;
    z-index: 9999;
    left: 50%;
    bottom: 30px;
    font-size: 1rem;
    border: 2px solid var(--green);
    box-shadow: 0 0 20px var(--green);
}

#toast.show {
    visibility: visible;
    -webkit-animation: fadein 0.5s, fadeout 0.5s 2.5s;
    animation: fadein 0.5s, fadeout 0.5s 2.5s;
}

/* Result Screen Actions */
.result-actions {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-top: 2rem;
    width: 100%;
}

.action-btn {
    background: transparent;
    border: 2px solid var(--dim);
    color: var(--dim);
    font-family: 'Press Start 2P', cursive;
    padding: 10px 15px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
    flex: 1;
}

.action-btn:hover {
    background: var(--dim);
    color: #fff;
    transform: translateY(-2px);
}

.action-btn.share {
    border-color: var(--yellow);
    color: var(--yellow);
}

.action-btn.share:hover {
    background: var(--yellow);
    color: #000;
}

@-webkit-keyframes fadein {
    from {
        bottom: 0;
        opacity: 0;
    }

    to {
        bottom: 30px;
        opacity: 1;
    }
}

@keyframes fadein {
    from {
        bottom: 0;
        opacity: 0;
    }

    to {
        bottom: 30px;
        opacity: 1;
    }
}

@-webkit-keyframes fadeout {
    from {
        bottom: 30px;
        opacity: 1;
    }

    to {
        bottom: 0;
        opacity: 0;
    }
}

@keyframes fadeout {
    from {
        bottom: 30px;
        opacity: 1;
    }

    to {
        bottom: 0;
        opacity: 0;
    }
}