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

body {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    background: linear-gradient(135deg, #0f0c29 0%, #302b63 50%, #24243e 100%);
    font-family: 'Arial', sans-serif;
    padding: 20px;
    position: relative;
    overflow-y: auto;
    overflow-x: hidden;
}

body::before {
    content: '';
    position: fixed;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(102, 126, 234, 0.1) 0%, transparent 70%);
    animation: moveBackground 15s ease-in-out infinite;
    pointer-events: none;
    z-index: -1;
}

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

/* 닉네임 모달 스타일 */
.nickname-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    backdrop-filter: blur(5px);
}

.nickname-modal {
    background: linear-gradient(135deg, rgba(15, 12, 41, 0.98) 0%, rgba(48, 43, 99, 0.98) 100%);
    padding: 50px;
    border-radius: 20px;
    border: 2px solid rgba(102, 126, 234, 0.8);
    box-shadow: 0 0 30px rgba(102, 126, 234, 0.8), 0 0 60px rgba(118, 75, 162, 0.6);
    text-align: center;
    max-width: 500px;
    width: 90%;
}

.nickname-modal h2 {
    color: #4ade80;
    font-size: 28px;
    margin-bottom: 20px;
    text-shadow: 0 0 10px rgba(74, 222, 128, 0.8);
}

.nickname-modal p {
    color: #64b5f6;
    font-size: 16px;
    margin-bottom: 10px;
    text-shadow: 0 0 5px rgba(100, 181, 246, 0.5);
}

#guestGreeting {
    font-size: 18px;
    font-weight: bold;
    margin-bottom: 5px;
}

.nickname-subtitle {
    font-size: 14px;
    color: #a0d8ff;
    margin-bottom: 30px;
}

.nickname-form {
    display: flex;
    gap: 10px;
    margin-bottom: 30px;
}

#nicknameInput {
    flex: 1;
    padding: 12px;
    border: 2px solid rgba(102, 126, 234, 0.5);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    font-size: 16px;
    transition: all 0.3s;
}

#nicknameInput:focus {
    outline: none;
    border-color: rgba(102, 126, 234, 0.8);
    background: rgba(255, 255, 255, 0.15);
    box-shadow: 0 0 10px rgba(102, 126, 234, 0.5);
}

#nicknameInput::placeholder {
    color: rgba(255, 255, 255, 0.5);
}

.nickname-button {
    padding: 12px 30px;
    background: linear-gradient(135deg, #4ade80 0%, #22c55e 100%);
    border: 2px solid rgba(74, 222, 128, 0.8);
    color: white;
    border-radius: 8px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 0 10px rgba(74, 222, 128, 0.5);
}

.nickname-button:hover {
    box-shadow: 0 0 15px rgba(74, 222, 128, 0.8);
    transform: translateY(-2px);
}

.nickname-button:active {
    transform: translateY(0);
}

.nickname-note {
    font-size: 12px;
    color: #888;
}

.nickname-modal-overlay.hidden {
    display: none;
}

.main-container {
    display: grid;
    grid-template-columns: 1fr 400px;
    gap: 30px;
    width: 100%;
    max-width: 1600px;
    position: relative;
    z-index: 1;
}

.game-section {
    text-align: center;
    min-width: 0;
}

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

h1 {
    color: #fff;
    font-size: 40px;
    text-shadow: 
        0 0 10px rgba(102, 126, 234, 0.8),
        0 0 20px rgba(118, 75, 162, 0.6),
        0 0 30px rgba(255, 0, 136, 0.4),
        2px 2px 4px rgba(0, 0, 0, 0.5);
    letter-spacing: 2px;
    font-weight: bold;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.2) 0%, rgba(118, 75, 162, 0.2) 100%);
    padding: 10px 20px;
    border-radius: 10px;
    border: 2px solid rgba(102, 126, 234, 0.5);
}

