/* General UI Enhancements (from previous) */
body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #1a1a1a;
    color: #e0e0e0;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
.mobile-hints { display: none; }
    box-sizing: border-box;
}

#topbar {
    width: 100%;
    max-width: 80%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 0;
    font-size: 1.5em;
    font-weight: bold;
    color: #00bcd4;
    /* background-color: gold; */
}

#topbar a {
    color: #00bcd4;
    text-decoration: none;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 15px;
}

#usernameDisplay {
    font-size: 0.9em;
    color: #a0a0a0;
}

.btn {
    background-color: #007bff;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1em;
    transition: background-color 0.3s ease, color 0.3s ease, transform 0.12s ease;
    box-shadow: 0 4px 10px rgba(0, 123, 255, 0.3);
}

.btn:hover {
    background-color: #06b6d4;
    color: #0b1220;
    transform: translateY(-2px);
}

#dashboardBtn:hover,
#accountBtn:hover {
    background-color: #06b6d4;
    color: #0b1220;
}

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

/* Typing test container: minimum 3-line viewport but can show more if container is larger */
/* Typing test container: exactly 3 visible lines (no more) */
#canvasContainer {
    position: relative;
    width: 100%;
    max-width: 80%;
    /* Calculate height for 3 lines using line-height (46px) plus vertical padding (28px top + 28px bottom) */
    height: calc(46px * 3 + 56px); /* 3 lines visible exactly */
    background-color: #2a2a2a;
    border-radius: 12px;
    padding: 28px;
    margin: 30px 0;
    overflow: hidden;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
    line-height: 46px; /* fixed line-height used by caret/snapping */
    font-size: 22px; /* larger test font */
    box-sizing: border-box;
}

#typingContent {
    white-space: pre-wrap;
    word-break: break-word;
    padding-right: 20px;
    line-height: 46px; /* explicit line-height used for snapping */
    font-size: 22px; /* larger for readability */
    transition: transform 0.08s ease-out;
    will-change: transform;
}

.word {
    display: inline-block;
    /* margin-right: 5px; */
}

.char {
    display: inline-block;
    transition: background-color 0.1s ease;
    border-bottom: 1px solid transparent;
    user-select: none;
    /* Prevent text selection */
}

.char.correct {
    color: #4CAF50;
}

.char.incorrect {
    color: #f44336;
    background-color: rgba(244, 67, 54, 0.2);
    border-bottom: 1px solid #f44336;
}

/* Add to your existing style.css */

#caret {
    position: absolute;
    background-color: #00bcd4;
    /* Your caret color */
    width: 2px;
    /* Or your desired caret width */
    /* Add transition for smooth movement */
    transition: left 0.06s cubic-bezier(.2,.8,.25,1), top 0.06s cubic-bezier(.2,.8,.25,1);
    /* Adjust time and easing as needed */
    will-change: left, top;
    /* Optimize for animation */
    pointer-events: none;
    /* Ensure it doesn't block clicks */
    left: 0;
    top: 0;
}

/* Initial character highlight before typing */
.initial-highlight {
    display: inline-block;
    transform-origin: left center;
    transform: scale(1.06);
    color: #ffffff;
    font-weight: 700;
    transition: transform 260ms cubic-bezier(.2,.9,.3,1), color 220ms ease, opacity 220ms ease;
}

.char {
    transition: color 140ms ease, transform 200ms ease;
}

@keyframes blink {

    from,
    to {
        opacity: 1;
    }

    50% {
        opacity: 0;
    }
}

#stats {
    font-size: 1.4em;
    color: #ddd;
    margin-top: 15px;
    display: flex;
    gap: 25px;
    font-weight: bold;
}

#stats #wpm,
#stats #accuracy,
#stats #timer {
    color: #00bcd4;
}


/* Mode Selector - ANIMATIONS & UI IMPROVEMENTS */
#modeSelector {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    margin-top: 20px;
    margin-bottom: 30px;
}

#mode-select {
    padding: 10px 15px;
    border-radius: 8px;
    border: 1px solid #00bcd4;
    background-color: #333;
    color: #e0e0e0;
    font-size: 1em;
    cursor: pointer;
    appearance: none;
    background-image: url('data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20256%20256%22%3E%3Cpath%20fill%3D%22%23e0e0e0%22%20d%3D%22M208.5%2080.5l-80%2080c-3.1%203.1-8.2%203.1-11.3%200l-80-80c-3.1-3.1-3.1-8.2%200-11.3s8.2-3.1%2011.3%200l74.3%2074.3%2074.3-74.3c3.1-3.1%208.2-3.1%2011.3%200s3.1%208.2%200%2011.3z%22%2F%3E%3C%2Fsvg%3E');
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 1em;
    transition: all 0.2s ease-in-out;
    /* Smooth transitions */
}

#mode-select:hover {
    background-color: #444;
}

