/* ===================================
   MonkeyType - Complete Theme System
   =================================== */

:root {
    /* Default Theme (Dark) */
    --bg-color: #323437;
    --bg-color-secondary: #2c2e31;
    --main-color: #ff7f00;
    --caret-color: #ff7f00;
    --sub-color: #646669;
    --sub-alt-color: #6f7277;
    --text-color: #d1d0c5;
    --error-color: #ca4754;
    --error-extra-color: #ff7f00;
    --font-family: 'Roboto Mono', 'Courier New', monospace;
    --font-size: 1rem;
    
    /* Sizing */
    --max-width: 1160px;
    --timer-font-size: 6rem;
}

[data-theme="light"] {
    --bg-color: #f5f5f5;
    --bg-color-secondary: #e8e8e8;
    --main-color: #323437;
    --caret-color: #323437;
    --sub-color: #999999;
    --sub-alt-color: #777777;
    --text-color: #323437;
    --error-color: #d32f2f;
    --error-extra-color: #323437;
}

[data-theme="dark"] {
    --bg-color: #1a1a1a;
    --bg-color-secondary: #141414;
    --main-color: #e2b714;
    --caret-color: #e2b714;
    --sub-color: #555555;
    --sub-alt-color: #444444;
    --text-color: #cccccc;
    --error-color: #ff4444;
    --error-extra-color: #e2b714;
}

[data-theme="ocean"] {
    --bg-color: #1a3a4a;
    --bg-color-secondary: #152a38;
    --main-color: #3a8aaa;
    --caret-color: #3a8aaa;
    --sub-color: #5a7a8a;
    --sub-alt-color: #4a6a7a;
    --text-color: #d4e4ec;
    --error-color: #aa4a5a;
    --error-extra-color: #3a8aaa;
}

[data-theme="forest"] {
    --bg-color: #1a2a1a;
    --bg-color-secondary: #141f14;
    --main-color: #4a8a4a;
    --caret-color: #4a8a4a;
    --sub-color: #5a7a5a;
    --sub-alt-color: #4a6a4a;
    --text-color: #d4e4d4;
    --error-color: #aa5a5a;
    --error-extra-color: #4a8a4a;
}

[data-theme="cherry"] {
    --bg-color: #2a1a1a;
    --bg-color-secondary: #1f1414;
    --main-color: #aa4a4a;
    --caret-color: #aa4a4a;
    --sub-color: #7a5a5a;
    --sub-alt-color: #6a4a4a;
    --text-color: #e4d4d4;
    --error-color: #ff6b6b;
    --error-extra-color: #aa4a4a;
}

[data-theme="mint"] {
    --bg-color: #1a2a23;
    --bg-color-secondary: #141f1b;
    --main-color: #4aaa7a;
    --caret-color: #4aaa7a;
    --sub-color: #5a8a6a;
    --sub-alt-color: #4a7a5a;
    --text-color: #d4e4d9;
    --error-color: #aa5a6a;
    --error-extra-color: #4aaa7a;
}

[data-theme="lavender"] {
    --bg-color: #2a1a2a;
    --bg-color-secondary: #1f141f;
    --main-color: #aa4aaa;
    --caret-color: #aa4aaa;
    --sub-color: #7a5a7a;
    --sub-alt-color: #6a4a6a;
    --text-color: #e4d4e4;
    --error-color: #cc6acc;
    --error-extra-color: #aa4aaa;
}

/* Flip Colors Mode */
.flip-colors {
    --bg-color: #d1d0c5;
    --bg-color-secondary: #c5c4bc;
    --text-color: #323437;
    --sub-color: #9c9b97;
    --error-color: #ca4754;
}

[data-theme="light"].flip-colors {
    --bg-color: #323437;
    --text-color: #f5f5f5;
}

/* ===================================
   Base Styles
   =================================== */

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

html {
    font-size: var(--font-size);
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: var(--font-family);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: background-color 0.3s, color 0.3s;
    overflow-x: hidden;
}

/* ===================================
   Screens
   =================================== */

