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

:root {
    --bg-color: #323437;
    --text-color: #e2b714;
    --sub-color: #646669;
    --main-color: #d1d0c5;
    --error-color: #ca4754;
    --error-extra-color: #7e2a33;
    --caret-color: #e2b714;
    --correct-glow: rgba(226, 183, 20, 0.3);
    --error-glow: rgba(202, 71, 84, 0.4);
}

body {
    font-family: 'Lexend Deca', 'Nunito', sans-serif;
    background-color: var(--bg-color);
    color: var(--main-color);
    height: 100vh;
    margin: 0;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-text-size-adjust: 100%;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
    width: 100%;
    animation: fadeInUp 0.4s ease-out;
}

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

.header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
    margin-bottom: 4rem;
    font-size: 1.2rem;
    flex-wrap: wrap;
    position: relative;
    transition: opacity 0.3s ease;
}

.header.focus-mode {
    opacity: 0.1;
}

.logo {
    color: var(--text-color);
    font-weight: 500;
    font-size: 1.8rem;
    letter-spacing: 0.02em;
}

.mode-selector {
    display: flex;
    gap: 0;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
}

.mode-btn, .option-btn {
    background: transparent;
    border: none;
    color: var(--sub-color);
    padding: 0.4rem 0.8rem;
    cursor: pointer;
    font-family: 'Lexend Deca', sans-serif;
    font-size: 1rem;
    font-weight: 400;
    transition: color 0.15s ease;
    white-space: nowrap;
    display: flex;
    align-items: center;
    justify-content: center;
    text-transform: lowercase;
    letter-spacing: 0.02em;
    -webkit-tap-highlight-color: transparent;
}

.divider {
    color: var(--sub-color);
    opacity: 0.5;
    margin: 0 0.5rem;
}

.mode-btn:hover, .option-btn:hover {
    color: var(--main-color);
}

.mode-btn.active, .option-btn.active {
    color: var(--text-color);
}

.options {
    display: flex;
    gap: 1.5rem;
    flex-wrap: wrap;
    justify-content: center;
}

.time-options, .word-options {
    display: flex;
    gap: 1.2rem;
    flex-wrap: wrap;
}

.toggles {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.toggle-btn {
    background: transparent;
    border: none;
    color: var(--sub-color);
    cursor: pointer;
    transition: color 0.15s ease;
    padding: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
}

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

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

.toggle-btn i {
    width: 18px;
    height: 18px;
}

.header-right {
    margin-left: auto;
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--sub-color);
    cursor: pointer;
    transition: color 0.15s ease;
    padding: 0.5rem;
    min-width: 40px;
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
}

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

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

.icon-btn i {
    width: 20px;
    height: 20px;
}

.main-content {
    position: relative;
}

.stats-bar {
    display: flex;
    justify-content: center;
    gap: 3rem;
    margin-bottom: 2rem;
    font-size: 1.3rem;
    color: var(--sub-color);
    font-weight: 300;
    flex-wrap: wrap;
    opacity: 0;
    animation: fadeIn 0.3s ease forwards;
}

@keyframes fadeIn {
    to {
        opacity: 1;
    }
}

.stat {
    font-weight: 300;
}

.stat span {
    color: var(--main-color);
}

.typing-area {
    position: relative;
    font-size: 1.5rem;
    line-height: 1.8;
    min-height: 150px;
    user-select: none;
    overflow-y: hidden;
    max-height: 40vh;
    -webkit-overflow-scrolling: touch;
    touch-action: none;
    font-family: 'JetBrains Mono', 'Roboto Mono', monospace;
    letter-spacing: 0.05em;
}

.caps-lock-warning {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 1.5rem;
    color: var(--error-color);
    font-size: 0.9rem;
    font-weight: 300;
    opacity: 0;
    animation: fadeIn 0.3s ease forwards;
}

.caps-lock-warning i {
    width: 16px;
    height: 16px;
}

.typing-area.flash-error {
    animation: flashError 0.3s ease;
}

.typing-area.error-lock {
    animation: errorPulse 0.5s ease infinite alternate;
}

.typing-area.error-streak-2 {
    background-color: rgba(202, 71, 84, 0.08);
    animation: errorShake 0.4s ease;
}

.typing-area.error-streak-3 {
    background-color: rgba(202, 71, 84, 0.12);
    animation: errorShake 0.4s ease, errorPulse 0.3s ease infinite alternate;
}

@keyframes flashError {
    0% {
        background-color: transparent;
    }
    50% {
        background-color: rgba(202, 71, 84, 0.1);
    }
    100% {
        background-color: transparent;
    }
}

@keyframes errorPulse {
    0% {
        background-color: rgba(202, 71, 84, 0.05);
    }
    100% {
        background-color: rgba(202, 71, 84, 0.1);
    }
}

@keyframes errorShake {
    0%, 100% {
        transform: translateX(0);
    }
    10%, 30%, 50%, 70%, 90% {
        transform: translateX(-4px);
    }
    20%, 40%, 60%, 80% {
        transform: translateX(4px);
    }
}

.words-container {
    color: var(--sub-color);
}

