:root {
    --bg-1: #0f1b2a;
    --bg-2: #1f3a52;
    --panel: rgba(10, 16, 24, 0.82);
    --line: rgba(255, 255, 255, 0.12);
    --text: #f4f7fb;
    --muted: #b8c3d1;
    --green: #3ea86f;
    --yellow: #d6a32f;
    --black: #1f252b;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    color: var(--text);
    font-family: 'Trebuchet MS', 'Segoe UI', sans-serif;
    background: radial-gradient(circle at 15% 20%, #355674 0%, var(--bg-1) 52%, #05080d 100%);
    display: grid;
    place-items: center;
    padding: 20px;
}

.page-bg {
    position: fixed;
    inset: 0;
    background-image: linear-gradient(120deg, rgba(255, 255, 255, 0.04) 0%, transparent 25%, transparent 75%, rgba(255, 255, 255, 0.03) 100%);
    pointer-events: none;
}

.game-shell {
    width: min(860px, 100%);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 20px;
    padding: 22px;
    backdrop-filter: blur(8px);
}

.game-header {
    position: relative;
    display: flex;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    padding-right: 250px;
}

.eyebrow {
    margin: 0;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: var(--muted);
    font-size: 12px;
}

h1 {
    margin: 4px 0;
    font-size: clamp(28px, 4vw, 38px);
}

.subtitle {
    margin: 0;
    color: var(--muted);
}

.header-meta {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    position: absolute;
    top: 0;
    right: 0;
    flex-wrap: wrap;
    justify-content: flex-end;
    max-width: 240px;
}

.meta-pill {
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 8px 12px;
    font-size: 12px;
    color: var(--muted);
}

.meta-pill.mode-random {
    border-color: rgba(214, 163, 47, 0.55);
    color: #f5d98d;
}

.meta-pill.mode-chain {
    border-color: rgba(62, 168, 111, 0.55);
    color: #9ee2bd;
}

.hud {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin-top: 16px;
}

.hud-card {
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 10px;
    background: rgba(255, 255, 255, 0.02);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.hud-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
}

.hud-card strong {
    font-size: 15px;
    white-space: nowrap;
}

.board {
    margin-top: 18px;
    display: grid;
    gap: 10px;
}

.row {
    display: grid;
    gap: 8px;
    justify-content: center;
    grid-template-columns: repeat(var(--letters, 5), minmax(0, 48px));
}

.tile {
    width: 48px;
    height: 48px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.03);
    display: grid;
    place-items: center;
    text-transform: uppercase;
    font-weight: 700;
    font-size: 20px;
}

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

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

.tile.absent {
    background: var(--black);
    border-color: transparent;
}

.ghost-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line);
    border-radius: 10px;
    color: var(--text);
    background: rgba(255, 255, 255, 0.06);
    padding: 10px 14px;
    cursor: pointer;
    text-decoration: none;
}

.ghost-button:hover {
    background: rgba(255, 255, 255, 0.12);
}

.message {
    margin-top: 10px;
    min-height: 24px;
    color: var(--muted);
}

.keyboard {
    margin-top: 16px;
    display: grid;
    gap: 8px;
}

.keyboard-row {
    display: flex;
    justify-content: center;
    gap: 6px;
}

.keyboard-key {
    min-width: 34px;
    height: 48px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.05);
    color: var(--text);
    font: inherit;
    font-size: 15px;
    font-weight: 700;
    text-transform: uppercase;
    cursor: pointer;
    padding: 0 10px;
}

.keyboard-key:hover {
    background: rgba(255, 255, 255, 0.12);
}

.keyboard-key.correct {
    background: var(--green);
    border-color: transparent;
}

.keyboard-key.present {
    background: var(--yellow);
    border-color: transparent;
}

.keyboard-key.absent {
    background: var(--black);
    border-color: transparent;
}

.keyboard-key.wide {
    min-width: 72px;
    font-size: 12px;
    letter-spacing: 0.08em;
}

