﻿:root {
    /* Colors - Dark Theme inspired by reference */
    --bg-primary: #2d2d2d;
    --bg-secondary: #3c3c3c;
    --bg-tertiary: #4a4a4a;

    --text-primary: #e0e0e0;
    --text-secondary: #a0a0a0;
    --text-muted: #666666;

    --accent-primary: #4caf50;
    --accent-secondary: #2196f3;

    --success: #4caf50;
    --error: #f44336;

    --spacing-xs: 0.25rem;
    --spacing-sm: 0.5rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --spacing-xl: 2rem;

    /* Border Radius */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;

    /* Fonts */
    --font-primary: 'IBM Plex Sans Arabic', sans-serif;

    /* RGB Helper Variables for Glassmorphism (Dark) */
    --bg-secondary-rgb: 60, 60, 60;
    --bg-tertiary-rgb: 74, 74, 74;
    --accent-rgb: 76, 175, 80;
    --border-color: #404040;
    --border-color-rgb: 64, 64, 64;
}

/* Light Theme Variables */
:root.light-mode,
body.light-mode {
    --bg-primary: #f5f5f5;
    --bg-secondary: #ffffff;
    --bg-tertiary: #e0e0e0;
    --text-primary: #212121;
    --text-secondary: #616161;
    --text-muted: #9e9e9e;
    --accent-primary: #2e7d32;
    --accent-secondary: #1976d2;

    /* RGB Helper Variables for Glassmorphism (Light) */
    --bg-secondary-rgb: 255, 255, 255;
    --bg-tertiary-rgb: 224, 224, 224;
    --accent-rgb: 46, 125, 50;
    --border-color: #d1d1d6;
    --border-color-rgb: 209, 209, 214;

    /* Keyboard Palette (Colorful Monochrome) */
    --key-zone-pinky: #e1bee7;
    /* Purple 100 */
    --key-zone-ring: #b39ddb;
    /* Deep Purple 200 */
    --key-zone-middle: #90caf9;
    /* Blue 200 */
    --key-zone-index: #80deea;
    /* Cyan 200 */
    --key-zone-center: #80cbc4;
    /* Teal 200 */
    --key-special: #cfd8dc;
    /* Blue Grey 100 */
    --key-space: #b0bec5;
    /* Blue Grey 200 */
    --key-text: #37474f;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-primary);
    height: 100vh;
    overflow-y: auto;
    direction: rtl;
}

.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    max-width: 1200px;
    margin: 0 auto;
    padding: var(--spacing-md);
}

/* Header */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-sm) 0;
    margin-bottom: var(--spacing-md);
    border-bottom: 1px solid var(--bg-tertiary);
}

.logo h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
}

.highlight {
    color: var(--accent-primary);
}

.nav-btn-link {
    text-decoration: none;
    display: flex;
}

.main-nav {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
}

.main-nav button,
.main-nav .nav-btn-link {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 1rem;
    margin: 0 var(--spacing-sm);
    cursor: pointer;
    padding: var(--spacing-xs) var(--spacing-sm);
    transition: color 0.2s;
    text-decoration: none;
    /* Ensure no underline for link */
    display: inline-block;
    /* Ensure it respects padding/margin */
}

.main-nav button:hover,
.main-nav button.active,
.main-nav .nav-btn-link:hover,
.main-nav .nav-btn-link.active {
    color: var(--text-primary);
    border-bottom: 2px solid var(--accent-primary);
}

.user-menu {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    color: var(--text-secondary);
    cursor: pointer;
}

/* Metrics HUD */
.metrics-hud {
    display: flex;
    justify-content: center;
    gap: var(--spacing-lg);
    margin-bottom: 3rem;
    flex-wrap: wrap;
    font-family: monospace;
}

.metric-card {
    display: flex;
    flex-direction: row;
    align-items: baseline;
    gap: var(--spacing-sm);
}

.metric-card .label {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.metric-card .value {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--success);
}

.metric-card .value small {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Key Status Bar */
.key-status-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-md);
}

.key-status-label {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.key-status-bar {
    display: flex;
    gap: 2px;
    background: var(--bg-secondary);
    padding: 4px;
    border-radius: var(--radius-sm);
}

.key-status-item {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    background: var(--bg-tertiary);
    color: var(--text-muted);
    border-radius: 2px;
    transition: all 0.3s;
}

/* Typing Area */
.typing-area-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin-bottom: var(--spacing-md);
    min-height: 150px;
}

.typing-display {
    font-family: 'IBM Plex Sans Arabic', monospace;
    font-size: 2.5rem;
    line-height: 1.6;
    text-align: center;
    color: var(--text-secondary);
    direction: rtl;
}

/* Default state (Future/Pending letters) - Bright White */
.typing-display .char {
    color: #ffffff;
    transition: color 0.2s;
    position: relative;
}

/* Past/Correct letters - Dimmed White */
.typing-display .char.correct {
    color: rgba(255, 255, 255, 0.6);
}

/* Incorrect letters - Red text, no background */
.typing-display .char.incorrect {
    color: var(--error);
    background: transparent;
}

/* Strict Mode: Current char is incorrect (Red override) */
.typing-display .char.current.incorrect {
    color: var(--error) !important;
}

/* Current letter - Blinking Caret */
.typing-display .char.current {
    color: #ffffff;
    border-bottom: none;
}

/* Cursor Styles */
/* Base Cursor Animation */
.typing-display .char.current::before {
    content: '';
    position: absolute;
    background-color: var(--accent-primary);
    animation: blink 1s infinite;
    /* Default to Line if no class present, but specific classes will override */
    right: -2px;
    top: 10%;
    height: 80%;
    width: 2px;
}

/* Line Cursor (Default) */
.typing-display.cursor-line .char.current::before {
    right: -2px;
    top: 10%;
    height: 80%;
    width: 2px;
}

/* Block Cursor */
.typing-display.cursor-block .char.current::before {
    right: 0;
    top: 0;
    width: 100%;
    height: 100%;
    opacity: 0.5;
    z-index: -1;
}

/* Underline Cursor */
.typing-display.cursor-underline .char.current::before {
    right: 0;
    bottom: -2px;
    top: auto;
    width: 100%;
    height: 3px;
}

/* No Cursor */
.typing-display.cursor-none .char.current::before {
    display: none;
}

/* Ghost Cursor */
.typing-display .char.ghost-cursor {
    position: relative;
}

.typing-display .char.ghost-cursor::after {
    content: '';
    position: absolute;
    right: -2px;
    top: 10%;
    height: 80%;
    width: 3px;
    background-color: rgba(57, 255, 20, 0.5);
    /* Semi-transparent neon green */
    box-shadow: 0 0 5px rgba(57, 255, 20, 0.8);
    z-index: -1;
}

/* Light Mode Ghost Cursor Override */
body.light-mode .typing-display .char.ghost-cursor::after {
    background-color: rgba(0, 122, 255, 0.5);
    /* Semi-transparent iOS blue */
    box-shadow: none;
}

@keyframes blink {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0;
    }
}

.current-key-info {
    margin-top: var(--spacing-md);
    color: var(--text-secondary);
    font-size: 1.1rem;
}