.screen {
    display: none;
    width: 100%;
    max-width: var(--max-width);
    padding: 20px;
}

.screen.active {
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* ===================================
   Language Selection Screen
   =================================== */

.language-container {
    text-align: center;
    margin-top: 10vh;
}

.logo {
    font-size: 3.5rem;
    font-weight: 700;
    color: var(--main-color);
    letter-spacing: 6px;
    margin-bottom: 8px;
    text-decoration: none;
}

.subtitle {
    color: var(--sub-color);
    font-size: 1rem;
    margin-bottom: 40px;
}

.language-buttons {
    display: flex;
    gap: 16px;
    justify-content: center;
    flex-wrap: wrap;
}

.lang-btn {
    background: transparent;
    border: 2px solid var(--sub-color);
    color: var(--text-color);
    padding: 24px 48px;
    font-size: 1.1rem;
    font-family: var(--font-family);
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 12px;
}

.lang-btn:hover {
    border-color: var(--main-color);
    color: var(--main-color);
    transform: translateY(-2px);
}

.lang-flag {
    font-size: 1.8rem;
}

/* ===================================
   Header
   =================================== */

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    margin-bottom: 32px;
    padding: 0 8px;
}

.header-left, .header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-right .btn-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.btn-label {
    font-size: 0.85rem;
    margin-left: 4px;
    color: var(--sub-color);
}

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

.header .logo {
    font-size: 1.4rem;
    margin-bottom: 0;
    letter-spacing: 3px;
}

.header-center {
    flex: 1;
    display: flex;
    justify-content: center;
}

.command-palette-trigger {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--sub-color);
    font-size: 0.75rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: color 0.2s;
}

.command-palette-trigger:hover {
    color: var(--text-color);
}

.command-palette-trigger kbd {
    background: var(--sub-color);
    color: var(--bg-color);
    padding: 1px 4px;
    border-radius: 2px;
    font-size: 0.65rem;
    font-family: var(--font-family);
}

.btn-icon {
    background: transparent;
    border: none;
    color: var(--sub-color);
    cursor: pointer;
    padding: 8px;
    border-radius: 4px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-icon:hover {
    color: var(--text-color);
    background: var(--bg-color-secondary);
}

/* ===================================
   Config Bar
   =================================== */

.config-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 12px;
}

.config-left, .config-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.config-group {
    display: flex;
    gap: 4px;
}

.config-btn {
    background: transparent;
    border: none;
    color: var(--sub-color);
    padding: 6px 12px;
    font-family: var(--font-family);
    font-size: 0.85rem;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.15s;
}

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

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

.config-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s;
    user-select: none;
}

.config-toggle:hover {
    background: var(--bg-color-secondary);
}

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

.toggle-label {
    color: var(--sub-color);
    font-size: 0.75rem;
}

.toggle-state {
    color: var(--sub-alt-color);
    font-size: 0.75rem;
    font-weight: 600;
}

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

.config-toggle.active .toggle-state::before {
    content: '';
}

.config-toggle .toggle-state::before {
    content: '';
}

#caps-lock-warning {
    color: var(--error-color);
    font-size: 0.75rem;
    font-weight: 600;
}

/* ===================================
   Mode Dropdown
   =================================== */

