/* One variable face covers every weight the site asks for (the font's wght axis
   runs 100-900), replacing the three static cuts it used to load. */
@font-face {
    font-family: 'Inter-Alia';
    src: url('fonts/InterAlia-VF.otf') format('opentype-variations');
    font-weight: 100 900;
    font-style: normal;
}

@font-face {
    font-family: 'Ormin';
    src: url('fonts/Ormin-Regular.otf') format('opentype');
    font-weight: 400;
    font-style: normal;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter-Alia', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

p {
    margin-bottom: 1em;
}

h3 {
    color: #333;
    margin-top: 1.5em;
    margin-bottom: 0.75em;
    font-size: 1.2em;
    font-weight: 600;
}

details {
    margin-bottom: 0.75em;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 0.5em;
}

summary {
    font-weight: 600;
    color: #667eea;
    cursor: pointer;
    padding: 0.5em;
    border-radius: 4px;
    transition: background-color 0.2s;
    user-select: none;
}

summary:hover {
    background-color: #f0f0ff;
}

summary::marker {
    color: #667eea;
}

details[open] summary {
    margin-bottom: 0.5em;
}

details > ul {
    margin-left: 2em;
    margin-top: 0.5em;
    margin-bottom: 0.5em;
}

ul {
    margin-left: 1.5em;
    margin-bottom: 0.5em;
}

li {
    margin-bottom: 0.25em;
    line-height: 1.5;
}

.container {
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    padding: 40px;
    max-width: 600px;
    width: 100%;
}

.header-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.back-btn {
    font-size: 24px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    color: #667eea;
    transition: color 0.3s;
    min-width: 40px;
}

.back-btn:hover {
    color: #5568d3;
}

.back-btn.hidden {
    visibility: hidden;
}

h1 {
    text-align: center;
    color: #333;
    margin: 0;
    font-size: 36px;
    font-weight: bold;
    font-family: 'Ormin', 'Inter-Alia', sans-serif;
    flex: 1;
}

.subtitle {
    text-align: center;
    color: #666;
    margin-bottom: 30px;
    font-size: 18px;
    font-weight: normal;
    font-style: italic;
}

.home-screen {
    display: flex;
    flex-direction: column;
    gap: 20px;
    margin-top: 50px;
}

.home-screen.hidden {
    display: none;
}

/* Bottom row pairs Scores + Settings as half-width secondary actions */
.home-btn-row {
    display: flex;
    gap: 16px;
    margin-top: 4px;
}

.home-btn-row .home-btn {
    flex: 1;
    padding: 17px;
    font-size: 20px;
}

.countdown-screen {
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 300px;
    padding: 40px;
    margin-top: 50px;
}

.countdown-screen.hidden {
    display: none !important;
}

.countdown-screen:not(.hidden) {
    display: flex;
}

.home-btn {
    padding: 20px;
    font-size: 24px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s;
    font-weight: 500;
}

.home-btn:hover {
    background: #5568d3;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.game-content {
    display: block;
}

.game-content.hidden {
    display: none;
}

.word-display {
    background: #f8f9fa;
    border-radius: 12px;
    padding: 30px;
    margin-bottom: 30px;
    min-height: 100px;
    position: relative;
    overflow: hidden;
}

.word-carousel {
    position: relative;
    height: 60px;
    overflow: hidden;
}

.word-slot {
    position: absolute;
    top: 50%;
    font-size: 48px; /* fixed base; word sizing is done via transform: scale() */
    font-family: 'Inter-Alia', sans-serif;
    /* No letter-spacing: it overrides the font's kerning pairs. Leaving it off
       lets the carousel words kern natively. Slot positions are measured live
       (offsetWidth), so the tighter spacing is accounted for automatically. */
    letter-spacing: 0;
    white-space: nowrap;
    font-kerning: normal;
    /* Scale about the left edge's vertical centre: translateX positions that
       left edge, scale grows the word rightward, and scaling about center keeps
       the baseline put (the box height never changes). */
    transform-origin: left center;
    /* Slide and scale live in one transform, so a single transition eases both
       together — GPU-composited, no per-frame text reflow, no baseline wobble. */
    transition: transform 0.3s cubic-bezier(0.22, 0.61, 0.36, 1),
                opacity 0.3s cubic-bezier(0.22, 0.61, 0.36, 1);
}

/* Position classes for the carousel - transform will be set dynamically */
.word-slot.pos-prev-prev {
    opacity: 0;
}

.word-slot.pos-prev {
    opacity: 0.2;
}

.word-slot.pos-current {
    opacity: 1;
}

.word-slot.pos-next {
    opacity: 0.3;
}

.word-slot.pos-next-next {
    opacity: 0;
}

.word-display .word {
    font-size: 48px;
    font-family: 'Inter-Alia', sans-serif;
    letter-spacing: 4px;
}

.word-display .char {
    display: inline-block;
    transition: all 0.2s ease;
    white-space: pre; /* Preserve spaces */
}

.word-display .char.correct {
    opacity: 0.4;
    color: #28a745;
}

.word-display .char.incorrect {
    color: #dc3545;
    font-weight: bold;
}

.input-container {
    margin-bottom: 20px;
}

#typingInput {
    width: 100%;
    padding: 15px;
    font-size: 32px;
    font-family: 'Inter-Alia', sans-serif;
    border: 3px solid #e0e0e0;
    border-radius: 10px;
    text-align: center;
    letter-spacing: 4px;
    transition: border-color 0.3s;
}

