:root {
    --color-midnight: #1a1a2e;
    --color-navy: #16213e;
    --color-charcoal: #0f3460;
    --color-slate: #2d3047;
    --color-fjord: #4a6fa5;
    --color-ice: #a8d0e6;
    --color-aurora: #66fcf1;
    --color-northern: #45a29e;
    --color-moss: #5d8c7b;
    --color-lichen: #c5d86d;
    --color-ember: #e74c3c;
    --color-sunset: #e67e22;
    --color-birch: #f8f9fa;
    --color-pine: #2c3e50;
    
    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 20px;
    --radius-xl: 30px;
    
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.15);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.2);
    --shadow-glow: 0 0 20px rgba(102, 252, 241, 0.3);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(135deg, var(--color-midnight) 0%, var(--color-navy) 100%);
    min-height: 100vh;
    color: var(--color-birch);
    overflow-x: hidden;
    line-height: 1.6;
    font-weight: 300;
}

/* Screen Management */
.screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    flex-direction: column;
    padding: 24px;
}

/* Login Screen */
#login-screen {
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, var(--color-midnight) 0%, var(--color-charcoal) 100%);
}

.login-container {
    background: rgba(26, 26, 46, 0.9);
    border-radius: var(--radius-xl);
    padding: 48px 36px;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow-lg);
    border: 1px solid rgba(168, 208, 230, 0.1);
    backdrop-filter: blur(10px);
}

.selection-title {
    color: var(--color-aurora);
    margin-bottom: 16px;
    font-size: 36px;
    text-align: center;
    font-weight: 400;
    letter-spacing: -0.5px;
}

.login-subtitle {
    color: var(--color-ice);
    margin-bottom: 36px;
    font-size: 16px;
    opacity: 0.8;
    text-align: center;
}

.input-group {
    margin-bottom: 24px;
}

.input-group label {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
    color: var(--color-ice);
    font-weight: 400;
    font-size: 15px;
}

.input-group input {
    width: 100%;
    padding: 14px 18px;
    background: rgba(15, 52, 96, 0.3);
    border: 1px solid rgba(168, 208, 230, 0.2);
    border-radius: var(--radius-md);
    font-size: 16px;
    transition: all 0.3s ease;
    color: var(--color-birch);
    font-weight: 300;
}

.input-group input:focus {
    border-color: var(--color-aurora);
    outline: none;
    box-shadow: var(--shadow-glow);
    background: rgba(15, 52, 96, 0.5);
}

.input-group input::placeholder {
    color: rgba(168, 208, 230, 0.5);
}

.login-btn {
    background: linear-gradient(135deg, var(--color-northern) 0%, var(--color-aurora) 100%);
    color: var(--color-midnight);
    border: none;
    padding: 16px 32px;
    border-radius: var(--radius-md);
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    transition: all 0.3s ease;
    margin-top: 24px;
    letter-spacing: 0.5px;
}

.login-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
    background: linear-gradient(135deg, var(--color-aurora) 0%, var(--color-northern) 100%);
}

.login-info {
    margin-top: 28px;
    padding: 20px;
    background: rgba(15, 52, 96, 0.2);
    border-radius: var(--radius-md);
    text-align: left;
    font-size: 14px;
    border: 1px solid rgba(168, 208, 230, 0.1);
}

.login-info p {
    margin: 8px 0;
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--color-ice);
    opacity: 0.8;
}

/* Mode Selection Screen */
#mode-selection {
    flex-direction: column;
    background: linear-gradient(135deg, var(--color-midnight) 0%, var(--color-charcoal) 100%);
    overflow-y: auto;
}

.mode-header {
    text-align: center;
    margin-bottom: 36px;
    padding: 24px;
}

.user-info {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 24px;
    padding: 12px 24px;
    background: rgba(15, 52, 96, 0.3);
    border-radius: var(--radius-lg);
    border: 1px solid rgba(168, 208, 230, 0.1);
    max-width: 400px;
    margin-left: auto;
    margin-right: auto;
}

.user-info i {
    color: var(--color-aurora);
}

#user-email-display {
    font-weight: 400;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--color-ice);
}

.logout-btn {
    background: none;
    border: none;
    color: var(--color-ember);
    cursor: pointer;
    padding: 6px;
    font-size: 16px;
    transition: transform 0.2s;
}