.word {
    display: inline-block;
    margin: 0 0.5rem;
    position: relative;
    transition: transform 0.2s ease, opacity 0.2s ease;
    white-space: nowrap;
}

.word.current-word {
    opacity: 1;
    transform: scale(1);
}

.word.completed {
    opacity: 0.7;
}

.word.shake {
    animation: wordShake 0.4s ease;
}

.word.error-locked {
    position: relative;
}

@keyframes wordShake {
    0%, 100% {
        transform: translateX(0);
    }
    10%, 30%, 50%, 70%, 90% {
        transform: translateX(-3px);
    }
    20%, 40%, 60%, 80% {
        transform: translateX(3px);
    }
}

.letter {
    position: relative;
    transition: color 0.15s ease;
    display: inline-block;
}

.letter.current {
    text-shadow: 0 0 10px var(--correct-glow);
}

@keyframes typePop {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
    100% {
        transform: scale(1);
    }
}

@keyframes shake {
    0%, 100% {
        transform: translateX(0);
    }
    10%, 30%, 50%, 70%, 90% {
        transform: translateX(-2px);
    }
    20%, 40%, 60%, 80% {
        transform: translateX(2px);
    }
}

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

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

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

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

.caret {
    position: absolute;
    left: 0;
    top: 0;
    width: 2px;
    height: 1.6em;
    background-color: var(--caret-color);
    animation: blink 0.53s infinite;
    transition: left 0.05s ease, top 0.05s ease;
    z-index: 10;
    pointer-events: none;
}

.caret.error-locked {
    background-color: var(--error-color);
}

@keyframes blinkError {
    0% {
        opacity: 0.3;
        transform: scaleX(1);
    }
    100% {
        opacity: 1;
        transform: scaleX(1.5);
    }
}

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

#hidden-input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
    top: 0;
    left: 0;
}

.focus-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 50;
    opacity: 1;
    transition: opacity 0.2s ease;
}

.message {
    color: var(--sub-color);
    font-size: 1.1rem;
    font-weight: 300;
    text-transform: lowercase;
    letter-spacing: 0.02em;
}

.shortcuts {
    text-align: center;
    margin-top: 2rem;
    color: var(--sub-color);
    font-size: 0.9rem;
    display: none;
}

.results-screen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 100;
    animation: fadeIn 0.35s ease;
}

.results-content {
    width: 100%;
    max-width: 800px;
    padding: 2rem;
}

.results-header {
    text-align: center;
    margin-bottom: 3rem;
}

.result-mode-info {
    color: var(--sub-color);
    font-size: 1rem;
    font-weight: 300;
    text-transform: lowercase;
    letter-spacing: 0.02em;
}

.results-stats {
    display: flex;
    gap: 3rem;
    margin-bottom: 3rem;
    flex-wrap: wrap;
    justify-content: center;
}

.result-item {
    text-align: center;
    opacity: 0;
    animation: fadeIn 0.35s ease forwards;
}

.result-label {
    color: var(--sub-color);
    font-size: 1rem;
    margin-bottom: 0.5rem;
    font-weight: 300;
    text-transform: lowercase;
    letter-spacing: 0.02em;
}

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

.result-value.primary {
    color: var(--text-color);
    font-size: 3rem;
}

.result-value.small {
    font-size: 1.2rem;
    font-family: 'JetBrains Mono', monospace;
}

.wpm-graph-container {
    width: 100%;
    height: 150px;
    margin-bottom: 2rem;
    opacity: 0;
    animation: fadeIn 0.35s ease 0.4s forwards;
}

#wpm-graph {
    width: 100%;
    height: 100%;
}

.restart-btn-container {
    display: flex;
    justify-content: center;
    margin-top: 2rem;
}

.restart-btn-icon {
    background: transparent;
    border: none;
    color: var(--sub-color);
    cursor: pointer;
    padding: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.15s ease, transform 0.4s ease;
    -webkit-tap-highlight-color: transparent;
}

.restart-btn-icon:hover {
    color: var(--text-color);
    transform: rotate(180deg);
}

.restart-btn-icon i {
    width: 32px;
    height: 32px;
}

@media screen and (max-width: 1024px) {
    .container {
        padding: 1.5rem;
    }
    
    .header {
        gap: 1.5rem;
        margin-bottom: 3rem;
        font-size: 1.1rem;
    }
    
    .logo {
        font-size: 1.6rem;
    }
    
    .typing-area {
        font-size: 1.4rem;
        max-height: 40vh;
    }
    
    .results-stats {
        gap: 2rem;
    }
    
    .result-value {
        font-size: 2.2rem;
    }
    
    .result-value.primary {
        font-size: 2.5rem;
    }
}

