:root {
    --bg-forest: #14221D;
    --surface: rgba(22, 39, 33, 0.94);
    --surface-light: rgba(255, 255, 255, 0.08);
    --border: rgba(148, 210, 189, 0.22);
    --emerald: #2A9D8F;
    --emerald-bright: #52B788;
    --amber: #E09F3E;
    --amber-light: #F3D59B;
    --text-main: #F1F5F2;
    --text-sub: #B7E4C7;
}

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

body {
    min-height: 100vh;
    background-color: var(--bg-forest);
    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: 18px 14px 28px;
    overflow-x: hidden;
    user-select: none;
    -webkit-user-select: none;
}

.forest-backdrop {
    position: fixed;
    inset: 0;
    z-index: -1;
    background:
        radial-gradient(circle at 18% 18%, rgba(82, 183, 136, 0.16), transparent 48%),
        radial-gradient(circle at 82% 22%, rgba(224, 159, 62, 0.12), transparent 45%),
        radial-gradient(circle at 50% 90%, rgba(42, 157, 143, 0.2), transparent 55%),
        linear-gradient(180deg, #12201B 0%, #1B3028 100%);
    pointer-events: none;
}

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

/* 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.7);
}

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

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

.home-link:hover {
    background: rgba(16, 185, 129, 0.22);
    border-color: var(--emerald-bright);
    transform: translateY(-1px);
}

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

.forest-badge {
    padding: 4px 10px;
    border-radius: 999px;
    background: rgba(16, 185, 129, 0.18);
    border: 1px solid rgba(52, 211, 153, 0.4);
    color: var(--emerald-bright);
    font-family: 'Outfit', sans-serif;
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.06em;
}

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

.best-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border-radius: 999px;
    background: rgba(245, 158, 11, 0.14);
    border: 1px solid rgba(245, 158, 11, 0.35);
    color: var(--amber-light);
    font-size: 0.85rem;
    font-weight: 700;
}

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

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

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

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

/* Character Bar */
.character-bar {
    padding: 12px 16px;
    border-radius: 18px;
    background: var(--surface);
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.char-list {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
}

.char-chip {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-main);
    font-family: inherit;
    text-align: left;
    cursor: pointer;
    transition: all 0.2s ease;
}

.char-chip:hover {
    border-color: rgba(52, 211, 153, 0.55);
    transform: translateY(-1px);
}

.char-chip.active {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.28), rgba(5, 150, 105, 0.22));
    border-color: var(--emerald-bright);
    box-shadow: 0 0 18px -6px rgba(52, 211, 153, 0.7);
}

.char-emoji {
    font-size: 1.55rem;
    line-height: 1;
}

.char-meta {
    display: flex;
    flex-direction: column;
    line-height: 1.25;
}

.char-meta strong {
    font-size: 0.88rem;
    font-weight: 800;
}

.char-meta small {
    font-size: 0.74rem;
    color: var(--text-sub);
}

.perk-banner {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--amber-light);
    text-align: center;
    padding-top: 2px;
}

/* Game Cabinet Frame */
.cabinet-frame {
    padding: 12px;
    border-radius: 24px;
    background: linear-gradient(145deg, rgba(20, 56, 44, 0.88), rgba(9, 25, 20, 0.95));
    border: 1px solid rgba(52, 211, 153, 0.32);
    box-shadow:
        0 0 42px -12px rgba(16, 185, 129, 0.35),
        0 26px 50px -18px rgba(0, 0, 0, 0.9);
}

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

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

/* Overlay */
.game-overlay {
    position: absolute;
    inset: 0;
    background: rgba(6, 18, 14, 0.72);
    backdrop-filter: blur(7px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 18px;
    z-index: 10;
    transition: opacity 0.25s ease;
}

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

.overlay-card {
    max-width: 520px;
    width: 100%;
    background: rgba(11, 29, 24, 0.92);
    border: 1px solid rgba(52, 211, 153, 0.35);
    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: 'Outfit', sans-serif;
    font-size: 0.74rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    margin-bottom: 10px;
}

.overlay-card h2 {
    font-size: clamp(1.4rem, 3vw, 1.85rem);
    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);
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.ov-stat span {
    font-size: 0.74rem;
    color: var(--text-sub);
}

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

.item-guide {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    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.1);
    font-size: 0.76rem;
    font-weight: 600;
    color: #E2E8F0;
}

.start-btn {
    padding: 13px 28px;
    border-radius: 14px;
    border: none;
    background: linear-gradient(135deg, #10B981, #059669);
    color: #FFFFFF;
    font-family: inherit;
    font-size: 1rem;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 12px 24px -8px rgba(16, 185, 129, 0.75);
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}

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

/* Bottom Action Pads (Overlaid Inside Game Screen: Slide Bottom-Left, Jump Bottom-Right) */
.controls-panel {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 6;
}

.touch-buttons {
    position: relative;
    width: 100%;
    height: 100%;
}

.action-pad {
    position: absolute;
    bottom: 14px;
    pointer-events: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 10px 16px;
    border-radius: 16px;
    border: 1px solid rgba(148, 210, 189, 0.36);
    background: rgba(11, 28, 22, 0.56);
    backdrop-filter: blur(4px);
    color: #FFFFFF;
    font-family: inherit;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
    transition: transform 0.12s ease, background-color 0.15s ease, box-shadow 0.15s ease;
}

.action-pad:active,
.action-pad.pressed {
    transform: scale(0.95);
}

.pad-slide {
    left: 16px;
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.3), rgba(217, 119, 6, 0.24));
    border-color: rgba(251, 191, 36, 0.48);
}

.pad-jump {
    right: 16px;
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.36), rgba(5, 150, 105, 0.28));
    border-color: rgba(52, 211, 153, 0.54);
}

.pad-icon {
    font-size: 1.45rem;
}

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

.pad-text strong {
    font-size: 0.98rem;
    font-weight: 800;
}

.pad-text small {
    font-size: 0.76rem;
    color: #CBD5E1;
}

.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);
    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;
    }

    .forest-backdrop,
    .hud-header,
    .character-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-pad {
        bottom: 8px;
        padding: 8px 14px;
        gap: 7px;
        border-radius: 999px;
    }

    .pad-slide {
        left: 12px;
    }

    .pad-jump {
        right: 12px;
    }

    .pad-icon {
        font-size: 1.1rem;
    }

    .pad-text strong {
        font-size: 0.85rem;
    }

    .pad-text small {
        display: none;
    }

    .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;
    }
}
