:root {
    --bg-arcade: #121824;
    --surface: rgba(22, 30, 46, 0.95);
    --surface-light: rgba(255, 255, 255, 0.08);
    --border: rgba(245, 158, 11, 0.24);
    --border-soft: rgba(148, 163, 184, 0.18);
    --amber: #F59E0B;
    --amber-light: #FDE68A;
    --emerald: #10B981;
    --emerald-bright: #34D399;
    --rose: #FB7185;
    --text-main: #F8FAFC;
    --text-sub: #CBD5E1;
}

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

body {
    min-height: 100vh;
    background-color: var(--bg-arcade);
    color: var(--text-main);
    font-family: 'Pretendard', 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 16px 14px 26px;
    overflow-x: hidden;
    user-select: none;
    -webkit-user-select: none;
}

.arcade-backdrop {
    position: fixed;
    inset: 0;
    z-index: -1;
    background:
        radial-gradient(circle at 15% 15%, rgba(245, 158, 11, 0.15), transparent 45%),
        radial-gradient(circle at 85% 20%, rgba(16, 185, 129, 0.14), transparent 42%),
        radial-gradient(circle at 50% 90%, rgba(59, 130, 246, 0.14), transparent 55%),
        linear-gradient(180deg, #101622 0%, #172033 100%);
    pointer-events: none;
}

.game-shell {
    width: 100%;
    max-width: 860px;
    display: flex;
    flex-direction: column;
    gap: 11px;
}

/* Top HUD Header */
.hud-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    padding: 12px 18px;
    border-radius: 18px;
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: 0 14px 30px -14px rgba(0, 0, 0, 0.65);
}

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

.home-link {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 8px 13px;
    border-radius: 999px;
    background: var(--surface-light);
    border: 1px solid var(--border-soft);
    color: var(--text-main);
    text-decoration: none;
    font-size: 0.84rem;
    font-weight: 700;
    transition: all 0.2s ease;
}

.home-link:hover {
    background: rgba(245, 158, 11, 0.2);
    border-color: var(--amber);
    transform: translateY(-1px);
}

.title-group {
    display: flex;
    align-items: center;
    gap: 9px;
}

.retro-badge {
    padding: 4px 10px;
    border-radius: 999px;
    background: rgba(245, 158, 11, 0.16);
    border: 1px solid rgba(245, 158, 11, 0.42);
    color: var(--amber-light);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.05em;
}

.hud-header h1 {
    font-size: 1.22rem;
    font-weight: 900;
    letter-spacing: -0.02em;
}

.stat-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 13px;
    border-radius: 999px;
    font-size: 0.83rem;
    font-weight: 700;
}

.best-pill {
    background: rgba(245, 158, 11, 0.14);
    border: 1px solid rgba(245, 158, 11, 0.35);
    color: var(--amber-light);
}

.stage-pill {
    background: rgba(16, 185, 129, 0.14);
    border: 1px solid rgba(16, 185, 129, 0.35);
    color: #A7F3D0;
}

.stat-pill strong {
    font-family: 'Outfit', sans-serif;
    font-size: 0.94rem;
    color: #FFFFFF;
}

.hud-btn {
    padding: 8px 13px;
    border-radius: 12px;
    border: 1px solid var(--border-soft);
    background: var(--surface-light);
    color: var(--text-main);
    font-family: inherit;
    font-size: 0.83rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.18s ease;
}

.hud-btn:hover {
    transform: translateY(-1px);
    border-color: var(--amber);
}

.hud-btn-accent {
    background: linear-gradient(135deg, #F59E0B, #D97706);
    border-color: transparent;
    color: #FFFFFF;
}

/* Stage Selector Bar */
.stage-bar {
    padding: 11px 16px;
    border-radius: 18px;
    background: var(--surface);
    border: 1px solid var(--border-soft);
    display: flex;
    flex-direction: column;
    gap: 9px;
}

.stage-list {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 8px;
}

.stage-chip {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 8px 10px;
    border-radius: 12px;
    border: 1px solid var(--border-soft);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-sub);
    font-family: inherit;
    font-size: 0.82rem;
    cursor: pointer;
    transition: all 0.18s ease;
}

.stage-chip:hover {
    border-color: rgba(245, 158, 11, 0.55);
    color: #FFFFFF;
    transform: translateY(-1px);
}

.stage-chip.active {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.28), rgba(217, 119, 6, 0.22));
    border-color: var(--amber);
    color: #FFFFFF;
    box-shadow: 0 0 16px -6px rgba(245, 158, 11, 0.65);
}

.stage-tag {
    padding: 2px 6px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.1);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--amber-light);
}

.stage-banner {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--amber-light);
    text-align: center;
}

