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

:root {
    --bg-primary: #0a0a1a;
    --bg-secondary: #12122a;
    --accent-gold: #ffd700;
    --accent-blue: #4169e1;
    --accent-purple: #9333ea;
    --text-primary: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.7);

    /* Sudoku specific colors */
    --cell-bg: #ffffff;
    --cell-initial: #1a1a2e;
    --cell-user: #4169e1;
    --cell-selected: rgba(173, 216, 255, 0.7);
    --cell-related: rgba(173, 216, 255, 0.45);
    --cell-same-num: rgba(255, 223, 128, 0.5);
    --grid-line: #4a5568;
    --grid-thick: #1a1a2e;
    --cell-wrong: #ff4444;
}

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

/* Background Effects */
.bg-effects {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: -1;
    overflow: hidden;
}

.bg-orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.4;
}

.bg-orb:nth-child(1) {
    width: 300px;
    height: 300px;
    background: var(--accent-purple);
    top: -100px;
    right: -100px;
    animation: float 8s ease-in-out infinite;
}

.bg-orb:nth-child(2) {
    width: 250px;
    height: 250px;
    background: var(--accent-blue);
    bottom: -50px;
    left: -50px;
    animation: float 10s ease-in-out infinite reverse;
}

@keyframes float {
    0%, 100% { transform: translate(0, 0); }
    50% { transform: translate(30px, -30px); }
}

/* Container */
.container {
    max-width: 500px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
}

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

.header-top {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    margin-bottom: 8px;
}