.mode-dropdown, .quote-length-dropdown, .funbox-dropdown {
    position: absolute;
    background: var(--bg-color-secondary);
    border: 1px solid var(--sub-color);
    border-radius: 8px;
    padding: 8px 0;
    z-index: 1000;
    min-width: 120px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.mode-option, .quote-option, .funbox-option {
    padding: 8px 16px;
    cursor: pointer;
    color: var(--text-color);
    font-size: 0.9rem;
    transition: all 0.1s;
}

.mode-option:hover, .quote-option:hover, .funbox-option:hover {
    background: var(--bg-color);
    color: var(--main-color);
}

.mode-option.active, .quote-option.active, .funbox-option.active {
    color: var(--main-color);
}

/* ===================================
   Test Container
   =================================== */

.test-container {
    width: 100%;
    max-width: 900px;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.test-container.no-animation {
    transition: none;
}

/* Tags */
.tags-container {
    width: 100%;
    margin-bottom: 16px;
}

.tags {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.tag {
    background: var(--bg-color-secondary);
    color: var(--sub-color);
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.15s;
}

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

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

.tag.pb {
    color: var(--main-color);
}

/* Stats Container */
.stats-container {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    width: 100%;
    margin-bottom: 20px;
    padding: 0 20px;
}

.timer {
    font-size: var(--timer-font-size);
    font-weight: 700;
    color: var(--sub-color);
    line-height: 1;
    transition: color 0.3s;
}

.timer.active {
    color: var(--text-color);
}

.live-stats {
    display: flex;
    gap: 24px;
}

.stat {
    text-align: right;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-color);
    display: block;
}

.stat-label {
    font-size: 0.7rem;
    color: var(--sub-color);
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Progress Bar */
.progress-container {
    width: 100%;
    max-width: 300px;
    height: 4px;
    background: var(--bg-color-secondary);
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 20px;
}

.progress-bar {
    height: 100%;
    background: var(--main-color);
    transition: width 0.3s ease;
}

/* Keymap */
.keymap-container {
    width: 100%;
    max-width: 700px;
    margin-bottom: 20px;
}

.keymap {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 4px;
}

.key {
    width: 40px;
    height: 36px;
    background: var(--bg-color-secondary);
    border: 1px solid var(--sub-color);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    color: var(--sub-color);
    transition: all 0.1s;
}

.key.active {
    background: var(--main-color);
    color: var(--bg-color);
    border-color: var(--main-color);
}

.key.correct {
    background: var(--main-color);
    color: var(--bg-color);
}

.key.incorrect {
    background: var(--error-color);
    color: white;
    border-color: var(--error-color);
}

/* Words Wrapper */
.words-wrapper {
    position: relative;
    width: 100%;
}

.words-container {
    min-height: 80px;
    max-height: 200px;
    overflow: hidden;
    padding: 4px 0;
}

.words {
    font-size: 1.4rem;
    line-height: 2.2;
    color: var(--sub-color);
    word-wrap: break-word;
    user-select: none;
}

.word {
    display: inline-block;
    margin-right: 8px;
    position: relative;
    transition: color 0.1s;
}

.word.active {
    color: var(--text-color);
}

.word.active::before {
    content: '';
    position: absolute;
    left: -2px;
    top: 10%;
    bottom: 10%;
    width: 2px;
    background: var(--caret-color);
    animation: blink 1s infinite;
}

.word.correct {
    color: var(--main-color);
}

.word.incorrect {
    color: var(--error-color);
}

.letter {
    position: relative;
}

.letter.correct {
    color: var(--main-color);
}

.letter.incorrect {
    color: var(--error-color);
    text-decoration: underline;
}

.letter.extra {
    color: var(--error-extra-color);
}

/* Caret */
.caret-wrapper {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.caret {
    position: absolute;
    width: 2px;
    height: 1.4rem;
    background: var(--caret-color);
    animation: blink 1s infinite;
    transition: left 0.1s ease, top 0.1s ease;
    display: none;
}

.caret.style-block {
    width: 0.6em;
    height: 1.2em;
    background: var(--caret-color);
    border-radius: 2px;
}

.caret.style-underline {
    height: 3px;
    width: 0.6em;
    top: auto;
    bottom: 0;
}

.caret.hidden {
    display: none;
}

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

/* Zen Mode */
.zen-container {
    width: 100%;
    min-height: 200px;
}

#zen-input {
    width: 100%;
    min-height: 200px;
    background: transparent;
    border: none;
    color: var(--text-color);
    font-family: var(--font-family);
    font-size: 1.4rem;
    line-height: 2.2;
    resize: none;
    outline: none;
    caret-color: var(--caret-color);
}

#zen-input::placeholder {
    color: var(--sub-color);
}

/* Focus Prompt */
.focus-prompt {
    text-align: center;
    color: var(--sub-color);
    font-size: 0.9rem;
    padding: 16px;
    border: 1px dashed var(--sub-color);
    border-radius: 8px;
    cursor: text;
    transition: opacity 0.3s;
    width: 100%;
    max-width: 400px;
    margin: 20px auto;
}

.focus-prompt.hidden {
    opacity: 0;
    pointer-events: none;
}

/* Input Field */
#input-field {
    position: absolute;
    opacity: 0;
    z-index: 10;
    width: 200px;
    height: 40px;
    top: 200px;
    left: 50%;
    transform: translateX(-50%);
    cursor: text;
}

/* Focus prompt should be clickable */
.focus-prompt {
    cursor: pointer;
    z-index: 20;
    position: relative;
}

/* ===================================
   Results
   =================================== */

.results {
    text-align: center;
    margin-top: 32px;
    padding: 32px;
    background: var(--bg-color-secondary);
    border-radius: 12px;
    width: 100%;
    max-width: 700px;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.results-header {
    margin-bottom: 24px;
}

.result-main {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.result-value {
    font-size: 6rem;
    font-weight: 700;
    color: var(--main-color);
    line-height: 1;
}

.result-label {
    font-size: 1rem;
    color: var(--sub-color);
    text-transform: uppercase;
    letter-spacing: 3px;
    margin-top: 4px;
}

.result-grid {
    display: flex;
    justify-content: center;
    gap: 32px;
    flex-wrap: wrap;
    margin-bottom: 24px;
    padding: 16px 0;
    border-top: 1px solid var(--sub-color);
    border-bottom: 1px solid var(--sub-color);
}

.result-item {
    text-align: center;
    min-width: 80px;
}

.result-item-value {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text-color);
    display: block;
}

.result-item-label {
    font-size: 0.7rem;
    color: var(--sub-color);
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Chart */
.chart-container {
    width: 100%;
    max-width: 500px;
    margin: 20px auto;
    height: 200px;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    padding: 10px;
}

#live-chart, #results-chart {
    width: 100%;
    height: 100% !important;
}

/* Test Info */
.test-info {
    display: flex;
    justify-content: center;
    gap: 20px;
    flex-wrap: wrap;
    margin-bottom: 24px;
    font-size: 0.8rem;
}

.info-item {
    color: var(--sub-color);
}

.info-label {
    color: var(--sub-alt-color);
}

.info-value {
    color: var(--text-color);
    text-transform: capitalize;
}

/* Result Buttons */
.results-buttons {
    display: flex;
    justify-content: center;
    gap: 12px;
    flex-wrap: wrap;
}

.result-btn {
    background: transparent;
    border: 2px solid var(--sub-color);
    color: var(--sub-color);
    padding: 10px 24px;
    font-family: var(--font-family);
    font-size: 0.9rem;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
}

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

.result-btn .shortcut {
    font-size: 0.65rem;
    padding: 2px 6px;
    background: var(--sub-color);
    color: var(--bg-color);
    border-radius: 3px;
}

/* XP Bar */
.xp-bar-container {
    width: 100%;
    max-width: 700px;
    margin-top: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.xp-bar {
    flex: 1;
    height: 6px;
    background: var(--bg-color-secondary);
    border-radius: 3px;
    overflow: hidden;
}

.xp-progress {
    height: 100%;
    background: linear-gradient(90deg, var(--main-color), #ffd700);
    transition: width 0.5s ease;
}

.xp-info {
    font-size: 0.75rem;
    color: var(--sub-color);
    min-width: 60px;
}

/* ===================================
   Command Palette
   =================================== */

.command-palette {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 9999;
    display: flex;
    justify-content: center;
    padding-top: 100px;
}

.command-palette-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
}

.command-palette-content {
    position: relative;
    width: 100%;
    max-width: 500px;
    background: var(--bg-color-secondary);
    border: 1px solid var(--sub-color);
    border-radius: 12px;
    overflow: hidden;
    max-height: 60vh;
    display: flex;
    flex-direction: column;
}

.command-palette-search {
    padding: 16px;
    border-bottom: 1px solid var(--sub-color);
}

.command-palette-search input {
    width: 100%;
    background: transparent;
    border: none;
    color: var(--text-color);
    font-family: var(--font-family);
    font-size: 1.1rem;
    outline: none;
}

.command-palette-search input::placeholder {
    color: var(--sub-color);
}

.command-palette-results {
    overflow-y: auto;
    flex: 1;
}

.command-result {
    padding: 12px 16px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.1s;
}

.command-result:hover, .command-result.selected {
    background: var(--bg-color);
}

.command-result-label {
    color: var(--text-color);
}

.command-result-shortcut {
    display: flex;
    gap: 4px;
}

.command-result-shortcut kbd {
    background: var(--sub-color);
    color: var(--bg-color);
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 0.65rem;
}

/* ===================================
   Modals
   =================================== */

.modal-content {
    background: var(--bg-color);
    color: var(--text-color);
    border: 1px solid var(--sub-color);
    border-radius: 12px;
}

.modal-header {
    border-bottom: 1px solid var(--sub-color);
    padding: 16px 20px;
}

.modal-body {
    padding: 20px;
}

.modal-footer {
    border-top: 1px solid var(--sub-color);
    padding: 16px 20px;
}

.btn-close {
    filter: invert(1) grayscale(100%) brightness(200%);
}

/* Settings Tabs */
.settings-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--sub-color);
    padding-bottom: 8px;
    overflow-x: auto;
}

.settings-tab {
    padding: 8px 12px;
    cursor: pointer;
    color: var(--sub-color);
    font-size: 0.85rem;
    border-radius: 4px;
    white-space: nowrap;
    transition: all 0.15s;
}

.settings-tab:hover {
    color: var(--text-color);
}

.settings-tab.active {
    color: var(--main-color);
    background: var(--bg-color-secondary);
}

.settings-group {
    display: none;
}

.settings-group.active {
    display: block;
}

.setting-item {
    margin-bottom: 20px;
}

.setting-item label {
    display: block;
    color: var(--text-color);
    margin-bottom: 8px;
    font-size: 0.9rem;
}

.form-select, .form-range {
    background-color: var(--bg-color-secondary);
    border: 1px solid var(--sub-color);
    color: var(--text-color);
    border-radius: 4px;
    padding: 8px 12px;
    width: 100%;
}

.form-select:focus, .form-range:focus {
    border-color: var(--main-color);
    box-shadow: 0 0 0 2px rgba(226, 183, 20, 0.2);
    outline: none;
}

.form-check {
    display: flex;
    align-items: center;
    gap: 8px;
}

.form-check-input {
    background-color: var(--bg-color-secondary);
    border-color: var(--sub-color);
    width: 40px;
    height: 20px;
    cursor: pointer;
}

.form-check-input:checked {
    background-color: var(--main-color);
    border-color: var(--main-color);
}

.form-check-label {
    color: var(--text-color);
    cursor: pointer;
    flex: 1;
}

/* Theme Grid */
.theme-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.theme-option {
    aspect-ratio: 1;
    border-radius: 8px;
    cursor: pointer;
    border: 2px solid transparent;
    background: var(--bg);
    position: relative;
    transition: transform 0.15s;
}

.theme-option:hover {
    transform: scale(1.05);
}

.theme-option.active {
    border-color: var(--main-color);
}

.theme-option::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40%;
    height: 40%;
    background: var(--main);
    border-radius: 50%;
}