/* Keyboard */
.keyboard-container {
    background: var(--bg-secondary);
    padding: var(--spacing-lg);
    border-radius: var(--radius-lg);
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-items: center;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
    direction: ltr;
    width: fit-content;
    position: relative;
    /* Anchor for overlay */
    overflow: hidden;
    /* Ensure overlay doesn't spill out */
}

.keyboard-row {
    display: flex;
    gap: 6px;
    justify-content: center;
}

.key {
    width: 50px;
    height: 50px;
    background: var(--bg-tertiary);
    border-radius: 6px;
    /* Slightly softer radius */
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-primary);
    color: var(--text-primary);
    position: relative;
    transition: all 0.1s cubic-bezier(0.4, 0, 0.2, 1);
    font-size: 1.1rem;
    user-select: none;
    flex-shrink: 0;

    /* 3D Mechanical Look */
    box-shadow:
        0 4px 0 rgba(0, 0, 0, 0.4),
        /* Deep shadow for height */
        0 5px 5px rgba(0, 0, 0, 0.2),
        /* Soft drop shadow */
        inset 0 1px 1px rgba(255, 255, 255, 0.1),
        /* Top highlight */
        inset 0 -1px 0 rgba(0, 0, 0, 0.2);
    /* Bottom lip */

    /* Surface Gradient (Concave feel) */
    background-image: linear-gradient(180deg, rgba(255, 255, 255, 0.05) 0%, rgba(0, 0, 0, 0.1) 100%);
    border: 1px solid rgba(0, 0, 0, 0.3);
}

.key:active,
.key.pressed {
    transform: translateY(4px);
    /* Move down by shadow height */
    box-shadow:
        0 0 0 rgba(0, 0, 0, 0.4),
        /* No shadow height */
        inset 0 2px 4px rgba(0, 0, 0, 0.3);
    /* Inner shadow for pressed feel */
    background-image: linear-gradient(180deg, rgba(0, 0, 0, 0.2) 0%, rgba(0, 0, 0, 0.1) 100%);
}

.key.special-key {
    font-size: 0.8rem;
    background: #333;
}

.key.active {
    border: 1px solid transparent;
    box-shadow: 0 0 20px #39ff14, 0 0 40px rgba(57, 255, 20, 0.4);
    z-index: 10;
}

.key.hit {
    background: var(--success);
    color: white;
}

.key.miss {
    background: var(--error);
    color: white;
}

/* Footer */
.app-footer {
    text-align: center;
    padding-top: var(--spacing-md);
    color: var(--text-muted);
    font-size: 0.8rem;
    border-top: 1px solid var(--bg-tertiary);
    margin-top: var(--spacing-lg);
}

/* Utilities */
.hidden {
    display: none !important;
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background: var(--bg-secondary);
    padding: var(--spacing-xl);
    border-radius: var(--radius-md);
    min-width: 400px;
    color: var(--text-primary);
}

.modal-content h2 {
    margin-bottom: var(--spacing-md);
    border-bottom: 1px solid var(--bg-tertiary);
    padding-bottom: var(--spacing-sm);
}

.modal-content button {
    background: var(--accent-primary);
    color: white;
    border: none;
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: var(--radius-md);
    border-left: 4px solid var(--accent-secondary);
}

/* Global Styled Select (Dropdown) */
select {
    width: 100%;
    padding: 12px 16px;
    padding-left: 40px;
    /* Space for the custom arrow */
    background-color: var(--bg-tertiary);
    background-image: linear-gradient(145deg, var(--bg-tertiary), var(--bg-secondary));
    border: 1px solid rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 1rem;
    cursor: pointer;
    outline: none;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow:
        0 2px 5px rgba(0, 0, 0, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.05);

    /* Custom Arrow (Pure SVG) */
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image:
        url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23a0a0a0' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e"),
        linear-gradient(145deg, var(--bg-tertiary), var(--bg-secondary));
    background-repeat: no-repeat;
    background-position: left 1rem center;
    background-size: 1em, 100%;
}

select:hover {
    border-color: var(--accent-primary);
    background-color: var(--bg-secondary);
    box-shadow:
        0 4px 12px rgba(0, 0, 0, 0.15),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
    transform: translateY(-1px);
}

select:focus {
    border-color: var(--accent-primary);
    box-shadow:
        0 0 0 3px rgba(76, 175, 80, 0.2),
        0 4px 12px rgba(0, 0, 0, 0.2);
    background-color: var(--bg-secondary);
}

/* Light Mode Select Overrides */
body.light-mode select {
    background-color: #ffffff;
    background-image: linear-gradient(180deg, #ffffff, #f9f9f9);
    border-color: #d2d2d7;
    color: #1d1d1f;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    background-image:
        url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23333333' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e"),
        linear-gradient(180deg, #ffffff, #f9f9f9) !important;
}

body.light-mode select:hover {
    background-color: #f5f5f7;
    border-color: var(--accent-primary);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

body.light-mode select:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.1);
}

/* Toggle Switch for Checkboxes */
.modal-body input[type="checkbox"] {
    appearance: none;
    width: 40px;
    height: 22px;
    background: var(--bg-tertiary);
    border-radius: 20px;
    position: relative;
    cursor: pointer;
    outline: none;
    vertical-align: middle;
    transition: background 0.3s;
}

.modal-body input[type="checkbox"]::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.3s;
}

.modal-body input[type="checkbox"]:checked {
    background: var(--accent-primary);
}

.modal-body input[type="checkbox"]:checked::after {
    transform: translateX(18px);
}

/* RTL Adjustment for Toggle */
body[style*="direction: rtl"] .modal-body input[type="checkbox"]::after {
    left: auto;
    right: 2px;
}

body[style*="direction: rtl"] .modal-body input[type="checkbox"]:checked::after {
    transform: translateX(-18px);
}

/* Tips & Warnings */
.shift-tip,
.layout-warning {
    text-align: center;
    margin: var(--spacing-md) auto;
    max-width: 600px;
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: var(--radius-md);
    background: var(--bg-secondary);
    border: 1px solid var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.shift-tip i,
.layout-warning i {
    font-size: 1.1rem;
}

.shift-tip {
    border-left: 4px solid var(--accent-secondary);
}

.layout-warning {
    border-left: 4px solid var(--error);
    color: var(--error);
    background: rgba(244, 67, 54, 0.1);
}

/* Profile Dashboard */
.profile-dashboard {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xl);
    padding: var(--spacing-md);
    max-width: 1000px;
    margin: 0 auto;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: var(--spacing-md);
}

.stat-item {
    background: var(--bg-secondary);
    padding: var(--spacing-md);
    border-radius: var(--radius-md);
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.stat-item .label {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: var(--spacing-xs);
}

.stat-item .value {
    color: var(--accent-primary);
    font-size: 1.4rem;
    font-weight: bold;
}

/* Streaks */
.streaks-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: var(--spacing-md);
}

.streak-card {
    background: var(--bg-secondary);
    padding: var(--spacing-md);
    border-radius: var(--radius-md);
    border-left: 4px solid var(--bg-tertiary);
    transition: transform 0.2s, border-color 0.2s;
}

.streak-card.active-streak {
    border-left-color: var(--accent-primary);
    background: linear-gradient(to right, rgba(76, 175, 80, 0.05), transparent);
}

