:root {
    --bg: #f1f3f4;
    --surface: #fff;
    --border: #dadce0;
    --text: #202124;
    --muted: #5f6368;
    --correct: #4ade80;
    --incorrect: #f87171;
    --primary: #a8d5ff;
    --accent: #1a73e8;
}

:root[data-theme="dark"] {
    --bg: #202124;
    --surface: #303134;
    --border: #5f6368;
    --text: #e8eaed;
    --muted: #9aa0a6;
    --correct: #4ade80;
    --incorrect: #f87171;
    --primary: #a8d5ff;
    --accent: #1a73e8;
}

:root[data-theme="dark"] body {
    background-image: 
        linear-gradient(to right, rgba(255, 255, 255, 0.05) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(255, 255, 255, 0.05) 1px, transparent 1px);
    background-size: 20px 20px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Sora', sans-serif;
    background: var(--bg);
    background-image: 
        linear-gradient(to right, rgba(0, 0, 0, 0.05) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(0, 0, 0, 0.05) 1px, transparent 1px);
    background-size: 20px 20px;
    color: var(--text);
    min-height: 100vh;
    padding: 2rem;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
}

.instruction {
    color: var(--muted);
    font-size: 0.9rem;
    text-align: left;
}

.instruction p {
    margin: 0;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.header-left {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: flex-start;
}

.header-right {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.5rem;
}

.header-center {
    flex: 0 0 auto;
    display: flex;
    justify-content: center;
    align-items: center;
}

.stat {
    text-align: center;
}

.stat-label {
    font-size: 0.85rem;
    color: var(--muted);
    text-transform: uppercase;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.stat-value {
    font-size: 2rem;
    font-weight: 600;
    color: var(--text);
}

.time-select {
    margin-left: 1rem;
    padding: 0.35rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    color: var(--text);
    font-family: 'Sora', sans-serif;
    font-size: 0.9rem;
    cursor: pointer;
    outline: none;
    transition: all 0.2s ease;
}

.time-select:hover {
    background: var(--bg);
    border-color: var(--muted);
}

.time-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(26, 115, 232, 0.1);
}

.theme-toggle {
    padding: 0.45rem;
    width: auto;
    height: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: auto;
}

.theme-icon {
    display: inline-block;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    border: 2px solid var(--border);
    transition: all 0.2s ease;
}

:root[data-theme="dark"] .theme-icon {
    background: #5f6368;
    border-color: #5f6368;
}

.btn {
    border: none;
    border-radius: 999px;
    padding: 0.45rem 1.25rem;
    cursor: pointer;
    font-size: 0.95rem;
    font-family: 'Sora', sans-serif;
    color: var(--text);
    background: transparent;
    transition: all 0.2s ease;
}

.btn.primary {
    background: var(--primary);
    color: #000;
    font-size: 0.9rem;
    text-transform: uppercase;
    font-weight: 600;
}

.btn.primary:hover {
    background: #8bc5ff;
}

.btn.ghost {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
}

.btn.ghost:hover {
    background: var(--surface);
}

.main-content {
    margin-bottom: 2rem;
}

.test-section {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.test-container {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 2rem;
    box-shadow: 0 1px 3px rgba(60, 64, 67, 0.1);
    transition: box-shadow 0.2s ease;
    aspect-ratio: 21 / 9;
    display: flex;
    flex-direction: column;
    justify-content: center;
    overflow: hidden;
}

.test-container:focus-within {
    box-shadow: 0 4px 8px rgba(60, 64, 67, 0.18);
}

.leaderboard-top-right {
    width: 100%;
}

.leaderboard-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 1.5rem;
    box-shadow: 0 1px 3px rgba(60, 64, 67, 0.1);
    max-height: 400px;
    overflow-y: auto;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE and Edge */
}

.leaderboard-section::-webkit-scrollbar {
    display: none; /* Chrome, Safari, Opera */
}

.words {
    font-size: 1.5rem;
    line-height: 2;
    word-wrap: break-word;
    user-select: none;
    font-family: 'Sora', sans-serif;
    color: var(--text);
    margin-bottom: 1.5rem;
    overflow-y: auto;
    flex: 1;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE and Edge */
}

.words::-webkit-scrollbar {
    display: none; /* Chrome, Safari, Opera */
}

.word {
    display: inline-block;
    margin: 0 0.5rem 0 0;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    transition: all 0.1s;
}

.word.current {
    background: rgba(168, 213, 255, 0.2);
    color: rgba(26, 115, 232, 0.8);
    position: relative;
}

:root[data-theme="dark"] .word.current {
    background: rgba(255, 255, 255, 0.2);
    color: rgba(255, 255, 255, 0.9);
}

.word.current::after {
    content: '';
    position: absolute;
    left: 0;
    bottom: -2px;
    width: 100%;
    height: 2px;
    background: var(--accent);
    animation: blink 1s infinite;
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

.word.typed {
    /* Let characters show their own colors */
}

.word.typed .char {
    color: inherit;
}

.word.typed .char.correct {
    color: rgba(144, 238, 144, 0.8) !important; /* pale green - dark mode */
}

:root:not([data-theme="dark"]) .word.typed .char.correct {
    color: rgba(100, 149, 237, 0.8) !important; /* pale dark blue - light mode */
}

.word.typed .char.incorrect {
    color: rgba(255, 182, 193, 0.8) !important; /* pale pink */
}

.word.correct {
    /* Let characters show their own colors */
}

.word.incorrect {
    background: rgba(248, 113, 113, 0.1);
    /* Let characters show their own colors */
}

.char {
    display: inline-block;
    color: var(--text);
}

.char.correct {
    color: rgba(144, 238, 144, 0.8) !important; /* pale green - dark mode */
}

:root:not([data-theme="dark"]) .char.correct {
    color: rgba(100, 149, 237, 0.8) !important; /* pale dark blue - light mode */
}

.char.incorrect {
    color: rgba(255, 182, 193, 0.8) !important; /* pale pink */
    background: rgba(248, 113, 113, 0.1);
    text-decoration: underline;
}

/* Ensure typed words show character colors */
.word.typed .char:not(.correct):not(.incorrect) {
    color: rgba(144, 238, 144, 0.8); /* Default to green for untyped chars in completed words - dark mode */
}

:root:not([data-theme="dark"]) .word.typed .char:not(.correct):not(.incorrect) {
    color: rgba(100, 149, 237, 0.8); /* Default to pale dark blue for untyped chars in completed words - light mode */
}

.input-container {
    position: relative;
}

.input {
    width: 100%;
    background: transparent;
    border: none;
    outline: none;
    color: transparent;
    caret-color: var(--accent);
    font-size: 1.5rem;
    font-family: 'Sora', sans-serif;
    padding: 0.5rem;
    position: absolute;
    z-index: -1;
    opacity: 0;
}

.leaderboard-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
}

.leaderboard {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.leaderboard-loading,
.leaderboard-empty {
    color: var(--muted);
    font-size: 0.9rem;
    text-align: center;
    padding: 1rem;
}

.leaderboard-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem;
    background: var(--bg);
    border-radius: 8px;
    border: 1px solid var(--border);
    transition: all 0.2s ease;
}

.leaderboard-item:hover {
    box-shadow: 0 2px 4px rgba(60, 64, 67, 0.1);
}

.leaderboard-item.rank-1 {
    background: linear-gradient(135deg, #ffd700 0%, #ffed4e 100%);
    color: #000;
    border-color: #ffd700;
}

.leaderboard-item.rank-2 {
    background: linear-gradient(135deg, #c0c0c0 0%, #e8e8e8 100%);
    color: #000;
    border-color: #c0c0c0;
}

.leaderboard-item.rank-3 {
    background: linear-gradient(135deg, #cd7f32 0%, #e6a55d 100%);
    color: #000;
    border-color: #cd7f32;
}

.leaderboard-rank {
    font-weight: 600;
    font-size: 0.9rem;
    min-width: 2rem;
}

.leaderboard-name {
    flex: 1;
    font-weight: 500;
    margin: 0 1rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.leaderboard-score {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.25rem;
}

.leaderboard-wpm {
    font-weight: 600;
    font-size: 1rem;
    color: var(--accent);
}

.leaderboard-acc {
    font-size: 0.75rem;
    color: var(--muted);
}

.result-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 2rem;
}

.result {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 2.5rem;
    text-align: center;
    box-shadow: 0 4px 8px rgba(60, 64, 67, 0.18);
    max-width: 600px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
}

.result h2 {
    font-size: 2rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 2rem;
}

.result-stats {
    display: flex;
    justify-content: space-around;
    margin-bottom: 2rem;
    flex-wrap: wrap;
    gap: 2rem;
}

.result-stat {
    text-align: center;
}

.result-value {
    font-size: 3rem;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 0.5rem;
}

.result-label {
    font-size: 0.85rem;
    color: var(--muted);
    text-transform: uppercase;
    font-weight: 500;
}

.name-input-container {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    align-items: baseline;
    margin-bottom: 1.5rem;
    flex-wrap: nowrap;
}

.name-input-container .name-input {
    flex: 0 1 auto;
    min-width: 200px;
    max-width: 300px;
}

.name-input-container .btn.primary {
    flex: 0 0 auto;
    align-self: baseline;
}

.name-input {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--bg);
    color: var(--text);
    font-family: 'Sora', sans-serif;
    font-size: 0.95rem;
    outline: none;
    transition: all 0.2s ease;
    min-width: 200px;
    box-sizing: border-box;
    line-height: 1.5;
}

.name-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(26, 115, 232, 0.1);
}

.result .btn {
    margin-top: 1rem;
}

@media (max-width: 768px) {
    body {
        padding: 1rem;
        font-size: 0.9rem;
    }

    .container {
        max-width: 100%;
    }

    .instruction {
        font-size: 0.8rem;
    }

    .header {
        flex-direction: column;
        align-items: center;
        gap: 0.75rem;
        margin-bottom: 1.5rem;
    }

    .header-left,
    .header-right {
        flex: 0;
        width: 100%;
        justify-content: center;
    }

    .header-center {
        width: 100%;
    }

    .stat-label {
        font-size: 0.75rem;
    }

    .stat-value {
        font-size: 1.5rem;
    }

    .time-select {
        font-size: 0.85rem;
        padding: 0.3rem 0.6rem;
    }

    .btn {
        font-size: 0.85rem;
        padding: 0.4rem 1rem;
    }

    .test-container {
        aspect-ratio: 16 / 9;
        padding: 1.5rem;
    }

    .words {
        font-size: 1.1rem;
        line-height: 1.6;
        margin-bottom: 1rem;
    }

    .input {
        font-size: 1.1rem;
    }

    .leaderboard-section {
        padding: 1rem;
        max-height: 300px;
    }

    .leaderboard-title {
        font-size: 0.9rem;
        margin-bottom: 0.75rem;
        padding-bottom: 0.5rem;
    }

    .leaderboard-item {
        padding: 0.5rem;
        font-size: 0.85rem;
    }

    .leaderboard-rank {
        font-size: 0.8rem;
        min-width: 1.5rem;
    }

    .leaderboard-name {
        font-size: 0.85rem;
        margin: 0 0.5rem;
    }

    .leaderboard-wpm {
        font-size: 0.9rem;
    }

    .leaderboard-acc {
        font-size: 0.7rem;
    }

    .result {
        padding: 1.5rem;
        max-width: 95%;
    }

    .result h2 {
        font-size: 1.5rem;
        margin-bottom: 1.5rem;
    }

    .result-stats {
        gap: 1rem;
        margin-bottom: 1.5rem;
    }

    .result-value {
        font-size: 2rem;
    }

    .result-label {
        font-size: 0.75rem;
    }

    .name-input {
        font-size: 0.85rem;
        padding: 0.4rem 0.8rem;
        min-width: 150px;
    }

    .name-input-container {
        gap: 0.5rem;
        margin-bottom: 1rem;
    }
}

@media (max-width: 480px) {
    body {
        padding: 0.75rem;
        font-size: 0.85rem;
    }

    .instruction {
        font-size: 0.75rem;
        margin-bottom: 0.75rem;
    }

    .header {
        margin-bottom: 1rem;
    }

    .stat-label {
        font-size: 0.7rem;
    }

    .stat-value {
        font-size: 1.25rem;
    }

    .time-select {
        font-size: 0.8rem;
        padding: 0.25rem 0.5rem;
    }

    .btn {
        font-size: 0.8rem;
        padding: 0.35rem 0.85rem;
    }

    .test-container {
        padding: 1rem;
    }

    .words {
        font-size: 1rem;
        line-height: 1.5;
    }

    .input {
        font-size: 1rem;
    }

    .leaderboard-section {
        padding: 0.75rem;
        max-height: 250px;
    }

    .leaderboard-title {
        font-size: 0.85rem;
    }

    .leaderboard-item {
        padding: 0.4rem;
        font-size: 0.8rem;
    }

    .result {
        padding: 1rem;
    }

    .result h2 {
        font-size: 1.25rem;
        margin-bottom: 1rem;
    }

    .result-value {
        font-size: 1.5rem;
    }

    .result-label {
        font-size: 0.7rem;
    }

    .name-input {
        font-size: 0.8rem;
        min-width: 120px;
    }
}