/* ===================================
   Leaderboard
   =================================== */

.leaderboard-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 16px;
}

.leaderboard-tab {
    padding: 8px 16px;
    cursor: pointer;
    color: var(--sub-color);
    border-radius: 4px;
    transition: all 0.15s;
}

.leaderboard-tab:hover {
    color: var(--text-color);
}

.leaderboard-tab.active {
    color: var(--main-color);
    background: var(--bg-color-secondary);
}

.leaderboard-list {
    max-height: 400px;
    overflow-y: auto;
}

.leaderboard-empty {
    text-align: center;
    color: var(--sub-color);
    padding: 40px;
}

.leaderboard-item {
    display: flex;
    align-items: center;
    padding: 12px;
    border-bottom: 1px solid var(--sub-color);
    gap: 12px;
}

.leaderboard-rank {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--main-color);
    min-width: 40px;
}

.leaderboard-name {
    flex: 1;
    text-align: left;
}

.leaderboard-wpm {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-color);
}

.leaderboard-acc {
    color: var(--sub-color);
    font-size: 0.9rem;
}

/* ===================================
   Account Modal
   =================================== */

.account-guest {
    text-align: center;
    padding: 20px;
}

.account-guest p {
    color: var(--sub-color);
    margin-bottom: 20px;
}

