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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.container {
    text-align: center;
    background: white;
    padding: 30px;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    max-width: 600px;
    width: 90%;
}

h1 {
    color: #333;
    margin-bottom: 20px;
    font-size: 2.5em;
}

@media (max-width: 768px) {
    h1 {
        font-size: 2em;
    }
}

.game-info {
    display: flex;
    justify-content: space-around;
    align-items: center;
    margin-bottom: 30px;
    font-size: 1.2em;
    font-weight: bold;
}

.level, .score, .timer, .combo {
    padding: 10px 20px;
    background: #f0f0f0;
    border-radius: 10px;
}

.level span, .score span {
    color: #667eea;
}

.timer span {
    color: #ff9800;
}

.combo {
    background: linear-gradient(135deg, #ff6b6b, #ff8e53);
    color: white;
    animation: combo-pulse 0.5s ease-in-out infinite alternate;
}

.combo span {
    color: white;
    font-weight: bold;
}

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

.chance-btn {
    padding: 10px 20px;
    font-size: 1em;
    background: #ffd700;
    color: #333;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s;
    font-weight: bold;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.chance-btn:hover:not(:disabled) {
    background: #ffed4e;
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2);
}

.chance-btn:active:not(:disabled) {
    transform: translateY(0);
}

.chance-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.timer-bar-container {
    width: 100%;
    height: 20px;
    background: #e0e0e0;
    border-radius: 10px;
    overflow: hidden;
    margin-bottom: 30px;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

.timer-bar {
    height: 100%;
    width: 100%;
    background: #4caf50;
    transition: background-color 0.3s ease;
    border-radius: 10px;
}

#game-board {
    display: grid;
    gap: 10px;
    margin: 0 auto;
    max-width: 500px;
    aspect-ratio: 1;
    margin-bottom: 20px;
}

.square {
    border-radius: 10px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.square:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2);
}

.square.hint {
    animation: pulse 0.5s ease-in-out 2;
    box-shadow: 0 0 20px 5px rgba(255, 215, 0, 0.8), 0 0 40px 10px rgba(255, 215, 0, 0.4);
}

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

.message {
    font-size: 1.5em;
    font-weight: bold;
    min-height: 40px;
    margin: 20px 0;
}

.message.success {
    color: #4caf50;
}

.message.fail {
    color: #f44336;
}

.message.warning {
    color: #ff9800;
}

.message.info {
    color: #2196f3;
}

.message.fever {
    color: #ff6b6b;
    font-size: 2em;
    animation: fever-shake 0.3s ease-in-out infinite;
}

@keyframes fever-shake {
    0%, 100% {
        transform: rotate(-2deg);
    }
    50% {
        transform: rotate(2deg);
    }
}

.fever-bar-container {
    width: 100%;
    height: 30px;
    background: linear-gradient(135deg, #ff6b6b, #ff8e53);
    border-radius: 10px;
    margin-bottom: 20px;
    position: relative;
    overflow: hidden;
    box-shadow: 0 4px 15px rgba(255, 107, 107, 0.5);
    animation: fever-glow 1s ease-in-out infinite alternate;
    opacity: 0;
    max-height: 0;
    transition: opacity 0.3s ease, max-height 0.3s ease, margin 0.3s ease;
}

.fever-bar-container[style*="display: block"] {
    opacity: 1;
    max-height: 30px;
}

@keyframes fever-glow {
    0% {
        box-shadow: 0 4px 15px rgba(255, 107, 107, 0.5);
    }
    100% {
        box-shadow: 0 4px 25px rgba(255, 107, 107, 0.8);
    }
}

.fever-bar {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, #ffd700, #ff8e53, #ffd700);
    background-size: 200% 100%;
    animation: fever-slide 2s linear infinite;
}

@keyframes fever-slide {
    0% {
        background-position: 0% 50%;
    }
    100% {
        background-position: 200% 50%;
    }
}

.fever-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-weight: bold;
    font-size: 1.2em;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
    z-index: 1;
}