/* Game Cabinet Frame */
.cabinet-frame {
    padding: 12px;
    border-radius: 24px;
    background: linear-gradient(145deg, rgba(28, 38, 58, 0.92), rgba(16, 22, 35, 0.98));
    border: 1px solid rgba(245, 158, 11, 0.3);
    box-shadow:
        0 0 42px -12px rgba(245, 158, 11, 0.24),
        0 26px 50px -18px rgba(0, 0, 0, 0.88);
}

.canvas-stage {
    position: relative;
    width: 100%;
    border-radius: 16px;
    overflow: hidden;
    background: #141C2B;
    border: 2px solid rgba(255, 255, 255, 0.12);
    transform: translateZ(0);
    backface-visibility: hidden;
}

canvas {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 800 / 520;
    transform: translateZ(0);
    backface-visibility: hidden;
}

/* Overlay */
.game-overlay {
    position: absolute;
    inset: 0;
    background: rgba(14, 20, 32, 0.76);
    backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 18px;
    z-index: 10;
}

.game-overlay.hidden {
    display: none;
}

.overlay-card {
    max-width: 520px;
    width: 100%;
    background: rgba(20, 28, 43, 0.96);
    border: 1px solid rgba(245, 158, 11, 0.42);
    border-radius: 22px;
    padding: 24px 26px;
    text-align: center;
    box-shadow: 0 24px 48px rgba(0, 0, 0, 0.65);
}

.overlay-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 999px;
    background: rgba(245, 158, 11, 0.16);
    border: 1px solid rgba(245, 158, 11, 0.4);
    color: var(--amber-light);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.74rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    margin-bottom: 10px;
}

.overlay-card h2 {
    font-size: clamp(1.38rem, 3vw, 1.82rem);
    font-weight: 900;
    margin-bottom: 8px;
}

.overlay-card p {
    font-size: 0.92rem;
    color: #CBD5E1;
    line-height: 1.5;
    margin-bottom: 16px;
}

.overlay-stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 16px;
}

.overlay-stats.hidden {
    display: none;
}

.ov-stat {
    padding: 10px 8px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--border-soft);
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.ov-stat span {
    font-size: 0.74rem;
    color: #94A3B8;
}

.ov-stat strong {
    font-family: 'Outfit', sans-serif;
    font-size: 1.12rem;
    color: var(--amber-light);
}

.item-guide {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 7px;
    margin-bottom: 18px;
}

.item-guide span {
    padding: 4px 10px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    font-size: 0.75rem;
    font-weight: 600;
    color: #E2E8F0;
}

.start-btn {
    padding: 13px 28px;
    border-radius: 14px;
    border: none;
    background: linear-gradient(135deg, #F59E0B, #D97706);
    color: #FFFFFF;
    font-family: inherit;
    font-size: 1rem;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 12px 24px -8px rgba(245, 158, 11, 0.7);
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.start-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 16px 28px -8px rgba(245, 158, 11, 0.9);
}

/* Arcade Controls Panel (Inside Game Screen: Jump Bottom-Left, Joystick Bottom-Right) */
.controls-panel {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 6;
}

.arcade-controls {
    position: relative;
    width: 100%;
    height: 100%;
}

.pad-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 10px 16px;
    border-radius: 16px;
    border: 1px solid rgba(52, 211, 153, 0.48);
    background: rgba(15, 23, 42, 0.56);
    backdrop-filter: blur(4px);
    color: #FFFFFF;
    font-family: inherit;
    cursor: pointer;
    pointer-events: auto;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
    transition: transform 0.1s ease, background-color 0.15s ease, border-color 0.15s ease;
}

.pad-btn span {
    font-size: 1.12rem;
    line-height: 1;
}

.pad-btn small {
    font-size: 0.72rem;
    color: var(--text-sub);
    font-weight: 600;
}

.pad-btn:active,
.pad-btn.pressed {
    transform: scale(0.95);
    border-color: var(--amber);
    background: rgba(245, 158, 11, 0.28);
}

.action-jump {
    position: absolute;
    left: 16px;
    bottom: 14px;
    flex-direction: row;
    gap: 10px;
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.36), rgba(5, 150, 105, 0.28));
    border-color: rgba(52, 211, 153, 0.52);
}

.action-jump.pressed {
    background: rgba(16, 185, 129, 0.5);
    border-color: #34D399;
}

.jump-icon {
    font-size: 1.35rem !important;
}

.jump-meta {
    display: flex;
    flex-direction: column;
    text-align: left;
    line-height: 1.25;
}

.jump-meta strong {
    font-size: 0.96rem;
    font-weight: 800;
}

.jump-meta small {
    font-size: 0.74rem;
    color: #CBD5E1;
}

/* Virtual Joystick (Bottom-Right Inside Game Screen) */
.joystick-zone {
    position: absolute;
    right: 16px;
    bottom: 12px;
    width: 120px;
    height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    cursor: grab;
}

.joystick-zone.active {
    cursor: grabbing;
}

