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

:root {
    --tile-size: 80px;
    --tile-font: 3rem;
    --key-size: 56px;
    --key-wide-size: 90px;
    --key-enter-size: 110px;
    --key-font: 1.3rem;
    --key-wide-font: 1.1rem;
    --board-gap: 8px;
    --tile-gap: 6px;
    --keyboard-gap: 8px;
    --key-gap: 6px;
    --spacer-row1: 35px;
    --spacer-row2: 70px;
    --font-title: 2.25rem;
    --font-xl: 2rem;
    --font-lg: 1.5rem;
    --font-body: 1.15rem;
    --font-pill: 1rem;
    --font-sm: 0.9rem;
    --font-xs: 0.8rem;
    --modal-max-width: 440px;

    --color-bg: #121213;
    --color-surface: #1a1a1b;
    --color-border: #3a3a3c;
    --color-border-hover: #565758;
    --color-text: #ffffff;
    --color-text-muted: #818384;
    --color-text-subtle: #565758;
    --color-green: #538d4e;
    --color-green-hover: #6aaa64;
    --color-yellow: #b59f3b;
    --color-yellow-hover: #d4b94b;
    --color-red: #dc2626;
    --color-red-hover: #ef4444;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    overflow-x: hidden;
    overflow-y: auto;
    user-select: none;
}

header {
    padding: 0.5rem 1rem;
    border-bottom: 1px solid var(--color-border);
    width: 100%;
}

.header-row {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    width: 100%;
    gap: 0.5rem;
}

h1 {
    font-size: var(--font-title);
    font-weight: 700;
    letter-spacing: 0.2em;
    color: var(--color-text);
    cursor: pointer;
    text-align: center;
    grid-column: 2;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.game-controls {
    grid-column: 3;
    justify-self: end;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.header-left {
    grid-column: 1;
    justify-self: start;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.header-left .timer {
    position: static;
}

#multiplayer-btn {
    text-decoration: none;
    padding: 0.4rem 0.8rem;
    font-size: var(--font-sm);
    border-color: var(--color-yellow);
    color: var(--color-yellow);
}

#multiplayer-btn:hover {
    border-color: var(--color-yellow-hover);
    color: var(--color-yellow-hover);
}

.mode-selector,
.difficulty-selector {
    display: flex;
    align-items: center;
    gap: 0.2rem;
}

.control-label {
    font-size: var(--font-sm);
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-right: 0.15rem;
}

.radio-pill {
    display: inline-block;
    padding: 0.4rem 0.8rem;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    font-size: var(--font-pill);
    color: var(--color-text-muted);
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
}

.radio-pill:hover {
    border-color: var(--color-border-hover);
    color: var(--color-text);
}

.mode-selector .radio-pill.active {
    border-color: var(--color-green);
    color: var(--color-text);
    background: rgba(83, 141, 78, 0.15);
}

.mode-selector.rush-selected .radio-pill.active {
    border-color: var(--color-yellow);
    color: var(--color-text);
    background: rgba(181, 159, 59, 0.15);
}

.difficulty-selector .radio-pill[data-difficulty="ez"]:hover {
    border-color: var(--color-green);
    color: var(--color-text);
}

.difficulty-selector .radio-pill[data-difficulty="normal"]:hover {
    border-color: var(--color-yellow);
    color: var(--color-text);
}

.difficulty-selector .radio-pill[data-difficulty="hard"]:hover {
    border-color: var(--color-red);
    color: var(--color-text);
}

.difficulty-selector .radio-pill[data-difficulty="ez"].active {
    border-color: var(--color-green);
    color: var(--color-text);
    background: rgba(83, 141, 78, 0.15);
}

.difficulty-selector .radio-pill[data-difficulty="normal"].active {
    border-color: var(--color-yellow);
    color: var(--color-text);
    background: rgba(181, 159, 59, 0.15);
}

.difficulty-selector .radio-pill[data-difficulty="hard"].active {
    border-color: var(--color-red);
    color: var(--color-text);
    background: rgba(220, 38, 38, 0.15);
}

.difficulty-selector.disabled {
    opacity: 0.35;
    pointer-events: none;
}

.radio-pill input[type="radio"] {
    display: none;
}

.stats-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    font-size: var(--font-body);
    color: var(--color-text-muted);
    width: 100%;
}

.stat-item {
    color: var(--color-text);
    font-weight: 600;
}

.stats-bar .sep {
    color: var(--color-border);
}

.stat-mode {
    font-weight: 600;
    text-transform: uppercase;
    font-size: var(--font-sm);
    letter-spacing: 0.1em;
}

.stat-mode.classic {
    color: var(--color-green);
}

.stat-mode.rush {
    color: var(--color-yellow);
}

main {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
    gap: 1rem;
    padding: 1rem;
}