#currentNickname {
    color: #4ade80;
    font-weight: bold;
    font-size: 16px;
    text-shadow: 0 0 5px rgba(74, 222, 128, 0.5);
}

.change-nickname-btn {
    background: rgba(102, 126, 234, 0.6);
    border: 1px solid rgba(102, 126, 234, 0.8);
    color: #a0d8ff;
    padding: 6px 12px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.3s;
}

.change-nickname-btn:hover {
    background: rgba(102, 126, 234, 0.8);
    color: white;
}

.ranking-section {
    min-width: 0;
}

h2 {
    color: #fff;
    margin-bottom: 20px;
    font-size: 28px;
    text-shadow: 
        0 0 10px rgba(102, 126, 234, 0.8),
        0 0 20px rgba(118, 75, 162, 0.6),
        2px 2px 4px rgba(0, 0, 0, 0.5);
    letter-spacing: 1px;
    font-weight: bold;
}

.game-info {
    display: flex;
    justify-content: space-around;
    margin-bottom: 20px;
    gap: 20px;
}

.score-board {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.2) 0%, rgba(118, 75, 162, 0.2) 100%);
    padding: 20px 40px;
    border-radius: 10px;
    border: 2px solid rgba(102, 126, 234, 0.5);
    box-shadow: 
        0 0 10px rgba(102, 126, 234, 0.5),
        0 0 20px rgba(118, 75, 162, 0.3),
        inset 0 0 10px rgba(255, 255, 255, 0.1);
    min-width: 200px;
    backdrop-filter: blur(10px);
}

.score-label {
    color: #64b5f6;
    font-size: 16px;
    font-weight: bold;
    margin-bottom: 5px;
    text-transform: uppercase;
    letter-spacing: 1px;
    text-shadow: 0 0 5px rgba(100, 181, 246, 0.8);
}

.score-value {
    color: #4ade80;
    font-size: 40px;
    font-weight: bold;
    text-shadow: 
        0 0 5px rgba(74, 222, 128, 0.8),
        0 0 10px rgba(74, 222, 128, 0.5);
}

.canvas-container {
    position: relative;
    display: inline-block;
    width: 100%;
    max-width: 850px;
    margin: 10px 0;
}

#gameCanvas {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    border: 4px solid rgba(102, 126, 234, 0.8);
    display: block;
    margin: 0 auto;
    width: 100%;
    height: auto;
    border-radius: 10px;
    box-shadow: 
        0 0 20px rgba(102, 126, 234, 0.8),
        0 0 40px rgba(118, 75, 162, 0.6),
        0 0 60px rgba(255, 0, 136, 0.4),
        0 0 80px rgba(0, 255, 255, 0.2),
        inset 0 0 20px rgba(255, 255, 255, 0.05);
    filter: drop-shadow(0 0 10px rgba(102, 126, 234, 0.5));
}

.canvas-container::before {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    background: linear-gradient(90deg, transparent, rgba(102, 126, 234, 0.3), transparent);
    border-radius: 10px;
    pointer-events: none;
    animation: neonGlow 2s ease-in-out infinite;
}

@keyframes neonGlow {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

.controls {
    color: #64b5f6;
    margin-top: 20px;
    font-size: 16px;
    text-shadow: 0 0 5px rgba(100, 181, 246, 0.8), 1px 1px 2px rgba(0, 0, 0, 0.5);
    letter-spacing: 0.5px;
}

.controls.hidden { display: none; }

.start-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    margin-top: 30px;
}

.start-section.hidden { display: none; }

