/* ========== RESET & BASE ========== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg: #f5f5f7;
    --bg-card: #ffffff;
    --bg-card-hover: #f0f0f5;
    --bg-dark: #e8e8ee;
    --primary: #d63031;
    --primary-glow: rgba(214, 48, 49, 0.15);
    --secondary: #2d3436;
    --accent: #00b894;
    --accent-glow: rgba(0, 184, 148, 0.15);
    --text: #1a1a2e;
    --text-dim: #636e72;
    --gold: #e17055;
    --danger: #d63031;
    --success: #00b894;
    --warning: #fdcb6e;
    --border: #dfe6e9;
    --font-body: 'Inter', system-ui, sans-serif;
    --font-mono: 'JetBrains Mono', 'Consolas', monospace;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 2px 12px rgba(0,0,0,0.06);
    --shadow-lg: 0 8px 30px rgba(0,0,0,0.08);
}

html, body {
    height: 100%;
    font-family: var(--font-body);
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0,0,0,0);
    border: 0;
}

/* ========== SCREENS ========== */
.screen {
    display: none;
    width: 100%;
    height: 100%;
}
.screen.active {
    display: flex;
}

/* ========== START SCREEN ========== */
#screen-start {
    align-items: center;
    justify-content: center;
    background: linear-gradient(180deg, #ffffff 0%, var(--bg) 100%);
}

.start-container {
    text-align: center;
    max-width: 560px;
    width: 100%;
    padding: 20px;
}

.logo-area {
    margin-bottom: 32px;
}

.logo-icon {
    font-size: 64px;
    margin-bottom: 8px;
    animation: float 3s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

.logo-area h1 {
    font-size: 2.4rem;
    font-weight: 900;
    line-height: 1.1;
    letter-spacing: -1px;
    color: var(--secondary);
}
.logo-area h1 span {
    background: linear-gradient(135deg, var(--primary), var(--gold));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    color: var(--text-dim);
    margin-top: 8px;
    font-size: 1rem;
}

/* Config Card */
.config-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 28px 24px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
}

.config-card h2 {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-dim);
    margin-bottom: 14px;
    margin-top: 20px;
}
.config-card h2:first-child {
    margin-top: 0;
}

/* Level Buttons */
.level-buttons {
    display: flex;
    gap: 10px;
}

.level-btn {
    flex: 1;
    background: var(--bg);
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px 8px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    color: var(--text);
}
.level-btn:hover {
    background: var(--bg-card-hover);
    border-color: #b2bec3;
}
.level-btn.selected {
    border-color: var(--primary);
    background: rgba(214, 48, 49, 0.05);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.level-emoji { font-size: 1.6rem; }
.level-name { font-weight: 700; font-size: 0.95rem; }
.level-desc { font-size: 0.68rem; color: var(--text-dim); text-align: center; }

/* Speed Control */
.speed-control {
    display: flex;
    align-items: center;
    gap: 12px;
}
.speed-label {
    font-size: 0.8rem;
    color: var(--text-dim);
    min-width: 50px;
}
#speed-slider {
    flex: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 6px;
    border-radius: 3px;
    background: var(--bg-dark);
    outline: none;
}
#speed-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    box-shadow: 0 2px 6px var(--primary-glow);
}
#speed-slider::-moz-range-thumb {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    border: none;
}

.speed-value {
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-dim);
    margin-top: 6px;
}
.speed-hint {
    font-size: 0.75rem;
    opacity: 0.6;
}

/* Buttons */
.btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 16px 32px;
    margin-top: 24px;
    font-size: 1.1rem;
    font-weight: 700;
    font-family: var(--font-body);
    color: #fff;
    background: linear-gradient(135deg, var(--primary), #c0392b);
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
    box-shadow: 0 4px 16px var(--primary-glow);
}
.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 24px var(--primary-glow);
}
.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 14px 32px;
    font-size: 1rem;
    font-weight: 600;
    font-family: var(--font-body);
    color: var(--text);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.15s;
}
.btn-secondary:hover {
    background: var(--bg-card-hover);
}

