* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Microsoft JhengHei', sans-serif;
    background: linear-gradient(135deg, #E3F2FD 0%, #F3E5F5 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.container {
    max-width: 1000px;
    width: 100%;
}

header {
    text-align: center;
    margin-bottom: 25px;
}

header h1 {
    color: #37474F;
    font-size: 2.2em;
    margin-bottom: 15px;
    font-weight: 600;
    letter-spacing: 1px;
}

.mode-selector {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.mode-btn {
    padding: 10px 28px;
    font-size: 1em;
    border: 2px solid #B0BEC5;
    border-radius: 20px;
    background: white;
    color: #546E7A;
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 500;
}

.mode-btn:hover {
    border-color: #5E92F3;
    color: #5E92F3;
    transform: translateY(-1px);
}

.mode-btn.active {
    background: #5E92F3;
    border-color: #5E92F3;
    color: white;
}

.game-area {
    background: white;
    border-radius: 16px;
    padding: 35px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.08);
    margin-bottom: 25px;
}

.screen {
    display: none;
}

.screen.active {
    display: block;
}

/* 開始畫面 */
#start-screen h2 {
    text-align: center;
    color: #37474F;
    margin-bottom: 25px;
    font-size: 1.6em;
    font-weight: 600;
}

.difficulty-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-bottom: 35px;
    flex-wrap: wrap;
}

.diff-btn {
    padding: 18px 35px;
    font-size: 1.1em;
    border: 2px solid #E0E0E0;
    border-radius: 12px;
    background: white;
    color: #546E7A;
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 500;
    min-width: 120px;
}

.diff-btn:hover {
    border-color: #66BB6A;
    color: #66BB6A;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 187, 106, 0.2);
}

.stats-display {
    text-align: center;
}

.stats-display h3 {
    color: #546E7A;
    margin-bottom: 15px;
    font-size: 1.2em;
    font-weight: 600;
}

#best-scores {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: 500px;
    margin: 0 auto;
}

.best-score-item {
    display: flex;
    justify-content: space-between;
    padding: 12px 20px;
    background: #F5F5F5;
    border-radius: 10px;
    border-left: 3px solid #5E92F3;
}

/* 遊戲畫面 */
.game-info {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    margin-bottom: 25px;
}

.info-item {
    text-align: center;
    padding: 18px;
    background: #FAFAFA;
    border-radius: 12px;
    border: 1px solid #EEEEEE;
}

.info-item .label {
    display: block;
    font-size: 0.85em;
    color: #78909C;
    margin-bottom: 6px;
    font-weight: 500;
}

.info-item .value {
    display: block;
    font-size: 1.8em;
    font-weight: 600;
    color: #37474F;
}

.text-display {
    background: #FAFAFA;
    border-radius: 12px;
    padding: 30px;
    margin-bottom: 20px;
    min-height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #EEEEEE;
}

#target-text {
    font-size: 1.6em;
    line-height: 1.8;
    color: #37474F;
    letter-spacing: 1px;
    user-select: none;
    font-weight: 500;
}

#target-text .char {
    position: relative;
}

#target-text .char.correct {
    color: #66BB6A;
    font-weight: 600;
}

#target-text .char.incorrect {
    color: #EF5350;
    background: #FFEBEE;
    border-radius: 2px;
}

#target-text .char.current {
    background: #5E92F3;
    color: white;
    border-radius: 2px;
    padding: 0 2px;
}

.input-area {
    margin-bottom: 20px;
}

#user-input {
    width: 100%;
    padding: 16px 20px;
    font-size: 1.3em;
    border: 2px solid #E0E0E0;
    border-radius: 10px;
    outline: none;
    transition: all 0.2s;
    background: white;
}

#user-input:focus {
    border-color: #5E92F3;
    box-shadow: 0 0 0 3px rgba(94, 146, 243, 0.1);
}

#user-input:disabled {
    background: #F5F5F5;
    cursor: not-allowed;
}

