/**
 * Typing Speed Test Styles
 * Uses blue theme from --cat-speed (speed games category)
 */

.game-container {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    box-sizing: border-box;
    font-family: var(--font-main, system-ui, -apple-system, sans-serif);
    transition: background-color 0.3s ease;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

/* State backgrounds - using speed category color */
.state-idle {
    background-color: var(--cat-speed, #3498DB);
}

.state-playing {
    background-color: #2C3E50; /* Dark gray for focus while typing */
}

.state-result {
    background-color: var(--cat-speed, #3498DB);
}

.state-result.new-best {
    animation: celebrate 0.6s ease-out;
}

@keyframes celebrate {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.02); }
}

.content {
    text-align: center;
    max-width: 600px;
    width: 100%;
}

.title {
    font-size: 2.5rem;
    margin: 0 0 0.5rem 0;
    color: white;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.instruction {
    font-size: 1.2rem;
    color: rgba(255, 255, 255, 0.9);
    margin: 0.5rem 0 1rem 0;
}

.timer-display {
    font-size: 3rem;
    font-weight: bold;
    color: white;
    margin: 1rem 0;
    font-variant-numeric: tabular-nums;
}

.state-playing .timer-display {
    color: var(--color-primary, #FFD93D);
}

.text-display {
    background: rgba(255, 255, 255, 0.95);
    border-radius: var(--radius-md, 12px);
    padding: 1.5rem;
    margin: 1rem 0;
    font-size: 1.4rem;
    line-height: 1.8;
    text-align: left;
    min-height: 100px;
    max-height: 200px;
    overflow-y: auto;
    font-family: 'Courier New', Courier, monospace;
    box-shadow: var(--shadow-card, 0 4px 12px rgba(0, 0, 0, 0.15));
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.text-display span {
    position: relative;
}

/* Character states in text display */
.text-display .pending {
    color: #666;
}

.text-display .correct {
    color: var(--color-success, #27AE60);
}

.text-display .error {
    color: var(--color-accent, #E74C3C);
    background-color: rgba(231, 76, 60, 0.2);
    border-radius: 2px;
}

.text-display .current {
    color: #333;
    background-color: var(--color-primary, #FFD93D);
    border-radius: 2px;
}

/* Hidden input that receives keyboard input */
.typing-input {
    position: absolute;
    left: -9999px;
    opacity: 0;
}

/* On mobile, show the input at bottom of screen while playing */
@media (max-width: 768px) {
    .state-playing .typing-input {
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        padding: 15px;
        font-size: 16px; /* Prevents iOS auto-zoom on focus */
        border: none;
        background: rgba(0, 0, 0, 0.8);
        color: white;
        opacity: 1;
        z-index: 100;
    }
}

.score {
    font-size: 4rem;
    font-weight: bold;
    color: white;
    margin: 1rem 0;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.state-result.new-best .score {
    animation: score-pop 0.4s ease-out;
}

@keyframes score-pop {
    0% { transform: scale(0.5); opacity: 0; }
    70% { transform: scale(1.1); }
    100% { transform: scale(1); opacity: 1; }
}

.best-score {
    font-size: 1.1rem;
    color: rgba(255, 255, 255, 0.8);
    margin: 0.5rem 0;
}

.share-container {
    margin: 1rem 0;
}

.hint {
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.6);
    margin: 1rem 0 0 0;
}

/* State visibility */
.state-idle .timer-display { display: block; }
.state-idle .text-display { display: none; }
.state-idle .score { display: none; }
.state-idle .share-container { display: none; }
.state-idle .hint { display: none; }

.state-playing .controls-inline { display: none; }
.state-playing .timer-display { display: block; }
.state-playing .text-display { display: block; }
.state-playing .score { display: none; }
.state-playing .best-score { display: none; }
.state-playing .share-container { display: none; }
.state-playing .hint { display: none; }

.state-result .controls-inline { display: none; }
.state-result .timer-display { display: none; }
.state-result .text-display { display: none; }
.state-result .score { display: block; }
.state-result .best-score { display: block; }
.state-result .share-container { display: block; }
.state-result .hint { display: block; }

/* Back to Games link */
.home-link {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    color: rgba(255, 255, 255, 0.7);
    text-decoration: none;
    font-size: 0.9rem;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    background: rgba(0, 0, 0, 0.1);
    transition: all 0.2s ease;
}

.home-link:hover {
    color: white;
    background: rgba(0, 0, 0, 0.2);
}

.home-link:focus-visible {
    outline: 2px solid white;
    outline-offset: 2px;
}

/* Mobile adjustments */
@media (max-width: 480px) {
    .title {
        font-size: 2rem;
    }

    .timer-display {
        font-size: 2.5rem;
    }

    .text-display {
        font-size: 1.1rem;
        padding: 1rem;
        min-height: 80px;
    }

    .score {
        font-size: 3rem;
    }

    .home-link {
        bottom: 10px;
    }
}

/* Safe area for notched devices */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .home-link {
        bottom: calc(20px + env(safe-area-inset-bottom));
    }

    @media (max-width: 768px) {
        .state-playing .typing-input {
            padding-bottom: calc(15px + env(safe-area-inset-bottom));
        }
    }
}