.account-guest .btn {
    margin: 4px;
}

/* ===================================
   History Panel
   =================================== */

.history-panel {
    position: fixed;
    right: 0;
    top: 0;
    width: 350px;
    height: 100vh;
    background: var(--bg-color);
    border-left: 1px solid var(--sub-color);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.3s ease;
}

.history-panel.open {
    transform: translateX(0);
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    border-bottom: 1px solid var(--sub-color);
}

.history-header h3 {
    font-size: 1.2rem;
    color: var(--text-color);
}

.history-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.history-item {
    padding: 12px;
    background: var(--bg-color-secondary);
    border-radius: 8px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: background 0.15s;
}

.history-item:hover {
    background: var(--bg-color);
}

.history-item-wpm {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--main-color);
}

.history-item-details {
    font-size: 0.8rem;
    color: var(--sub-color);
    margin-top: 4px;
}

/* ===================================
   AI Modal
   =================================== */

.ai-input textarea {
    width: 100%;
    background: var(--bg-color-secondary);
    border: 1px solid var(--sub-color);
    color: var(--text-color);
    border-radius: 6px;
    padding: 12px;
    font-family: var(--font-family);
    resize: none;
    margin-bottom: 12px;
}

.ai-input textarea:focus {
    border-color: var(--main-color);
    outline: none;
}

