/* CSS Variables */
:root {
    --bg-primary: #0a0a1a;
    --bg-secondary: #12122a;
    --accent-gold: #ffd700;
    --accent-cyan: #00d4ff;
    --accent-purple: #a855f7;
    --accent-pink: #ff6b9d;
    --accent-green: #22c55e;
    --accent-orange: #ff8c00;
    --text-primary: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.7);

    /* Moon Cave 2 specific */
    --game-bg: #1a1a2e;
    --game-accent: #88ddff;
    --game-highlight: #aaffcc;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

body {
    font-family: 'Noto Sans KR', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
}

/* Background effects */
.bg-effects {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    overflow: hidden;
    z-index: 0;
}

.bg-orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.3;
    animation: float 20s infinite ease-in-out;
}

.bg-orb:nth-child(1) {
    width: 400px;
    height: 400px;
    background: var(--accent-purple);
    top: -100px;
    left: -100px;
}

.bg-orb:nth-child(2) {
    width: 300px;
    height: 300px;
    background: var(--accent-cyan);
    bottom: -50px;
    right: -50px;
    animation-delay: -10s;
}

@keyframes float {
    0%, 100% { transform: translate(0, 0) scale(1); }
    33% { transform: translate(30px, -30px) scale(1.1); }
    66% { transform: translate(-20px, 20px) scale(0.9); }
}

/* Container */
.container {
    position: relative;
    z-index: 1;
    max-width: 600px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
header {
    text-align: center;
    margin-bottom: 15px;
}

.header-top {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    margin-bottom: 5px;
}

.back-btn {
    position: absolute;
    left: 0;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.85rem;
    border-radius: 8px;
    transition: all 0.2s ease;
}

.back-btn:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.1);
}

.back-btn svg {
    width: 18px;
    height: 18px;
}

header h1 {
    font-family: 'Black Han Sans', sans-serif;
    font-size: 1.8rem;
    background: linear-gradient(135deg, var(--accent-cyan), var(--accent-purple));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* Game Container */
.game-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
    flex: 1;
}

/* Game Wrapper */
.game-wrapper {
    position: relative;
    width: 100%;
    aspect-ratio: 16/10;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    border: 2px solid rgba(255, 255, 255, 0.1);
}

#gameCanvas {
    width: 100%;
    height: 100%;
    display: block;
    cursor: pointer;
    touch-action: none;
}

/* HUD */
.hud {
    position: absolute;
    top: 12px;
    left: 12px;
    right: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    pointer-events: none;
    z-index: 10;
}

.hud-left, .hud-right {
    display: flex;
    align-items: center;
    gap: 20px;
}

.hud-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 20px;
    backdrop-filter: blur(4px);
}

.hud-icon {
    font-size: 1rem;
}

.hud-value {
    font-family: 'Orbitron', 'Noto Sans KR', sans-serif;
    font-size: 0.9rem;
    font-weight: 700;
    color: #fff;
    text-shadow: 0 0 10px rgba(150, 220, 255, 0.5);
}

.hud-value.score-value {
    font-size: 1.2rem;
    color: var(--game-highlight);
    text-shadow: 0 0 10px rgba(100, 255, 180, 0.5);
}

/* Game Overlay */
.game-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 20;
    opacity: 1;
    transition: opacity 0.3s;
    backdrop-filter: blur(4px);
}

.game-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.game-title {
    font-family: 'Orbitron', 'Black Han Sans', sans-serif;
    font-size: 2rem;
    font-weight: 900;
    color: var(--accent-cyan);
    text-shadow: 0 0 30px var(--accent-cyan), 0 2px 0 #5588bb;
    margin-bottom: 8px;
    letter-spacing: 4px;
}

.game-subtitle {
    font-size: 0.75rem;
    color: rgba(255, 200, 220, 0.7);
    margin-bottom: 20px;
    letter-spacing: 2px;
}

/* Overlay two-column layout */
.overlay-content {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 30px;
    width: 100%;
    max-width: 450px;
    padding: 0 15px;
}