#typingInput:focus {
    outline: none;
    border-color: #667eea;
}

.stats {
    display: flex;
    justify-content: space-around;
    margin-top: 20px;
    padding-top: 20px;
    border-top: 2px solid #e0e0e0;
}

.stat {
    text-align: center;
}

.stat-label {
    color: #666;
    font-size: 14px;
    margin-bottom: 5px;
}

.stat-value {
    color: #333;
    font-size: 24px;
    font-weight: bold;
}

.countdown-text {
    font-size: 72px;
    font-weight: bold;
    color: #667eea;
    animation: countdown-pulse 0.5s ease-in-out;
}

@keyframes countdown-pulse {
    0% {
        transform: scale(0.5);
        opacity: 0;
    }
    50% {
        transform: scale(1.1);
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes error-flash {
    0% {
        background-color: #e74c3c;
    }
    100% {
        background-color: white;
    }
}

.completion-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    justify-content: center;
    align-items: center;
    z-index: 2000;
    overscroll-behavior: contain;
}

.completion-modal.show {
    display: flex;
}

.completion-content {
    background: white;
    padding: 40px;
    border-radius: 20px;
    text-align: center;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    overscroll-behavior: contain;
    animation: slideIn 0.3s ease;
}

/* Play completion: a non-scrolling frame (pinned × and footer buttons) with a
   scrolling middle, so the dialog fits on small screens. */
.completion-content.scrollable-modal {
    display: flex;
    flex-direction: column;
    overflow: visible;
}

/* Compact one-line stats: "time 0:24   wpm 32.2   acc 98%", time/wpm prominent. */
.completion-stats {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px 24px;
    margin: 16px 0;
}

.completion-stats .stat {
    color: #999;
    font-size: 14px;
}

.completion-stats .stat .value {
    color: #333;
    font-weight: bold;
    font-size: 22px;
    margin-left: 4px;
}

/* Per-level accuracy as a two-column grid (6 levels -> 3 rows). */
.level-stats-container.level-stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px 16px;
    text-align: left;
}

.level-stats-grid .level-stat {
    border-bottom: none;
    padding: 2px 0;
}

/* Completion leaderboard: cap height and scroll, with room for a few rows, so it
   never pushes the footer buttons off-screen. */

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

.completion-content h2 {
    color: #667eea;
    font-size: 36px;
    margin-bottom: 20px;
}

.completion-content .stat-row {
    margin: 10px 0;
    font-size: 18px;
    color: #666;
}

.level-stats-container {
    margin: 20px 0;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 10px;
    max-height: 200px;
    overflow-y: auto;
}

.level-stat {
    padding: 5px 0;
    font-size: 14px;
    color: #555;
    border-bottom: 1px solid #e0e0e0;
}

.level-stat:last-child {
    border-bottom: none;
}

.completion-content button {
    margin-top: 30px;
    padding: 15px 40px;
    font-size: 18px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.3s;
}

.completion-content button:hover {
    background: #5568d3;
}

/* Pinned footer holding the Done / Play Again buttons below the scrolling body. */
.completion-footer {
    flex-shrink: 0;
    padding-top: 20px;
}

