/* ==========================================================================
   KEY-IN: TYPING TUTOR STYLESHEET
   Aesthetics: Ultra-premium Dark Mode, Glassmorphism, Neon/Glow Accents, Responsive Keyboard
   ========================================================================== */

/* DESIGN TOKENS & SYSTEM VARIABLES */
:root {
    --bg-main: #090c15;
    --bg-card: rgba(17, 24, 39, 0.7);
    --bg-input: rgba(31, 41, 55, 0.5);

    --border-color: rgba(255, 255, 255, 0.08);
    --border-hover: rgba(255, 255, 255, 0.15);

    /* Neon accents */
    --accent-primary: #8b5cf6;
    /* Violet */
    --accent-secondary: #06b6d4;
    /* Cyan */
    --accent-success: #10b981;
    /* Emerald */
    --accent-error: #ef4444;
    /* Red */
    --accent-warning: #f59e0b;
    /* Amber */

    /* Text colors */
    --text-primary: #f3f4f6;
    --text-secondary: #9ca3af;
    --text-muted: #4b5563;

    /* Fonts */
    --font-ui: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;

    /* Transitions */
    --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-normal: 0.3s cubic-bezier(0.4, 0, 0.2, 1);

    /* Finger mapping colors - Touch Typing */
    --finger-l-pinky: #ec4899;
    /* Pink */
    --finger-l-ring: #d946ef;
    /* Fuchsia */
    --finger-l-middle: #8b5cf6;
    /* Violet */
    --finger-l-index: #3b82f6;
    /* Blue */
    --finger-r-index: #06b6d4;
    /* Cyan */
    --finger-r-middle: #14b8a6;
    /* Teal */
    --finger-r-ring: #10b981;
    /* Emerald */
    --finger-r-pinky: #f59e0b;
    /* Amber */
    --finger-thumb: #6b7280;
    /* Slate */
}

/* RESET & BASE STYLES */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-main);
    background-image:
        radial-gradient(circle at 10% 20%, rgba(139, 92, 246, 0.15) 0%, transparent 40%),
        radial-gradient(circle at 90% 80%, rgba(6, 182, 212, 0.15) 0%, transparent 40%);
    color: var(--text-primary);
    font-family: var(--font-ui);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 24px 16px;
    overflow-x: hidden;
}

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

::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
}

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

::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* APP CONTAINER */
.app-container {
    width: 100%;
    max-width: 1150px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* LAYOUT WRAPPER (THREE-COLUMN GRID) */
.layout-wrapper {
    display: grid;
    grid-template-columns: 220px 1fr 240px;
    /* reduced left sidebar width */
    gap: 20px;
    align-items: start;
    width: 100%;
}

/* LEFT SIDEBAR */
.app-sidebar {
    display: flex;
    flex-direction: column;
    gap: 20px;
    position: sticky;
    top: 24px;
}

/* RIGHT SIDEBAR (RULES GUIDE) */
.app-rules-sidebar {
    position: sticky;
    top: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    max-height: calc(100vh - 48px);
    overflow-y: auto;
    scrollbar-width: thin;
}

.app-rules-sidebar .rules-guide {
    padding: 16px;
}

.app-rules-sidebar .rules-guide h2 {
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--accent-primary);
    margin-bottom: 14px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 8px;
}

.app-rules-sidebar .rules-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.app-rules-sidebar .rule-card {
    padding: 12px;
}

.app-rules-sidebar .rule-card h3 {
    font-size: 11px;
    margin-bottom: 8px;
}

.app-rules-sidebar .rule-table {
    font-size: 11px;
}

.app-rules-sidebar .rule-table th,
.app-rules-sidebar .rule-table td {
    padding: 5px 6px;
}

.app-rules-sidebar .rule-table td strong {
    font-size: 11px;
    padding: 1px 4px;
}

/* SETTINGS PANEL */
.settings-panel {
    background: var(--bg-card);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 20px;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.settings-panel h3 {
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--accent-primary);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 8px;
    margin-bottom: 4px;
}