.streak-header {
    font-weight: bold;
    color: var(--text-primary);
    margin-bottom: var(--spacing-md);
    font-size: 1.1rem;
    border-bottom: 1px solid var(--bg-tertiary);
    padding-bottom: var(--spacing-sm);
}

.streak-body {
    display: flex;
    align-items: center;
    justify-content: space-around;
}

.streak-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.streak-val {
    font-size: 1.8rem;
    font-weight: bold;
    color: var(--text-primary);
}

.active-streak .streak-val {
    color: var(--accent-primary);
}

.streak-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.streak-divider {
    width: 1px;
    height: 40px;
    background: var(--bg-tertiary);
}

/* Charts */
.charts-section {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--spacing-xl);
}

.chart-container h3 {
    color: var(--text-primary);
    margin-bottom: var(--spacing-md);
}

.chart-wrapper {
    background: var(--bg-secondary);
    padding: var(--spacing-md);
    border-radius: var(--radius-md);
    height: 250px;
    width: 100%;
}

.line-chart {
    width: 100%;
    height: 100%;
}

.no-data {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
}

/* Key Speed Chart */
.key-chart-wrapper {
    background: var(--bg-secondary);
    padding: var(--spacing-md);
    border-radius: var(--radius-md);
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
    max-height: 400px;
    overflow-y: auto;
}

.key-stat-row {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
}

.key-char {
    width: 30px;
    font-weight: bold;
    text-align: center;
}

.key-bar-container {
    flex: 1;
    background: var(--bg-tertiary);
    height: 10px;
    border-radius: 5px;
    overflow: hidden;
}

.key-bar {
    height: 100%;
    transition: width 0.5s ease;
}

.key-val {
    width: 60px;
    text-align: right;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* Overlay */
.keyboard-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-secondary);
    /* Dark background behind image */
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: opacity 0.5s ease, visibility 0.5s;
    border-radius: var(--radius-lg);
}

.keyboard-overlay.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.keyboard-overlay img {
    width: 100%;
    height: 100%;
    object-fit: fill;
    /* Stretch to cover the area exactly as requested */
    position: absolute;
    top: 0;
    left: 0;
    opacity: 0.6;
    /* Dim the image slightly so text pops */
    z-index: 1;
}

.settings-group h3 {
    color: var(--text-primary);
    margin-bottom: var(--spacing-md);
    border-bottom: 2px solid var(--bg-tertiary);
    padding-bottom: var(--spacing-xs);
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-md);
    background: var(--bg-secondary);
    padding: var(--spacing-md);
    border-radius: var(--radius-md);
}

.setting-item input[type='checkbox'] {
    width: 20px;
    height: 20px;
    accent-color: var(--accent-primary);
    cursor: pointer;
}



body.light-mode .key {
    box-shadow: 0 4px 0 rgba(0, 0, 0, 0.15), 0 5px 5px rgba(0, 0, 0, 0.1), inset 0 1px 1px rgba(255, 255, 255, 0.8), inset 0 -1px 0 rgba(0, 0, 0, 0.1);
    background-image: linear-gradient(180deg, rgba(255, 255, 255, 0.4) 0%, rgba(255, 255, 255, 0) 100%);
    border: 1px solid rgba(0, 0, 0, 0.1);
    color: var(--key-text);
    background-color: var(--key-bg, #f5f5f5);
    /* Fallback */
}

body.light-mode .key.active {
    border: 1px solid transparent;
    box-shadow: 0 0 20px #39ff14, 0 0 40px rgba(57, 255, 20, 0.4);
    z-index: 10;
}

body.light-mode .typing-display .char {
    color: #bdbdbd;
}

body.light-mode .typing-display .char.correct {
    color: #424242;
}

/* Light Mode Incorrect (Non-Strict / Past) */
body.light-mode .typing-display .char.incorrect {
    color: var(--error);
}

body.light-mode .typing-display .char.current {
    color: #000000;
}

/* Light Mode Strict Error Override */
body.light-mode .typing-display .char.current.incorrect {
    color: var(--error) !important;
}

body.light-mode .typing-display .char.current {
    color: #000000;
}

/* Overlay Text Styling */
.keyboard-overlay-text {
    position: relative;
    z-index: 2;
    color: var(--text-primary);
    font-size: 1rem;
    font-weight: normal;
    text-align: center;
    background: var(--bg-secondary);
    padding: var(--spacing-sm) var(--spacing-lg);
    border-radius: var(--radius-md);
    margin-top: auto;
    /* Push to bottom or center */
    margin-bottom: var(--spacing-xl);
    pointer-events: none;
    border: 1px solid var(--accent-primary);
    border-left: 4px solid var(--accent-primary);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

/* Key Speed Chart */
.key-chart-wrapper {
    background: var(--bg-secondary);
    padding: var(--spacing-md);
    border-radius: var(--radius-md);
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
    max-height: 400px;
    overflow-y: auto;
}

.key-stat-row {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
}

.key-char {
    width: 30px;
    font-weight: bold;
    text-align: center;
}

.key-bar-container {
    flex: 1;
    background: var(--bg-tertiary);
    height: 10px;
    border-radius: 5px;
    overflow: hidden;
}

.key-bar {
    height: 100%;
    transition: width 0.5s ease;
}

.key-val {
    width: 60px;
    text-align: right;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* Overlay */
.keyboard-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-secondary);
    /* Dark background behind image */
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: opacity 0.5s ease, visibility 0.5s;
    border-radius: var(--radius-lg);
}

.keyboard-overlay.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.keyboard-overlay img {
    width: 100%;
    height: 100%;
    object-fit: fill;
    /* Stretch to cover the area exactly as requested */
    position: absolute;
    top: 0;
    left: 0;
    opacity: 0.6;
    /* Dim the image slightly so text pops */
    z-index: 1;
}

.settings-group h3 {
    color: var(--text-primary);
    margin-bottom: var(--spacing-md);
    border-bottom: 2px solid var(--bg-tertiary);
    padding-bottom: var(--spacing-xs);
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-md);
    background: var(--bg-secondary);
    padding: var(--spacing-md);
    border-radius: var(--radius-md);
}

.setting-item input[type='checkbox'] {
    width: 20px;
    height: 20px;
    accent-color: var(--accent-primary);
    cursor: pointer;
}

/* Light Mode Variables */
body.light-mode {
    --bg-primary: #f5f5f5;
    --bg-secondary: #ffffff;
    --bg-tertiary: #e0e0e0;
    --text-primary: #212121;
    --text-secondary: #616161;
    --text-muted: #9e9e9e;
    --accent-primary: #2e7d32;
    --accent-secondary: #1976d2;

    /* Keyboard Palette (Colorful Monochrome) */
    --key-zone-pinky: #e1bee7;
    /* Purple 100 */
    --key-zone-ring: #b39ddb;
    /* Deep Purple 200 */
    --key-zone-middle: #90caf9;
    /* Blue 200 */
    --key-zone-index: #80deea;
    /* Cyan 200 */
    --key-zone-center: #80cbc4;
    /* Teal 200 */
    --key-special: #cfd8dc;
    /* Blue Grey 100 */
    --key-space: #b0bec5;
    /* Blue Grey 200 */
    --key-text: #37474f;
}