.logout-btn:hover {
    transform: scale(1.1);
}

.user-stats {
    display: flex;
    justify-content: center;
    gap: 24px;
    margin-top: 24px;
    flex-wrap: wrap;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 20px;
    background: rgba(15, 52, 96, 0.3);
    border-radius: var(--radius-lg);
    border: 1px solid rgba(168, 208, 230, 0.1);
    min-width: 180px;
    justify-content: center;
}

.stat-item i {
    color: var(--color-aurora);
}

.mode-container {
    max-width: 1000px;
    margin: 0 auto;
    width: 100%;
}

.mode-category {
    margin-bottom: 32px;
    background: rgba(15, 52, 96, 0.2);
    padding: 28px;
    border-radius: var(--radius-xl);
    border: 1px solid rgba(168, 208, 230, 0.1);
    backdrop-filter: blur(10px);
}

.category-title {
    text-align: center;
    margin-bottom: 24px;
    color: var(--color-aurora);
    font-size: 24px;
    font-weight: 400;
    letter-spacing: -0.5px;
}

.mode-buttons {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 18px;
}

.mode-btn {
    padding: 24px;
    text-align: center;
    background: rgba(26, 26, 46, 0.6);
    border: 1px solid rgba(168, 208, 230, 0.15);
    border-radius: var(--radius-lg);
    color: var(--color-birch);
    font-size: 18px;
    font-weight: 400;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    backdrop-filter: blur(10px);
}

.mode-btn:hover {
    background: rgba(102, 252, 241, 0.1);
    border-color: var(--color-aurora);
    transform: translateY(-4px);
    box-shadow: var(--shadow-glow);
}

.mode-btn small {
    font-size: 14px;
    font-weight: 300;
    opacity: 0.8;
    color: var(--color-ice);
}

.mode-btn i {
    font-size: 28px;
    margin-bottom: 8px;
    color: var(--color-aurora);
}

.mode-btn[data-level="n5"] {
    border-color: var(--color-moss);
}

.mode-btn[data-level="n5"] i {
    color: var(--color-moss);
}

.mode-btn[data-level="n4"] {
    border-color: var(--color-fjord);
}

.mode-btn[data-level="n4"] i {
    color: var(--color-fjord);
}

.mode-btn[data-level="n3n1"] {
    border-color: var(--color-northern);
}

.mode-btn[data-level="n3n1"] i {
    color: var(--color-northern);
}

.mode-btn[data-level="all"] {
    border-color: var(--color-lichen);
}

.mode-btn[data-level="all"] i {
    color: var(--color-lichen);
}

.mode-btn[data-level="review"] {
    border-color: var(--color-ember);
}

.mode-btn[data-level="review"] i {
    color: var(--color-ember);
}

.game-info {
    margin-top: 36px;
    padding: 28px;
    background: rgba(15, 52, 96, 0.2);
    border-radius: var(--radius-xl);
    text-align: left;
    border: 1px solid rgba(168, 208, 230, 0.1);
}

.game-info p {
    margin: 14px 0;
    display: flex;
    align-items: flex-start;
    gap: 14px;
    color: var(--color-ice);
    line-height: 1.7;
}

.game-info i {
    color: var(--color-aurora);
    margin-top: 2px;
}

/* Game Screen */
#game-screen {
    flex-direction: column;
    background: linear-gradient(135deg, var(--color-midnight) 0%, var(--color-charcoal) 100%);
}

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 24px;
    background: rgba(15, 52, 96, 0.3);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(168, 208, 230, 0.1);
    border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.score-display {
    font-size: 17px;
    font-weight: 400;
    padding: 10px 18px;
    background: rgba(26, 26, 46, 0.6);
    border-radius: var(--radius-md);
    min-width: 140px;
    text-align: center;
    border: 1px solid rgba(168, 208, 230, 0.1);
}

.level-display {
    padding: 10px 20px;
    background: rgba(26, 26, 46, 0.6);
    border-radius: var(--radius-md);
    color: var(--color-ice);
    font-weight: 400;
    border: 1px solid rgba(168, 208, 230, 0.1);
}

.timer-container {
    height: 8px;
    background: rgba(26, 26, 46, 0.4);
    margin: 16px 24px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 1px solid rgba(168, 208, 230, 0.1);
}

