:root {
    --bg-primary: #0a0a1a;
    --bg-secondary: #12122a;
    --accent-gold: #ffd700;
    --accent-cyan: #06b6d4;
    --accent-orange: #ff8c00;
    --text-primary: #ffffff;
    --text-secondary: rgba(255,255,255,0.7);
    
    --board-bg: #1e293b;
    --cell-bg: #334155;
    --pipe-color: #94a3b8;
    --water-color: #0ea5e9;
    --sidebar-bg: #0f172a;
}

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

body {
    min-height: 100vh;
    background: var(--bg-primary);
    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;
    gap: 5px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    transition: color 0.3s;
}

.back-btn:hover {
    color: var(--accent-cyan);
}

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

h1 {
    font-family: 'Black Han Sans', sans-serif;
    font-size: 2.5rem;
    color: var(--accent-cyan);
    text-shadow: 0 0 20px rgba(6, 182, 212, 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: 1px solid rgba(255,255,255,0.1);
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}

@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.2);
    padding: 10px 15px;
    border-radius: 8px;
}

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

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

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

.btn-level-select {
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 4px;
    color: var(--accent-cyan);
    padding: 2px 8px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: background 0.2s;
}

.btn-level-select:hover {
    background: rgba(255,255,255,0.2);
}

/* 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: 1px solid rgba(255,255,255,0.1);
}

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

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

.tab {
    flex: 1;
    padding: 10px 5px;
    background: rgba(255,255,255,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;
}

.tab:hover {
    background: rgba(255,255,255,0.15);
}

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

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

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

.level-btn:hover {
    background: rgba(6, 182, 212, 0.3);
    border-color: var(--accent-cyan);
}

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

.level-btn.current {
    background: rgba(6, 182, 212, 0.3);
    border-color: var(--accent-cyan);
}

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

.btn-close:hover {
    background: rgba(255,255,255,0.2);
}

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

.celebration-content p {
    color: var(--text-secondary);
    margin-bottom: 10px;
}

.celebration-content .infinite-msg {
    color: var(--accent-cyan);
    font-size: 0.9rem;
}

.celebration-content .btn-next {
    margin-top: 20px;
}

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

/* 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, #1dd1a1, #10ac84); color: white; }
.btn-retry { background: linear-gradient(45deg, #54a0ff, #2e86de); color: white; }
.btn-fast { background: linear-gradient(45deg, #ffd700, #ff8c00); color: #1a1a2e; font-weight: bold; }

/* 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-cyan);
    margin-bottom: 15px;
}

.resume-content .saved-info {
    color: var(--text-secondary);
    margin-bottom: 20px;
    font-size: 1rem;
}

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

.resume-buttons .btn {
    min-width: 160px;
}

.btn-resume {
    background: linear-gradient(45deg, var(--accent-cyan), #0891b2);
    color: white;
}

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

.btn-new:hover {
    background: rgba(255,255,255,0.2);
}

/* Board */
.board {
    display: grid;
    gap: 2px;
    background-color: var(--board-bg);
    padding: 5px;
    border-radius: 8px;
    border: 2px solid #334155;
}

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

.cell:hover:not(.fixed):not(.blocked) {
    background-color: #475569;
}

.cell.fixed {
    cursor: default;
    background-color: #1e293b;
    border: 1px solid #334155;
}

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

.cell.blocked::after {
    content: '🚧';
    font-size: 1.5rem;
    opacity: 0.5;
}

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

/* 연결된 타일 하이라이트 */
.cell.connected {
    background-color: #3d5a6a !important;
    box-shadow: inset 0 0 15px rgba(6, 182, 212, 0.4);
}

/* 경로 끝 (END 미도달 시 마지막 연결 위치) */
.cell.path-end {
    background-color: #5a3d3d !important;
    box-shadow: inset 0 0 15px rgba(239, 68, 68, 0.6), 0 0 10px rgba(239, 68, 68, 0.4);
    animation: pathEndPulse 1s ease-in-out infinite;
}

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

.cell.connected.fixed {
    background-color: #2a4a5a !important;
}

/* 워프 포탈 스타일 */
.cell.warp-portal {
    position: relative;
}

.cell.warp-top {
    border-top: 2px solid #a855f7 !important;
}

.cell.warp-bottom {
    border-bottom: 2px solid #a855f7 !important;
}

.warp-indicator {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 0.6rem;
    color: #a855f7;
    pointer-events: none;
    z-index: 10;
}

.warp-top .warp-indicator {
    top: -2px;
    left: 50%;
    transform: translateX(-50%);
}

.warp-bottom .warp-indicator {
    bottom: -2px;
    left: 50%;
    transform: translateX(-50%);
}

.warp-arrow {
    font-size: 0.8rem;
    line-height: 1;
    animation: warpPulse 1.5s ease-in-out infinite;
}

.warp-target {
    font-family: 'Black Han Sans', sans-serif;
    font-size: 0.55rem;
    background: rgba(168, 85, 247, 0.8);
    color: white;
    padding: 1px 4px;
    border-radius: 3px;
    line-height: 1;
}

@keyframes warpPulse {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

/* 연결된 워프 포탈 */
.cell.warp-portal.connected {
    box-shadow: inset 0 0 15px rgba(168, 85, 247, 0.5);
}

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

.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(255,255,255,0.1);
}

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

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

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

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

.game-content .tip-box {
    background: rgba(0,0,0,0.2);
    padding: 15px;
    border-radius: 8px;
    margin-top: 10px;
}

.game-content p {
    margin-bottom: 10px;
}

/* 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: white;
}

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

/* 폭죽 이펙트 (퍼펙트 클리어) */
.fireworks-container {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 3rem;
    animation: fireworksBurst 2s ease-out forwards;
    pointer-events: none;
    z-index: 1000;
    text-shadow: 0 0 20px rgba(255, 215, 0, 0.8);
}

@keyframes fireworksBurst {
    0% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(0.5);
        letter-spacing: 0;
    }
    50% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1.5);
        letter-spacing: 20px;
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(2);
        letter-spacing: 40px;
    }
}

/* 파괴 이펙트 (파이프 교체 시) */
.cell.destroying {
    animation: destroyPipe 0.5s ease-out;
}

.cell.destroying .pipe-svg {
    animation: destroyPipeSVG 0.5s ease-out;
}

@keyframes destroyPipe {
    0% {
        background-color: var(--cell-bg);
    }
    50% {
        background-color: rgba(239, 68, 68, 0.5);
        box-shadow: 0 0 15px rgba(239, 68, 68, 0.6);
    }
    100% {
        background-color: var(--cell-bg);
    }
}

@keyframes destroyPipeSVG {
    0% {
        transform: scale(1) rotate(0deg);
        opacity: 1;
    }
    50% {
        transform: scale(1.2) rotate(15deg);
        opacity: 0.5;
    }
    100% {
        transform: scale(0) rotate(30deg);
        opacity: 0;
    }
}