body.light-mode .key {
    box-shadow: 0 4px 0 rgba(0, 0, 0, 0.15), 0 5px 5px rgba(0, 0, 0, 0.1), inset 0 1px 1px rgba(255, 255, 255, 0.8), inset 0 -1px 0 rgba(0, 0, 0, 0.1);
    background-image: linear-gradient(180deg, rgba(255, 255, 255, 0.4) 0%, rgba(255, 255, 255, 0) 100%);
    border: 1px solid rgba(0, 0, 0, 0.1);
    color: var(--key-text);
    background-color: var(--key-bg, #f5f5f5);
    /* Fallback */
}

body.light-mode .key.active {
    border: 1px solid transparent;
    box-shadow: 0 0 20px #39ff14, 0 0 40px rgba(57, 255, 20, 0.4);
    z-index: 10;
}

body.light-mode .typing-display .char {
    color: #bdbdbd;
}

body.light-mode .typing-display .char.correct {
    color: #424242;
}

/* Light Mode Incorrect (Non-Strict / Past) */
body.light-mode .typing-display .char.incorrect {
    color: var(--error);
}

body.light-mode .typing-display .char.current {
    color: #000000;
}

/* Light Mode Strict Error Override */
body.light-mode .typing-display .char.current.incorrect {
    color: var(--error) !important;
}

body.light-mode .typing-display .char.current {
    color: #000000;
}

/* Overlay Text Styling */
.keyboard-overlay-text {
    position: relative;
    z-index: 2;
    color: var(--text-primary);
    font-size: 1rem;
    font-weight: normal;
    text-align: center;
    background: var(--bg-secondary);
    padding: var(--spacing-sm) var(--spacing-lg);
    border-radius: var(--radius-md);
    margin-top: auto;
    /* Push to bottom or center */
    margin-bottom: var(--spacing-xl);
    pointer-events: none;
    border: 1px solid var(--accent-primary);
    border-left: 4px solid var(--accent-primary);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.keyboard-overlay-text i {
    color: var(--accent-primary);
}

/* Auth Modal Styles */
.auth-content {
    max-width: 400px;
    width: 90%;
}

.auth-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-lg);
}

.auth-header h2 {
    margin: 0;
    border: none;
    padding: 0;
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-secondary);
    cursor: pointer;
}

.auth-tabs {
    display: flex;
    margin-bottom: var(--spacing-lg);
    border-bottom: 2px solid var(--bg-tertiary);
}

.auth-tab {
    flex: 1;
    background: none;
    border: none;
    padding: var(--spacing-sm);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.3s;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
}

.auth-tab.active {
    color: var(--accent-primary);
    border-bottom-color: var(--accent-primary);
    font-weight: bold;
}

.form-group {
    margin-bottom: var(--spacing-md);
}

.form-group label {
    display: block;
    margin-bottom: var(--spacing-xs);
    color: var(--text-secondary);
}

.form-group input {
    width: 100%;
    padding: var(--spacing-sm);
    background: var(--bg-tertiary);
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 1rem;
}

.form-group input:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.submit-btn {
    width: 100%;
    padding: var(--spacing-md);
    background: var(--accent-primary);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.2s;
    margin-top: var(--spacing-md);
}


.setting-item input[type='checkbox'] {
    width: 20px;
    height: 20px;
    accent-color: var(--accent-primary);
    cursor: pointer;
}

/* Light Mode Variables */
body.light-mode {
    --bg-primary: #f5f5f5;
    --bg-secondary: #ffffff;
    --bg-tertiary: #e0e0e0;
    --text-primary: #212121;
    --text-secondary: #616161;
    --text-muted: #9e9e9e;
    --accent-primary: #2e7d32;
    --accent-secondary: #1976d2;

    /* Keyboard Palette (Colorful Monochrome) */
    --key-zone-pinky: #e1bee7;
    /* Purple 100 */
    --key-zone-ring: #b39ddb;
    /* Deep Purple 200 */
    --key-zone-middle: #90caf9;
    /* Blue 200 */
    --key-zone-index: #80deea;
    /* Cyan 200 */
    --key-zone-center: #80cbc4;
    /* Teal 200 */
    --key-special: #cfd8dc;
    /* Blue Grey 100 */
    --key-space: #b0bec5;
    /* Blue Grey 200 */
    --key-text: #37474f;
}

body.light-mode .key {
    box-shadow: 0 4px 0 rgba(0, 0, 0, 0.15), 0 5px 5px rgba(0, 0, 0, 0.1), inset 0 1px 1px rgba(255, 255, 255, 0.8), inset 0 -1px 0 rgba(0, 0, 0, 0.1);
    background-image: linear-gradient(180deg, rgba(255, 255, 255, 0.4) 0%, rgba(255, 255, 255, 0) 100%);
    border: 1px solid rgba(0, 0, 0, 0.1);
    color: var(--key-text);
    background-color: var(--key-bg, #f5f5f5);
    /* Fallback */
}

body.light-mode .key.active {
    border: 1px solid transparent;
    box-shadow: 0 0 20px #39ff14, 0 0 40px rgba(57, 255, 20, 0.4);
    z-index: 10;
}

body.light-mode .typing-display .char {
    color: #bdbdbd;
}

body.light-mode .typing-display .char.correct {
    color: #424242;
}

/* Light Mode Incorrect (Non-Strict / Past) */
body.light-mode .typing-display .char.incorrect {
    color: var(--error);
}

body.light-mode .typing-display .char.current {
    color: #000000;
}

/* Light Mode Strict Error Override */
body.light-mode .typing-display .char.current.incorrect {
    color: var(--error) !important;
}

body.light-mode .typing-display .char.current {
    color: #000000;
}

/* Ghost Cursor */
.typing-display .char.ghost-cursor {
    background-color: rgba(255, 215, 0, 0.3);
    /* Gold tint */
    border-bottom: 2px solid #FFD700;
    transition: background-color 0.1s;
}

/* Overlay Text Styling */
.keyboard-overlay-text {
    position: relative;
    z-index: 2;
    color: var(--text-primary);
    font-size: 1rem;
    font-weight: normal;
    text-align: center;
    background: var(--bg-secondary);
    padding: var(--spacing-sm) var(--spacing-lg);
    border-radius: var(--radius-md);
    margin-top: auto;
    /* Push to bottom or center */
    margin-bottom: var(--spacing-xl);
    pointer-events: none;
    border: 1px solid var(--accent-primary);
    border-left: 4px solid var(--accent-primary);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.keyboard-overlay-text i {
    color: var(--accent-primary);
}

/* Auth Modal Styles */
.auth-content {
    max-width: 400px;
    width: 90%;
}

.auth-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-lg);
}

.auth-header h2 {
    margin: 0;
    border: none;
    padding: 0;
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-secondary);
    cursor: pointer;
}

.auth-tabs {
    display: flex;
    margin-bottom: var(--spacing-lg);
    border-bottom: 2px solid var(--bg-tertiary);
}

.auth-tab {
    flex: 1;
    background: none;
    border: none;
    padding: var(--spacing-sm);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.3s;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
}

.auth-tab.active {
    color: var(--accent-primary);
    border-bottom-color: var(--accent-primary);
    font-weight: bold;
}

