:root {
    --bg-primary: #0a0a1a;
    --bg-secondary: #1a1a2e;
    --accent-gold: #ffd700;
    --accent-cyan: #06b6d4;
    --accent-orange: #ff8c00;
    --accent-purple: #a855f7;
    --accent-red: #ef4444;
    --accent-green: #22c55e;
    --text-primary: #ffffff;
    --text-secondary: rgba(255,255,255,0.7);

    --board-bg: #2d1b4e;
    --cell-bg: #3d2b5e;
    --path-color: #8b7355;
    --path-walked: #4ade80;
    --sidebar-bg: #16213e;
}

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

body {
    min-height: 100vh;
    background: var(--bg-primary);
    background-image:
        radial-gradient(ellipse at top, #1a1a3e 0%, transparent 50%),
        radial-gradient(ellipse at bottom, #0f0f2a 0%, transparent 50%);
    font-family: 'Noto Sans KR', sans-serif;
    color: var(--text-primary);
    display: flex;
    flex-direction: column;
    align-items: center;
}

.container {
    width: 100%;
    max-width: 800px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Header */
header {
    text-align: center;
}

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

.back-btn {
    position: absolute;
    left: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    transition: all 0.3s;
    min-width: 44px;
    min-height: 44px;
    padding: 8px;
    margin-left: -8px;
    border-radius: 8px;
}

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

.back-btn svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

h1 {
    font-family: 'Black Han Sans', sans-serif;
    font-size: 2.5rem;
    background: linear-gradient(135deg, var(--accent-gold), var(--accent-orange));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: 0 0 30px rgba(255, 215, 0, 0.3);
}

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

/* Game Area */
.game-area {
    display: flex;
    justify-content: center;
}

.game-wrapper {
    display: flex;
    flex-direction: row;
    gap: 20px;
    background: var(--bg-secondary);
    padding: 20px;
    border-radius: 16px;
    border: 2px solid rgba(168, 85, 247, 0.3);
    box-shadow: 0 10px 30px rgba(0,0,0,0.5), inset 0 0 60px rgba(168, 85, 247, 0.05);
}

@media (max-width: 600px) {
    .game-wrapper {
        flex-direction: column;
        align-items: center;
    }
}

.main-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
}

.header-status {
    width: 100%;
    margin-bottom: 15px;
    background: rgba(0,0,0,0.3);
    padding: 10px 15px;
    border-radius: 8px;
    border: 1px solid rgba(168, 85, 247, 0.2);
}

.top-status {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
    font-family: 'Jua', sans-serif;
}

.status-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 60px;
}

.status-item span:first-child {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.status-item span:last-child {
    font-size: 1.2rem;
    color: var(--accent-gold);
}

.hero-status span:last-child {
    color: var(--accent-green);
}

.boss-status span:last-child {
    color: var(--accent-red);
}

.level-select-wrap {
    flex-direction: row;
    gap: 5px;
}

.level-select-wrap span {
    font-size: 1rem;
    color: var(--accent-purple);
}

.btn-level-select {
    background: rgba(168, 85, 247, 0.2);
    border: 1px solid rgba(168, 85, 247, 0.4);
    border-radius: 8px;
    color: var(--accent-purple);
    padding: 8px 16px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
    min-height: 36px;
}

.btn-level-select:hover {
    background: rgba(168, 85, 247, 0.3);
}

/* Pixel Art Characters */
.pixel-hero, .pixel-hero-small {
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

.pixel-hero-small {
    width: 24px;
    height: 24px;
    background: linear-gradient(180deg,
        transparent 0%, transparent 12.5%,
        #4a90d9 12.5%, #4a90d9 25%,
        #ffcc99 25%, #ffcc99 37.5%,
        #3366cc 37.5%, #3366cc 62.5%,
        #2255bb 62.5%, #2255bb 75%,
        #8b4513 75%, #8b4513 87.5%,
        transparent 87.5%, transparent 100%
    );
    position: relative;
}

.pixel-hero-small::before {
    content: '';
    position: absolute;
    left: 50%;
    top: 0;
    transform: translateX(-50%);
    width: 8px;
    height: 8px;
    background: #c0c0c0;
    clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
}

.pixel-boss-small {
    width: 24px;
    height: 24px;
    background: radial-gradient(circle at 30% 40%, #ff6b6b 30%, #cc0000 100%);
    border-radius: 50% 50% 40% 40%;
    position: relative;
}

.pixel-boss-small::before {
    content: '';
    position: absolute;
    top: 8px;
    left: 4px;
    width: 4px;
    height: 4px;
    background: #ffff00;
    border-radius: 50%;
    box-shadow: 12px 0 0 #ffff00;
}

/* Board */
.board {
    display: grid;
    gap: 2px;
    background-color: var(--board-bg);
    padding: 5px;
    border-radius: 8px;
    border: 3px solid #4a3a6e;
    width: fit-content;
    box-shadow: inset 0 0 30px rgba(0,0,0,0.5);
}

.cell {
    width: 60px;
    height: 60px;
    background-color: var(--cell-bg);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s;
    aspect-ratio: 1;
    position: relative;
}

.cell:hover:not(.fixed):not(.blocked) {
    background-color: #5d4b7e;
    box-shadow: 0 0 10px rgba(168, 85, 247, 0.4);
}

.cell.fixed {
    cursor: default;
    background-color: #2d1b4e;
    border: 1px solid #4a3a6e;
}

.cell.blocked {
    background-color: #1a0a2e;
    cursor: not-allowed;
    position: relative;
}

.cell.blocked::after {
    content: '';
    width: 70%;
    height: 70%;
    background: linear-gradient(45deg, #3a2a4e 25%, #2a1a3e 25%, #2a1a3e 50%, #3a2a4e 50%, #3a2a4e 75%, #2a1a3e 75%);
    background-size: 8px 8px;
    border-radius: 4px;
}

.cell.wall {
    background-color: #0f0a1e;
    cursor: default;
}

/* Connected (walked) path highlight */
.cell.connected {
    background-color: #2a4a3a !important;
    box-shadow: inset 0 0 15px rgba(74, 222, 128, 0.4);
}

.cell.connected.fixed {
    background-color: #1a3a2a !important;
}

/* Path end indicator */
.cell.path-end {
    background-color: #4a3a2a !important;
    box-shadow: inset 0 0 15px rgba(255, 165, 0, 0.6), 0 0 10px rgba(255, 165, 0, 0.4);
    animation: pathEndPulse 1s ease-in-out infinite;
}

@keyframes pathEndPulse {
    0%, 100% { box-shadow: inset 0 0 15px rgba(255, 165, 0, 0.6), 0 0 10px rgba(255, 165, 0, 0.4); }
    50% { box-shadow: inset 0 0 20px rgba(255, 165, 0, 0.8), 0 0 20px rgba(255, 165, 0, 0.6); }
}

/* Sidebar (Next Pieces) */
.sidebar {
    background: var(--sidebar-bg);
    padding: 15px;
    border-radius: 12px;
    min-width: 100px;
    text-align: center;
    border: 1px solid rgba(168, 85, 247, 0.2);
}

.sidebar h3 {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-bottom: 15px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    padding-bottom: 5px;
}

.preview-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
    align-items: center;
}

.preview-item {
    display: flex;
    align-items: center;
    gap: 10px;
}

.preview-box {
    width: 50px;
    height: 50px;
    background: var(--cell-bg);
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    border: 1px solid rgba(168, 85, 247, 0.3);
}

.arrow-indicator {
    color: var(--accent-gold);
    font-weight: bold;
    animation: bounceX 1s infinite;
}

@keyframes bounceX {
    0%, 100% { transform: translateX(0); }
    50% { transform: translateX(-5px); }
}

/* Path SVG styles */
.path-svg {
    width: 100%;
    height: 100%;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Info Panel */
.info-panel {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 40px;
    font-weight: bold;
}

.timer-box {
    color: var(--accent-orange);
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Path requirement indicator */
.path-requirement {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 1.1rem;
    font-weight: bold;
    padding: 6px 14px;
    border-radius: 20px;
    background: rgba(0, 0, 0, 0.8);
    border: 2px solid;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
}

.path-requirement.path-ok {
    color: #4ade80;
    border-color: #4ade80;
    text-shadow: 0 0 10px #4ade80;
}

.path-requirement.path-need {
    color: #fbbf24;
    border-color: #fbbf24;
    animation: pulse-need 1.5s ease-in-out infinite;
}

@keyframes pulse-need {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

/* Buttons */
.btn {
    padding: 6px 16px;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    font-family: 'Jua', sans-serif;
    font-size: 0.9rem;
    transition: transform 0.2s;
}

.btn:hover {
    transform: scale(1.05);
}

.btn-start { background: linear-gradient(45deg, #ff6b6b, #ee5253); color: white; }
.btn-next { background: linear-gradient(45deg, #ffd700, #ff8c00); color: #1a1a2e; font-weight: bold; }
.btn-retry { background: linear-gradient(45deg, #a855f7, #7c3aed); color: white; }
.btn-fast { background: linear-gradient(45deg, #4ade80, #22c55e); color: #1a1a2e; font-weight: bold; }

/* Level Select Overlay */
.level-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.85);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 200;
}

.level-overlay.show {
    display: flex;
    animation: fadeIn 0.3s ease-out;
}

.level-select-content {
    background: var(--bg-secondary);
    padding: 25px;
    border-radius: 16px;
    max-width: 350px;
    width: 90%;
    text-align: center;
    border: 2px solid rgba(168, 85, 247, 0.3);
}

.level-select-content h2 {
    font-family: 'Black Han Sans', sans-serif;
    color: var(--accent-gold);
    margin-bottom: 20px;
}

/* Difficulty Tabs */
.difficulty-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
}

.diff-tab {
    flex: 1;
    padding: 10px 5px;
    background: rgba(168, 85, 247, 0.1);
    border: 2px solid transparent;
    border-radius: 10px;
    color: var(--text-secondary);
    cursor: pointer;
    font-family: 'Jua', sans-serif;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.diff-tab:hover {
    background: rgba(168, 85, 247, 0.2);
}

.diff-tab.active {
    border-color: var(--accent-gold);
    color: var(--accent-gold);
}

.diff-tab.locked {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Level Grid */
.level-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
    margin-bottom: 20px;
}

.level-btn {
    aspect-ratio: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(168, 85, 247, 0.1);
    border: 2px solid rgba(168, 85, 247, 0.3);
    border-radius: 10px;
    color: white;
    font-family: 'Black Han Sans', sans-serif;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
}

.level-btn:hover {
    background: rgba(255, 215, 0, 0.2);
    border-color: var(--accent-gold);
}

.level-btn.completed {
    background: rgba(34, 197, 94, 0.3);
    border-color: #22c55e;
}

.level-btn.current {
    background: rgba(255, 215, 0, 0.2);
    border-color: var(--accent-gold);
}

.level-btn.locked {
    opacity: 0.5;
    cursor: not-allowed;
    background: rgba(100, 100, 100, 0.3) !important;
}

.level-best {
    font-size: 0.6rem;
    color: var(--accent-gold);
    font-family: 'Noto Sans KR', sans-serif;
}

.btn-close {
    background: rgba(255,255,255,0.1);
    color: var(--text-secondary);
    border: 1px solid rgba(255,255,255,0.2);
    padding: 10px 30px;
}

/* Resume Overlay */
.resume-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(10, 10, 26, 0.95);
    border-radius: 12px;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.resume-overlay.show {
    display: flex;
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.resume-content {
    text-align: center;
    padding: 30px;
}

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

.resume-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: center;
}

.btn-resume {
    background: linear-gradient(45deg, var(--accent-gold), var(--accent-orange));
    color: #1a1a2e;
}

.btn-new {
    background: rgba(255,255,255,0.1);
    color: var(--text-primary);
    border: 1px solid rgba(255,255,255,0.3);
}

/* Level Up Overlay */
.levelup-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 150;
    pointer-events: none;
}

.levelup-overlay.show {
    display: flex;
    animation: levelUpFlash 1s ease-out forwards;
}

@keyframes levelUpFlash {
    0% { opacity: 0; }
    20% { opacity: 1; }
    80% { opacity: 1; }
    100% { opacity: 0; }
}

.levelup-content {
    text-align: center;
    animation: levelUpBounce 0.5s ease-out;
}

@keyframes levelUpBounce {
    0% { transform: scale(0.5); }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

.levelup-hero {
    width: 64px;
    height: 64px;
    margin: 0 auto 15px;
}

.levelup-text {
    font-family: 'Black Han Sans', sans-serif;
    font-size: 2.5rem;
    color: var(--accent-gold);
    text-shadow: 0 0 20px rgba(255, 215, 0, 0.8);
    animation: levelUpGlow 0.5s ease-in-out infinite alternate;
}

@keyframes levelUpGlow {
    from { text-shadow: 0 0 20px rgba(255, 215, 0, 0.5); }
    to { text-shadow: 0 0 40px rgba(255, 215, 0, 1); }
}

.levelup-level {
    font-family: 'Jua', sans-serif;
    font-size: 1.5rem;
    color: var(--accent-green);
}

/* Victory Overlay */
.victory-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 160;
    pointer-events: none;
}

.victory-overlay.show {
    display: flex;
}

.victory-content {
    text-align: center;
    display: flex;
    align-items: center;
    gap: 30px;
}

.victory-hero, .victory-boss {
    width: 80px;
    height: 80px;
}

.victory-vs {
    font-family: 'Black Han Sans', sans-serif;
    font-size: 2rem;
    color: var(--accent-orange);
}

.victory-result {
    position: absolute;
    bottom: 30%;
    left: 50%;
    transform: translateX(-50%);
    font-family: 'Black Han Sans', sans-serif;
    font-size: 3rem;
    animation: victoryPulse 0.5s ease-in-out infinite alternate;
}

.victory-result.win {
    color: var(--accent-gold);
    text-shadow: 0 0 30px rgba(255, 215, 0, 0.8);
}

.victory-result.lose {
    color: var(--accent-red);
    text-shadow: 0 0 30px rgba(239, 68, 68, 0.8);
}

@keyframes victoryPulse {
    from { transform: translateX(-50%) scale(1); }
    to { transform: translateX(-50%) scale(1.1); }
}

/* Victory/Defeat Character Animations */
@keyframes heroCheer {
    0%, 100% {
        transform: translateY(0) rotate(0deg) scale(1);
    }
    25% {
        transform: translateY(-15px) rotate(-8deg) scale(1.1);
    }
    50% {
        transform: translateY(-20px) rotate(0deg) scale(1.15);
    }
    75% {
        transform: translateY(-15px) rotate(8deg) scale(1.1);
    }
}

@keyframes fallSideways {
    0% {
        transform: translateY(0) translateX(0) rotate(0deg);
        opacity: 1;
    }
    30% {
        transform: translateY(5px) translateX(10px) rotate(25deg);
        opacity: 1;
    }
    60% {
        transform: translateY(15px) translateX(20px) rotate(55deg);
        opacity: 0.8;
    }
    100% {
        transform: translateY(25px) translateX(30px) rotate(90deg);
        opacity: 0.4;
        filter: grayscale(80%);
    }
}

@keyframes bossCheer {
    0%, 100% {
        transform: scale(1) rotate(-3deg);
    }
    25% {
        transform: scale(1.15) rotate(5deg);
    }
    50% {
        transform: scale(1.2) rotate(-5deg);
    }
    75% {
        transform: scale(1.15) rotate(5deg);
    }
}

@keyframes sparkle {
    0%, 100% {
        filter: drop-shadow(0 0 5px gold) drop-shadow(0 0 10px gold);
    }
    50% {
        filter: drop-shadow(0 0 15px gold) drop-shadow(0 0 25px yellow);
    }
}

/* Win state: Hero celebrates (만세!), Boss falls sideways */
.victory-overlay.win .victory-hero {
    animation: heroCheer 0.4s ease-in-out infinite, sparkle 0.6s ease-in-out infinite;
}

.victory-overlay.win .victory-boss {
    animation: fallSideways 0.8s ease-out forwards;
    transform-origin: bottom right;
}

/* Lose state: Boss celebrates, Hero falls sideways */
.victory-overlay.lose .victory-boss {
    animation: bossCheer 0.35s ease-in-out infinite;
    filter: drop-shadow(0 0 10px #ef4444) drop-shadow(0 0 20px #dc2626);
}

.victory-overlay.lose .victory-hero {
    animation: fallSideways 0.8s ease-out forwards;
    transform-origin: bottom left;
}

/* VS text animation */
.victory-overlay.win .victory-vs {
    animation: victoryVsPulse 0.5s ease-in-out infinite alternate;
    color: var(--accent-gold);
}

.victory-overlay.lose .victory-vs {
    animation: victoryVsPulse 0.5s ease-in-out infinite alternate;
    color: var(--accent-red);
}

@keyframes victoryVsPulse {
    from { transform: scale(1); opacity: 0.7; }
    to { transform: scale(1.2); opacity: 1; }
}

/* Celebration Overlay */
.celebration-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.9);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 250;
}

.celebration-overlay.show {
    display: flex;
    animation: fadeIn 0.3s ease-out;
}

.celebration-content {
    text-align: center;
    padding: 40px;
}

.celebration-content .fireworks {
    font-size: 4rem;
    animation: bounce 0.5s ease-in-out infinite alternate;
}

@keyframes bounce {
    from { transform: scale(1); }
    to { transform: scale(1.2); }
}

.celebration-content h2 {
    font-family: 'Black Han Sans', sans-serif;
    font-size: 2.5rem;
    background: linear-gradient(135deg, #ffd700, #ff8c00);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin: 20px 0 10px;
}

/* Pixel Art Hero (larger) */
.pixel-hero {
    width: 48px;
    height: 48px;
    position: relative;
    image-rendering: pixelated;
}

/* Hero using CSS box-shadow pixel art */
.pixel-hero::before {
    content: '';
    position: absolute;
    width: 4px;
    height: 4px;
    background: transparent;
    box-shadow:
        /* Helmet */
        12px 0 0 #4a4a4a, 16px 0 0 #4a4a4a, 20px 0 0 #4a4a4a,
        8px 4px 0 #4a4a4a, 12px 4px 0 #6a6a6a, 16px 4px 0 #6a6a6a, 20px 4px 0 #6a6a6a, 24px 4px 0 #4a4a4a,
        8px 8px 0 #4a4a4a, 12px 8px 0 #5a5a5a, 16px 8px 0 #5a5a5a, 20px 8px 0 #5a5a5a, 24px 8px 0 #4a4a4a,
        /* Face */
        8px 12px 0 #ffcc99, 12px 12px 0 #ffcc99, 16px 12px 0 #ffcc99, 20px 12px 0 #ffcc99, 24px 12px 0 #ffcc99,
        8px 16px 0 #ffcc99, 12px 16px 0 #333, 16px 16px 0 #ffcc99, 20px 16px 0 #333, 24px 16px 0 #ffcc99,
        8px 20px 0 #ffcc99, 12px 20px 0 #ffcc99, 16px 20px 0 #cc8866, 20px 20px 0 #ffcc99, 24px 20px 0 #ffcc99,
        /* Armor */
        4px 24px 0 #3366cc, 8px 24px 0 #3366cc, 12px 24px 0 #3366cc, 16px 24px 0 #ffd700, 20px 24px 0 #3366cc, 24px 24px 0 #3366cc, 28px 24px 0 #3366cc,
        0 28px 0 #c0c0c0, 4px 28px 0 #3366cc, 8px 28px 0 #3366cc, 12px 28px 0 #3366cc, 16px 28px 0 #3366cc, 20px 28px 0 #3366cc, 24px 28px 0 #3366cc, 28px 28px 0 #3366cc, 32px 28px 0 #8b4513,
        0 32px 0 #c0c0c0, 4px 32px 0 #2255bb, 8px 32px 0 #2255bb, 12px 32px 0 #2255bb, 16px 32px 0 #2255bb, 20px 32px 0 #2255bb, 24px 32px 0 #2255bb, 28px 32px 0 #2255bb, 32px 32px 0 #8b4513,
        0 36px 0 #c0c0c0, 4px 36px 0 #2255bb, 8px 36px 0 #2255bb, 12px 36px 0 #2255bb, 16px 36px 0 #2255bb, 20px 36px 0 #2255bb, 24px 36px 0 #2255bb, 28px 36px 0 #2255bb, 32px 36px 0 #8b4513,
        /* Legs */
        8px 40px 0 #8b4513, 12px 40px 0 #8b4513, 20px 40px 0 #8b4513, 24px 40px 0 #8b4513,
        8px 44px 0 #6b3513, 12px 44px 0 #6b3513, 20px 44px 0 #6b3513, 24px 44px 0 #6b3513;
    transform: scale(1.5);
}

/* Pixel Art Boss */
.pixel-boss {
    width: 48px;
    height: 48px;
    position: relative;
    image-rendering: pixelated;
}

.pixel-boss::before {
    content: '';
    position: absolute;
    width: 4px;
    height: 4px;
    background: transparent;
    box-shadow:
        /* Horns */
        4px 0 0 #8b0000, 28px 0 0 #8b0000,
        4px 4px 0 #8b0000, 8px 4px 0 #8b0000, 24px 4px 0 #8b0000, 28px 4px 0 #8b0000,
        /* Head */
        8px 8px 0 #cc0000, 12px 8px 0 #cc0000, 16px 8px 0 #cc0000, 20px 8px 0 #cc0000, 24px 8px 0 #cc0000,
        4px 12px 0 #cc0000, 8px 12px 0 #ff4444, 12px 12px 0 #ff4444, 16px 12px 0 #ff4444, 20px 12px 0 #ff4444, 24px 12px 0 #ff4444, 28px 12px 0 #cc0000,
        4px 16px 0 #cc0000, 8px 16px 0 #ffff00, 12px 16px 0 #ff4444, 16px 16px 0 #ff4444, 20px 16px 0 #ff4444, 24px 16px 0 #ffff00, 28px 16px 0 #cc0000,
        4px 20px 0 #cc0000, 8px 20px 0 #ff4444, 12px 20px 0 #ff4444, 16px 20px 0 #000, 20px 20px 0 #ff4444, 24px 20px 0 #ff4444, 28px 20px 0 #cc0000,
        8px 24px 0 #cc0000, 12px 24px 0 #ffff00, 16px 24px 0 #ffff00, 20px 24px 0 #ffff00, 24px 24px 0 #cc0000,
        /* Body */
        4px 28px 0 #660000, 8px 28px 0 #990000, 12px 28px 0 #990000, 16px 28px 0 #990000, 20px 28px 0 #990000, 24px 28px 0 #990000, 28px 28px 0 #660000,
        0 32px 0 #660000, 4px 32px 0 #990000, 8px 32px 0 #990000, 12px 32px 0 #660000, 16px 32px 0 #990000, 20px 32px 0 #660000, 24px 32px 0 #990000, 28px 32px 0 #990000, 32px 32px 0 #660000,
        0 36px 0 #660000, 4px 36px 0 #990000, 8px 36px 0 #990000, 12px 36px 0 #990000, 16px 36px 0 #990000, 20px 36px 0 #990000, 24px 36px 0 #990000, 28px 36px 0 #990000, 32px 36px 0 #660000,
        /* Legs */
        8px 40px 0 #440000, 12px 40px 0 #440000, 20px 40px 0 #440000, 24px 40px 0 #440000,
        8px 44px 0 #330000, 12px 44px 0 #330000, 20px 44px 0 #330000, 24px 44px 0 #330000;
    transform: scale(1.5);
}

/* Confetti */
.confetti {
    position: fixed;
    z-index: 999;
    pointer-events: none;
}

@keyframes confettiFall {
    0% { transform: translateY(-100px) rotate(0deg); opacity: 1; }
    100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}

/* Destroy effect */
.cell.destroying {
    animation: destroyPath 0.5s ease-out;
}

@keyframes destroyPath {
    0% { background-color: var(--cell-bg); }
    50% { background-color: rgba(168, 85, 247, 0.5); box-shadow: 0 0 15px rgba(168, 85, 247, 0.6); }
    100% { background-color: var(--cell-bg); }
}

/* Exploding animation */
.cell.exploding {
    animation: explodePath 0.6s ease-out forwards;
    z-index: 10;
}

@keyframes explodePath {
    0% { background-color: var(--cell-bg); transform: scale(1); }
    30% { background-color: rgba(255, 100, 50, 0.8); box-shadow: 0 0 25px rgba(255, 100, 50, 0.9); transform: scale(1.15); }
    100% { background-color: var(--cell-bg); box-shadow: none; transform: scale(1); }
}

.cell.exploding .pipe-svg {
    animation: explodePathSVG 0.6s ease-out forwards;
}

@keyframes explodePathSVG {
    0% { transform: scale(1); opacity: 1; }
    30% { transform: scale(1.3) rotate(10deg); opacity: 1; filter: brightness(2); }
    60% { transform: scale(0.5) rotate(-20deg); opacity: 0.5; }
    100% { transform: scale(0) rotate(45deg); opacity: 0; }
}

/* Hero Walker Container - persistent overlay on the board */
.hero-walker-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 20;
}

/* Hero Walker - 보드 위 이동 캐릭터 */
.hero-walker {
    position: absolute;
    z-index: 20;
    width: 28px;
    height: 36px;
    pointer-events: none;
    image-rendering: pixelated;
    filter: drop-shadow(0 0 4px rgba(34, 197, 94, 0.9)) drop-shadow(0 1px 2px rgba(0,0,0,0.5));
    animation: heroIdle 0.4s ease-in-out infinite alternate;
    /* Transform origin at center-bottom for proper facing flip */
    transform-origin: center center;
}

/* Walking state: smooth transition between cells */
.hero-walker.walking {
    transition-property: left, top;
    transition-timing-function: ease-in-out;
}

/* Leg animation when walking */
.hero-walker.walking .hero-leg-left {
    animation: heroLegLeft 0.25s ease-in-out infinite;
}

.hero-walker.walking .hero-leg-right {
    animation: heroLegRight 0.25s ease-in-out infinite;
}

.hero-walker.walking .hero-boot-left {
    animation: heroBootLeft 0.25s ease-in-out infinite;
}

.hero-walker.walking .hero-boot-right {
    animation: heroBootRight 0.25s ease-in-out infinite;
}

.hero-walker svg {
    width: 100%;
    height: 100%;
}

@keyframes heroIdle {
    0% { transform: translate(-50%, -55%); }
    100% { transform: translate(-50%, -60%); }
}

/* Walking leg cycle animation */
@keyframes heroLegLeft {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-2px); }
}

@keyframes heroLegRight {
    0%, 100% { transform: translateY(-2px); }
    50% { transform: translateY(0); }
}

@keyframes heroBootLeft {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-2px); }
}

@keyframes heroBootRight {
    0%, 100% { transform: translateY(-2px); }
    50% { transform: translateY(0); }
}

/* Hero Falling Animation */
.hero-walker.falling {
    animation: heroFall 0.8s ease-in forwards;
}

@keyframes heroFall {
    0% { transform: scale(1) rotate(0deg); opacity: 1; }
    15% { transform: translateY(-25px) scale(1.2) rotate(-5deg); opacity: 1; }
    100% { transform: translateY(200px) scale(0.3) rotate(360deg); opacity: 0; }
}

/* Instructions & SEO Content */
.instructions, .game-content {
    background: var(--bg-secondary);
    padding: 20px;
    border-radius: 12px;
    border: 1px solid rgba(168, 85, 247, 0.2);
    color: var(--text-secondary);
    line-height: 1.6;
}

.instructions h3, .game-content h2 {
    color: var(--accent-gold);
    margin-bottom: 10px;
    font-family: 'Jua', sans-serif;
}

.game-content .tip-box {
    background: rgba(0,0,0,0.3);
    padding: 15px;
    border-radius: 8px;
    margin-top: 10px;
    border-left: 3px solid var(--accent-purple);
}

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

footer a {
    color: var(--text-secondary);
    text-decoration: none;
}

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

/* Mobile */
@media (max-width: 600px) {
    html, body {
        overflow-x: hidden;
        overflow-y: auto;
    }

    .container {
        padding: 4px;
        padding-bottom: 70px;
        max-width: 100vw;
    }

    header {
        margin-bottom: 4px;
    }

    h1 {
        font-size: 1.4rem;
    }

    .subtitle {
        display: none;
    }

    .game-wrapper {
        padding: 4px;
        gap: 0;
        flex-direction: column;
        width: 100%;
    }

    .main-area {
        width: 100%;
    }

    .header-status {
        padding: 4px 6px;
        margin-bottom: 4px;
    }

    .top-status {
        margin-bottom: 2px;
        flex-wrap: wrap;
        gap: 4px;
    }

    .status-item {
        min-width: 40px;
    }

    .status-item span:first-child {
        font-size: 0.6rem;
    }

    .status-item span:last-child {
        font-size: 0.8rem;
    }

    .pixel-hero-small, .pixel-boss-small {
        width: 18px;
        height: 18px;
    }

    .board {
        width: calc(100vw - 16px);
        max-width: calc(100vw - 16px);
        padding: 2px;
        gap: 1px;
    }

    .cell {
        width: auto;
        height: auto;
        aspect-ratio: 1;
        border-radius: 0;
    }

    .hero-walker {
        width: 20px;
        height: 26px;
    }

    .hero-walker.walking .hero-leg-left,
    .hero-walker.walking .hero-leg-right,
    .hero-walker.walking .hero-boot-left,
    .hero-walker.walking .hero-boot-right {
        animation-duration: 0.2s;
    }

    .sidebar {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        background: rgba(22, 33, 62, 0.98);
        backdrop-filter: blur(10px);
        padding: 6px 12px;
        padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px));
        border-radius: 0;
        border-top: 2px solid rgba(168, 85, 247, 0.4);
        z-index: 9999;
    }

    .sidebar h3 {
        display: none;
    }

    .preview-list {
        flex-direction: row;
        justify-content: center;
        gap: 4vw;
    }

    .preview-box {
        width: 9vw;
        height: 9vw;
        max-width: 40px;
        max-height: 40px;
    }

    .instructions {
        display: none;
    }

    .btn {
        padding: 5px 10px;
        font-size: 0.7rem;
    }
}

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

body.fullscreen-active .game-wrapper {
    width: 100%;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

body.fullscreen-active .main-area {
    width: min(calc(100vw - 40px), calc(100vh - 200px));
    display: flex;
    flex-direction: column;
    align-items: center;
}

body.fullscreen-active .board {
    width: min(calc(100vw - 40px), calc(100vh - 200px));
    max-width: min(calc(100vw - 40px), calc(100vh - 200px));
    margin: 0 auto;
}

body.fullscreen-active .cell {
    width: auto;
    height: auto;
    aspect-ratio: 1;
}

/* === Fullscreen: Bottom-left - Status panel === */
body.fullscreen-active .header-status {
    display: block;
    position: fixed !important;
    bottom: 0;
    left: 0;
    width: 50%;
    z-index: 9999;
    background: rgba(15, 23, 42, 0.98);
    backdrop-filter: blur(10px);
    border-top: 2px solid rgba(168, 85, 247, 0.4);
    border-radius: 0;
    margin-bottom: 0;
    padding: 10px 20px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    border-right: 1px solid rgba(168, 85, 247, 0.2);
}

body.fullscreen-active .top-status {
    flex-wrap: nowrap;
    gap: 12px;
    margin-bottom: 6px;
    justify-content: space-around;
}

body.fullscreen-active .status-item {
    min-width: auto;
}

body.fullscreen-active .status-item span:first-child {
    font-size: 0.9rem;
}

body.fullscreen-active .status-item span:last-child {
    font-size: 1.4rem;
}

body.fullscreen-active .info-panel {
    height: auto;
    font-size: 1.1rem;
}

/* === Fullscreen: Bottom-right - NEXT pieces === */
body.fullscreen-active .sidebar {
    position: fixed !important;
    bottom: 0 !important;
    left: 50% !important;
    right: 0 !important;
    top: auto !important;
    background: rgba(15, 23, 42, 0.98);
    backdrop-filter: blur(10px);
    padding: 8px 12px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    min-width: auto;
    width: auto;
    border-radius: 0;
    border-top: 2px solid rgba(6, 182, 212, 0.4);
    z-index: 9999;
}

body.fullscreen-active .sidebar h3 {
    display: inline-block;
    font-size: 0.85rem;
    margin-bottom: 0;
    margin-right: 10px;
    border-bottom: none;
    padding-bottom: 0;
    vertical-align: middle;
}

body.fullscreen-active .preview-list {
    display: inline-flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    gap: 10px;
    vertical-align: middle;
}

body.fullscreen-active .preview-item {
    flex-direction: row;
    align-items: center;
    gap: 6px;
}

body.fullscreen-active .preview-box {
    width: 40px;
    height: 40px;
    border-radius: 4px;
}

/* === Fullscreen: Prevent content overlap === */
body.fullscreen-active .container {
    padding-bottom: 100px !important;
}

/* === Mobile Fullscreen: 일반 모바일과 유사한 UI 유지 === */
@media (max-width: 600px) {
    /* 컨테이너: 중앙보다 약간 아래 배치 (한손 터치 용이) */
    body.fullscreen-active .container {
        justify-content: center !important;
        padding-top: 8vh !important;
        padding-bottom: 60px !important;
    }

    /* game-area, game-wrapper: flex 확장 해제 */
    body.fullscreen-active .game-area {
        flex: none;
    }

    body.fullscreen-active .game-wrapper {
        flex: none;
        justify-content: flex-start;
    }

    /* header-status: 보드 위 인라인 (!important로 데스크톱 fixed 오버라이드) */
    body.fullscreen-active .header-status {
        position: static !important;
        width: 100% !important;
        bottom: auto !important;
        left: auto !important;
        z-index: auto !important;
        background: transparent !important;
        backdrop-filter: none !important;
        border-top: none;
        border-right: none;
        border-radius: 8px;
        margin-bottom: 4px;
        padding: 4px 6px;
    }

    body.fullscreen-active .top-status {
        flex-wrap: wrap;
        gap: 4px;
        margin-bottom: 2px;
    }

    body.fullscreen-active .status-item {
        min-width: 40px;
    }

    body.fullscreen-active .status-item span:first-child {
        font-size: 0.6rem;
    }

    body.fullscreen-active .status-item span:last-child {
        font-size: 0.8rem;
    }

    body.fullscreen-active .info-panel {
        height: auto;
        font-size: 0.9rem;
    }

    /* sidebar(NEXT): 하단 풀와이드 인라인 */
    body.fullscreen-active .sidebar {
        position: static !important;
        left: auto !important;
        right: auto !important;
        bottom: auto !important;
        top: auto !important;
        width: 100% !important;
        background: transparent !important;
        backdrop-filter: none !important;
        z-index: auto !important;
        border-radius: 0;
        border-top: 1px solid rgba(168, 85, 247, 0.3);
        padding: 6px 12px;
        margin-top: 4px;
    }

    body.fullscreen-active .sidebar h3 {
        display: none;
    }

    body.fullscreen-active .preview-list {
        flex-direction: row;
        justify-content: center;
        gap: 4vw;
    }

    body.fullscreen-active .preview-box {
        width: 9vw;
        height: 9vw;
        max-width: 40px;
        max-height: 40px;
    }

    /* 보드 크기: status/sidebar 인라인 높이 반영 */
    body.fullscreen-active .main-area {
        width: min(calc(100vw - 16px), calc(100dvh - 120px));
    }

    body.fullscreen-active .board {
        width: min(calc(100vw - 16px), calc(100dvh - 120px));
        max-width: min(calc(100vw - 16px), calc(100dvh - 120px));
    }
}