.timer-bar {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, var(--color-northern), var(--color-aurora));
    transition: width 1s linear, background-color 1s;
    border-radius: var(--radius-sm);
}

.game-area {
    flex: 1;
    position: relative;
    margin: 24px;
    border-radius: var(--radius-xl);
    overflow: hidden;
    background: rgba(15, 52, 96, 0.15);
    border: 1px solid rgba(168, 208, 230, 0.1);
}

.quadrant {
    position: absolute;
    width: 50%;
    height: 50%;
    transition: background-color 0.3s;
}

.quadrant-nw {
    top: 0;
    left: 0;
    background: rgba(93, 140, 123, 0.05);
}

.quadrant-ne {
    top: 0;
    right: 0;
    background: rgba(74, 111, 165, 0.05);
}

.quadrant-sw {
    bottom: 0;
    left: 0;
    background: rgba(197, 216, 109, 0.05);
}

.quadrant-se {
    bottom: 0;
    right: 0;
    background: rgba(102, 252, 241, 0.05);
}

.direction-label {
    position: absolute;
    padding: 16px 24px;
    background: rgba(26, 26, 46, 0.95);
    border-radius: var(--radius-lg);
    font-size: 20px;
    font-weight: 400;
    color: var(--color-birch);
    box-shadow: var(--shadow-md);
    z-index: 10;
    text-align: center;
    min-width: 100px;
    transition: transform 0.2s ease;
    border: 1px solid rgba(168, 208, 230, 0.2);
    backdrop-filter: blur(10px);
}

.corner-nw {
    top: 24px;
    left: 24px;
    border-color: var(--color-moss);
    color: var(--color-moss);
}

.corner-ne {
    top: 24px;
    right: 24px;
    border-color: var(--color-fjord);
    color: var(--color-fjord);
}

.corner-sw {
    bottom: 24px;
    left: 24px;
    border-color: var(--color-lichen);
    color: var(--color-lichen);
}

.corner-se {
    bottom: 24px;
    right: 24px;
    border-color: var(--color-aurora);
    color: var(--color-aurora);
}

.card {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 220px;
    height: 300px;
    background: rgba(248, 249, 250, 0.05);
    backdrop-filter: blur(20px);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 20;
    cursor: grab;
    user-select: none;
    border: 1px solid rgba(168, 208, 230, 0.2);
    overflow: hidden;
}

.card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--color-northern), var(--color-aurora));
}

.card.swiping {
    cursor: grabbing;
    transition: none;
}

.card.swipe-off {
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.character {
    font-size: 88px;
    font-weight: 400;
    color: var(--color-birch);
    text-align: center;
    margin-bottom: 16px;
    font-family: "Hiragino Mincho Pro", "Yu Mincho", serif;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

.character-info {
    font-size: 15px;
    color: var(--color-ice);
    text-align: center;
    padding: 0 24px;
    opacity: 0.8;
    font-style: italic;
}

.game-stats {
    display: flex;
    justify-content: space-around;
    padding: 18px;
    background: rgba(15, 52, 96, 0.3);
    backdrop-filter: blur(10px);
    border-top: 1px solid rgba(168, 208, 230, 0.1);
    border-radius: 0 0 var(--radius-md) var(--radius-md);
}

.game-stats .stat {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--color-ice);
    font-weight: 300;
}

.game-stats .stat i {
    color: var(--color-aurora);
}

/* End Screen */
#end-screen {
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, var(--color-midnight) 0%, var(--color-charcoal) 100%);
    overflow-y: auto;
    padding: 48px 24px;
}

.end-title {
    font-size: 48px;
    margin-bottom: 36px;
    text-align: center;
    color: var(--color-aurora);
    font-weight: 400;
    letter-spacing: -1px;
}

.stats-container {
    background: rgba(15, 52, 96, 0.3);
    border-radius: var(--radius-xl);
    padding: 36px;
    margin-bottom: 36px;
    width: 100%;
    max-width: 520px;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(168, 208, 230, 0.1);
}

.stats-container .stat {
    display: flex;
    justify-content: space-between;
    margin: 18px 0;
    padding: 14px 0;
    border-bottom: 1px solid rgba(168, 208, 230, 0.1);
    font-size: 17px;
}