.form-group {
    margin-bottom: var(--spacing-md);
}

.form-group label {
    display: block;
    margin-bottom: var(--spacing-xs);
    color: var(--text-secondary);
}

.form-group input {
    width: 100%;
    padding: var(--spacing-sm);
    background: var(--bg-tertiary);
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 1rem;
}

.form-group input:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.submit-btn {
    width: 100%;
    padding: var(--spacing-md);
    background: var(--accent-primary);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.2s;
    margin-top: var(--spacing-md);
}

.submit-btn:hover {
    background: var(--accent-secondary);
}

.error-message {
    color: var(--error);
    background: rgba(244, 67, 54, 0.1);
    padding: var(--spacing-sm);
    border-radius: var(--radius-sm);
    margin-bottom: var(--spacing-md);
    font-size: 0.9rem;
    text-align: center;
}

/* Social Login */
.auth-divider {
    display: flex;
    align-items: center;
    text-align: center;
    margin: var(--spacing-md) 0;
    color: var(--text-secondary);
}

.auth-divider::before,
.auth-divider::after {
    content: '';
    flex: 1;
    border-bottom: 1px solid var(--bg-tertiary);
}

.auth-divider span {
    padding: 0 10px;
    font-size: 0.9rem;
}

.social-btn {
    width: 100%;
    padding: var(--spacing-md);
    border: none;
    border-radius: var(--radius-md);
    font-size: 1rem;
    cursor: pointer;
    margin-bottom: var(--spacing-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: opacity 0.2s;
    color: white;
}

.social-btn:hover {
    opacity: 0.9;
}

.google-btn {
    background: #db4437;
}

.facebook-btn {
    background: #4267B2;
}

/* Ad Slots Layout (Obfuscated) */
.main-layout {
    display: flex;
    justify-content: center;
    gap: var(--spacing-md);
    width: 100%;
    min-height: 100vh;
}

.layout-sidebar {
    width: 160px;
    min-width: 160px;
    display: none;
    /* Hidden on small screens */
    flex-direction: column;
    padding-top: var(--spacing-xl);
}

.sidebar-content {
    width: 160px;
    height: 600px;
    background: var(--bg-secondary);
    border: 2px dashed var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    border-radius: var(--radius-md);
    font-weight: bold;
    position: sticky;
    top: var(--spacing-md);
}

/* Show ads on large screens */
@media (min-width: 1400px) {
    .layout-sidebar {
        display: flex;
    }

    .app-container {
        max-width: 1600px;
        /* Increased to allow wider blog layout */
        margin: 0;
        /* Let flexbox handle centering */
    }
}

/* Adblock Warning Modal */
.adblock-content {
    text-align: center;
    max-width: 500px;
    border-top: 5px solid var(--error);
}

.adblock-icon {
    font-size: 4rem;
    margin-bottom: var(--spacing-md);
}

.adblock-content h2 {
    margin-bottom: var(--spacing-md);
    color: var(--text-primary);
}

.adblock-content p {
    margin-bottom: var(--spacing-md);
    color: var(--text-secondary);
    line-height: 1.6;
}

.primary-btn {
    background: var(--accent-primary);
    color: white;
    border: none;
    padding: var(--spacing-sm) var(--spacing-xl);
    border-radius: var(--radius-md);
    font-size: 1rem;
    cursor: pointer;
    transition: opacity 0.2s;
}

.primary-btn:hover {
    opacity: 0.9;
}


.secondary-btn {
    background: transparent;
    color: var(--text-primary);
    border: 1px solid var(--text-secondary);
    padding: var(--spacing-sm) var(--spacing-xl);
    border-radius: var(--radius-md);
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s;
}

.secondary-btn:hover {
    background: var(--bg-tertiary);
    border-color: var(--text-primary);
}

/* Footer Links */
.footer-links {
    margin-bottom: var(--spacing-sm);
}

.footer-links a {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.9rem;
    transition: color 0.2s;
}

.footer-links a:hover {
    color: var(--accent-primary);
}

.footer-links .separator {
    margin: 0 var(--spacing-sm);
    color: var(--text-muted);
    opacity: 0.5;
}

/* Cookies Banner */
.cookie-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: var(--bg-secondary);
    border-top: 1px solid var(--bg-tertiary);
    padding: var(--spacing-md);
    z-index: 1000;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.2);
    display: flex;
    justify-content: center;
}

.cookie-content {
    max-width: 1000px;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--spacing-md);
}

.cookie-content p {
    align-items: center;
    text-align: center;
    margin: var(--spacing-md) 0;
    color: var(--text-secondary);
}

.auth-divider::before,
.auth-divider::after {
    content: '';
    flex: 1;
    border-bottom: 1px solid var(--bg-tertiary);
}

.auth-divider span {
    padding: 0 10px;
    font-size: 0.9rem;
}

.social-btn {
    width: 100%;
    padding: var(--spacing-md);
    border: none;
    border-radius: var(--radius-md);
    font-size: 1rem;
    cursor: pointer;
    margin-bottom: var(--spacing-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: opacity 0.2s;
    color: white;
}

.social-btn:hover {
    opacity: 0.9;
}

.google-btn {
    background: #db4437;
}

.facebook-btn {
    background: #4267B2;
}

/* Ad Slots Layout (Obfuscated) */
.main-layout {
    display: flex;
    justify-content: center;
    gap: var(--spacing-md);
    width: 100%;
    min-height: 100vh;
}

.layout-sidebar {
    width: 160px;
    min-width: 160px;
    display: none;
    /* Hidden on small screens */
    flex-direction: column;
    padding-top: var(--spacing-xl);
}

.sidebar-content {
    width: 160px;
    height: 600px;
    background: var(--bg-secondary);
    border: 2px dashed var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    border-radius: var(--radius-md);
    font-weight: bold;
    position: sticky;
    top: var(--spacing-md);
}

/* Show ads on large screens */
@media (min-width: 1400px) {
    .layout-sidebar {
        display: flex;
    }

    .app-container {
        max-width: 1600px;
        /* Increased to allow wider blog layout */
        margin: 0;
        /* Let flexbox handle centering */
    }
}

/* Adblock Warning Modal */
.adblock-content {
    text-align: center;
    max-width: 500px;
    border-top: 5px solid var(--error);
}

.adblock-icon {
    font-size: 4rem;
    margin-bottom: var(--spacing-md);
}

.adblock-content h2 {
    margin-bottom: var(--spacing-md);
    color: var(--text-primary);
}

.adblock-content p {
    margin-bottom: var(--spacing-md);
    color: var(--text-secondary);
    line-height: 1.6;
}

.primary-btn {
    background: var(--accent-primary);
    color: white;
    border: none;
    padding: var(--spacing-sm) var(--spacing-xl);
    border-radius: var(--radius-md);
    font-size: 1rem;
    cursor: pointer;
    transition: opacity 0.2s;
}

.primary-btn:hover {
    opacity: 0.9;
}

/* Footer Links */
.footer-links {
    margin-bottom: var(--spacing-sm);
}

.footer-links a {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.9rem;
    transition: color 0.2s;
}

.footer-links a:hover {
    color: var(--accent-primary);
}

.footer-links .separator {
    margin: 0 var(--spacing-sm);
    color: var(--text-muted);
    opacity: 0.5;
}

/* Cookies Banner */
.cookie-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: var(--bg-secondary);
    border-top: 1px solid var(--bg-tertiary);
    padding: var(--spacing-md);
    z-index: 1000;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.2);
    display: flex;
    justify-content: center;
}