.completion-footer button {
    margin-top: 0;
}

/* The player's own row in the post-game leaderboard */
.leaderboard-you {
    background: #eef0fd;
    font-weight: 600;
}

/* Dismiss control on the provisional row: muted until hovered, then it reddens
   to signal that clicking opts the score out of the leaderboard. */
#dismissEntryBtn {
    display: inline-flex;
    transition: color 0.15s;
}

#dismissEntryBtn:hover {
    color: #d9534f;
}

/* A modal whose body scrolls while the frame (and its pinned × close mark) stays
   put. The base .settings-content scrolls itself, which lets an absolutely
   positioned .modal-close ride up out of view; this turns the frame into a
   non-scrolling flex column with a scrolling body instead. */
.settings-content.scrollable-modal {
    display: flex;
    flex-direction: column;
    overflow: visible;
}

.modal-scroll-body {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    /* Keep touch scrolling inside the dialog: don't chain to the page behind it
       when reaching the top/bottom (iOS Safari scroll bleed-through). */
    overscroll-behavior: contain;
}

/* Action area pinned below a .modal-scroll-body (for modals whose action is a
   button rather than a × close mark). */
.modal-footer {
    flex-shrink: 0;
    padding-top: 20px;
}

/* Scores dialog: fixed header (title+tabs) and footer (Close), scrolling middle.
   Two-class selector to override the base .settings-content scroll rules. */
.settings-content.scores-content {
    display: flex;
    flex-direction: column;
    max-height: 85vh;
    overflow: visible;
}

.scores-scroll {
    flex: 1;
    overflow-y: auto;
    margin-top: 20px;
    overscroll-behavior: contain;
}

.scores-footer {
    text-align: center;
    padding-top: 20px;
    border-top: 2px solid #e0e0e0;
}

/* Scores dialog: My Scores / Leaderboard view tabs */
.scores-tabs {
    display: flex;
    gap: 24px;
    justify-content: center;
    border-bottom: 2px solid #e0e0e0;
    margin-top: 16px;
}

.scores-tab {
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    padding: 8px 4px;
    font-size: 16px;
    color: #999;
    cursor: pointer;
}

.scores-tab.active {
    color: #667eea;
    border-bottom-color: #667eea;
    font-weight: 600;
}

/* Settings dialog tab panels (reuse the .scores-tabs/.scores-tab styling). */
.settings-tab-panel {
    margin-top: 20px;
}

/* Scores dialog: section headings and per-board scrollable tiles */
.scores-heading {
    margin: 0 0 8px;
    color: #667eea;
}

/* Scores dialog: layout/device filter dropdowns at the top of the Leaderboard
   view (bare selects — the "All layouts"/"All devices" defaults are self-evident) */
.scores-filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    justify-content: center;
}

.scores-filter-bar select {
    padding: 6px 8px;
    font-size: 14px;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
}

.scores-tile {
    max-height: 220px;
    overflow: auto;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
}

.mode-btn {
    padding: 10px 30px;
    font-size: 16px;
    border: 2px solid #667eea;
    background: white;
    color: #667eea;
    border-radius: 8px;
    cursor: pointer;
    margin: 0 10px;
    transition: all 0.3s;
}

.mode-btn:hover {
    background: #f0f0ff;
}

.mode-btn.active {
    background: #667eea;
    color: white;
}

.settings-btn {
    padding: 10px 20px;
    font-size: 16px;
    border: 2px solid #667eea;
    background: white;
    color: #667eea;
    border-radius: 8px;
    cursor: pointer;
    margin-left: 15px;
    transition: all 0.3s;
}

.settings-btn:hover {
    background: #f0f0ff;
}

.settings-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    justify-content: center;
    align-items: center;
    z-index: 2000;
    overscroll-behavior: contain;
}

.settings-modal.show {
    display: flex;
}

.settings-content {
    background: white;
    padding: 40px;
    border-radius: 20px;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    overscroll-behavior: contain;
    animation: slideIn 0.3s ease;
}

.settings-content h2 {
    color: #667eea;
    font-size: 28px;
    margin-bottom: 25px;
}

.settings-option {
    margin-bottom: 20px;
    padding-bottom: 20px;
    border-bottom: 1px solid #e0e0e0;
}