.btn-arrow {
    transition: transform 0.2s;
}
.btn-primary:hover .btn-arrow {
    transform: translateX(4px);
}

/* ========== SHARED HEADER ========== */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 24px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.badge {
    background: var(--secondary);
    color: #fff;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    white-space: nowrap;
}

.btn-back {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-dim);
    font-family: var(--font-body);
    font-size: 0.8rem;
    font-weight: 600;
    padding: 5px 12px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
}
.btn-back:hover {
    background: var(--bg-dark);
    color: var(--text);
}

.story-title {
    font-size: 0.9rem;
    color: var(--text-dim);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 300px;
}

.header-right {
    display: flex;
    gap: 20px;
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
}
.stat-label {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-dim);
}
.stat-value {
    font-family: var(--font-mono);
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text);
}
.err-color {
    color: var(--danger);
}
.warn-color {
    color: #e17055;
}

/* ========== TYPING MODE (Básico / Medio) ========== */
#screen-typing {
    flex-direction: column;
}

.typing-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Story Info Bar */
.story-info-bar {
    flex-shrink: 0;
    padding: 14px 24px;
    background: linear-gradient(135deg, #ffeaa7 0%, #fdcb6e 100%);
    border-bottom: 1px solid #f0c040;
}

.story-info-inner {
    max-width: 900px;
    margin: 0 auto;
}

.story-author {
    font-weight: 700;
    font-size: 0.9rem;
    color: #2d3436;
    margin-bottom: 4px;
}

.story-description {
    font-size: 0.8rem;
    color: #636e72;
    line-height: 1.5;
}

.text-display-wrapper {
    flex: 1;
    overflow-y: auto;
    padding: 32px 40px;
    display: flex;
    justify-content: center;
    background: #fff;
}

.text-display {
    font-family: var(--font-mono);
    font-size: 1.35rem;
    line-height: 2.4;
    max-width: 900px;
    width: 100%;
    letter-spacing: 0.5px;
    word-wrap: break-word;
    user-select: none;
    color: var(--text);
}

/* Character states */
.char {
    position: relative;
    display: inline;
    border-radius: 2px;
    transition: background 0.1s, color 0.1s;
}

.char.pending {
    color: #b2bec3;
}

.char.current {
    color: var(--primary);
    background: rgba(214, 48, 49, 0.08);
    border-bottom: 2px solid var(--primary);
    animation: blink-cursor 1s step-end infinite;
}

@keyframes blink-cursor {
    0%, 100% { border-bottom-color: var(--primary); }
    50% { border-bottom-color: transparent; }
}

.char.correct,
.char.corrected {
    color: var(--success);
}

.char.incorrect {
    color: #fff;
    background: var(--danger);
    border-radius: 3px;
}

.char.space-char.incorrect {
    background: rgba(214, 48, 49, 0.25);
    border-bottom: 2px solid var(--danger);
}

/* Keyboard Hint Bar */
.keyboard-hint-bar {
    flex-shrink: 0;
    padding: 10px 24px;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.key-hint {
    font-family: var(--font-mono);
    font-size: 0.9rem;
    color: var(--text-dim);
    text-align: center;
}

.key-hint .hint-key {
    display: inline-block;
    background: var(--bg-dark);
    color: var(--secondary);
    padding: 2px 10px;
    border-radius: 4px;
    font-weight: 700;
    margin: 0 3px;
    border: 1px solid var(--border);
    box-shadow: 0 2px 0 rgba(0,0,0,0.08);
    font-size: 0.95rem;
}

.key-hint .hint-char {
    color: var(--primary);
    font-weight: 700;
    font-size: 1.1rem;
    margin: 0 2px;
}

/* Hidden input for capturing keystrokes */
.typing-input-zone {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.typing-hidden-input {
    position: absolute;
    top: -9999px;
}

/* Progress Bar */
.progress-bar-container {
    height: 4px;
    background: var(--bg-dark);
    flex-shrink: 0;
}
.progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--accent), var(--primary));
    transition: width 0.3s;
}