#mode-select:focus {
    outline: none;
    border-color: #00aacc;
    box-shadow: 0 0 0 3px rgba(0, 188, 212, 0.5);
}

#mode-options-navbar {
    display: flex;
    gap: 10px;
    background-color: #2a2a2a;
    padding: 8px;
    border-radius: 10px;
    box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.2);
    /* Add transition for display property (requires JS help) */
    opacity: 0;
    transform: translateY(-10px);
    transition: opacity 0.3s ease-out, transform 0.3s ease-out;
}

#mode-options-navbar.show {
    opacity: 1;
    transform: translateY(0);
}


.mode-option-btn {
    background-color: #444;
    color: #e0e0e0;
    border: none;
    padding: 8px 15px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.95em;
    transition: background-color 0.2s ease, color 0.2s ease, transform 0.1s ease, box-shadow 0.2s ease;
    outline: none;
    position: relative;
    /* For custom input styling */
}

.mode-option-btn:hover {
    background-color: #555;
    transform: translateY(-1px);
}

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

.mode-option-btn.active {
    background-color: #00bcd4 !important;
    color: #1a1a1a !important;
    font-weight: bold;
    box-shadow: 0 2px 8px rgba(0, 188, 212, 0.4);
}

.mode-option-btn input.mode-option-custom {
    background: transparent;
    border: none;
    color: #e0e0e0;
    width: 60px;
    text-align: center;
    font-size: 0.95em;
    padding: 0;
    margin: 0;
    outline: none;
    border-bottom: 1px solid #777;
    transition: border-bottom-color 0.2s ease;
}

.mode-option-btn input.mode-option-custom:focus {
    border-bottom-color: #00bcd4;
}

/* Results Screen */
#resultsScreen {
    background-color: #2a2a2a;
    padding: 30px;
    border-radius: 15px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    margin-top: 40px;
    width: 100%;
    max-width: 700px;
    display: none;
    /* Add animation for results screen */
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.4s ease-out, transform 0.4s ease-out;
}

#resultsScreen.show {
    opacity: 1;
    transform: translateY(0);
}

#resultsScreen h2 {
    color: #00bcd4;
    margin-bottom: 20px;
    font-size: 2em;
}

#resultsSummary {
    font-size: 1.3em;
    line-height: 1.6;
    color: #e0e0e0;
    margin-bottom: 25px;
}

#resultsCanvas {
    width: 100%;
    height: 250px;
    /* Increased height for better graph visibility */
    display: block;
    margin: 0 auto 25px auto;
    border: 1px solid #444;
    border-radius: 8px;
    background-color: #1f1f1f;
}

/* Graph Tooltip */
#graphTooltip {
    position: absolute;
    background-color: rgba(0, 0, 0, 0.8);
    color: #fff;
    padding: 8px 12px;
    border-radius: 5px;
    font-size: 0.9em;
    pointer-events: none;
    /* Important: don't block mouse events on canvas */
    white-space: nowrap;
    z-index: 10;
    opacity: 0;
    transition: opacity 0.2s ease;
    transform: translate(-50%, -100%) translateY(-10px);
}

#graphTooltip.show {
    opacity: 1;
    transform: translate(-50%, -100%) translateY(-5px);
    /* Move slightly down on show */
}


/* Modal Styling (from previous) */
.modal {
    display: none;
    position: fixed;
    z-index: 1001;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.7);
    justify-content: center;
    align-items: center;
    animation: fadeIn 0.3s ease-out;
}

.modal-content {
    background-color: #2a2a2a;
    margin: auto;
    padding: 30px;
    border-radius: 15px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
    position: relative;
    animation: slideIn 0.3s ease-out;
}

.modal-content h2 {
    color: #00bcd4;
    text-align: center;
    margin-bottom: 25px;
    font-size: 1.8em;
}