.back-btn {
    position: absolute;
    left: 20px;
    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:active {
    background: rgba(255, 255, 255, 0.15);
}

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

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

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

/* Game Status */
.game-status {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    margin-bottom: 15px;
}

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

.level-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.difficulty-badge {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: bold;
    text-transform: uppercase;
}

.difficulty-badge.easy {
    background: linear-gradient(135deg, #22c55e, #16a34a);
    color: white;
}

.difficulty-badge.normal {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: white;
}

.difficulty-badge.hard {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: white;
}

.level-text {
    font-family: 'Black Han Sans', sans-serif;
    font-size: 1.1rem;
    color: var(--accent-gold);
}

.lives {
    display: flex;
    gap: 4px;
}

.heart {
    font-size: 1.4rem;
    color: #ff4444;
    transition: all 0.3s;
}

.heart:not(.active) {
    color: #333;
    opacity: 0.3;
}

.heart.breaking {
    animation: heartBreak 0.5s forwards;
}

@keyframes heartBreak {
    0% { transform: scale(1); }
    30% { transform: scale(1.4); color: #ff0000; }
    100% { transform: scale(0.8); opacity: 0.3; color: #333; }
}

/* Game Container */
.game-container {
    display: flex;
    justify-content: center;
    margin-bottom: 15px;
}

/* Sudoku Board */
.sudoku-board {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    gap: 1px;
    background: var(--grid-line);
    border: 3px solid var(--grid-thick);
    border-radius: 8px;
    width: calc(100% - 4px);
    max-width: 360px;
    aspect-ratio: 1;
    margin: 0 auto;
}

.sudoku-cell {
    background: var(--cell-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    aspect-ratio: 1;
    cursor: pointer;
    position: relative;
    transition: background 0.15s;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

/* 3x3 box borders - box-shadow로 레이아웃에 영향 없이 구분선 표시 */
.sudoku-cell.box-right {
    box-shadow: inset -2px 0 0 var(--grid-thick);
}

.sudoku-cell.box-bottom {
    box-shadow: inset 0 -2px 0 var(--grid-thick);
}

.sudoku-cell.box-right.box-bottom {
    box-shadow: inset -2px -2px 0 var(--grid-thick);
}

/* Cell states */
.sudoku-cell.selected {
    background: var(--cell-selected) !important;
}

.sudoku-cell.related {
    background: var(--cell-related);
}

.sudoku-cell.same-number {
    background: var(--cell-same-num);
}

.sudoku-cell.wrong {
    animation: wrongShake 0.4s;
}

@keyframes wrongShake {
    0%, 100% { transform: translateX(0); background: var(--cell-bg); }
    20% { transform: translateX(-4px); background: rgba(255, 68, 68, 0.3); }
    40% { transform: translateX(4px); background: rgba(255, 68, 68, 0.3); }
    60% { transform: translateX(-4px); background: rgba(255, 68, 68, 0.3); }
    80% { transform: translateX(4px); background: rgba(255, 68, 68, 0.3); }
}

/* Cell number */
.cell-number {
    font-family: 'Black Han Sans', sans-serif;
    font-size: clamp(1.2rem, 5vw, 1.6rem);
    line-height: 1;
}

.sudoku-cell.initial .cell-number {
    color: var(--cell-initial);
}

.sudoku-cell.user-input .cell-number {
    color: var(--cell-user);
}

/* Memo grid */
.memo-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    width: 100%;
    height: 100%;
    padding: 1px;
}

.memo-num {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(0.45rem, 1.8vw, 0.6rem);
    color: transparent;
    font-weight: 600;
}

.memo-num.active {
    color: var(--accent-blue);
}

/* Controls */
.controls {
    margin-bottom: 15px;
}

.number-pad {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    gap: 5px;
    max-width: 360px;
    margin: 0 auto 12px;
}

.num-btn {
    aspect-ratio: 1;
    font-family: 'Black Han Sans', sans-serif;
    font-size: clamp(1rem, 4vw, 1.3rem);
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    color: white;
    cursor: pointer;
    transition: all 0.2s;
}

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

.num-btn:active {
    transform: scale(0.92);
}

.num-btn.completed {
    opacity: 0.25;
    pointer-events: none;
}

.num-btn.disabled {
    background: rgba(100, 100, 100, 0.2);
    border-color: rgba(100, 100, 100, 0.3);
    color: #666;
    cursor: not-allowed;
    pointer-events: none;
}

.action-buttons {
    display: flex;
    justify-content: center;
    gap: 12px;
}

.action-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 25px;
    color: white;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
}

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

.action-btn.active {
    background: var(--accent-blue);
    border-color: var(--accent-blue);
}

.btn-icon {
    font-weight: bold;
}

/* Game Menu */
.game-menu {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 25px;
}

.menu-btn {
    padding: 10px 20px;
    background: rgba(255, 215, 0, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 25px;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s;
}

.menu-btn:hover {
    border-color: var(--accent-gold);
    color: var(--accent-gold);
}

/* Overlays */
.overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 20px;
}

.overlay.show {
    display: flex;
}

.overlay-content {
    background: linear-gradient(135deg, #1a1a2e, #16162a);
    border-radius: 20px;
    padding: 30px;
    text-align: center;
    max-width: 400px;
    width: 100%;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

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

/* Start Overlay */
.start-content .start-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.start-btn {
    padding: 15px 30px;
    font-size: 1.1rem;
    font-family: 'Jua', sans-serif;
    border: none;
    border-radius: 30px;
    cursor: pointer;
    transition: all 0.3s;
}

.start-btn.continue {
    background: linear-gradient(135deg, var(--accent-gold), #ffaa00);
    color: #1a1a2e;
}

.start-btn.new-game {
    background: linear-gradient(135deg, var(--accent-blue), #3b5998);
    color: white;
}

.start-btn:hover {
    transform: scale(1.03);
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.3);
}

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

.tab {
    flex: 1;
    padding: 10px;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid transparent;
    border-radius: 10px;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: bold;
    transition: all 0.2s;
}

.tab small {
    font-weight: normal;
    opacity: 0.7;
}

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

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

.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: 1.1rem;
    cursor: pointer;
    transition: all 0.2s;
}

.level-btn:hover {
    background: rgba(255, 215, 0, 0.3);
    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.3);
    border-color: var(--accent-gold);
}

.close-overlay-btn,
.home-btn {
    display: inline-block;
    padding: 12px 30px;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 25px;
    color: white;
    cursor: pointer;
    font-size: 0.9rem;
    text-decoration: none;
    transition: all 0.2s;
}

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

/* Complete Overlay */
.complete-content h2 {
    font-size: 2rem;
    animation: celebratePulse 0.5s ease-in-out;
}

@keyframes celebratePulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

.complete-level {
    font-size: 1.3rem;
    color: var(--text-secondary);
    margin-bottom: 25px;
}

.complete-buttons, .gameover-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.primary-btn {
    padding: 15px 30px;
    background: linear-gradient(135deg, var(--accent-gold), #ffaa00);
    border: none;
    border-radius: 30px;
    color: #1a1a2e;
    font-family: 'Jua', sans-serif;
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.2s;
}

.primary-btn:hover {
    transform: scale(1.03);
}

.secondary-btn {
    padding: 12px 25px;
    background: rgba(255, 215, 0, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 25px;
    color: var(--text-secondary);
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s;
}

.secondary-btn:hover {
    border-color: white;
    color: white;
}

/* Game Over */
.gameover-content h2 {
    color: #ff4444;
}

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

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

/* Game Content */
.game-content {
    background: rgba(255, 255, 255, 0.03);
    border-radius: 15px;
    padding: 25px;
    margin-bottom: 20px;
}

.game-content h2 {
    font-family: 'Jua', sans-serif;
    font-size: 1.2rem;
    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, 215, 0, 0.1);
    border-left: 3px solid var(--accent-gold);
    padding: 15px;
    border-radius: 0 10px 10px 0;
}

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

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

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

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

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

/* Mobile - 컨트롤 하단 고정 */
@media (max-width: 600px) {
    .controls {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: rgba(10, 10, 26, 0.95);
        backdrop-filter: blur(10px);
        padding: 12px 16px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
        margin-bottom: 0;
        z-index: 50;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
    }

    .game-container {
        padding-bottom: 140px;
    }

    .game-content {
        margin-bottom: calc(140px + env(safe-area-inset-bottom));
    }

    .number-pad {
        margin-bottom: 10px;
    }
}

/* Responsive - 420px 이하 */
@media (max-width: 420px) {
    .container {
        padding: 12px;
    }

    .sudoku-board {
        width: calc(100% - 8px);
        max-width: none;
    }

    .number-pad {
        width: calc(100% - 8px);
        max-width: none;
        gap: 4px;
    }

    .num-btn {
        font-size: 1.1rem;
        min-height: 38px;
    }

    .game-status {
        padding: 10px 12px;
    }

    .action-btn {
        padding: 10px 16px;
        font-size: 0.85rem;
        min-height: 44px;
    }
}

/* Responsive - 340px 이하 (초소형 폰) */
@media (max-width: 340px) {
    .container {
        padding: 10px;
    }

    .sudoku-board {
        width: calc(100% - 4px);
    }

    .number-pad {
        width: calc(100% - 4px);
        gap: 3px;
    }

    .num-btn {
        font-size: 1rem;
    }

    .game-status {
        padding: 8px 10px;
        font-size: 0.85rem;
    }

    .action-btn {
        padding: 6px 12px;
        font-size: 0.75rem;
    }
}