.ai-options {
    margin-bottom: 16px;
}

#generate-ai-btn {
    width: 100%;
    margin-bottom: 16px;
}

.ai-result {
    padding: 16px;
    background: var(--bg-color-secondary);
    border-radius: 8px;
}

.ai-result h6 {
    color: var(--main-color);
    margin-bottom: 8px;
}

.ai-result p {
    color: var(--text-color);
    font-size: 0.9rem;
    line-height: 1.6;
    margin-bottom: 12px;
}

#use-ai-text-btn {
    width: 100%;
}

/* ===================================
   Loading Overlay
   =================================== */

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 9998;
    display: flex;
    align-items: center;
    justify-content: center;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 3px solid var(--sub-color);
    border-top-color: var(--main-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ===================================
   Notifications
   =================================== */

.notification-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9997;
}

.notification {
    background: var(--bg-color-secondary);
    border: 1px solid var(--sub-color);
    border-radius: 8px;
    padding: 12px 16px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 12px;
    animation: slideIn 0.3s ease;
    min-width: 280px;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.notification.success {
    border-color: var(--main-color);
}

.notification.error {
    border-color: var(--error-color);
}

.notification-icon {
    font-size: 1.2rem;
}

.notification-text {
    flex: 1;
    color: var(--text-color);
    font-size: 0.9rem;
}

/* ===================================
   Responsive
   =================================== */

@media (max-width: 700px) {
    .header {
        flex-wrap: wrap;
        gap: 8px;
    }
    
    .header-center {
        order: 3;
        width: 100%;
    }
    
    .command-palette-trigger {
        display: none;
    }
    
    .config-bar {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .config-left, .config-right {
        flex-wrap: wrap;
    }
    
    .stats-container {
        flex-direction: column;
        align-items: center;
        gap: 16px;
    }
    
    .timer {
        font-size: 4rem;
    }
    
    .live-stats {
        gap: 16px;
    }
    
    .result-value {
        font-size: 4rem;
    }
    
    .result-grid {
        gap: 16px;
    }
    
    .result-item {
        min-width: 60px;
    }
    
    .result-item-value {
        font-size: 1.2rem;
    }
    
    .words {
        font-size: 1.2rem;
    }
    
    .history-panel {
        width: 100%;
    }
}

/* Font Sizes */
.font-size-1 { --font-size: 1rem; }
.font-size-125 { --font-size: 1.25rem; }
.font-size-15 { --font-size: 1.5rem; }
.font-size-2 { --font-size: 2rem; }

/* Colorful Mode */
.colorful-mode .word.correct {
    color: var(--main-color);
}

.colorful-mode .letter.correct {
    color: var(--main-color);
}

/* Hide Elements */
.hide-extra-letters .word.active .letter.extra {
    visibility: hidden;
}

/* Tape Mode */
.tape-mode .words-container {
    max-height: 50px;
    overflow: hidden;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-color);
}

::-webkit-scrollbar-thumb {
    background: var(--sub-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--sub-alt-color);
}

/* Animations */
.smooth-caret .caret,
.smooth-caret .word.active::before {
    transition: left 0.1s ease, top 0.1s ease;
}

.smooth-line-scroll .words-container {
    transition: max-height 0.3s ease;
}

/* PB Badge */
.pb-badge {
    display: inline-block;
    background: var(--main-color);
    color: var(--bg-color);
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 700;
    margin-left: 8px;
}

/* Out of Focus Warning */
.out-of-focus .test-container {
    opacity: 0.5;
}

.out-focus-warning {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--bg-color);
    border: 2px solid var(--main-color);
    padding: 20px 40px;
    border-radius: 12px;
    z-index: 100;
    text-align: center;
}