.cookie-content {
    max-width: 1000px;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--spacing-md);
}

.cookie-content p {
    margin: 0;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.cookie-actions {
    display: flex;
    gap: var(--spacing-sm);
    align-items: center;
}

.cookie-actions .primary-btn.small.pulse {
    padding: 0.6rem 2rem;
    font-size: 0.95rem;
    font-weight: 600;
    box-shadow: 0 0 0 0 rgba(var(--accent-rgb), 0.7);
    animation: pulse-button 2s infinite;
}

.cookie-actions .secondary-btn.small.ghost {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 0.85rem;
    text-decoration: underline;
    padding: 0.5rem;
    cursor: pointer;
    opacity: 0.7;
    transition: opacity 0.2s, color 0.2s;
}

.cookie-actions .secondary-btn.small.ghost:hover {
    opacity: 1;
    color: var(--text-secondary);
    background: transparent;
}

@keyframes pulse-button {
    0% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(var(--accent-rgb), 0.7);
    }

    70% {
        transform: scale(1.05);
        box-shadow: 0 0 0 10px rgba(var(--accent-rgb), 0);
    }

    100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(var(--accent-rgb), 0);
    }
}

@media (max-width: 768px) {
    .cookie-content {
        flex-direction: column;
        text-align: center;
    }
}

/* Utility Classes */
.hidden {
    display: none !important;
}

/* --- Gamification & Notifications --- */

/* Notifications */
.notification-container {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: none;
}

.toast {
    background: var(--bg-secondary);
    color: var(--text-primary);
    padding: 1rem 1.5rem;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    border-right: 4px solid var(--primary);
    transform: translateY(20px);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    pointer-events: auto;
    min-width: 300px;
    text-align: center;
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}

.toast-success {
    border-color: var(--accent-secondary);
}

.toast-info {
    border-color: var(--primary);
}

/* Gamification Header in Profile */
.gamification-header {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-bottom: 2rem;
}

@media (max-width: 768px) {
    .gamification-header {
        grid-template-columns: 1fr;
    }
}

/* Level Card */
.level-card {
    background: var(--bg-secondary);
    padding: 1.5rem;
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 1.5rem;
    border: 1px solid var(--bg-tertiary);
}

.level-icon {
    font-size: 3.5rem;
    background: var(--bg-primary);
    width: 80px;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.level-info {
    flex: 1;
}

.level-label {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 0.2rem;
}

.level-title {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 0.8rem;
}

.level-progress-container {
    background: var(--bg-primary);
    height: 8px;
    border-radius: 4px;
    overflow: hidden;
    position: relative;
}

.level-progress-bar {
    background: linear-gradient(45deg,
            #2ecc71 25%,
            #27ae60 25%,
            #27ae60 50%,
            #2ecc71 50%,
            #2ecc71 75%,
            #27ae60 75%,
            #27ae60 100%);
    background-size: 20px 20px;
    height: 100%;
    width: 0%;
    transition: width 0.5s ease-out;
    animation: progress-stripes 1s linear infinite;
    box-shadow: 0 0 10px rgba(46, 204, 113, 0.5);
    /* Glow */
}

@keyframes progress-stripes {
    0% {
        background-position: 0 0;
    }

    100% {
        background-position: 20px 0;
    }
}

/* Badges Preview */
.badges-preview {
    background: var(--bg-secondary);
    padding: 1.5rem;
    border-radius: 12px;
    border: 1px solid var(--bg-tertiary);
}

.badges-preview h3 {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.dot.weak {
    background: hsl(0, 75%, 45%);
}

.dot.avg {
    background: hsl(60, 75%, 45%);
}

.dot.good {
    background: hsl(120, 75%, 45%);
}

/* Insights Panel */
.heatmap-insights h3 {
    margin-bottom: var(--spacing-lg);
    color: var(--text-primary);
    font-size: 1.2rem;
}

.insights-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--spacing-md);
}

.insight-card {
    background: var(--bg-primary);
    padding: var(--spacing-md);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    border-left: 4px solid transparent;
    transition: transform 0.2s;
}

.insight-card:hover {
    transform: translateX(-5px);
}

.insight-card.success {
    border-left-color: var(--success);
}

.insight-card.danger {
    border-left-color: var(--error);
}

.insight-card.warning {
    border-left-color: #ff9800;
}

.insight-icon {
    font-size: 1.5rem;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
    border-radius: 50%;
}

.insight-info {
    display: flex;
    flex-direction: column;
}

.insight-info .label {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.insight-info .value {
    font-weight: bold;
    font-size: 1.1rem;
    color: var(--text-primary);
}

.insight-info .value small {
    font-size: 0.8rem;
    font-weight: normal;
    color: var(--text-muted);
    margin-right: 4px;
}

/* --- Restored Styles --- */

/* Badges Preview */
.badges-preview {
    background: var(--bg-secondary);
    padding: 1.5rem;
    border-radius: 12px;
    border: 1px solid var(--bg-tertiary);
}

.badges-preview h3 {
    margin-bottom: 1rem;
    font-size: 1.1rem;
    color: var(--text-secondary);
}

.badges-grid-mini {
    display: flex;
    gap: 0.8rem;
    flex-wrap: wrap;
}

.badge-item {
    width: 50px;
    height: 50px;
    background: var(--bg-primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    transition: transform 0.2s, filter 0.2s;
    cursor: help;
    border: 2px solid transparent;
}

.badge-item.locked {
    filter: grayscale(100%) opacity(0.4);
}

.badge-item.unlocked {
    border-color: var(--accent-secondary);
    box-shadow: 0 0 10px rgba(var(--accent-secondary-rgb), 0.3);
}

.badge-item:hover {
    transform: scale(1.1);
}

/* Heatmap Analytics Dashboard */
.heatmap-section {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: var(--spacing-lg);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}

.heatmap-grid {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xl);
}

/* Visual Heatmap Container */
.heatmap-visual {
    background: linear-gradient(145deg, var(--bg-tertiary), var(--bg-secondary));
    border-radius: var(--radius-md);
    padding: var(--spacing-lg);
    position: relative;
    overflow: hidden;
    box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.heatmap-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-lg);
}

.heatmap-controls {
    display: flex;
    background: var(--bg-primary);
    padding: 4px;
    border-radius: 8px;
    gap: 4px;
}

.heatmap-controls .secondary-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 6px 16px;
    font-size: 0.85rem;
    border-radius: 6px;
    transition: all 0.2s ease;
}

.heatmap-controls .secondary-btn:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}