.game-controls {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.control-btn {
    padding: 12px 28px;
    font-size: 0.95em;
    border: 2px solid #E0E0E0;
    border-radius: 10px;
    background: white;
    color: #546E7A;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
}

.control-btn:hover {
    border-color: #5E92F3;
    color: #5E92F3;
    transform: translateY(-1px);
}

/* 結束畫面 */
#end-screen h2 {
    text-align: center;
    color: #37474F;
    margin-bottom: 25px;
    font-size: 1.8em;
    font-weight: 600;
}

/* 玩家名稱輸入 */
.player-name-input {
    text-align: center;
    margin-bottom: 25px;
    padding: 20px;
    background: #FAFAFA;
    border-radius: 12px;
    border: 1px solid #EEEEEE;
}

.player-name-input label {
    display: block;
    font-size: 1em;
    color: #546E7A;
    margin-bottom: 12px;
    font-weight: 500;
}

.player-name-input input {
    padding: 12px 20px;
    font-size: 1em;
    border: 2px solid #E0E0E0;
    border-radius: 8px;
    margin-right: 10px;
    width: 200px;
    transition: all 0.2s;
}

.player-name-input input:focus {
    outline: none;
    border-color: #5E92F3;
}

.submit-btn {
    padding: 12px 25px;
    font-size: 1em;
    border: none;
    border-radius: 8px;
    background: #5E92F3;
    color: white;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
}

.submit-btn:hover {
    background: #4A7FE0;
    transform: translateY(-1px);
}

.submit-btn:disabled {
    background: #CFD8DC;
    cursor: not-allowed;
    transform: none;
}

.submit-message {
    margin-top: 12px;
    padding: 10px;
    border-radius: 8px;
    font-weight: 500;
    font-size: 0.95em;
}

.submit-message.success {
    background: #E8F5E9;
    color: #2E7D32;
}

.submit-message.error {
    background: #FFEBEE;
    color: #C62828;
}

.submit-message.hidden {
    display: none;
}

.final-stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
    margin-bottom: 25px;
}

.stat-item {
    text-align: center;
    padding: 25px;
    background: #FAFAFA;
    border-radius: 12px;
    border: 1px solid #EEEEEE;
}

.stat-label {
    display: block;
    font-size: 0.95em;
    color: #78909C;
    margin-bottom: 10px;
    font-weight: 500;
}

.stat-value {
    display: block;
    font-size: 2.2em;
    font-weight: 600;
    color: #37474F;
}

.new-record {
    text-align: center;
    font-size: 1.3em;
    color: #FFA726;
    margin-bottom: 20px;
    font-weight: 600;
}

.new-record.hidden {
    display: none;
}

.end-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
}

.action-btn {
    padding: 14px 35px;
    font-size: 1.1em;
    border: none;
    border-radius: 10px;
    background: #5E92F3;
    color: white;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
}

.action-btn:hover {
    background: #4A7FE0;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(94, 146, 243, 0.3);
}

/* 排行榜 */
.leaderboard {
    background: white;
    border-radius: 16px;
    padding: 30px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.08);
}

.leaderboard h3 {
    text-align: center;
    color: #37474F;
    margin-bottom: 20px;
    font-size: 1.6em;
    font-weight: 600;
}

.leaderboard-mode {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-bottom: 15px;
}

.mode-tab-btn {
    padding: 10px 25px;
    border: 2px solid #E0E0E0;
    border-radius: 20px;
    background: white;
    color: #546E7A;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.95em;
    font-weight: 500;
}

.mode-tab-btn:hover {
    border-color: #5E92F3;
    color: #5E92F3;
}

.mode-tab-btn.active {
    background: #5E92F3;
    border-color: #5E92F3;
    color: white;
}

.leaderboard-tabs {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-bottom: 15px;
}

.tab-btn {
    padding: 8px 22px;
    border: 2px solid #E0E0E0;
    border-radius: 18px;
    background: white;
    color: #546E7A;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.9em;
    font-weight: 500;
}