.start-button {
    background: linear-gradient(135deg, #4ade80 0%, #22c55e 100%);
    border: 2px solid rgba(74, 222, 128, 0.8);
    color: white;
    font-size: 24px;
    font-weight: bold;
    padding: 20px 60px;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 0 20px rgba(74, 222, 128, 0.6), 0 0 40px rgba(74, 222, 128, 0.3);
    text-transform: uppercase;
    letter-spacing: 2px;
    animation: pulseButton 1.5s ease-in-out infinite;
}

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

.start-button:hover {
    background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
    box-shadow: 0 0 30px rgba(74, 222, 128, 0.8), 0 0 60px rgba(74, 222, 128, 0.4);
    transform: scale(1.08);
}

.start-button:active { transform: scale(0.98); }

.touch-controls {
    display: none;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
    margin-top: 30px;
    max-width: 300px;
    margin-left: auto;
    margin-right: auto;
}

.touch-controls.show {
    display: grid;
}

.direction-btn {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.8) 0%, rgba(118, 75, 162, 0.8) 100%);
    border: 2px solid rgba(102, 126, 234, 0.6);
    color: white;
    font-size: 28px;
    padding: 24px;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 0 10px rgba(102, 126, 234, 0.5), 0 0 20px rgba(118, 75, 162, 0.3), inset 0 0 5px rgba(255, 255, 255, 0.1);
    user-select: none;
    touch-action: manipulation;
}

.direction-btn:active {
    transform: scale(0.95);
    box-shadow: 0 0 15px rgba(102, 126, 234, 0.8), 0 0 30px rgba(118, 75, 162, 0.5), inset 0 0 10px rgba(255, 255, 255, 0.2);
}

.direction-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 0 15px rgba(102, 126, 234, 0.8), 0 0 30px rgba(118, 75, 162, 0.5), inset 0 0 10px rgba(255, 255, 255, 0.2);
}

.direction-btn.up { grid-column: 2; }
.direction-btn.left { grid-column: 1; grid-row: 2; }
.direction-btn.center { 
    grid-column: 2;
    grid-row: 2;
    background: linear-gradient(135deg, rgba(100, 100, 120, 0.5) 0%, rgba(80, 80, 100, 0.5) 100%);
    border-color: rgba(100, 100, 120, 0.4);
    cursor: not-allowed;
}
.direction-btn.right { grid-column: 3; grid-row: 2; }
.direction-btn.down { grid-column: 2; grid-row: 3; }

.ranking-board {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.15) 0%, rgba(118, 75, 162, 0.15) 100%);
    border: 2px solid rgba(102, 126, 234, 0.6);
    border-radius: 15px;
    padding: 20px;
    box-shadow: 
        0 0 20px rgba(102, 126, 234, 0.6),
        0 0 40px rgba(118, 75, 162, 0.3),
        inset 0 0 10px rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(10px);
    height: fit-content;
    max-height: 700px;
    overflow-y: auto;
    position: sticky;
    top: 20px;
}

.ranking-board::-webkit-scrollbar {
    width: 6px;
}

.ranking-board::-webkit-scrollbar-track {
    background: rgba(102, 126, 234, 0.1);
    border-radius: 10px;
}

.ranking-board::-webkit-scrollbar-thumb {
    background: rgba(102, 126, 234, 0.5);
    border-radius: 10px;
}

.ranking-board::-webkit-scrollbar-thumb:hover {
    background: rgba(102, 126, 234, 0.8);
}

.rank-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    margin-bottom: 10px;
    background: linear-gradient(90deg, rgba(102, 126, 234, 0.2) 0%, rgba(118, 75, 162, 0.1) 100%);
    border-left: 4px solid rgba(102, 126, 234, 0.6);
    border-radius: 8px;
    transition: all 0.3s;
}

.rank-item:hover {
    background: linear-gradient(90deg, rgba(102, 126, 234, 0.3) 0%, rgba(118, 75, 162, 0.2) 100%);
    transform: translateX(5px);
    box-shadow: 0 0 15px rgba(102, 126, 234, 0.4);
}

.rank-item.top-1 {
    background: linear-gradient(90deg, rgba(255, 215, 0, 0.2) 0%, rgba(255, 165, 0, 0.1) 100%);
    border-left-color: #ffd700;
}