.modal-content form {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.modal-content input[type="email"],
.modal-content input[type="password"] {
    padding: 12px;
    border: 1px solid #444;
    border-radius: 8px;
    background-color: #3a3a3a;
    color: #e0e0e0;
    font-size: 1em;
}

.modal-content input[type="email"]::placeholder,
.modal-content input[type="password"]::placeholder {
    color: #888;
}

.modal-content .btn {
    width: 100%;
    margin-top: 10px;
}

.close {
    color: #aaa;
    position: absolute;
    top: 15px;
    right: 20px;
    font-size: 30px;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.2s ease;
}

.close:hover,
.close:focus {
    color: #e0e0e0;
    text-decoration: none;
    cursor: pointer;
}

/* Animations for modals */
@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes slideIn {
    from {
        transform: translateY(-30px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Focus Modal Styling (from previous) */
#focusModal {
    transition: opacity 0.3s ease-out, display 0.3s ease-out;
    background: rgba(0, 0, 0, 0.6);
}

#focusModal>div {
    background: rgba(30, 30, 30, 0.98);
    color: #fff;
    padding: 50px 70px;
    border-radius: 18px;
    font-size: 2.2rem;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
    cursor: pointer;
    opacity: 0.98;
    text-align: center;
    border: 2px solid #00bcd4;
}

#focusModal>div div:last-child {
    font-size: 1.2rem;
    opacity: 0.8;
    margin-top: 15px;
}

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

        .brand-title {
            font-size: 2em;
            font-weight: bold;
            color: #06b6d4;
            cursor: pointer;
            user-select: none;
            letter-spacing: 1px;
            transition: color 0.3s ease;
        }

        .brand-title:hover {
            color: #ffffff;
        }

        .alpha-badge code {
            background: #222;
            color: #ffb300;
            border-radius: 6px;
            padding: 2px 8px;
            font-size: 0.9em;
            margin-left: 4px;
        }

/* Refresh Animation for Test Content */
@keyframes refreshFadeIn {
    from {
        opacity: 0.3;
        transform: scale(0.98);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

#typingContent.refresh-animate {
    animation: refreshFadeIn 0.5s ease-out;
}

@keyframes statsGlow {
    from {
        opacity: 0.5;
        box-shadow: 0 0 0 rgba(0, 188, 212, 0);
    }
    to {
        opacity: 1;
        box-shadow: 0 0 12px rgba(0, 188, 212, 0.4);
    }
}

#stats.refresh-animate {
    animation: statsGlow 0.5s ease-out;
}

/* Portrait-specific shrink using vh to make UI scale smaller on short mobile screens */
@media (max-width: 480px) and (orientation: portrait) {
    /* Scale base font-size by viewport height so UI elements scale proportionally */
    html, body {
        /* 2.2vh gives reasonably small but readable text on many phones */
        font-size: calc(2.2vh + 8px);
    }

    /* Make the typing area take more vertical space but scale text with vh */
    #canvasContainer {
        padding: 3vh 3vw !important;
    }
    #typingContent {
        font-size: calc(2.8vh + 6px) !important;
        line-height: 1.25 !important;
    }

    /* Reduce sizes of header and nav to avoid cramping */
    header, .topnav, nav {
        font-size: calc(1.8vh + 6px) !important;
        padding: 1vh 2vw !important;
    }

    /* Make buttons slightly smaller and touch-friendly */
    button, .mode-option-btn {
        padding: 1.2vh 2vw !important;
        font-size: calc(1.8vh + 6px) !important;
    }

    /* Ensure results overlay fits on short screens */
    #resultsScreen {
        padding: 2vh 3vw !important;
    }
}

/* Focused testing mode: hide distractions and emphasize test area */
/* testing-mode: fade only non-essential controls while keeping brand and stats visible */
body.testing-mode #modeSelector,
body.testing-mode #dashboardBtn,
body.testing-mode #loginBtn,
body.testing-mode #signupBtn,
body.testing-mode #snarkycoinDisplay,
body.testing-mode .alpha-badge {
    opacity: 0.18;
    pointer-events: none;
    transform: translateY(-4px);
}

body.testing-mode #canvasContainer {
    max-width: 95%;
    box-shadow: 0 16px 40px rgba(0,0,0,0.6);
    padding: 36px;
    font-size: 24px;
}

/* Nav hide/show transitions */
#topbar {
    transition: opacity 0.18s ease, transform 0.18s ease;
}

/* SnarkyCoin icon sizing */
.sc-icon { width: 1em; height: 1em; object-fit: contain; vertical-align: middle; margin-right: 8px; display:inline-block; }

/* Light mode variables */
body.light-mode {
    --bg: #e5e5e5;
    --panel: #ffffff;
    --muted: #333333;
    --accent: #04afed;
    color: var(--muted);
    background: var(--bg);
}

body.light-mode #topbar { background: var(--panel); border-bottom-color: #d0d7de; }
body.light-mode .brand-title:hover { background:#1a1a1a; color: var(--accent); }
body.light-mode a, body.light-mode .btn { color: var(--muted); }

/* Broader light-mode overrides for common UI panels and inputs */
body.light-mode #canvasContainer { background: var(--panel); }
body.light-mode #typingContent { color: var(--muted); }
body.light-mode #stats, body.light-mode .settings-header, body.light-mode .settings-section, body.light-mode .register-header { background: var(--panel); color: var(--muted); border-color: #dcdcdc; }
body.light-mode .modal-content { background: var(--panel); color: var(--muted); }
body.light-mode input, body.light-mode textarea, body.light-mode select { background: #fff; color: var(--muted); border-color: #d0d7de; }
body.light-mode #resultsScreen { background: var(--panel); border-color: #d0d7de; }
body.light-mode #topbar { color: var(--muted); }
body.light-mode .alpha-badge { background: transparent; color: var(--muted); }