@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
    --bg-canvas: #DFDFDF;
    --panel-color: #FFFFFF;
    --text-dark: #333333;
    --accent-color: #D69396;
    --shadow-color: #B07C7F;
    --font-style: 'Inter', sans-serif;
    --border-radius: 6px;
}

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

body {
    font-family: var(--font-style);
    background: var(--bg-canvas);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    color: var(--text-dark);
}

.container {
    background: var(--panel-color);
    border-radius: 12px;
    padding: 30px 35px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    max-width: 750px;
    width: 100%;
    position: relative;
}

.credit {
    position: absolute;
    top: 15px;
    left: 20px;
    font-size: 0.75em;
    color: #999;
    font-weight: 500;
    letter-spacing: 0.5px;
}

h1 {
    text-align: center;
    color: var(--accent-color);
    margin-top: 15px;
    margin-bottom: 20px;
    font-size: 1.8em;
    font-weight: 700;
    letter-spacing: -0.5px;
}

h2 {
    text-align: center;
    color: var(--text-dark);
    margin-bottom: 20px;
    font-size: 1.2em;
    font-weight: 600;
}

h3 {
    text-align: center;
    color: var(--accent-color);
    margin-bottom: 15px;
    font-weight: 600;
}

.hidden {
    display: none !important;
}

/* 遊戲規則 */
.game-rules {
    background: #EEEEEE;
    border: none;
    border-radius: 8px;
    padding: 18px 16px;
    margin-bottom: 30px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.rule-item {
    font-size: 0.95em;
    color: var(--text-dark);
    padding: 7px 0;
    text-align: center;
    font-weight: 500;
    line-height: 1.5;
}

/* 按鈕通用樣式 */
.mode-selection, .time-selection, .game-type-selection, .ai-difficulty-selection {
    text-align: center;
    padding: 10px 0;
}

.mode-btn, .time-btn, .game-type-btn, .difficulty-btn {
    background: var(--accent-color);
    color: white;
    border: none;
    padding: 15px 30px;
    margin: 8px 6px;
    font-size: 1em;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 0 var(--shadow-color);
    font-family: var(--font-style);
    letter-spacing: 0.3px;
}

.mode-btn:hover, .time-btn:hover, .game-type-btn:hover, .difficulty-btn:hover {
    background: #C88488;
    transform: translateY(-2px);
    box-shadow: 0 6px 0 var(--shadow-color);
}

.mode-btn:active, .time-btn:active, .game-type-btn:active, .difficulty-btn:active {
    transform: translateY(4px);
    box-shadow: 0 0 0 var(--shadow-color);
}

.control-btn-small {
    background: #999;
    color: white;
    border: none;
    padding: 12px 24px;
    margin-top: 25px;
    font-size: 0.95em;
    font-weight: 500;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: var(--font-style);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.control-btn-small:hover {
    background: #777;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.control-btn-small:active {
    transform: translateY(1px);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* 遊戲區域 */
.game-area, .battle-area {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.stats, .battle-stats {
    display: flex;
    justify-content: space-around;
    background: #F5F5F5;
    padding: 20px 18px;
    border-radius: 8px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
}

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

.stat-label {
    display: block;
    font-size: 0.85em;
    color: #666;
    margin-bottom: 5px;
    font-weight: 500;
}

#timer, #battle-timer, #speed, #accuracy, #sentence-count {
    font-size: 1.5em;
    font-weight: 700;
    color: var(--accent-color);
}

.timer-big {
    font-size: 2em !important;
    color: var(--accent-color) !important;
}

/* 對戰進度 */
.battle-progress {
    background: #F5F5F5;
    padding: 20px 18px;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    gap: 18px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
}

.player-section, .ai-section {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.player-header, .ai-header {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.1em;
    font-weight: 600;
}

.player-icon, .ai-icon {
    font-size: 1.5em;
}

.player-name, .ai-name {
    flex: 1;
}

.player-score, .ai-score {
    color: var(--accent-color);
    font-size: 1.1em;
    font-weight: 700;
}

.progress-bar-container {
    background: #E0E0E0;
    height: 30px;
    border-radius: var(--border-radius);
    overflow: hidden;
    position: relative;
}

.progress-bar-fill {
    height: 100%;
    width: 0%;
    transition: width 0.3s ease-out;
    border-radius: var(--border-radius);
}

.player-progress {
    background: var(--accent-color);
}

.ai-progress {
    background: #999;
}

/* 文字顯示區 */
.text-display {
    background: #FAFAFA;
    padding: 28px 25px;
    border-radius: 8px;
    min-height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #F0F0F0;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.03);
}

.target-text {
    font-size: 1.3em;
    line-height: 1.7;
    letter-spacing: 1px;
    color: var(--text-dark);
    font-family: 'Courier New', monospace;
    font-weight: 500;
}

.target-text .char {
    position: relative;
    transition: all 0.15s;
}

.target-text .char.correct {
    color: var(--accent-color);
    font-weight: 600;
}

.target-text .char.incorrect {
    color: #E57373;
    background-color: #FFEBEE;
}

.target-text .char.current {
    background-color: #E0E0E0;
    border-radius: 3px;
}

/* AI 打字顯示 */
.ai-typing-display {
    background: #F8F8F8;
    padding: 15px 18px;
    border-radius: 8px;
    margin-top: 15px;
    border: 2px solid #DEDEDE;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
}

.ai-typing-label {
    font-size: 0.85em;
    color: #666;
    font-weight: 600;
    margin-bottom: 8px;
}

.ai-typing-text {
    font-size: 1.1em;
    line-height: 1.6;
    letter-spacing: 1px;
    color: #555;
    font-family: 'Courier New', monospace;
    font-weight: 500;
    min-height: 30px;
}

.ai-typing-text .char {
    transition: all 0.15s ease;
}

.ai-typing-text .char.ai-typed {
    color: #999;
    font-weight: 600;
}

/* 輸入區域 */
.input-area {
    width: 100%;
}

#user-input, #battle-input {
    width: 100%;
    padding: 15px 18px;
    font-size: 1.05em;
    border: 2px solid #E0E0E0;
    border-radius: 8px;
    outline: none;
    transition: all 0.3s ease;
    font-family: var(--font-style);
    color: var(--text-dark);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.03);
}

#user-input:focus, #battle-input:focus {
    border-color: var(--accent-color);
    box-shadow: 0 4px 12px rgba(214, 147, 150, 0.2);
    transform: translateY(-1px);
}

/* 控制按鈕 */
.controls {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-top: 5px;
}

.control-btn {
    background: var(--accent-color);
    color: white;
    border: none;
    padding: 12px 28px;
    font-size: 0.95em;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: var(--font-style);
    box-shadow: 0 4px 0 var(--shadow-color);
    letter-spacing: 0.3px;
}

.control-btn:hover {
    background: #C88488;
    transform: translateY(-2px);
    box-shadow: 0 6px 0 var(--shadow-color);
}

.control-btn:active {
    transform: translateY(4px);
    box-shadow: 0 0 0 var(--shadow-color);
}

/* 結果畫面 */
.result-area, .battle-result-area {
    text-align: center;
    padding: 5px 0;
}

.result-stats {
    background: #F5F5F5;
    padding: 22px 20px;
    border-radius: 8px;
    margin: 20px 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.result-item {
    margin: 10px 0;
    font-size: 1.05em;
}

.result-label {
    color: #666;
    margin-right: 10px;
    font-weight: 500;
}

#final-time, #final-speed, #final-accuracy, #final-sentences, #final-chars,
#battle-final-speed, #battle-final-accuracy, #player-final-sentences, #ai-final-sentences {
    font-weight: 700;
    color: var(--accent-color);
    font-size: 1.2em;
}

/* 星級評分 */
.star-rating {
    margin: 15px 0;
}

.stars {
    font-size: 2.2em;
    display: flex;
    justify-content: center;
    gap: 6px;
}

.star {
    display: inline-block;
    animation: star-appear 0.4s ease-out backwards;
}

.star:nth-child(1) { animation-delay: 0.1s; }
.star:nth-child(2) { animation-delay: 0.2s; }
.star:nth-child(3) { animation-delay: 0.3s; }
.star:nth-child(4) { animation-delay: 0.4s; }
.star:nth-child(5) { animation-delay: 0.5s; }

@keyframes star-appear {
    0% {
        opacity: 0;
        transform: scale(0) rotate(0deg);
    }
    50% {
        transform: scale(1.15) rotate(180deg);
    }
    100% {
        opacity: 1;
        transform: scale(1) rotate(360deg);
    }
}

/* 成就列表 */
.achievements-earned {
    background: #F0F7F4;
    border: 2px solid var(--accent-color);
    border-radius: 8px;
    padding: 16px;
    margin: 18px 0;
}

.achievement-list {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
}

.achievement-badge {
    background: white;
    border: 2px solid var(--accent-color);
    border-radius: var(--border-radius);
    padding: 10px 15px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.achievement-badge-icon {
    font-size: 1.5em;
}

.achievement-badge-text {
    font-size: 0.9em;
    color: var(--text-dark);
    font-weight: 600;
}

/* 對戰結果 */
.battle-winner {
    margin: 30px 0;
}

.winner-icon {
    font-size: 5em;
    margin-bottom: 10px;
    animation: winner-bounce 0.8s ease-in-out;
}

@keyframes winner-bounce {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.15);
    }
}