#restart-btn {
    padding: 15px 40px;
    font-size: 1.1em;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    transition: background 0.3s, transform 0.2s;
    font-weight: bold;
}

#restart-btn:hover {
    background: #5568d3;
    transform: translateY(-2px);
}

#restart-btn:active {
    transform: translateY(0);
}

#start-screen {
    text-align: center;
    padding: 50px 20px;
}

#start-screen h1 {
    font-size: 3em;
    margin-bottom: 20px;
}

.description {
    font-size: 1.3em;
    color: #666;
    margin-bottom: 30px;
}

.ranking-preview {
    background: linear-gradient(135deg, #667eea20, #764ba220);
    border-radius: 15px;
    padding: 20px;
    margin-bottom: 30px;
}

.ranking-preview h3 {
    font-size: 1.5em;
    color: #667eea;
    margin-bottom: 15px;
}

.preview-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.preview-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: white;
    padding: 12px 20px;
    border-radius: 10px;
    transition: transform 0.2s;
}

.preview-item:hover {
    transform: translateX(5px);
}

.preview-medal {
    font-size: 1.5em;
    min-width: 40px;
}

.preview-name {
    flex: 1;
    font-size: 1.1em;
    font-weight: bold;
    color: #333;
    text-align: left;
    margin-left: 10px;
}

.preview-score {
    font-size: 1.1em;
    font-weight: bold;
    color: #667eea;
}

.loading, .no-ranking-preview {
    padding: 20px;
    text-align: center;
    color: #999;
    font-size: 1em;
}

#start-btn {
    padding: 20px 60px;
    font-size: 1.5em;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    transition: background 0.3s, transform 0.2s;
    font-weight: bold;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

#start-btn:hover {
    background: #5568d3;
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.5);
}

#start-btn:active {
    transform: translateY(0);
}

#gameover-screen {
    text-align: center;
    padding: 50px 20px;
}

#gameover-screen h1 {
    font-size: 3em;
    margin-bottom: 40px;
    color: #f44336;
}

.result-box {
    background: #f5f5f5;
    border-radius: 20px;
    padding: 40px;
    margin-bottom: 40px;
    display: flex;
    justify-content: space-around;
    gap: 40px;
}

.result-item {
    flex: 1;
}

.result-label {
    font-size: 1.2em;
    color: #666;
    margin-bottom: 15px;
    font-weight: bold;
}

.result-value {
    font-size: 3em;
    color: #667eea;
    font-weight: bold;
}

@media (max-width: 768px) {
    .container {
        padding: 20px;
        width: 95%;
    }

    .game-info {
        flex-direction: column;
        gap: 10px;
        font-size: 1em;
    }

    .level, .score {
        padding: 8px 16px;
    }

    .chance-btn {
        padding: 8px 16px;
        font-size: 0.9em;
        width: 100%;
    }

    #game-board {
        max-width: 100%;
        gap: 8px;
    }

    .message {
        font-size: 1.2em;
    }

    #start-screen h1, #gameover-screen h1 {
        font-size: 2em;
    }

    #start-screen, #gameover-screen {
        padding: 30px 10px;
    }

    .description {
        font-size: 1.1em;
    }

    .ranking-preview {
        padding: 15px;
    }

    .ranking-preview h3 {
        font-size: 1.3em;
    }

    .preview-item {
        padding: 10px 15px;
    }

    .preview-medal {
        font-size: 1.3em;
        min-width: 35px;
    }

    .preview-name {
        font-size: 1em;
    }

    .preview-score {
        font-size: 1em;
    }

    #start-btn {
        padding: 15px 40px;
        font-size: 1.2em;
    }

    .result-box {
        flex-direction: column;
        gap: 20px;
        padding: 30px 20px;
    }

    .result-value {
        font-size: 2.5em;
    }

    .result-label {
        font-size: 1em;
    }

    #restart-btn {
        padding: 12px 30px;
        font-size: 1em;
    }
}