.heatmap-controls .secondary-btn.active {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.scaled-keyboard {
    transform: scale(0.85);
    transform-origin: top center;
    margin-bottom: -30px;
    width: 100%;
}

/* Legend */
.heatmap-legend {
    display: flex;
    justify-content: center;
    gap: var(--spacing-lg);
    margin-top: var(--spacing-md);
    padding-top: var(--spacing-md);
    border-top: 1px solid rgba(0, 0, 0, 0.1);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.dot.weak {
    background: hsl(0, 75%, 45%);
}

.dot.avg {
    background: hsl(60, 75%, 45%);
}

.dot.good {
    background: hsl(120, 75%, 45%);
}

/* RESPONSIVE LAYOUT FIXES */
@media (max-width: 1200px) {
    .main-layout {
        display: block;
        /* Stack or block instead of grid/flex to fill width */
        padding: 0;
    }

    .layout-sidebar {
        display: none !important;
    }

    .app-container {
        max-width: 100%;
        padding: var(--spacing-sm);
        margin: 0;
    }

    /* Creative Nav Icon Animation */
    .wiggle-rat {
        display: inline-block;
        animation: wiggle 2s linear infinite;
    }

    .blog-container {
        grid-template-columns: 1fr;
        padding: 1.5rem;
        margin: 1rem;
    }

    .blog-toc {
        display: none;
    }

    .blog-header h1 {
        font-size: 2rem;
    }

    /* Ensure tables scroll on small screens */
    .mapping-table-wrapper,
    .data-table-wrapper {
        overflow-x: auto;
        max-width: 100%;
    }
}

@keyframes wiggle {

    0%,
    100% {
        transform: rotate(0deg);
    }

    25% {
        transform: rotate(-10deg);
    }

    75% {
        transform: rotate(10deg);
    }
}

/* --- Race Mode Enhancements --- */
.race-room {
    position: relative;
    transition: all 0.3s ease;
}

.finish-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(18, 18, 18, 0.85);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    border-radius: var(--radius-lg);
    animation: fadeIn 0.4s ease-out;
}

.finish-banner {
    text-align: center;
    background: var(--bg-primary);
    padding: 2.5rem;
    border-radius: var(--radius-xl);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
    border: 1px solid var(--accent-primary);
    transform: translateY(20px);
    opacity: 0;
    animation: slideUpFade 0.5s ease-out forwards;
}

.finish-emoji {
    font-size: 3.5rem;
    display: block;
    margin-bottom: 1rem;
}

.finish-banner h2 {
    color: var(--accent-primary);
    margin-bottom: 0.5rem;
    font-size: 2rem;
}

.finish-banner p {
    color: var(--text-secondary);
}

@keyframes slideUpFade {
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.race-concluding .typing-display {
    opacity: 0.6;
    pointer-events: none;
    filter: grayscale(0.5);
}

.concluding-results .race-results {
    background: none;
    padding: 0;
    box-shadow: none;
    border: none;
}

/* UI Feedback: Particles */
.particle {
    position: absolute;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    pointer-events: none;
    z-index: 10000;
}

.particle.spark {
    width: 4px;
    height: 4px;
}

.particle.burst {
    width: 8px;
    height: 8px;
    filter: blur(1px);
}

/* Interactive Widgets */
.interactive-widget {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 2rem;
    margin: 2rem 0;
    text-align: center;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.interactive-widget h3 {
    color: var(--accent-primary);
    margin-top: 0;
    margin-bottom: 1rem;
}

.widget-controls {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin: 1.5rem 0;
}

.widget-controls input {
    padding: 0.5rem 1rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    width: 120px;
    text-align: center;
    font-size: 1.1rem;
}

.speed-result {
    font-size: 1.2rem;
    font-weight: 600;
    min-height: 2rem;
    transition: all 0.3s;
}

.speed-result.novice {
    color: var(--text-secondary);
}

.speed-result.average {
    color: #2196f3;
}

.speed-result.good {
    color: #4caf50;
}

.speed-result.pro {
    color: #ff9800;
}

.speed-result.expert {
    color: #9c27b0;
}

.speed-result.error {
    color: var(--error);
}

.speed-emoji {
    font-size: 1.5rem;
    margin-left: 0.5rem;
}

/* Home Row Challenge */
.challenge-box {
    background: var(--bg-tertiary);
    padding: 1.5rem;
    border-radius: var(--radius-md);
    margin-top: 1rem;
    border: 1px solid var(--border-color);
}

.target-text {
    font-size: 2rem;
    font-family: monospace;
    margin-bottom: 1rem;
    letter-spacing: 2px;
    color: var(--text-primary);
}

.challenge-box input {
    width: 100%;
    max-width: 300px;
    padding: 0.8rem;
    font-size: 1.2rem;
    text-align: center;
    border-radius: var(--radius-md);
    border: 2px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-primary);
    margin-bottom: 1rem;
    font-family: inherit;
}

.challenge-box input.success-input {
    border-color: var(--success);
    color: var(--success);
    background: rgba(76, 175, 80, 0.1);
}

.homerow-feedback {
    font-weight: bold;
    min-height: 1.5rem;
}

.homerow-feedback.success {
    color: var(--success);
}

.homerow-feedback.error {
    color: var(--error);
}

/* Reading Progress Bar */
.reading-progress-bar {
    position: fixed;
    top: 0;
    left: 0;
    width: 0%;
    height: 4px;
    background: var(--accent-primary);
    z-index: 9999;
    transition: width 0.1s;
    box-shadow: 0 0 10px var(--accent-primary);
}


/* Speed Test Styles */
.word-display {
    font-size: 2rem;
    margin: 1rem 0;
    min-height: 3rem;
    color: var(--text-primary);
    direction: rtl;
}

.word-display .current {
    color: var(--accent-primary);
    border-bottom: 2px solid var(--accent-primary);
}

.word-display .pending {
    color: var(--text-secondary);
    opacity: 0.6;
}

.word-display .done-correct {
    color: var(--success);
}

.word-display .done-error {
    color: var(--error);
    text-decoration: line-through;
}

.keyboard-preview .key {
    transition: all 0.1s;
}

.keyboard-preview .key.active {
    background: var(--accent-primary) !important;
    color: white !important;
    transform: translateY(2px);
}


/* Scroll Animations */
.fade-in-up {
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 0.8s cubic-bezier(0.5, 0, 0, 1), transform 0.8s cubic-bezier(0.5, 0, 0, 1);
}

.fade-in-up.aos-animate {
    opacity: 1;
    transform: translateY(0);
}

/* Staggered delays for children if needed */
.fade-in-up.delay-100 {
    transition-delay: 0.1s;
}

.fade-in-up.delay-200 {
    transition-delay: 0.2s;
}

/* Enhanced Section Styling */
.blog-content section {
    margin-bottom: 5rem;
}


/* Blog Animations & Refinements */
.animate-on-scroll {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.6s ease-out, transform 0.6s ease-out;
    will-change: opacity, transform;
}

.animate-on-scroll.is-visible {
    opacity: 1;
    transform: translateY(0);
}

.delay-1 {
    transition-delay: 0.1s;
}

.delay-2 {
    transition-delay: 0.2s;
}

.blog-hero {
    text-align: center;
    padding: 3rem 1rem;
    background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-tertiary) 100%);
    border-radius: 16px;
    margin-bottom: 3rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}

.blog-hero h1 {
    font-size: 2.5rem;
    color: var(--primary);
    margin-bottom: 1rem;
}

.tip-box.important-note {
    background: rgba(33, 150, 243, 0.08);
    /* Light Blue Tint */
    border-right: 4px solid #2196f3;
    padding: 1.5rem;
    border-radius: 8px;
    display: flex;
    gap: 1.5rem;
    align-items: flex-start;
    margin: 2rem 0;
}