.settings-option:last-child {
    border-bottom: none;
}

.settings-option label {
    display: flex;
    align-items: center;
    font-size: 16px;
    color: #333;
    cursor: pointer;
}

.settings-option input[type="checkbox"] {
    margin-right: 12px;
    width: 20px;
    height: 20px;
    cursor: pointer;
}

.settings-option-desc {
    font-size: 13px;
    color: #666;
    margin-top: 8px;
    margin-left: 32px;
}

.settings-close-btn {
    margin-top: 25px;
    padding: 12px 30px;
    font-size: 16px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.3s;
}

.settings-close-btn:hover {
    background: #5568d3;
}

/* Inline buttons in the Player ID settings row (Copy / Use this ID) */
/* A bordered card grouping one self-contained concern in the Advanced dialog,
   so distinct features (Player ID vs welcome-dialog reset) read as orthogonal. */
.advanced-box {
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    padding: 16px;
    margin-bottom: 16px;
}

.advanced-box:last-child {
    margin-bottom: 0;
}

.player-id-btn {
    padding: 8px 14px;
    font-size: 14px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.3s;
}

.player-id-btn:hover {
    background: #5568d3;
}

.modal-close {
    position: absolute;
    top: 15px;
    right: 15px;
    font-size: 32px;
    font-weight: bold;
    color: #999;
    cursor: pointer;
    transition: color 0.2s;
    line-height: 1;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-close:hover {
    color: #333;
}

.completion-content,
.settings-content {
    position: relative;
}

#lengthSelect {
    padding: 8px 15px;
    font-size: 16px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    background: white;
    cursor: pointer;
}

.burger-menu {
    position: relative;
    display: inline-block;
    min-width: 40px;
}

.burger-btn {
    font-size: 24px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    color: #667eea;
    transition: color 0.3s;
}

.burger-btn:hover {
    color: #5568d3;
}

.burger-dropdown {
    display: none;
    position: absolute;
    right: 0;
    top: 100%;
    background: white;
    min-width: 160px;
    box-shadow: 0 8px 16px rgba(0,0,0,0.2);
    border-radius: 8px;
    z-index: 2000;
    overflow: hidden;
}

.burger-dropdown.show {
    display: block;
}

.burger-dropdown a {
    color: #333;
    padding: 12px 16px;
    text-decoration: none;
    display: block;
    transition: background 0.3s;
}

.burger-dropdown a:hover {
    background: #f0f0ff;
}

.copyright {
    text-align: center;
    color: #000000;
    font-size: 14px;
    margin-top: 20px;
    padding: 10px;
}

.lesson-option {
    padding: 15px;
    margin: 10px 0;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
}

.lesson-option:hover {
    border-color: #667eea;
    background: #f8f9ff;
}

.lesson-option strong {
    color: #333;
    font-size: 16px;
}

/* Mobile-friendly compact layout */
@media (max-width: 768px) {
    body {
        justify-content: flex-start;
        padding-top: 40px;
    }

    h1 {
        font-size: 32px;
        margin-bottom: 10px;
    }

    .subtitle {
        font-size: 16px;
        margin-bottom: 20px;
    }

    .word-display {
        padding: 20px;
        margin-bottom: 20px;
        min-height: 60px;
    }

    .word-display .word {
        font-size: 36px;
        letter-spacing: 2px;
    }

    #typingInput {
        padding: 12px;
        font-size: 24px;
    }

    .input-container {
        margin-bottom: 15px;
    }

    .stats {
        gap: 15px;
        margin-bottom: 15px;
    }

    .countdown-text {
        font-size: 48px;
    }
}

/* Center keyboard images */
img[src$=".png"] {
    display: block;
    margin: 10px auto;
}

/* Keyboard documentation styles */
.key-style {
    background-color: #e8e8e8;
    padding: 0px 0px;
    border-radius: 3px;
    font-family: 'Inter-Alia', monospace;
    border: 1px solid #ccc;
    white-space: nowrap;
}

.modal-content ul {
    background-color: #f5f5f5;
    padding: 12px 20px 12px 40px;
    border-left: 3px solid #555fdc;
    margin: 10px 0;
    border-radius: 4px;
}

.modal-content ul li {
    margin: 6px 0;
    color: #444;
}