.control-group-vertical {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.control-group-vertical .control-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.icon-buttons-sidebar {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.icon-buttons-sidebar .icon-btn {
    width: 100%;
    height: auto;
    padding: 10px 16px;
    justify-content: flex-start;
    gap: 10px;
}

.icon-buttons-sidebar .icon-btn span {
    font-size: 13px;
    font-weight: 600;
}

.w-full {
    width: 100%;
}

/* ==========================================================================
   HEADER & CONTROL BAR
   ========================================================================== */
.app-header {
    background: var(--bg-card);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 16px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    width: 32px;
    height: 32px;
    color: var(--accent-primary);
    filter: drop-shadow(0 0 8px rgba(139, 92, 246, 0.5));
}

.logo-text h1 {
    font-size: 20px;
    font-weight: 800;
    letter-spacing: -0.5px;
    background: linear-gradient(135deg, var(--text-primary) 30%, #a78bfa 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.logo-text span {
    font-size: 11px;
    color: var(--text-secondary);
    display: block;
    margin-top: -2px;
}

.settings-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 20px;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.control-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* STYLED SELECT */
.styled-select {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 8px 16px;
    border-radius: 8px;
    font-family: var(--font-ui);
    font-size: 14px;
    font-weight: 500;
    outline: none;
    cursor: pointer;
    transition: var(--transition-fast);
}

.styled-select:hover {
    border-color: var(--border-hover);
    background: rgba(55, 65, 81, 0.6);
}

.styled-select:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.2);
}

/* BUTTONS */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-family: var(--font-ui);
    font-size: 14px;
    font-weight: 600;
    padding: 8px 16px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    transition: var(--transition-fast);
    outline: none;
}

.btn-icon {
    width: 16px;
    height: 16px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent-primary) 0%, #7c3aed 100%);
    color: white;
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(139, 92, 246, 0.4);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    border-color: var(--border-hover);
    background: rgba(55, 65, 81, 0.6);
    color: white;
}

.icon-buttons {
    display: flex;
    gap: 8px;
}

.icon-btn {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    width: 38px;
    height: 38px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition-fast);
}

.icon-btn svg {
    width: 18px;
    height: 18px;
}

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

.icon-btn.active {
    background: rgba(139, 92, 246, 0.15);
    border-color: rgba(139, 92, 246, 0.4);
    color: var(--accent-primary);
}

.hidden {
    display: none !important;
}

/* TOGGLE SWITCH STYLE (Telex / VNI) */
.toggle-switch-container {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-input);
    padding: 4px 8px;
    border-radius: 20px;
    border: 1px solid var(--border-color);
}

.toggle-option-label {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    transition: var(--transition-fast);
}

.toggle-option-label.active {
    color: var(--text-primary);
}

.switch {
    position: relative;
    display: inline-block;
    width: 36px;
    height: 20px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--text-muted);
    transition: .3s;
}