.actions-row {
    margin-top: 16px;
    display: flex;
    gap: 0;
    flex-wrap: wrap;
}

.actions-row-top {
    margin-top: 16px;
}

.actions-row .ghost-button {
    flex: 1 1 0;
    border-radius: 0;
}

.actions-row .ghost-button:first-child {
    border-top-left-radius: 10px;
    border-bottom-left-radius: 10px;
}

.actions-row .ghost-button:last-child {
    border-top-right-radius: 10px;
    border-bottom-right-radius: 10px;
}

.actions-row .ghost-button+.ghost-button {
    margin-left: -1px;
}

.game-footer {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--line);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    color: var(--muted);
    font-size: 12px;
    flex-wrap: wrap;
}

.footer-link {
    color: var(--muted);
    text-decoration: none;
}

.footer-link:hover {
    color: var(--text);
    text-decoration: underline;
}

@media (max-width: 640px) {
    body {
        display: block;
        padding: 0;
    }

    .game-shell {
        width: 100%;
        min-height: 100vh;
        border-radius: 0;
        border-left: 0;
        border-right: 0;
        padding: 12px 12px calc(20px + env(safe-area-inset-bottom));
    }

    .game-header {
        gap: 4px;
        padding-right: 0;
        flex-direction: column;
    }

    .eyebrow {
        display: none;
    }

    .subtitle {
        display: none;
    }

    h1 {
        font-size: 20px;
        margin: 0;
    }

    .header-meta {
        position: static;
        max-width: none;
        flex-direction: row;
        flex-wrap: nowrap;
        gap: 5px;
    }

    .meta-pill {
        padding: 4px 8px;
        font-size: 10px;
    }

    .tile {
        width: 52px;
        height: 52px;
        font-size: 22px;
    }

    .row {
        gap: 6px;
        grid-template-columns: repeat(var(--letters, 5), minmax(0, 52px));
    }

    .hud {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 4px;
        margin-top: 10px;
    }

    .hud-card {
        padding: 7px 8px;
        gap: 4px;
        border-radius: 8px;
        min-width: 0;
    }

    .hud-label {
        font-size: 9px;
        letter-spacing: 0.06em;
    }

    .hud-card strong {
        font-size: 12px;
    }

    .keyboard-row {
        gap: 4px;
    }

    .keyboard {
        position: sticky;
        bottom: 0;
        margin-top: 14px;
        margin-left: -12px;
        margin-right: -12px;
        padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
        background: rgba(10, 16, 24, 0.97);
        border-top: 1px solid var(--line);
        backdrop-filter: blur(10px);
        z-index: 30;
    }

    .keyboard-key {
        min-width: 0;
        flex: 1 1 0;
        height: 44px;
        padding: 0 4px;
        font-size: 13px;
    }

    .keyboard-key.wide {
        flex: 1.5 1 0;
        min-width: 54px;
        font-size: 11px;
    }

    .actions-row {
        margin-top: 10px;
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0;
        position: sticky;
        top: 0;
        z-index: 20;
        padding: 0;
        background: linear-gradient(180deg, rgba(10, 16, 24, 0.98) 0%, rgba(10, 16, 24, 0.88) 72%, rgba(10, 16, 24, 0) 100%);
    }

    .ghost-button {
        min-width: 0;
        padding: 12px 6px;
        font-size: 12px;
        text-align: center;
    }

    .actions-row .ghost-button {
        border-radius: 0;
    }

    .actions-row .ghost-button:first-child {
        border-top-left-radius: 12px;
        border-bottom-left-radius: 12px;
    }

    .actions-row .ghost-button:last-child {
        border-top-right-radius: 12px;
        border-bottom-right-radius: 12px;
    }

    .message {
        margin-top: 12px;
        margin-bottom: 8px;
    }

    .game-footer {
        margin-top: 8px;
        padding: 10px 0 calc(10px + env(safe-area-inset-bottom));
        justify-content: center;
        text-align: center;
        gap: 6px;
        font-size: 11px;
    }
}