.out-focus-warning h3 {
    color: var(--main-color);
    margin-bottom: 8px;
}

.out-focus-warning p {
    color: var(--sub-color);
}

/* ===================================
   Results Page
   =================================== */

.results-page {
    width: 100%;
    max-width: var(--max-width);
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.results-page .header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    margin-bottom: 40px;
    padding: 0 8px;
}

.results-page .header-left,
.results-page .header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.results-page .logo {
    font-size: 1.4rem;
    color: var(--main-color);
    letter-spacing: 3px;
    text-decoration: none;
}

.results-page .btn-icon {
    display: flex;
    align-items: center;
    gap: 8px;
    background: transparent;
    border: 2px solid var(--sub-color);
    color: var(--sub-color);
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-family: var(--font-family);
    font-size: 0.9rem;
    transition: all 0.2s;
}

.results-page .btn-icon:hover {
    border-color: var(--main-color);
    color: var(--main-color);
}

.results-container {
    width: 100%;
    max-width: 700px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.results-page .results {
    text-align: center;
    margin-bottom: 40px;
}

.results-page .history-section {
    width: 100%;
}

.results-page .history-section h3 {
    color: var(--sub-color);
    font-size: 1rem;
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 16px;
    text-align: center;
}

.results-page .history-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.results-page .history-item {
    display: flex;
    align-items: center;
    padding: 16px;
    background: var(--bg-color-secondary);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.results-page .history-item:hover {
    background: var(--sub-color);
}

.results-page .history-item:hover .history-item-wpm {
    color: var(--bg-color);
}

.results-page .history-item-main {
    display: flex;
    align-items: baseline;
    gap: 4px;
    min-width: 100px;
}

.results-page .history-item-wpm {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--main-color);
    transition: color 0.2s;
}

.results-page .history-item-label {
    font-size: 0.8rem;
    color: var(--sub-color);
}

.results-page .history-item-details {
    flex: 1;
    display: flex;
    gap: 16px;
    justify-content: center;
    font-size: 0.85rem;
    color: var(--sub-color);
}

.results-page .history-item-date {
    font-size: 0.75rem;
    color: var(--sub-alt-color);
}

.results-page .history-empty {
    text-align: center;
    color: var(--sub-color);
    padding: 40px;
}

.results-page .result-btn svg {
    margin-left: 8px;
}