@media screen and (max-width: 768px) {
    .container {
        padding: 1rem;
    }
    
    .header {
        gap: 1rem;
        margin-bottom: 2rem;
        font-size: 1rem;
        flex-direction: column;
        align-items: center;
    }
    
    .logo {
        font-size: 1.4rem;
        margin-bottom: 0.5rem;
    }
    
    .mode-btn, .option-btn {
        padding: 0.4rem 0.8rem;
        font-size: 0.9rem;
    }
    
    .mode-selector {
        margin-bottom: 0.5rem;
    }
    
    .options {
        width: 100%;
        justify-content: center;
        margin-top: 0.5rem;
    }
    
    .header-right {
        position: absolute;
        top: 0;
        right: 1rem;
        margin-left: 0;
    }
    
    .toggles {
        display: none;
    }
    
    .stats-bar {
        gap: 2rem;
        font-size: 1.1rem;
    }
    
    .typing-area {
        font-size: 1.2rem;
        min-height: 120px;
        max-height: 35vh;
    }
    
    .word {
        margin: 0 0.3rem;
    }
    
    .caret {
        width: 2px;
        height: 1.4em;
    }
    
    .results-stats {
        gap: 1.5rem;
    }
    
    .result-label {
        font-size: 0.9rem;
    }
    
    .result-value {
        font-size: 1.8rem;
    }
    
    .result-value.primary {
        font-size: 2.2rem;
    }
    
    .result-value.small {
        font-size: 1rem;
    }
    
    .restart-btn-icon i {
        width: 28px;
        height: 28px;
    }
}

@media screen and (max-width: 480px) {
    .container {
        padding: 0.5rem;
    }
    
    .header {
        gap: 0.5rem;
        margin-bottom: 1.5rem;
        font-size: 0.9rem;
        flex-direction: column;
        align-items: center;
    }
    
    .logo {
        font-size: 1.2rem;
        margin-bottom: 0.5rem;
    }
    
    .mode-selector {
        gap: 0;
        margin-bottom: 0.5rem;
    }
    
    .header-right {
        order: -1;
        margin-left: 0;
        margin-bottom: 0.5rem;
        top: 0;
        right: 0.5rem;
    }
    
    .options {
        width: 100%;
        justify-content: center;
        gap: 1rem;
    }
    
    .mode-btn, .option-btn {
        padding: 0.4rem 0.8rem;
        font-size: 0.9rem;
    }
    
    .time-options, .word-options {
        gap: 1rem;
    }
    
    .stats-bar {
        gap: 1.5rem;
        font-size: 1rem;
        margin-bottom: 1rem;
    }
    
    .typing-area {
        font-size: 1rem;
        min-height: 80px;
        max-height: 30vh;
        line-height: 1.7;
    }
    
    .word {
        margin: 0 0.15rem;
    }
    
    .caret {
        width: 2px;
        height: 1.2em;
    }
    
    .results-stats {
        gap: 1rem;
        margin-bottom: 1.5rem;
    }
    
    .result-item {
        flex: 1 1 45%;
        min-width: 100px;
    }
    
    .result-label {
        font-size: 0.8rem;
    }
    
    .result-value {
        font-size: 1.5rem;
    }
    
    .result-value.primary {
        font-size: 1.8rem;
    }
    
    .result-value.small {
        font-size: 0.9rem;
    }
    
    .wpm-graph-container {
        height: 120px;
    }
    
    .restart-btn-icon i {
        width: 24px;
        height: 24px;
    }
    
    .caps-lock-warning {
        font-size: 0.8rem;
    }
}

@media screen and (max-width: 320px) {
    .container {
        padding: 0.25rem;
    }
    
    .header {
        margin-bottom: 1rem;
        gap: 0.3rem;
    }
    
    .logo {
        font-size: 1rem;
    }
    
    .mode-btn, .option-btn {
        padding: 0.3rem 0.6rem;
        font-size: 0.85rem;
    }
    
    .typing-area {
        font-size: 0.9rem;
        max-height: 25vh;
        min-height: 70px;
    }
    
    .word {
        margin: 0 0.1rem;
    }
    
    .stats-bar {
        font-size: 0.9rem;
        gap: 1rem;
    }
    
    .result-value {
        font-size: 1.2rem;
    }
    
    .result-value.primary {
        font-size: 1.4rem;
    }
    
    .result-label {
        font-size: 0.7rem;
    }
}

@media screen and (max-height: 600px) and (orientation: landscape) {
    .container {
        padding: 1rem;
    }
    
    .header {
        margin-bottom: 1.5rem;
        gap: 1rem;
    }
    
    .logo {
        font-size: 1.4rem;
    }
    
    .typing-area {
        max-height: 25vh;
        font-size: 1.2rem;
    }
    
    .results-stats {
        margin-bottom: 1.5rem;
    }
}

@media screen and (orientation: portrait) {
    .typing-area {
        max-height: 35vh;
    }
}

@media print {
    body {
        background: white;
        color: black;
    }
    
    .header, .stats-bar, .focus-overlay, .icon-btn, .toggles {
        display: none;
    }
}

@media screen and (min-width: 1200px) {
    .container {
        padding: 3rem;
    }
    
    .typing-area {
        font-size: 1.6rem;
    }
}

@media screen and (min-width: 1600px) {
    .container {
        max-width: 1400px;
    }
    
    .typing-area {
        font-size: 1.8rem;
    }
    
    .result-value {
        font-size: 3rem;
    }
    
    .result-value.primary {
        font-size: 3.5rem;
    }
}