.slider:before {
    position: absolute;
    content: "";
    height: 14px;
    width: 14px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .3s;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

input:checked+.slider {
    background-color: var(--accent-secondary);
}

input:focus+.slider {
    box-shadow: 0 0 1px var(--accent-secondary);
}

input:checked+.slider:before {
    transform: translateX(16px);
}

.slider.round {
    border-radius: 20px;
}

.slider.round:before {
    border-radius: 50%;
}

/* ==========================================================================
   STATISTICS DASHBOARD
   ========================================================================== */
.stats-board {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.stat-card {
    background: var(--bg-card);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 16px;
    text-align: center;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.15);
    transition: transform var(--transition-fast);
}

.stat-card:hover {
    transform: translateY(-2px);
    border-color: var(--border-hover);
}

.stat-value {
    font-family: var(--font-mono);
    font-size: 28px;
    font-weight: 700;
    color: var(--accent-secondary);
    text-shadow: 0 0 10px rgba(6, 182, 212, 0.3);
    margin-bottom: 4px;
}

.stat-label {
    font-size: 12px;
    color: var(--text-secondary);
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.5px;
}

/* ==========================================================================
   TYPING PRACTICE CARD & EDITOR
   ========================================================================== */
.typing-section {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.ime-alert {
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid rgba(245, 158, 11, 0.3);
    color: #fbd38d;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 10px;
    line-height: 1.5;
}

.alert-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.practice-card {
    position: relative;
    background: var(--bg-card);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 32px;
    box-shadow: 0 12px 40px 0 rgba(0, 0, 0, 0.25);
    overflow: hidden;
}

/* Text Display & Typing Styling */
.text-display {
    font-family: var(--font-mono);
    font-size: 20px;
    line-height: 1.8;
    color: var(--text-secondary);
    white-space: pre-wrap;
    word-break: break-word;
    user-select: none;
    min-height: 120px;
    margin-bottom: 24px;
    letter-spacing: 0.5px;
}

/* Letters states */
.letter {
    position: relative;
    transition: color var(--transition-fast), background-color var(--transition-fast);
}

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

.letter.incorrect {
    color: var(--accent-error);
    background-color: rgba(239, 68, 68, 0.15);
    border-bottom: 2px solid var(--accent-error);
}

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

/* BLINKING CURSOR */
.cursor {
    position: absolute;
    left: 0;
    bottom: -2px;
    width: 2px;
    height: 100%;
    background-color: var(--accent-primary);
    animation: blink 1s infinite;
}

@keyframes blink {

    0%,
    100% {
        opacity: 0;
    }

    50% {
        opacity: 1;
    }
}

/* GUIDE BAR (TELEX/VNI phím gợi ý) */
.guide-bar {
    border-top: 1px dashed var(--border-color);
    padding-top: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}

.guide-word-preview {
    font-size: 14px;
    color: var(--text-secondary);
}

.highlight-word {
    font-family: var(--font-mono);
    font-weight: 700;
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
    padding: 2px 8px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
}

.guide-keystrokes {
    font-size: 14px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.sequence-list {
    display: inline-flex;
    gap: 4px;
}

.key-badge {
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: 12px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    padding: 2px 6px;
    border-radius: 4px;
    color: var(--accent-secondary);
    min-width: 20px;
    text-align: center;
}

.key-badge.current-hint {
    background: rgba(6, 182, 212, 0.2);
    border-color: var(--accent-secondary);
    color: white;
    box-shadow: 0 0 8px rgba(6, 182, 212, 0.4);
    animation: pulseHint 1s infinite alternate;
}

@keyframes pulseHint {
    0% {
        transform: scale(1);
    }

    100% {
        transform: scale(1.1);
    }
}

/* HIDDEN KEYBOARD CAPTURE FIELD */
.keyboard-capture {
    position: absolute;
    top: -100px;
    left: -100px;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

/* FOCUS OVERLAY */
.focus-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(9, 12, 21, 0.85);
    backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-normal);
}

.focus-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.focus-box {
    text-align: center;
    padding: 32px;
    border-radius: 16px;
    border: 1px solid var(--border-color);
    background: rgba(17, 24, 39, 0.8);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    max-width: 400px;
    cursor: pointer;
    transform: translateY(20px);
    transition: transform var(--transition-normal);
}

.focus-overlay.active .focus-box {
    transform: translateY(0);
}

.focus-icon {
    width: 48px;
    height: 48px;
    color: var(--accent-primary);
    margin-bottom: 16px;
    animation: pulseIcon 2s infinite alternate;
}

@keyframes pulseIcon {
    0% {
        transform: scale(1);
        filter: drop-shadow(0 0 2px rgba(139, 92, 246, 0.3));
    }

    100% {
        transform: scale(1.1);
        filter: drop-shadow(0 0 12px rgba(139, 92, 246, 0.7));
    }
}

.focus-box h3 {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 8px;
    color: white;
}

.focus-box p {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.5;
}

.practice-actions {
    display: flex;
    justify-content: center;
}

/* ==========================================================================
   VIRTUAL KEYBOARD SECTION
   ========================================================================== */
.keyboard-section {
    background: var(--bg-card);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 32px;
    /* increased padding for better spacing */
    margin: 16px 0;
    /* added vertical spacing */
    box-shadow: 0 12px 40px 0 rgba(0, 0, 0, 0.2);
}

.keyboard {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
}

.key-row {
    display: flex;
    gap: 6px;
    justify-content: space-between;
}

.key {
    background: rgba(26, 32, 44, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-bottom: 3px solid rgba(255, 255, 255, 0.03);
    color: var(--text-secondary);
    border-radius: 8px;
    height: 40px;
    /* reduced key height for better balance */
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-family: var(--font-ui);
    font-size: 14px;
    font-weight: 600;
    cursor: default;
    user-select: none;
    transition: background-color 0.1s, border-color 0.1s, color 0.1s, box-shadow 0.1s, transform 0.05s;
    position: relative;
}

/* Custom spans for dual characters e.g. ! 1 */
.key span.top {
    font-size: 10px;
    color: var(--text-muted);
    line-height: 1;
    margin-bottom: 2px;
}

.key span.bottom {
    font-size: 13px;
    line-height: 1;
}

/* SPECIAL MODIFIER KEYS SIZE */
.key-grow-1 {
    flex: 1.5;
}

.key-grow-1-5 {
    flex: 1.8;
}

.key-grow-2 {
    flex: 2.2;
}

.key-grow-2-5 {
    flex: 2.7;
}

.key-space {
    flex: 8.5;
}

/* FINGER COLORS - default subtle border */
.keyboard-section.use-finger-colors .key[data-finger="l-pinky"] {
    border-top: 2px solid var(--finger-l-pinky);
}

.keyboard-section.use-finger-colors .key[data-finger="l-ring"] {
    border-top: 2px solid var(--finger-l-ring);
}

.keyboard-section.use-finger-colors .key[data-finger="l-middle"] {
    border-top: 2px solid var(--finger-l-middle);
}

.keyboard-section.use-finger-colors .key[data-finger="l-index"] {
    border-top: 2px solid var(--finger-l-index);
}

.keyboard-section.use-finger-colors .key[data-finger="r-index"] {
    border-top: 2px solid var(--finger-r-index);
}

.keyboard-section.use-finger-colors .key[data-finger="r-middle"] {
    border-top: 2px solid var(--finger-r-middle);
}

.keyboard-section.use-finger-colors .key[data-finger="r-ring"] {
    border-top: 2px solid var(--finger-r-ring);
}

.keyboard-section.use-finger-colors .key[data-finger="r-pinky"] {
    border-top: 2px solid var(--finger-r-pinky);
}

.keyboard-section.use-finger-colors .key[data-finger="thumb"] {
    border-top: 2px solid var(--finger-thumb);
}

.keyboard-section.use-finger-colors .key[data-finger="l-thumb"] {
    border-top: 2px solid var(--finger-thumb);
}

.keyboard-section.use-finger-colors .key[data-finger="r-thumb"] {
    border-top: 2px solid var(--finger-thumb);
}

/* KEY ACTIVE STATE (When physically pressed) */
.key.active {
    background: var(--text-primary);
    color: var(--bg-main) !important;
    border-top-color: transparent !important;
    border-bottom: 1px solid var(--text-primary);
    transform: translateY(2px);
    box-shadow: 0 0 15px rgba(255, 255, 255, 0.4);
}

/* HIGHLIGHT KEY (The key suggested to type next) */
.key.highlight-next {
    animation: keyPulse 0.8s infinite alternate;
}

.keyboard-section.use-finger-colors .key.highlight-next {
    /* If finger colors are enabled, highlight with the color of the finger! */
    background: rgba(255, 255, 255, 0.04);
}

.keyboard-section.use-finger-colors .key.highlight-next[data-finger="l-pinky"] {
    border-color: var(--finger-l-pinky);
    box-shadow: 0 0 12px rgba(236, 72, 153, 0.4);
}

.keyboard-section.use-finger-colors .key.highlight-next[data-finger="l-ring"] {
    border-color: var(--finger-l-ring);
    box-shadow: 0 0 12px rgba(217, 70, 239, 0.4);
}

.keyboard-section.use-finger-colors .key.highlight-next[data-finger="l-middle"] {
    border-color: var(--finger-l-middle);
    box-shadow: 0 0 12px rgba(139, 92, 246, 0.4);
}

.keyboard-section.use-finger-colors .key.highlight-next[data-finger="l-index"] {
    border-color: var(--finger-l-index);
    box-shadow: 0 0 12px rgba(59, 130, 246, 0.4);
}

.keyboard-section.use-finger-colors .key.highlight-next[data-finger="r-index"] {
    border-color: var(--finger-r-index);
    box-shadow: 0 0 12px rgba(6, 182, 212, 0.4);
}

.keyboard-section.use-finger-colors .key.highlight-next[data-finger="r-middle"] {
    border-color: var(--finger-r-middle);
    box-shadow: 0 0 12px rgba(20, 184, 166, 0.4);
}

.keyboard-section.use-finger-colors .key.highlight-next[data-finger="r-ring"] {
    border-color: var(--finger-r-ring);
    box-shadow: 0 0 12px rgba(16, 185, 129, 0.4);
}

.keyboard-section.use-finger-colors .key.highlight-next[data-finger="r-pinky"] {
    border-color: var(--finger-r-pinky);
    box-shadow: 0 0 12px rgba(245, 158, 11, 0.4);
}

.keyboard-section.use-finger-colors .key.highlight-next[data-finger="thumb"] {
    border-color: var(--finger-thumb);
    box-shadow: 0 0 12px rgba(107, 114, 128, 0.4);
}

/* If finger colors are off, default hint is purple glow */
.keyboard-section:not(.use-finger-colors) .key.highlight-next {
    border-color: var(--accent-primary);
    background: rgba(139, 92, 246, 0.1);
    box-shadow: 0 0 12px rgba(139, 92, 246, 0.4);
    color: var(--text-primary);
}

@keyframes keyPulse {
    0% {
        transform: translateY(0);
        filter: brightness(1);
    }

    100% {
        transform: translateY(-1px);
        filter: brightness(1.3);
    }
}

/* ==========================================================================
   TYPING RULES GUIDE & TABLES
   ========================================================================== */
.rules-guide {
    background: var(--bg-card);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 24px;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.15);
}

.rules-guide h2 {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 20px;
    text-align: center;
    color: var(--text-primary);
}

.rules-container {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
}

.rule-card {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 16px;
}

.rule-card h3 {
    font-size: 14px;
    font-weight: 700;
    margin-bottom: 12px;
    color: var(--accent-primary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    text-align: center;
}

/* VNI gets a green tint title, Telex gets a purple one */
#rule-card-vni h3 {
    color: var(--accent-secondary);
}

.rule-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    color: var(--text-secondary);
}

.rule-table th,
.rule-table td {
    padding: 8px 12px;
    text-align: left;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.rule-table th {
    font-weight: 600;
    color: var(--text-primary);
}

.rule-table tr:last-child td {
    border-bottom: none;
}

.rule-table td strong {
    color: white;
    font-family: var(--font-mono);
    background: var(--bg-input);
    padding: 2px 6px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
}

.credits {
    text-align: center;
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 16px;
}

/* ==========================================================================
   MODAL DIALOG (CUSTOM INPUT)
   ========================================================================== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(12px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-normal);
}

.modal.active {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background: #0f1322;
    border: 1px solid var(--border-color);
    box-shadow: 0 25px 60px -15px rgba(0, 0, 0, 0.8);
    border-radius: 20px;
    width: 90%;
    max-width: 550px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: scale(0.9);
    transition: transform var(--transition-normal);
}

.modal.active .modal-content {
    transform: scale(1);
}

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

.modal-header h2 {
    font-size: 18px;
    font-weight: 700;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 24px;
    cursor: pointer;
    outline: none;
    transition: var(--transition-fast);
}

.modal-close:hover {
    color: var(--accent-error);
}

.modal-body {
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.modal-desc {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.5;
}

#custom-text-input {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: 12px;
    padding: 16px;
    font-family: var(--font-ui);
    font-size: 14px;
    line-height: 1.6;
    height: 150px;
    resize: none;
    outline: none;
    transition: var(--transition-fast);
}

#custom-text-input:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.2);
}

.char-counter {
    align-self: flex-end;
    font-size: 12px;
    color: var(--text-muted);
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

/* ==========================================================================
   RESPONSIVE DESIGN (PC/LAPTOP FOCUS)
   ========================================================================== */
@media (max-width: 900px) {
    .layout-wrapper {
        grid-template-columns: 1fr;
    }

    .app-sidebar {
        position: static;
        flex-direction: column;
    }

    .stats-board {
        grid-template-columns: repeat(4, 1fr);
    }

    .icon-buttons-sidebar {
        flex-direction: row;
    }

    .icon-buttons-sidebar .icon-btn {
        flex: 1;
    }

    .rules-container {
        grid-template-columns: 1fr;
    }

    .app-header {
        flex-direction: column;
        align-items: flex-start;
    }
}

@media (max-width: 600px) {
    .stats-board {
        grid-template-columns: repeat(2, 1fr);
    }

    .icon-buttons-sidebar {
        flex-direction: column;
    }

    .key {
        height: 38px;
        font-size: 11px;
        border-radius: 4px;
    }

    .key span.top {
        font-size: 8px;
    }

    .key span.bottom {
        font-size: 10px;
    }

    .text-display {
        font-size: 16px;
    }
}

/* ==========================================================================
   LIGHT MODE STYLES & OVERRIDES
   ========================================================================== */
body.light-mode {
    --bg-main: #f3f4f6;
    --bg-card: rgba(255, 255, 255, 0.85);
    --bg-input: rgba(243, 244, 246, 0.9);

    --border-color: rgba(0, 0, 0, 0.08);
    --border-hover: rgba(0, 0, 0, 0.15);

    /* Accents tailored for light background contrast */
    --accent-primary: #6d28d9;
    /* Deep Purple */
    --accent-secondary: #0891b2;
    /* Cyan */
    --accent-success: #059669;
    /* Emerald */
    --accent-error: #dc2626;
    /* Red */
    --accent-warning: #d97706;
    /* Amber */

    /* Text colors */
    --text-primary: #0f172a;
    /* Slate 900 */
    --text-secondary: #475569;
    /* Slate 600 */
    --text-muted: #94a3b8;
    /* Slate 400 */
}

/* Light mode overrides for specific elements */
body.light-mode {
    background-image:
        radial-gradient(circle at 10% 20%, rgba(109, 40, 217, 0.06) 0%, transparent 40%),
        radial-gradient(circle at 90% 80%, rgba(8, 145, 178, 0.06) 0%, transparent 40%);
}

body.light-mode .logo-text h1 {
    background: linear-gradient(135deg, var(--text-primary) 30%, var(--accent-primary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

body.light-mode .key {
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid rgba(0, 0, 0, 0.06);
    border-bottom: 3px solid rgba(0, 0, 0, 0.1);
    color: var(--text-primary);
}

body.light-mode .key span.top {
    color: var(--text-secondary);
}

body.light-mode .key.active {
    background: var(--text-primary);
    color: var(--bg-main) !important;
    border-bottom: 1px solid var(--text-primary);
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.15);
}

body.light-mode .key.highlight-next {
    background: rgba(109, 40, 217, 0.08);
}

body.light-mode .keyboard-section.use-finger-colors .key.highlight-next {
    background: rgba(0, 0, 0, 0.02);
}

body.light-mode .rule-card {
    background: rgba(0, 0, 0, 0.015);
}

body.light-mode .rule-table td strong {
    color: var(--accent-primary);
    background: var(--bg-input);
}

body.light-mode .modal-content {
    background: #ffffff;
}

body.light-mode .focus-overlay {
    background: rgba(243, 244, 246, 0.85);
}

body.light-mode .focus-box {
    background: #ffffff;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.15);
}

body.light-mode .focus-box h3 {
    color: var(--text-primary);
}

body.light-mode .highlight-word {
    background: rgba(0, 0, 0, 0.03);
}

body.light-mode .ime-alert {
    background: rgba(217, 119, 6, 0.08);
    border: 1px solid rgba(217, 119, 6, 0.2);
    color: #b45309;
}

body.light-mode .key-badge {
    color: var(--accent-primary);
}

body.light-mode .completion-banner h2 {
    color: var(--text-primary);
}

/* SMOOTH THEME TOGGLE TRANSITIONS */
body {
    transition: background-color var(--transition-normal), color var(--transition-normal);
}

.app-header,
.stats-board,
.stat-card,
.settings-panel,
.practice-card,
.keyboard-section,
.rules-guide,
.key,
.btn,
.icon-btn,
.styled-select,
.modal-content,
.ime-alert {
    transition: background-color var(--transition-normal), border-color var(--transition-normal), color var(--transition-normal), box-shadow var(--transition-normal);
}