.tab-btn:hover {
    border-color: #5E92F3;
    color: #5E92F3;
}

.tab-btn.active {
    background: #5E92F3;
    border-color: #5E92F3;
    color: white;
}

/* 難度選擇標籤 */
.difficulty-tabs {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin-bottom: 20px;
}

.diff-tab-btn {
    padding: 8px 18px;
    border: 2px solid #E0E0E0;
    border-radius: 18px;
    background: white;
    color: #546E7A;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.85em;
    font-weight: 500;
}

.diff-tab-btn:hover {
    border-color: #66BB6A;
    color: #66BB6A;
}

.diff-tab-btn.active {
    background: #66BB6A;
    border-color: #66BB6A;
    color: white;
}

#leaderboard-content {
    max-height: 450px;
    overflow-y: auto;
}

.leaderboard-item {
    display: grid;
    grid-template-columns: 50px 1fr 100px 100px 110px;
    gap: 12px;
    padding: 15px 18px;
    margin-bottom: 10px;
    background: #FAFAFA;
    border-radius: 10px;
    align-items: center;
    transition: all 0.2s;
    border-left: 3px solid transparent;
}

.leaderboard-item:hover {
    transform: translateX(3px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.leaderboard-item.top-1 {
    background: linear-gradient(135deg, #FFF9C4 0%, #FFEB3B 100%);
    border-left-color: #F9A825;
}

.leaderboard-item.top-2 {
    background: linear-gradient(135deg, #ECEFF1 0%, #CFD8DC 100%);
    border-left-color: #78909C;
}

.leaderboard-item.top-3 {
    background: linear-gradient(135deg, #FFCCBC 0%, #FF8A65 100%);
    border-left-color: #D84315;
}

.rank {
    font-size: 1.3em;
    font-weight: 700;
    color: #37474F;
    text-align: center;
}

.difficulty-tag {
    padding: 5px 12px;
    border-radius: 12px;
    font-size: 0.8em;
    font-weight: 600;
    display: inline-block;
}

.difficulty-tag.easy {
    background: #C8E6C9;
    color: #2E7D32;
}

.difficulty-tag.medium {
    background: #FFE082;
    color: #F57C00;
}

.difficulty-tag.hard {
    background: #FFCDD2;
    color: #C62828;
}

.score-value {
    font-weight: 600;
    color: #37474F;
    font-size: 0.95em;
}

.wpm-value {
    font-weight: 600;
    color: #66BB6A;
    font-size: 0.9em;
}

.date {
    font-size: 0.8em;
    color: #90A4AE;
}

.empty-leaderboard {
    text-align: center;
    padding: 40px;
    color: #90A4AE;
    font-size: 1em;
}

/* 響應式設計 */
@media (max-width: 768px) {
    header h1 {
        font-size: 1.6em;
    }

    .game-area {
        padding: 25px;
    }

    .game-info {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    #target-text {
        font-size: 1.2em;
    }

    #user-input {
        font-size: 1.1em;
    }

    .final-stats {
        grid-template-columns: 1fr;
    }

    .difficulty-buttons {
        flex-direction: column;
        align-items: stretch;
    }

    .diff-btn {
        width: 100%;
    }

    .leaderboard-item {
        grid-template-columns: 40px 1fr 70px;
        font-size: 0.85em;
    }

    .wpm-value, .date {
        display: none;
    }

    .player-name-input input {
        width: 100%;
        margin-right: 0;
        margin-bottom: 10px;
    }

    .submit-btn {
        width: 100%;
    }
}

/* 自訂捲軸 */
#leaderboard-content::-webkit-scrollbar {
    width: 8px;
}

#leaderboard-content::-webkit-scrollbar-track {
    background: #F5F5F5;
    border-radius: 10px;
}

#leaderboard-content::-webkit-scrollbar-thumb {
    background: #CFD8DC;
    border-radius: 10px;
}

#leaderboard-content::-webkit-scrollbar-thumb:hover {
    background: #B0BEC5;
}