.board {
    display: grid;
    grid-template-rows: repeat(6, 1fr);
    gap: var(--board-gap);
    padding: 0.5rem;
}

.row {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: var(--tile-gap);
}

.tile {
    width: var(--tile-size);
    height: var(--tile-size);
    border: 2px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--tile-font);
    font-weight: 700;
    text-transform: uppercase;
    color: var(--color-text);
    background: transparent;
    transition: transform 0.1s ease;
}

.tile.filled {
    border-color: var(--color-border-hover);
    animation: pop 0.1s ease;
}

.tile.green {
    background: var(--color-green);
    border-color: var(--color-green);
}

.tile.yellow {
    background: var(--color-yellow);
    border-color: var(--color-yellow);
}

.tile.gray {
    background: var(--color-border);
    border-color: var(--color-border);
}

.tile.cursor {
    border-color: var(--color-border-hover);
    border-width: 3px;
    animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { border-color: var(--color-border-hover); }
    50% { border-color: var(--color-text); }
}

@keyframes pop {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

.message {
    font-size: var(--font-lg);
    font-weight: 600;
    min-height: 1.5rem;
    text-align: center;
    color: var(--color-text);
}

.message:not(:empty) {
    padding: 0.5rem 1rem;
    border-radius: 6px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
}

.keyboard {
    display: flex;
    flex-direction: column;
    gap: var(--keyboard-gap);
    align-items: center;
}

.keyboard .row {
    display: flex;
    gap: var(--key-gap);
    justify-content: center;
}

.keyboard .row[data-row="1"]::before {
    content: "";
    width: var(--spacer-row1);
    flex-shrink: 0;
}

.keyboard .row[data-row="2"]::before {
    content: "";
    width: var(--spacer-row2);
    flex-shrink: 0;
}

.keyboard button {
    background: var(--color-text-muted);
    border: none;
    border-radius: 5px;
    color: var(--color-text);
    font-size: var(--key-font);
    font-weight: 700;
    padding: 0;
    width: var(--key-size);
    height: var(--key-size);
    flex: 0 0 auto;
    cursor: pointer;
    text-transform: uppercase;
    font-family: inherit;
    transition: background 0.1s ease;
    line-height: 1;
}

.keyboard button:hover {
    background: color-mix(in srgb, var(--color-text-muted), var(--color-text) 10%);
}

.keyboard button:active {
    transform: scale(0.95);
}

.keyboard button.wide {
    width: var(--key-wide-size);
    font-size: var(--key-wide-font);
}

.keyboard button[data-key="ENTER"] {
    width: var(--key-enter-size);
}

.keyboard button.green {
    background: var(--color-green);
}

.keyboard button.yellow {
    background: var(--color-yellow);
}

.keyboard button.gray {
    background: var(--color-border);
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.result-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    animation: fadeIn 0.15s ease;
}

.result-overlay.hidden {
    display: none;
}

.result-modal {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    padding: 2.5rem;
    width: 90%;
    max-width: var(--modal-max-width);
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.result-modal h2 {
    font-size: var(--font-xl);
    font-weight: 700;
}

.result-word {
    font-size: var(--font-xl);
    font-weight: 700;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--color-green);
}

.result-attempts {
    font-size: var(--font-body);
    color: var(--color-text-muted);
}

.result-stats {
    display: flex;
    gap: 2rem;
    margin: 0.5rem 0;
}

.result-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.2rem;
}

.stat-num {
    font-size: var(--font-xl);
    font-weight: 700;
}

.stat-label {
    font-size: var(--font-sm);
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.modal-btn {
    background: var(--color-green);
    border: none;
    border-radius: 6px;
    color: var(--color-text);
    font-size: 1.3rem;
    font-weight: 700;
    padding: 1rem 3rem;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s;
}

.modal-btn:hover {
    background: var(--color-green-hover);
}

.modal-btn.secondary {
    background: none;
    border: 1px solid var(--color-border);
    color: var(--color-text-muted);
}

.modal-btn.secondary:hover {
    background: rgba(255, 255, 255, 0.03);
    border-color: var(--color-border-hover);
    color: var(--color-text);
}

.game-btn {
    background: none;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    color: var(--color-text-muted);
    font-size: var(--font-body);
    font-weight: 600;
    padding: 0.7rem 1.5rem;
    cursor: pointer;
    font-family: inherit;
    transition: color 0.15s, border-color 0.15s;
}

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

.game-btn.restart-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    padding: 0.3rem 0.55rem;
    line-height: 1;
}

.hamburger-menu {
    position: relative;
    display: flex;
    align-items: center;
    margin-left: 0.5rem;
}

.hamburger-btn {
    background: none;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    color: var(--color-text-muted);
    font-size: 1.3rem;
    padding: 0.3rem 0.55rem;
    cursor: pointer;
    font-family: inherit;
    transition: color 0.15s, border-color 0.15s;
    line-height: 1;
}

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