.overlay-left {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.overlay-right {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.final-score-box {
    margin-bottom: 15px;
    text-align: center;
}

.final-label {
    font-size: 0.65rem;
    color: rgba(255, 200, 220, 0.6);
    letter-spacing: 2px;
    text-transform: uppercase;
}

.final-value {
    font-family: 'Orbitron', 'Black Han Sans', sans-serif;
    font-size: 2.5rem;
    font-weight: 900;
    color: #ffffff;
    text-shadow: 0 0 15px #ffaacc;
}

.new-record {
    color: var(--accent-gold);
    font-size: 0.75rem;
    margin-top: 8px;
    animation: blink 1s infinite;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.play-btn {
    font-family: 'Jua', sans-serif;
    padding: 10px 35px;
    font-size: 0.9rem;
    font-weight: 700;
    color: #1a1a2e;
    background: linear-gradient(180deg, var(--accent-cyan), #0891b2);
    border: none;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 0 20px rgba(0, 212, 255, 0.4);
    min-height: 40px;
}

.play-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 0 30px rgba(0, 212, 255, 0.6);
}

.controls-hint {
    margin-top: 10px;
    font-size: 0.6rem;
    color: rgba(255, 220, 240, 0.5);
    text-align: center;
    line-height: 1.6;
}

.controls-hint span {
    color: var(--accent-cyan);
    padding: 1px 6px;
    background: rgba(0, 212, 255, 0.15);
    border-radius: 4px;
}

/* Game Content Article */
.game-content {
    margin-top: 20px;
    padding: 20px;
    background: var(--bg-secondary);
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.game-content h2 {
    font-family: 'Black Han Sans', sans-serif;
    font-size: 1.3rem;
    color: var(--accent-gold);
    margin-bottom: 10px;
}

.game-content p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.6;
    margin-bottom: 15px;
}

.tip-box {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    padding: 15px;
}

.tip-box p {
    margin-bottom: 8px;
}

.tip-box p:last-child {
    margin-bottom: 0;
}

/* Footer */
footer {
    text-align: center;
    padding: 20px;
    margin-top: auto;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

footer a {
    color: var(--accent-cyan);
    text-decoration: none;
    transition: color 0.2s;
}

footer a:hover {
    color: var(--accent-gold);
}

/* Timer Warning */
.hud-value.warning {
    color: #ef4444 !important;
    animation: timerBlink 0.5s infinite;
}

@keyframes timerBlink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Leaderboard Section */
.leaderboard-section {
    width: 100%;
    max-width: 160px;
    margin: 0;
    padding: 10px;
    background: rgba(0, 0, 0, 0.4);
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.leaderboard-section h3 {
    font-family: 'Jua', sans-serif;
    font-size: 0.85rem;
    color: var(--accent-gold);
    margin-bottom: 8px;
    text-align: center;
}

.leaderboard-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.leaderboard-entry {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 5px 8px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 5px;
    font-size: 0.75rem;
    transition: all 0.2s;
}

.leaderboard-entry.current {
    background: rgba(0, 212, 255, 0.2);
    border: 1px solid var(--accent-cyan);
}

.leaderboard-entry.top-three {
    background: rgba(255, 215, 0, 0.1);
}

.leaderboard-entry .rank {
    min-width: 24px;
    font-size: 0.9rem;
}

.leaderboard-entry .entry-score {
    flex: 1;
    text-align: center;
    font-family: 'Orbitron', monospace;
    font-weight: 700;
    font-size: 0.75rem;
    color: var(--game-highlight);
}

.leaderboard-entry .entry-status {
    min-width: 22px;
    text-align: right;
}

.no-records {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.75rem;
    padding: 10px;
}

.my-score {
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px dashed rgba(255, 255, 255, 0.2);
    text-align: center;
    font-size: 0.7rem;
    color: var(--text-secondary);
}

.my-score .my-score-value {
    font-family: 'Orbitron', monospace;
    font-weight: 700;
    color: var(--accent-pink);
}

/* Mobile Control Panel - 기본적으로 숨김 */
.mobile-controls {
    display: none;
}

/* Mobile Portrait Mode */
@media (max-width: 600px) and (orientation: portrait) {
    .container {
        padding: 10px;
        justify-content: flex-start;
    }

    header {
        margin-bottom: 10px;
    }

    header h1 {
        font-size: 1.3rem;
    }

    .subtitle {
        font-size: 0.75rem;
    }

    /* 게임 영역을 더 크게 */
    .game-container {
        flex: 1;
        display: flex;
        flex-direction: column;
    }

    .game-wrapper {
        flex: none;
        aspect-ratio: auto !important;
        height: 55vh !important;
        min-height: 280px;
        max-height: 55vh;
        position: relative;
    }

    #gameCanvas {
        position: absolute !important;
        top: 0 !important;
        left: 0 !important;
        width: 100% !important;
        height: 100% !important;
        display: block;
    }

    /* 모바일 컨트롤 표시 */
    .mobile-controls {
        display: flex;
        justify-content: center;
        align-items: center;
        padding: 10px 15px;
        margin-top: 8px;
        flex: 1;
        min-height: 100px;
    }

    .tap-btn {
        width: 100%;
        max-width: 300px;
        height: 90px;
        border: none;
        border-radius: 20px;
        background: linear-gradient(180deg, var(--accent-cyan), #0891b2);
        color: #1a1a2e;
        font-family: 'Jua', sans-serif;
        cursor: pointer;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 8px;
        box-shadow: 0 8px 30px rgba(0, 212, 255, 0.4);
        transition: all 0.1s ease;
        -webkit-tap-highlight-color: transparent;
    }

    .tap-btn:active,
    .tap-btn.active {
        transform: scale(0.95);
        background: linear-gradient(180deg, #0891b2, #065f82);
        box-shadow: 0 4px 15px rgba(0, 212, 255, 0.6);
    }

    .tap-icon {
        font-size: 2.5rem;
    }

    .tap-text {
        font-size: 1.5rem;
        font-weight: 700;
        letter-spacing: 2px;
    }

    /* HUD 조정 */
    .hud-left, .hud-right {
        gap: 10px;
    }

    .hud-item {
        padding: 3px 6px;
    }

    .hud-icon {
        font-size: 0.85rem;
    }

    .hud-value {
        font-size: 0.7rem;
    }

    .hud-value.score-value {
        font-size: 0.9rem;
    }

    /* 오버레이 조정 */
    .game-title {
        font-size: 1.2rem;
    }

    .game-subtitle {
        font-size: 0.6rem;
        margin-bottom: 10px;
    }

    .overlay-content {
        flex-direction: column;
        gap: 10px;
    }

    .final-value {
        font-size: 1.5rem;
    }

    .play-btn {
        padding: 10px 30px;
        font-size: 0.9rem;
    }

    .controls-hint {
        display: none;
    }

    .leaderboard-section {
        max-width: 180px;
    }
}

/* Mobile Landscape & Desktop */
@media (max-width: 600px) and (orientation: landscape) {
    .mobile-controls {
        display: none;
    }

    .game-wrapper {
        aspect-ratio: 16/10;
    }
}

/* Desktop & Tablet Responsive */
@media (max-width: 600px) {
    .container {
        padding: 15px 10px;
    }

    header h1 {
        font-size: 1.5rem;
    }

    .back-btn span {
        display: none;
    }

    .back-btn {
        padding: 8px;
    }

    .game-wrapper {
        border-radius: 8px;
    }

    .hud {
        top: 8px;
        left: 8px;
        right: 8px;
    }

    .hud-item {
        padding: 4px 8px;
    }

    .hud-value {
        font-size: 0.8rem;
    }

    .hud-value.score-value {
        font-size: 1rem;
    }

    .game-title {
        font-size: 1.4rem;
    }

    .game-subtitle {
        margin-bottom: 15px;
        font-size: 0.65rem;
    }

    /* Overlay layout mobile */
    .overlay-content {
        gap: 15px;
        padding: 0 10px;
    }

    .final-value {
        font-size: 1.8rem;
    }

    .controls-hint {
        font-size: 0.5rem;
        margin-top: 6px;
    }

    .play-btn {
        padding: 8px 25px;
        font-size: 0.8rem;
        min-height: 36px;
    }

    /* Leaderboard mobile */
    .leaderboard-section {
        max-width: 120px;
        padding: 8px;
        margin: 0;
    }

    .leaderboard-section h3 {
        font-size: 0.75rem;
        margin-bottom: 6px;
    }

    .leaderboard-list {
        gap: 3px;
    }

    .leaderboard-entry {
        padding: 4px 6px;
        font-size: 0.65rem;
    }

    .leaderboard-entry .rank {
        min-width: 20px;
        font-size: 0.75rem;
    }

    .leaderboard-entry .entry-score {
        font-size: 0.65rem;
    }

    .leaderboard-entry .entry-status {
        min-width: 18px;
    }

    .my-score {
        margin-top: 4px;
        padding-top: 4px;
        font-size: 0.6rem;
    }
}

/* Fullscreen mode */
body.fullscreen-active .game-container {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    width: 100%;
    overflow: hidden;
}

body.fullscreen-active .game-wrapper {
    width: min(100%, 780px) !important;
    aspect-ratio: 16/10 !important;
    flex: none !important;
    height: auto !important;
    min-height: auto !important;
    max-height: none !important;
}

/* Mobile Fullscreen Portrait: 일반 모바일과 동일한 비율/위치 유지 */
@media (max-width: 600px) and (orientation: portrait) {
    body.fullscreen-active .container {
        justify-content: flex-start !important;
        padding: 8px !important;
    }

    body.fullscreen-active .game-container {
        justify-content: flex-start;
        align-items: stretch;
        flex: 1;
    }

    body.fullscreen-active .game-wrapper {
        aspect-ratio: auto !important;
        width: 100% !important;
        height: 60dvh !important;
        min-height: 280px !important;
        max-height: 65dvh !important;
        border-radius: 8px;
    }

    body.fullscreen-active #gameCanvas {
        position: absolute !important;
        top: 0 !important;
        left: 0 !important;
        width: 100% !important;
        height: 100% !important;
    }

    body.fullscreen-active .mobile-controls {
        flex: 1;
        min-height: 100px;
    }

    body.fullscreen-active .tap-btn {
        width: 100%;
        max-width: 300px;
        height: 90px;
    }
}