.tip-box .icon {
    font-size: 2.5rem;
}

.card-3d {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 2rem;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.05), 0 6px 6px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    border: 1px solid var(--bg-tertiary);
}

.card-3d:hover {
    transform: translateY(-5px);
    box-shadow: 0 15px 30px rgba(0, 0, 0, 0.1), 0 10px 10px rgba(0, 0, 0, 0.08);
}

.pulse-btn {
    animation: pulse-soft 2s infinite;
}

@keyframes pulse-soft {
    0% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(76, 175, 80, 0.4);
    }

    70% {
        transform: scale(1.02);
        box-shadow: 0 0 0 10px rgba(76, 175, 80, 0);
    }

    100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(76, 175, 80, 0);
    }
}

.advanced-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
    margin-top: 1.5rem;
}

.info-card {
    background: var(--bg-secondary);
    padding: 1.5rem;
    border-radius: 8px;
    border: 1px solid var(--bg-tertiary);
}


/* Fallback: If JS fails (no is-visible class), show content after 3s delay as safety net, 
   OR rely on JS adding a 'js-loaded' class to body? 
   Better: Default to visible, JS adds .animate-on-scroll which sets opacity 0? 
   No, let's just make sure the keyframes are robust.
*/
.animate-on-scroll {
    opacity: 0;
    /* Safety net: If JS crashes, force visible after delay? No, that requires animation.
       Let's stick to fixing the JS. */
}


/* Ensure visibility class works regardless of specificity */
.animate-on-scroll.is-visible {
    opacity: 1 !important;
    transform: translateY(0) !important;
}

/* --- Blog Specific Styles (Restored) --- */
.blog-header {
    text-align: center;
    padding: 4rem 1rem 2rem;
    background: linear-gradient(180deg, var(--bg-secondary) 0%, var(--bg-primary) 100%);
    border-bottom: 1px solid var(--bg-tertiary);
    margin-bottom: 2rem;
}

.blog-hero-img {
    max-width: 100%;
    border-radius: var(--radius-lg);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    margin-top: 2rem;
    border: 1px solid var(--bg-tertiary);
}

.blog-layout-img {
    width: 100%;
    border-radius: var(--radius-md);
    border: 2px solid var(--accent-primary);
    box-shadow: 0 0 15px rgba(76, 175, 80, 0.2);
    margin: 1.5rem 0;
    transition: transform 0.3s;
}

.blog-layout-img:hover {
    transform: scale(1.02);
}

.text-key {
    display: inline-block;
    padding: 0.1rem 0.5rem;
    margin: 0 0.1rem;
    background: #3a3a3a;
    border: 1px solid #555;
    border-radius: 4px;
    box-shadow: 0 2px 0 #222;
    font-family: inherit;
    font-weight: bold;
    color: #fff;
    font-size: 0.9em;
    transform: translateY(-1px);
}

/* Typography Hierarchy */
.blog-article {
    font-size: 1.1rem;
    line-height: 1.8;
    color: #e0e0e0;
}

.blog-article p {
    margin-bottom: 2rem;
}

.blog-article h2 {
    font-size: 2rem;
    color: #ffffff !important;
    margin-top: 3.5rem;
    margin-bottom: 1.5rem;
    font-weight: 700;
}

.blog-article h3 {
    font-size: 1.4rem;
    color: var(--accent-primary);
    margin-top: 2.5rem;
    margin-bottom: 1rem;
    font-weight: 600;
}

/* Finger Distribution Matrix Table */
.finger-matrix-container {
    margin: 2.5rem 0;
    overflow-x: auto;
    background: rgba(255, 255, 255, 0.02);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    border: 1px solid var(--bg-tertiary);
}

.finger-matrix {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0.5rem;
    min-width: 600px;
}

.finger-matrix th {
    color: var(--accent-primary);
    font-weight: bold;
    padding: 0.75rem;
    text-align: center;
    border-bottom: 2px solid var(--bg-tertiary);
    font-size: 1.1rem;
}

.finger-matrix td {
    padding: 0.75rem;
    background: rgba(30, 30, 30, 0.6);
    border-radius: var(--radius-sm);
    text-align: center;
    border: 1px solid var(--bg-tertiary);
    vertical-align: middle;
}

/* First Column (Row Labels) */
.finger-matrix td:first-child {
    font-weight: bold;
    color: var(--text-secondary);
    background: transparent;
    border: none;
    text-align: right;
    width: 120px;
}

/* Key Badges in Matrix */
.finger-matrix .key-badge {
    display: inline-block;
    padding: 2px 6px;
    margin: 2px;
    background: #333;
    border: 1px solid #555;
    border-radius: 4px;
    color: #fff;
    font-family: inherit;
    font-size: 0.9rem;
    box-shadow: 0 2px 0 #222;
}

/* Movement List */
.movement-list {
    list-style: none;
    padding: 0;
    margin: 2rem 0;
}

.movement-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
    font-size: 1rem;
    flex-wrap: wrap;
}

.movement-icon {
    color: var(--accent-primary);
}

/* Interactive Widget Override */
.interactive-widget {
    background: var(--bg-secondary);
    border: 1px solid var(--bg-tertiary);
    border-radius: 12px;
    padding: 2rem;
    margin: 2rem 0;
    text-align: center;
}

.widget-title {
    color: var(--primary);
    margin-bottom: 1rem;
}

/* Interactive Widgets Styles */
.reading-progress-bar {
    position: fixed;
    top: 0;
    left: 0;
    height: 4px;
    background: var(--primary);
    width: 0%;
    z-index: 9999;
    transition: width 0.1s ease;
    box-shadow: 0 0 10px var(--primary);
}

.speed-test-area,
.homerow-input-area {
    margin-top: 1.5rem;
    background: rgba(var(--bg-tertiary-rgb), 0.3);
    padding: 1.5rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

.word-display {
    font-size: 1.5rem;
    margin-bottom: 1rem;
    min-height: 2em;
    line-height: 1.6;
    direction: rtl;
}

.word-display span {
    display: inline-block;
    padding: 0 5px;
    border-radius: 4px;
}

.word-display span.current {
    background: rgba(var(--primary-rgb), 0.2);
    border-bottom: 2px solid var(--primary);
}

.word-display span.correct {
    color: var(--success);
}

.word-display span.error {
    color: var(--error);
    text-decoration: line-through;
}

.speed-input,
.homerow-input {
    width: 100%;
    padding: 1rem;
    font-size: 1.2rem;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-input);
    color: var(--text-primary);
    font-family: inherit;
    transition: border-color 0.3s ease;
}

.speed-input:focus,
.homerow-input:focus {
    border-color: var(--primary);
    outline: none;
    box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.2);
}

.speed-result {
    margin-top: 1rem;
    font-weight: bold;
    font-size: 1.2rem;
    color: var(--accent-primary);
    min-height: 1.5em;
}

.homerow-feedback {
    margin-top: 1rem;
    min-height: 1.5rem;
    font-weight: bold;
}

.homerow-feedback.success {
    color: var(--success);
}

.homerow-feedback.error {
    color: var(--error);
}

.hidden {
    display: none !important;
}