.rank-item.top-2 {
    background: linear-gradient(90deg, rgba(192, 192, 192, 0.2) 0%, rgba(169, 169, 169, 0.1) 100%);
    border-left-color: #c0c0c0;
}

.rank-item.top-3 {
    background: linear-gradient(90deg, rgba(205, 127, 50, 0.2) 0%, rgba(184, 115, 51, 0.1) 100%);
    border-left-color: #cd7f32;
}

.rank-badge {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 35px;
    height: 35px;
    border-radius: 50%;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.6) 0%, rgba(118, 75, 162, 0.6) 100%);
    color: white;
    font-weight: bold;
    font-size: 16px;
    flex-shrink: 0;
    box-shadow: 0 0 10px rgba(102, 126, 234, 0.5);
}

.rank-item.top-1 .rank-badge {
    background: linear-gradient(135deg, #ffd700 0%, #ffa500 100%);
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.8);
}

.rank-item.top-2 .rank-badge {
    background: linear-gradient(135deg, #c0c0c0 0%, #a9a9a9 100%);
    box-shadow: 0 0 15px rgba(192, 192, 192, 0.6);
}

.rank-item.top-3 .rank-badge {
    background: linear-gradient(135deg, #cd7f32 0%, #b8733b 100%);
    box-shadow: 0 0 15px rgba(205, 127, 50, 0.6);
}

.rank-info {
    flex: 1;
    text-align: left;
    min-width: 0;
}

.rank-name {
    color: #4ade80;
    font-weight: bold;
    font-size: 14px;
    margin-bottom: 2px;
    text-shadow: 0 0 5px rgba(74, 222, 128, 0.5);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.rank-date {
    color: #64b5f6;
    font-size: 11px;
    text-shadow: 0 0 3px rgba(100, 181, 246, 0.5);
}

.rank-score {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 3px;
    flex-shrink: 0;
}

.rank-points {
    color: #ffd700;
    font-weight: bold;
    font-size: 16px;
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.6);
}

.rank-level {
    color: #64b5f6;
    font-size: 10px;
    text-transform: uppercase;
}

.ranking-stats {
    background: linear-gradient(135deg, rgba(74, 222, 128, 0.1) 0%, rgba(34, 197, 94, 0.05) 100%);
    border: 1px solid rgba(74, 222, 128, 0.3);
    border-radius: 10px;
    padding: 15px;
    margin-bottom: 20px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.stat-item {
    text-align: center;
}

.stat-label {
    color: #64b5f6;
    font-size: 11px;
    font-weight: bold;
    text-transform: uppercase;
    margin-bottom: 3px;
}

.stat-value {
    color: #4ade80;
    font-size: 18px;
    font-weight: bold;
    text-shadow: 0 0 5px rgba(74, 222, 128, 0.5);
}

.refresh-btn {
    width: 100%;
    padding: 10px;
    margin-top: 15px;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.8) 0%, rgba(118, 75, 162, 0.8) 100%);
    border: 2px solid rgba(102, 126, 234, 0.6);
    color: white;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
    font-size: 12px;
    text-transform: uppercase;
    transition: all 0.3s;
    box-shadow: 0 0 10px rgba(102, 126, 234, 0.5);
}

.refresh-btn:hover {
    background: linear-gradient(135deg, rgba(102, 126, 234, 1) 0%, rgba(118, 75, 162, 1) 100%);
    box-shadow: 0 0 15px rgba(102, 126, 234, 0.8);
    transform: translateY(-2px);
}

.refresh-btn:active {
    transform: translateY(0);
}

.empty-ranking {
    color: #64b5f6;
    text-align: center;
    padding: 30px 20px;
    font-size: 14px;
}

.loading-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(102, 126, 234, 0.3);
    border-top: 3px solid rgba(102, 126, 234, 0.8);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.game-over {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: linear-gradient(135deg, rgba(15, 12, 41, 0.95) 0%, rgba(48, 43, 99, 0.95) 100%);
    padding: 40px;
    border-radius: 15px;
    border: 2px solid rgba(102, 126, 234, 0.8);
    box-shadow: 0 0 30px rgba(102, 126, 234, 0.8), 0 0 60px rgba(118, 75, 162, 0.6), 0 0 90px rgba(255, 0, 136, 0.3);
    text-align: center;
    z-index: 1000;
    backdrop-filter: blur(10px);
    max-width: 400px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
}

.game-over.show {
    display: block;
    animation: popUp 0.3s ease-out;
}

@keyframes popUp {
    0% { transform: translate(-50%, -50%) scale(0.8); opacity: 0; }
    100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

.game-over h2 {
    color: #4ade80;
    margin-bottom: 20px;
    font-size: 28px;
    text-shadow: 0 0 10px rgba(74, 222, 128, 0.8), 0 0 20px rgba(74, 222, 128, 0.5);
}

.game-over p {
    color: #64b5f6;
    margin-bottom: 10px;
    font-size: 18px;
    text-shadow: 0 0 5px rgba(100, 181, 246, 0.5);
}

.final-nickname {
    color: #ffd700;
    font-size: 16px;
    font-weight: bold;
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
}

.status-message {
    margin-top: 10px;
    padding: 10px;
    border-radius: 5px;
    font-size: 12px;
    display: none;
    word-break: break-word;
}

.status-message.success {
    background: rgba(74, 222, 128, 0.2);
    color: #4ade80;
    border: 1px solid rgba(74, 222, 128, 0.5);
    display: block;
}

.status-message.error {
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.5);
    display: block;
}

.status-message.loading {
    background: rgba(100, 181, 246, 0.2);
    color: #64b5f6;
    border: 1px solid rgba(100, 181, 246, 0.5);
    display: block;
}

.button-group {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

.button-group button {
    flex: 1;
    padding: 12px;
    border: none;
    border-radius: 5px;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
}

.save-button {
    background: linear-gradient(135deg, #4ade80 0%, #22c55e 100%);
    color: white;
    box-shadow: 0 0 10px rgba(74, 222, 128, 0.5);
}

.save-button:hover {
    box-shadow: 0 0 15px rgba(74, 222, 128, 0.8);
    transform: translateY(-2px);
}

.save-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.skip-button {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.8) 0%, rgba(118, 75, 162, 0.8) 100%);
    color: white;
    box-shadow: 0 0 10px rgba(102, 126, 234, 0.5);
}

.skip-button:hover {
    box-shadow: 0 0 15px rgba(102, 126, 234, 0.8);
    transform: translateY(-2px);
}

.overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 999;
    backdrop-filter: blur(5px);
}

.overlay.show { display: block; }

@media (max-width: 1024px) {
    .main-container {
        grid-template-columns: 1fr;
        gap: 20px;
    }

    .ranking-board {
        position: static;
        max-height: 400px;
    }

    h1 { font-size: 32px; }
    h2 { font-size: 24px; }
}

@media (max-width: 600px) {
    body {
        padding: 10px;
    }

    .main-container {
        gap: 15px;
    }

    .game-section {
        display: flex;
        flex-direction: column;
        align-items: center;
    }

    .canvas-container {
        max-width: 100%;
    }

    #gameCanvas {
        width: 100% !important;
        height: auto !important;
    }

    h1 { 
        font-size: 24px;
        margin-bottom: 15px;
    }

    .user-info {
        flex-wrap: wrap;
        gap: 8px;
    }

    .score-board {
        padding: 12px 20px;
        min-width: 120px;
    }

    .score-value {
        font-size: 32px;
    }

    .start-button { 
        padding: 14px 40px; 
        font-size: 18px;
    }

    .touch-controls.show {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
        margin-top: 20px;
        max-width: 220px;
    }

    .direction-btn { 
        padding: 14px;
        font-size: 20px;
    }
}