.joystick-base {
    position: relative;
    width: 110px;
    height: 110px;
    border-radius: 50%;
    background: radial-gradient(circle at center, rgba(30, 41, 59, 0.54) 0%, rgba(15, 23, 42, 0.4) 100%);
    border: 2px solid rgba(245, 158, 11, 0.42);
    box-shadow: inset 0 0 16px rgba(0, 0, 0, 0.45), 0 8px 18px rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(4px);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.joystick-zone.active .joystick-base {
    border-color: rgba(251, 191, 36, 0.85);
    box-shadow: inset 0 0 20px rgba(245, 158, 11, 0.25), 0 8px 22px rgba(0, 0, 0, 0.45);
}

.joy-arrow {
    position: absolute;
    font-size: 0.62rem;
    line-height: 1;
    color: rgba(248, 250, 252, 0.44);
    pointer-events: none;
}

.joy-up {
    top: 7px;
    left: 50%;
    transform: translateX(-50%);
}

.joy-down {
    bottom: 7px;
    left: 50%;
    transform: translateX(-50%);
}

.joy-left {
    left: 8px;
    top: 50%;
    transform: translateY(-50%);
}

.joy-right {
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
}

.joystick-knob {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 44px;
    height: 44px;
    margin-left: -22px;
    margin-top: -22px;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, #FBBF24, #D97706);
    border: 2px solid rgba(255, 255, 255, 0.68);
    box-shadow: 0 6px 14px rgba(0, 0, 0, 0.55);
    transform: translate3d(0, 0, 0);
    transition: transform 0.08s ease-out;
    pointer-events: none;
}

.joystick-zone.active .joystick-knob {
    transition: none;
    box-shadow: 0 0 16px rgba(245, 158, 11, 0.72);
}

.mobile-overlay-bar {
    display: none;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 14px;
}

.mob-ov-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 7px 12px;
    border-radius: 999px;
    border: 1px solid var(--border-soft);
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-main);
    font-family: inherit;
    font-size: 0.78rem;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
}

@media (max-width: 940px), ((hover: none) and (pointer: coarse) and (max-height: 560px)) {
    html,
    body {
        width: 100%;
        height: 100%;
        padding: 0;
        margin: 0;
        overflow: hidden;
        position: fixed;
        inset: 0;
        touch-action: none;
    }

    .arcade-backdrop,
    .hud-header,
    .stage-bar,
    .item-guide {
        display: none !important;
    }

    .game-shell {
        width: 100vw;
        height: 100vh;
        height: 100dvh;
        max-width: none;
        margin: 0;
        padding: 0;
        gap: 0;
    }

    .cabinet-frame,
    .canvas-stage {
        width: 100%;
        height: 100%;
        max-width: none;
        margin: 0;
        padding: 0;
        border: none;
        border-radius: 0;
        box-shadow: none;
        background: transparent;
    }

    canvas {
        width: 100%;
        height: 100%;
        aspect-ratio: auto;
        display: block;
    }

    .action-jump {
        left: 10px;
        bottom: 6px;
        padding: 6px 13px;
        gap: 6px;
        border-radius: 999px;
        background: linear-gradient(135deg, rgba(16, 185, 129, 0.3), rgba(5, 150, 105, 0.24));
    }

    .jump-icon {
        font-size: 1.05rem !important;
    }

    .jump-meta strong {
        font-size: 0.84rem;
    }

    .jump-meta small {
        display: none;
    }

    .joystick-zone {
        right: 10px;
        bottom: 5px;
        width: 96px;
        height: 96px;
    }

    .joystick-base {
        width: 88px;
        height: 88px;
    }

    .joystick-knob {
        width: 36px;
        height: 36px;
        margin-left: -18px;
        margin-top: -18px;
    }

    .game-overlay {
        padding: 10px 14px;
    }

    .overlay-card {
        padding: 12px 16px;
        max-width: min(520px, 92%);
        max-height: calc(100% - 16px);
        overflow-y: auto;
        border-radius: 16px;
    }

    .overlay-badge {
        margin-bottom: 4px;
        padding: 3px 10px;
        font-size: 0.68rem;
    }

    .overlay-card h2 {
        font-size: 1.22rem;
        margin-bottom: 4px;
    }

    .overlay-card p {
        font-size: 0.82rem;
        line-height: 1.38;
        margin-bottom: 10px;
    }

    .overlay-stats {
        gap: 8px;
        margin-bottom: 10px;
    }

    .start-btn {
        padding: 10px 22px;
        font-size: 0.92rem;
    }

    .mobile-overlay-bar {
        display: flex;
        margin-top: 8px;
        gap: 6px;
    }

    .mob-ov-btn {
        padding: 5px 10px;
        font-size: 0.74rem;
    }
}

@media ((max-width: 940px) and (orientation: portrait)) {
    .game-shell {
        position: fixed;
        top: 0;
        left: 100vw;
        width: 100vh;
        width: 100dvh;
        height: 100vw;
        transform: rotate(90deg);
        transform-origin: top left;
        z-index: 20;
    }
}