/* 랭킹 관련 스타일 */
.nickname-input-box {
    margin: 30px 0;
    display: flex;
    gap: 10px;
    justify-content: center;
    align-items: center;
}

#nickname-input {
    padding: 12px 20px;
    font-size: 1.1em;
    border: 2px solid #667eea;
    border-radius: 10px;
    outline: none;
    transition: border-color 0.3s;
    flex: 1;
    max-width: 200px;
}

#nickname-input:focus {
    border-color: #5568d3;
}

#submit-score-btn {
    padding: 12px 30px;
    font-size: 1.1em;
    background: #4caf50;
    color: white;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.3s, transform 0.2s;
    font-weight: bold;
}

#submit-score-btn:hover {
    background: #45a049;
    transform: translateY(-2px);
}

#submit-score-btn:active {
    transform: translateY(0);
}

.button-group {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-top: 20px;
}

#view-ranking-btn {
    padding: 15px 40px;
    font-size: 1.1em;
    background: #ff9800;
    color: white;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    transition: background 0.3s, transform 0.2s;
    font-weight: bold;
}

#view-ranking-btn:hover {
    background: #f57c00;
    transform: translateY(-2px);
}

#view-ranking-btn:active {
    transform: translateY(0);
}

#ranking-screen {
    text-align: center;
    padding: 50px 20px;
}

#ranking-screen h1 {
    font-size: 3em;
    margin-bottom: 40px;
    color: #ff9800;
}

.ranking-table {
    background: #f5f5f5;
    border-radius: 20px;
    padding: 20px;
    margin-bottom: 30px;
    max-height: 500px;
    overflow-y: auto;
}

.ranking-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 15px 20px;
    background: white;
    border-radius: 10px;
    margin-bottom: 10px;
    transition: transform 0.2s;
}

.ranking-item:hover {
    transform: translateX(5px);
}

.rank {
    font-size: 1.5em;
    font-weight: bold;
    min-width: 60px;
    text-align: left;
}

.player-name {
    font-size: 1.2em;
    font-weight: bold;
    color: #333;
    flex: 1;
    text-align: left;
}

.player-score {
    font-size: 1.3em;
    font-weight: bold;
    color: #667eea;
    min-width: 80px;
}

.player-level {
    font-size: 1.1em;
    color: #666;
    min-width: 60px;
}

.no-ranking {
    padding: 40px;
    font-size: 1.2em;
    color: #999;
}

#back-to-game-btn {
    padding: 15px 40px;
    font-size: 1.1em;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    transition: background 0.3s, transform 0.2s;
    font-weight: bold;
}

#back-to-game-btn:hover {
    background: #5568d3;
    transform: translateY(-2px);
}

#back-to-game-btn:active {
    transform: translateY(0);
}

@media (max-width: 768px) {
    .nickname-input-box {
        flex-direction: column;
        gap: 15px;
    }

    #nickname-input {
        max-width: 100%;
        width: 100%;
    }

    #submit-score-btn {
        width: 100%;
    }

    .button-group {
        flex-direction: column;
        gap: 10px;
    }

    #view-ranking-btn, #restart-btn {
        width: 100%;
    }

    .ranking-item {
        flex-direction: column;
        text-align: center;
        gap: 10px;
    }

    .rank, .player-name, .player-score, .player-level {
        min-width: auto;
        text-align: center;
    }

    #ranking-screen h1 {
        font-size: 2em;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 15px;
    }

    h1 {
        font-size: 1.5em;
    }

    .game-info {
        font-size: 0.9em;
    }

    #game-board {
        gap: 5px;
    }

    .message {
        font-size: 1em;
    }

    #start-screen h1, #gameover-screen h1 {
        font-size: 1.5em;
    }

    .description {
        font-size: 1em;
    }

    #start-btn {
        padding: 12px 30px;
        font-size: 1em;
    }

    .result-value {
        font-size: 2em;
    }
}