.stat-value {
    font-weight: 400;
    font-size: 22px;
    color: var(--color-aurora);
}

.kanji-progress {
    background: rgba(15, 52, 96, 0.3);
    border-radius: var(--radius-xl);
    padding: 28px;
    margin: 28px 0;
    width: 100%;
    max-width: 520px;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(168, 208, 230, 0.1);
    text-align: center;
}

.kanji-progress h3 {
    color: var(--color-aurora);
    margin-bottom: 20px;
    font-weight: 400;
    font-size: 22px;
}

.progress-bar {
    height: 12px;
    background: rgba(26, 26, 46, 0.6);
    border-radius: var(--radius-sm);
    overflow: hidden;
    margin: 20px 0;
    border: 1px solid rgba(168, 208, 230, 0.1);
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--color-northern), var(--color-aurora));
    transition: width 0.8s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: var(--radius-sm);
}

.kanji-progress p {
    color: var(--color-ice);
    font-size: 15px;
    margin-top: 16px;
}

.action-buttons {
    display: flex;
    gap: 18px;
    margin-top: 28px;
    flex-wrap: wrap;
    justify-content: center;
}

.play-again-btn, .mode-select-btn {
    padding: 16px 32px;
    border: none;
    border-radius: var(--radius-md);
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    transition: all 0.3s ease;
    min-width: 180px;
    letter-spacing: 0.5px;
}

.play-again-btn {
    background: linear-gradient(135deg, var(--color-northern) 0%, var(--color-aurora) 100%);
    color: var(--color-midnight);
}

.mode-select-btn {
    background: linear-gradient(135deg, var(--color-fjord) 0%, var(--color-moss) 100%);
    color: var(--color-birch);
}

.play-again-btn:hover, .mode-select-btn:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
}

.play-again-btn:hover {
    background: linear-gradient(135deg, var(--color-aurora) 0%, var(--color-northern) 100%);
}

.mode-select-btn:hover {
    background: linear-gradient(135deg, var(--color-moss) 0%, var(--color-fjord) 100%);
}

/* Feedback */
.feedback {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(1.2);
    font-size: 96px;
    font-weight: 300;
    opacity: 0;
    transition: opacity 0.3s, transform 0.3s;
    z-index: 1000;
    pointer-events: none;
    text-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.correct-feedback {
    color: var(--color-aurora);
    text-shadow: 0 0 30px rgba(102, 252, 241, 0.5);
}

.incorrect-feedback {
    color: var(--color-ember);
    text-shadow: 0 0 30px rgba(231, 76, 60, 0.5);
}

/* Responsive Design */
@media (max-width: 768px) {
    .mode-buttons {
        grid-template-columns: 1fr;
    }
    
    .user-stats {
        flex-direction: column;
        gap: 12px;
        align-items: center;
    }
    
    .stat-item {
        min-width: 240px;
    }
    
    .game-stats {
        flex-wrap: wrap;
        gap: 12px;
    }
    
    .action-buttons {
        flex-direction: column;
        width: 100%;
        max-width: 300px;
    }
    
    .card {
        width: 180px;
        height: 250px;
    }
    
    .character {
        font-size: 64px;
    }
    
    .direction-label {
        padding: 12px 18px;
        font-size: 16px;
        min-width: 80px;
    }
    
    .game-header {
        flex-wrap: wrap;
        gap: 12px;
        justify-content: center;
    }
    
    .score-display {
        min-width: auto;
        flex: 1;
    }
    
    .end-title {
        font-size: 36px;
    }
    
    .stats-container {
        padding: 24px;
    }
    
    .stats-container .stat {
        font-size: 15px;
    }
    
    .stat-value {
        font-size: 18px;
    }
    
    .feedback {
        font-size: 72px;
    }
}

@media (max-width: 480px) {
    .login-container,
    .mode-container,
    .stats-container,
    .kanji-progress {
        padding: 24px;
    }
    
    .selection-title {
        font-size: 28px;
    }
    
    .mode-category {
        padding: 20px;
    }
    
    .mode-btn {
        padding: 20px;
    }
    
    .card {
        width: 160px;
        height: 220px;
    }
    
    .character {
        font-size: 56px;
    }
    
    .direction-label {
        padding: 10px 14px;
        font-size: 14px;
        min-width: 70px;
    }
}