/* ========== FALLING WORDS MODE (Avanzado) ========== */
#screen-game {
    flex-direction: column;
}

.game-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}

.falling-words-container {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: linear-gradient(180deg, #ffffff 0%, var(--bg) 100%);
}

.falling-word {
    position: absolute;
    font-family: var(--font-mono);
    font-size: 1.2rem;
    font-weight: 700;
    padding: 6px 16px;
    border-radius: 6px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    white-space: nowrap;
    transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
    z-index: 1;
    user-select: none;
    color: var(--text);
    box-shadow: var(--shadow);
}

.falling-word.highlight {
    border-color: var(--gold);
    box-shadow: 0 0 12px rgba(225, 112, 85, 0.25);
    background: rgba(225, 112, 85, 0.06);
}

.falling-word.correct {
    background: rgba(0, 184, 148, 0.1);
    border-color: var(--success);
    color: var(--success);
    animation: wordCorrect 0.4s ease-out forwards;
}

.falling-word.missed {
    background: rgba(214, 48, 49, 0.1);
    border-color: var(--danger);
    color: var(--danger);
    animation: wordMissed 0.3s ease-out forwards;
}

@keyframes wordCorrect {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.2); }
    100% { transform: scale(0); opacity: 0; }
}

@keyframes wordMissed {
    0% { opacity: 1; }
    100% { opacity: 0; transform: translateY(20px); }
}

.input-zone {
    padding: 16px 24px;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.word-input {
    width: 100%;
    padding: 14px 20px;
    font-family: var(--font-mono);
    font-size: 1.3rem;
    font-weight: 600;
    color: var(--text);
    background: var(--bg);
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    outline: none;
    text-align: center;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.word-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}
.word-input.input-correct {
    border-color: var(--success) !important;
    box-shadow: 0 0 0 3px var(--accent-glow) !important;
}
.word-input.input-wrong {
    border-color: var(--danger) !important;
    box-shadow: 0 0 0 3px var(--primary-glow) !important;
}

/* ========== RESULTS SCREEN ========== */
#screen-results {
    align-items: center;
    justify-content: center;
    background: linear-gradient(180deg, #ffffff 0%, var(--bg) 100%);
}

.results-container {
    text-align: center;
    max-width: 560px;
    width: 100%;
    padding: 20px;
}

.results-header {
    margin-bottom: 28px;
}

.results-emoji {
    font-size: 72px;
    animation: float 3s ease-in-out infinite;
}

.results-header h2 {
    font-size: 2rem;
    font-weight: 900;
    margin-top: 8px;
    color: var(--secondary);
}

.results-story {
    color: var(--text-dim);
    font-size: 0.9rem;
    margin-top: 4px;
}

.results-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 24px;
}

.result-card {
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    padding: 16px 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.result-icon { font-size: 1.4rem; }
.result-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-dim);
}
.result-value {
    font-family: var(--font-mono);
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text);
}

.results-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.penalty-note {
    font-size: 0.8rem;
    color: var(--text-dim);
    margin-top: 6px;
    line-height: 1.5;
}
.penalty-note strong {
    color: var(--danger);
}
.penalty-note .corrected-label {
    color: #e17055;
}

/* ========== RESPONSIVE ========== */
@media (max-width: 640px) {
    .logo-area h1 { font-size: 1.8rem; }
    .level-buttons { flex-direction: column; }
    .header-right { gap: 10px; }
    .stat-value { font-size: 0.9rem; }
    .story-title { max-width: 140px; font-size: 0.75rem; }
    .text-display { font-size: 1.1rem; line-height: 2.2; }
    .text-display-wrapper { padding: 20px 16px; }
    .falling-word { font-size: 1rem; padding: 4px 12px; }
    .word-input { font-size: 1.1rem; }
    .results-grid { grid-template-columns: repeat(2, 1fr); }
}