.winner-text {
    font-size: 2em;
    font-weight: 700;
    color: var(--accent-color);
    margin-top: 10px;
}

.battle-comparison {
    background: #F5F5F5;
    padding: 20px;
    border-radius: var(--border-radius);
    margin: 20px 0;
}

.comparison-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    margin: 10px 0;
    background: white;
    border-radius: var(--border-radius);
    font-size: 1.2em;
}

.comparison-label {
    font-weight: 600;
}

.comparison-value {
    color: var(--accent-color);
    font-weight: 700;
    font-size: 1.2em;
}

/* 響應式設計 */
@media (max-width: 600px) {
    .container {
        padding: 20px 15px 25px;
    }

    .credit {
        position: relative;
        top: auto;
        left: auto;
        text-align: center;
        font-size: 0.7em;
        margin-bottom: 15px;
    }

    h1 {
        font-size: 1.5em;
        margin-top: 10px;
        margin-bottom: 20px;
    }

    .game-rules {
        padding: 20px 15px;
        margin-bottom: 30px;
    }

    .rule-item {
        font-size: 0.9em;
        padding: 8px 0;
    }

    .mode-btn, .time-btn, .game-type-btn, .difficulty-btn {
        display: block;
        width: 100%;
        margin: 10px 0;
        padding: 16px 24px;
        font-size: 1em;
    }

    .stats, .battle-stats {
        flex-direction: column;
        gap: 15px;
        padding: 20px 15px;
    }

    .text-display {
        padding: 20px 15px;
    }

    .target-text {
        font-size: 1.1em;
    }

    .ai-typing-display {
        padding: 12px 15px;
        margin-top: 12px;
    }

    .ai-typing-text {
        font-size: 1em;
    }

    .stars {
        font-size: 2em;
    }

    .game-area, .battle-area {
        gap: 20px;
    }

    h2 {
        font-size: 1.2em;
        margin-bottom: 20px;
    }
}
