:root {
    --bg-color: #1a1a1a;
    --text-color: #ffffff;
    --sub-color: #646669;
    --main-color: #e2b714;
    --error-color: #ca4754;
    --config-bg: rgba(255, 255, 255, 0.05);
    --font-mono: 'JetBrains Mono', monospace;
    --font-jp: 'Noto Sans JP', sans-serif;
    --font-kr: 'Noto Sans KR', sans-serif;
    --font-zh: 'Noto Sans SC', sans-serif;
}

body.light-mode {
    --bg-color: #e5e5e5;
    --text-color: #1a1a1a;
    --sub-color: #999999;
    --main-color: #d1a500;
    --error-color: #ca4754;
    --config-bg: rgba(0, 0, 0, 0.05);
}

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

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: var(--font-mono);
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding-top: 25vh;
    overflow: hidden;
    transition: background-color 0.2s, color 0.2s;
}

.container {
    width: 100%;
    max-width: 1000px;
    padding: 0 2rem;
    display: flex;
    flex-direction: column;
    gap: 3.5rem;
}

header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2rem;
    font-size: 0.9rem;
    color: var(--sub-color);
}

.logo {
    font-weight: 500;
    letter-spacing: 0.2rem;
    color: var(--main-color);
}

.config-bar {
    display: flex;
    gap: 2rem;
    background: var(--config-bg);
    padding: 0.5rem 1.5rem;
    border-radius: 8px;
    align-items: center;
}

.config-group {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.config-btn {
    background: none;
    border: none;
    color: var(--sub-color);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.8rem;
    transition: color 0.2s;
    outline: none;
}

.config-btn:hover {
    color: var(--text-color);
}

.config-btn.active {
    color: var(--main-color);
}

.volume-slider {
    width: 80px;
    height: 4px;
    -webkit-appearance: none;
    background: var(--sub-color);
    border-radius: 2px;
    outline: none;
    opacity: 0.7;
    transition: opacity .2s;
    cursor: pointer;
}

.volume-slider:hover {
    opacity: 1;
}

.volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 12px;
    height: 12px;
    background: var(--main-color);
    border-radius: 50%;
    cursor: pointer;
}

main {
    position: relative;
    width: 100%;
    min-height: 300px;
}

.quote {
    font-size: 1.8rem;
    line-height: 1.6;
    word-break: break-all;
    user-select: none;
    color: var(--sub-color);
    width: 100%;
    white-space: pre-wrap; /* Preserve spaces and wrap naturally */
}

.lang-JP .quote { font-family: var(--font-jp); }
.lang-KR .quote { font-family: var(--font-kr); }
.lang-ZH .quote { font-family: var(--font-zh); }

.quote span {
    position: relative;
    display: inline; /* Back to inline for natural wrapping */
}

.quote span.correct {
    color: var(--text-color) !important;
}

/* 
   FIXED: Original text NEVER disappears. 
   Incorrect characters simply turn red.
*/
.quote span.incorrect {
    color: var(--error-color) !important;
}

.quote span.composing {
    color: var(--sub-color);
    border-bottom: 2px solid var(--sub-color);
}

.quote-input {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: default;
    resize: none;
    z-index: 10;
    outline: none;
    border: none;
    background: transparent;
    color: transparent;
    overflow: hidden;
}

.caret {
    position: absolute;
    width: 2px;
    height: 1.8rem;
    background-color: var(--main-color);
    top: 0;
    left: 0;
    display: none;
    pointer-events: none;
    transition: transform 0.05s linear;
}

.caret.active {
    display: block;
    animation: blink 1s infinite;
}

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

/* Result Overlay */
.result-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-color);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 20;
    transition: opacity 0.2s;
}

.result-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.result-card {
    text-align: center;
    max-width: 500px;
}

.result-card h2 {
    color: var(--sub-color);
    font-weight: 400;
    margin-bottom: 2rem;
}

.result-stats {
    display: flex;
    justify-content: space-between;
    gap: 4rem;
    margin-bottom: 3rem;
}

.result-stat {
    display: flex;
    flex-direction: column;
}

.result-stat .label {
    color: var(--sub-color);
    font-size: 0.8rem;
}

.result-stat .value {
    color: var(--main-color);
    font-size: 2.5rem;
    font-weight: 500;
}

.next-btn {
    background: none;
    border: 1px solid var(--sub-color);
    color: var(--sub-color);
    padding: 0.8rem 2.5rem;
    border-radius: 4px;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.2s;
}

.next-btn:hover {
    border-color: var(--main-color);
    color: var(--main-color);
}

footer {
    display: flex;
    justify-content: center;
    color: var(--sub-color);
    font-size: 0.9rem;
    margin-top: 2rem;
}

.stats {
    display: flex;
    gap: 3rem;
}

#wpm, #accuracy, #timer {
    color: var(--main-color);
    font-weight: 500;
}