.hamburger-dropdown {
    display: none;
    position: absolute;
    right: 0;
    top: 100%;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 6px;
    min-width: 130px;
    z-index: 50;
    overflow: hidden;
}

.hamburger-dropdown.open {
    display: block;
}

.hamburger-dropdown button {
    display: block;
    width: 100%;
    padding: 0.6rem 1rem;
    background: none;
    border: none;
    color: var(--color-text-muted);
    font-size: var(--font-sm);
    font-family: inherit;
    cursor: pointer;
    text-align: left;
    transition: background 0.1s, color 0.1s;
}

.hamburger-dropdown button:hover {
    background: rgba(255,255,255,0.04);
    color: var(--color-text);
}

.hamburger-dropdown button.active {
    color: var(--color-green);
    font-weight: 600;
}

.timer {
    font-size: 1.75rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.05em;
    min-width: 4rem;
    text-align: center;
}

.timer.ez {
    color: var(--color-green);
}

.timer.normal {
    color: var(--color-yellow);
}

.timer.hard {
    color: var(--color-red);
}

.timer.warning {
    color: var(--color-red);
    animation: warning-pulse 0.5s ease-in-out infinite;
}

@keyframes warning-pulse {
    0%, 100% { color: var(--color-red); }
    50% { color: var(--color-red-hover); }
}

.timer.hidden {
    display: none;
}

@media (max-width: 900px) {
    .header-row {
        grid-template-columns: 1fr;
        gap: 0.4rem;
    }

    .header-row > * {
        grid-column: 1;
    }

    .header-row > h1 {
        order: -1;
    }

    .header-left {
        justify-self: center;
    }

    .game-controls {
        justify-self: center;
        flex-wrap: wrap;
        justify-content: center;
    }
}

@media (max-width: 560px) {
    .result-stats {
        gap: 1rem;
    }
}

    @media (max-width: 480px) {
        :root {
            --tile-size: 62px;
            --tile-font: 1.8rem;
            --key-size: 40px;
            --key-wide-size: 62px;
            --key-enter-size: 78px;
            --key-font: 1rem;
            --key-wide-font: 0.85rem;
            --board-gap: 5px;
            --tile-gap: 4px;
            --keyboard-gap: 5px;
            --key-gap: 4px;
            --spacer-row1: 22px;
            --spacer-row2: 44px;
            --font-title: 1.6rem;
            --modal-max-width: 360px;
        }

    .result-modal {
        padding: 1.5rem;
    }

    .result-stats {
        gap: 0.75rem;
        flex-wrap: wrap;
        justify-content: center;
    }

    .stats-bar {
        flex-wrap: wrap;
        gap: 0.2rem 0.4rem;
        font-size: var(--font-sm);
    }

    .game-controls {
        gap: 0.4rem;
    }

    .radio-pill {
        padding: 0.3rem 0.5rem;
        font-size: var(--font-xs);
    }

    #multiplayer-btn {
        padding: 0.3rem 0.5rem;
        font-size: var(--font-xs);
    }

    .keyboard {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        width: 100%;
        max-width: 100%;
    }
}

@media (max-width: 380px) {
    :root {
        --tile-size: 52px;
        --tile-font: 1.5rem;
        --key-size: 32px;
        --key-wide-size: 50px;
        --key-enter-size: 62px;
        --key-font: 0.85rem;
        --key-wide-font: 0.75rem;
        --board-gap: 4px;
        --tile-gap: 3px;
        --keyboard-gap: 4px;
        --key-gap: 3px;
        --spacer-row1: 18px;
        --spacer-row2: 32px;
        --font-title: 1.3rem;
        --font-lg: 1.15rem;
        --modal-max-width: 310px;
    }

    .result-modal {
        padding: 1rem;
    }

    .result-stats {
        gap: 0.5rem;
    }

    .result-stats .stat-num {
        font-size: 1.3rem;
    }

    .header-row {
        gap: 0.2rem;
    }

    h1 {
        font-size: var(--font-title);
        letter-spacing: 0.1em;
    }

    .stat-mode {
        font-size: var(--font-xs);
    }

    #back-btn {
        font-size: var(--font-xs);
        padding: 0.25rem 0.5rem;
    }
}

@media (max-height: 950px) {
    :root {
        --tile-size: 74px;
        --tile-font: 2.5rem;
        --key-size: 50px;
        --key-wide-size: 80px;
        --key-enter-size: 100px;
        --key-font: 1.15rem;
        --key-wide-font: 1rem;
        --board-gap: 6px;
        --tile-gap: 5px;
        --keyboard-gap: 6px;
        --key-gap: 5px;
        --spacer-row1: 30px;
        --spacer-row2: 60px;
    }
}
