:root {
    color-scheme: light dark;
    --cols: 5;
    --tile: clamp(44px, 9vw, 72px);
    --gap: clamp(2px, 1.2vw, 6px);
    --radius: 12px;
    --font-stack: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

    --bg: #f6f5f2;
    --surface: #ffffff;
    --text: #1f2a24;
    --muted: #5d6a63;
    --outline: rgba(31, 42, 36, 0.1);
    --primary: #345b45;
    --accent: #d59f52;
    --tile-correct: #2f8f4e;
    --tile-present: #d6a200;
    --tile-absent: #b5bab7;
    --focus: rgba(52, 91, 69, 0.35);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #111c18;
        --surface: #16241f;
        --text: #f1f5f3;
        --muted: #9db1a6;
        --outline: rgba(240, 250, 245, 0.15);
        --primary: #7dd3a6;
        --accent: #f4c77c;
        --tile-correct: #47d986;
        --tile-present: #f2c84a;
        --tile-absent: #4f5a55;
        --focus: rgba(125, 211, 166, 0.35);
    }
}

body[data-theme="dark"] {
    --bg: #111c18;
    --surface: #16241f;
    --text: #f1f5f3;
    --muted: #9db1a6;
    --outline: rgba(240, 250, 245, 0.15);
    --primary: #7dd3a6;
    --accent: #f4c77c;
    --tile-correct: #47d986;
    --tile-present: #f2c84a;
    --tile-absent: #4f5a55;
    --focus: rgba(125, 211, 166, 0.35);
}

body[data-theme="light"] {
    --bg: #f6f5f2;
    --surface: #ffffff;
    --text: #1f2a24;
    --muted: #5d6a63;
    --outline: rgba(31, 42, 36, 0.1);
    --primary: #345b45;
    --accent: #d59f52;
    --tile-correct: #2f8f4e;
    --tile-present: #d6a200;
    --tile-absent: #b5bab7;
    --focus: rgba(52, 91, 69, 0.35);
}

body.high-contrast {
    --bg: #ffffff;
    --surface: #ffffff;
    --text: #000000;
    --muted: #2b2b2b;
    --outline: #000000;
    --primary: #003366;
    --accent: #cc5500;
    --tile-correct: #007f00;
    --tile-present: #cc9200;
    --tile-absent: #555555;
    --focus: rgba(0, 51, 102, 0.35);
}

[hidden] {
    display: none !important;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: var(--font-stack);
    background: var(--bg);
    color: var(--text);
    display: flex;
    flex-direction: column;
    padding-bottom: env(safe-area-inset-bottom);
}

a {
    color: inherit;
    text-decoration: none;
}

a:focus-visible,
button:focus-visible,
select:focus-visible,
input:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
    border-radius: 6px;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.9rem clamp(1rem, 3vw, 2.25rem);
    background: var(--surface);
    border-bottom: 1px solid var(--outline);
    gap: 1rem;
    position: sticky;
    top: 0;
    z-index: 20;
}

.menu-toggle {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    width: 44px;
    height: 44px;
    border-radius: 999px;
    border: 1px solid var(--outline);
    background: transparent;
    cursor: pointer;
}

.menu-toggle__bar {
    width: 20px;
    height: 2px;
    background: var(--text);
    border-radius: 999px;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.topbar__left {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: clamp(0.5rem, 1.8vw, 1.25rem);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 700;
    font-size: clamp(1.1rem, 2.5vw, 1.4rem);
}

.brand__logo {
    width: 32px;
    height: 32px;
}

.menu {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex: 1 1 auto;
}

.menu.menu--open {
    display: flex;
}

.menu__links {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.menu__actions {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-left: auto;
}

.menu__toggles {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

.menu__link,
.menu__auth button {
    padding: 0.4rem 0.9rem;
    border-radius: 999px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
    border: 1px solid var(--outline);
    background: rgba(52, 91, 69, 0.12);
    color: var(--text);
    text-decoration: none;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.menu__link:hover,
.menu__link:focus-visible,
.menu__auth button:hover,
.menu__auth button:focus-visible {
    background: rgba(52, 91, 69, 0.22);
    border-color: rgba(52, 91, 69, 0.4);
    color: var(--text);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.08);
}

.menu__link:active,
.menu__auth button:active {
    transform: translateY(1px);
}

.menu__link--ghost,
.menu__auth button {
    background: var(--surface);
    border-color: var(--outline);
    color: var(--primary);
}

.menu__link--ghost:hover,
.menu__link--ghost:focus-visible,
.menu__auth button:hover,
.menu__auth button:focus-visible {
    color: var(--primary);
}

.menu__link--primary {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
    box-shadow: 0 10px 22px rgba(52, 91, 69, 0.25);
}

.menu__link--primary:hover,
.menu__link--primary:focus-visible {
    background: #3b6a51;
    border-color: var(--primary);
    color: #fff;
    box-shadow: 0 12px 26px rgba(52, 91, 69, 0.3);
}

.menu__auth {
    display: inline-flex;
    margin: 0;
    gap: 0.6rem;
    align-items: center;
}

.confetti-container {
    position: fixed;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
    z-index: 1600;
}

.confetti-piece {
    position: absolute;
    top: -12%;
    width: 10px;
    height: 16px;
    border-radius: 3px;
    opacity: 0;
    animation: confetti-fall var(--confetti-duration, 4.5s) linear forwards;
}

@keyframes confetti-fall {
    0% {
        transform: translate3d(0, -12vh, 0) rotate(0deg);
        opacity: 1;
    }
    100% {
        transform: translate3d(var(--confetti-x, 0px), 110vh, 0) rotate(var(--confetti-rotation, 720deg));
        opacity: 0;
    }
}

.topbar__actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.toggles {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    flex-wrap: wrap;
}

.toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.9rem;
    color: var(--muted);
}

.toggle input {
    appearance: none;
    width: 38px;
    height: 20px;
    border-radius: 999px;
    border: 1px solid var(--outline);
    background: rgba(0, 0, 0, 0.08);
    position: relative;
    transition: background 0.2s ease, border-color 0.2s ease;
    cursor: pointer;
}

.toggle input::after {
    content: "";
    position: absolute;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--surface);
    top: 50%;
    left: 4px;
    transform: translateY(-50%);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18);
    transition: transform 0.2s ease, background 0.2s ease;
}

.toggle input:checked {
    background: var(--primary);
    border-color: transparent;
}

.toggle input:checked::after {
    transform: translate(14px, -50%);
    background: #fff;
}

.switch {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.9rem;
    color: var(--muted);
}

.switch input {
    accent-color: var(--primary);
}




.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    padding: 0.65rem 1.4rem;
    border-radius: 999px;
    border: 1px solid transparent;
    background: var(--primary);
    color: #fff;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.btn:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.08);
}

.btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.btn--ghost {
    background: rgba(0, 0, 0, 0.03);
    color: var(--primary);
    border-color: var(--outline);
}

.page {
    width: min(960px, 95vw);
    margin: clamp(1rem, 3vw, 2.5rem) auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: clamp(1.5rem, 4vw, 2.5rem);
}

.game {
    background: var(--surface);
    border-radius: clamp(12px, 2vw, 18px);
    padding: clamp(1rem, 4vw, 2.5rem);
    box-shadow: 0 20px 45px rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    gap: clamp(1rem, 3vw, 1.75rem);
}

.game__header {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.game__options {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: flex-end;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    font-size: 0.95rem;
}

.field__label {
    font-weight: 600;
    color: var(--muted);
}

.field select {
    padding: 0.55rem 0.75rem;
    border-radius: 8px;
    border: 1px solid var(--outline);
    background: rgba(0, 0, 0, 0.03);
    color: inherit;
}

.game__buttons {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.game__meta {
    margin: 0;
    color: var(--muted);
    font-size: 0.95rem;
    min-height: 1.4rem;
}

.board-wrapper {
    display: flex;
    justify-content: center;
}

.board {
    --cols: 5;
    display: grid;
    gap: var(--gap);
    justify-content: center;
    margin: 0 auto;
    width: min(calc(var(--cols) * var(--tile) + (var(--cols) - 1) * var(--gap)), 100%);
}

.board__row {
    display: grid;
    grid-template-columns: repeat(var(--cols), var(--tile));
    gap: var(--gap);
}

.tile {
    width: var(--tile);
    aspect-ratio: 1 / 1;
    border-radius: clamp(6px, 1.4vw, var(--radius));
    border: 2px solid var(--outline);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-transform: uppercase;
    font-weight: 700;
    font-size: clamp(1.1rem, 4vw, 1.75rem);
    line-height: 1;
    background: var(--surface);
    color: #101820;
    transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

.tile--filled {
    border-color: var(--primary);
}

.tile--green {
    background: var(--tile-correct);
    color: #101820;
    border-color: var(--tile-correct);
}

.tile--yellow {
    background: var(--tile-present);
    color: #101820;
    border-color: var(--tile-present);
}

.tile--grey {
    background: var(--tile-absent);
    color: #101820;
    border-color: var(--tile-absent);
}

.tile--active {
    box-shadow: 0 0 0 3px var(--focus);
}

.tile--flip {
    animation: flip 0.45s ease forwards;
}

.tile--bounce {
    animation: bounce 380ms ease forwards;
}

@keyframes flip {
    0% { transform: rotateX(0); }
    45% { transform: rotateX(-90deg); }
    55% { transform: rotateX(-90deg); }
    100% { transform: rotateX(-180deg); }
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    35% { transform: translateY(-10%); }
    65% { transform: translateY(4%); }
}

.keyboard {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 0 0.5rem clamp(0.75rem, 4vw, 1.5rem);
    background: rgba(0, 0, 0, 0.03);
}

.keyboard__row {
    display: flex;
    justify-content: center;
    gap: 0.4rem;
}

.key {
    flex: 1 1 0;
    max-width: 3.25rem;
    min-height: 44px;
    padding: 0.65rem 0.35rem;
    border-radius: 8px;
    border: 1px solid var(--outline);
    background: rgba(0, 0, 0, 0.06);
    color: var(--text);
    font-weight: 600;
    text-transform: uppercase;
    cursor: pointer;
    transition: transform 0.1s ease, background 0.1s ease;
}

.key[data-key="ENTER"],
.key[data-key="↵"] {
    flex: 1.5 1 0;
    max-width: none;
}

.key[data-key="⌫"] {
    flex: 1.3 1 0;
    max-width: none;
}

.key:hover,
.key:focus-visible {
    background: rgba(0, 0, 0, 0.12);
}

.key[data-state="correct"],
.key--correct {
    background: var(--tile-correct);
    color: #1f2a24;
    border-color: var(--tile-correct);
}

.key[data-state="present"],
.key--present {
    background: var(--tile-present);
    color: #1f2a24;
    border-color: var(--tile-present);
}

.key[data-state="absent"],
.key--absent {
    background: var(--tile-absent);
    color: #1f2a24;
    border-color: var(--tile-absent);
}

.mobile-input {
    position: fixed;
    left: 50%;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 12px);
    transform: translateX(-50%);
    opacity: 0;
    pointer-events: auto;
    width: 2px;
    height: 2px;
    border: 0;
    background: rgba(0, 0, 0, 0.03);
    color: transparent;
    caret-color: transparent;
    z-index: -1;
}

.game__actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    justify-content: center;
}

.game__status {
    text-align: center;
    min-height: 1.5rem;
    font-weight: 600;
}

.game__status[data-variant="warning"] {
    color: var(--tile-present);
}

.game__status[data-variant="error"] {
    color: #c04747;
}

.footer {
    text-align: center;
    color: var(--muted);
    padding: 1.5rem clamp(1rem, 3vw, 2rem);
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* --- Tetris --- */
.tetris {
    display: flex;
    flex-direction: column;
    gap: clamp(1rem, 3vw, 1.75rem);
}

.tetris__header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 1rem;
    align-items: flex-end;
}

.tetris__heading h1 {
    margin: 0;
    font-size: clamp(1.75rem, 4vw, 2.5rem);
}

.tetris__subtitle {
    margin: 0.35rem 0 0;
    color: var(--muted);
}

.tetris__controls {
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
    flex-wrap: wrap;
}

.tetris__mode {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    font-size: 0.95rem;
}

.tetris__mode select {
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    border: 1px solid var(--outline);
    background: rgba(0, 0, 0, 0.03);
    color: inherit;
}

.tetris__layout {
    display: grid;
    grid-template-columns: minmax(0, 260px) minmax(0, 1fr);
    gap: clamp(1rem, 3vw, 2rem);
}

.tetris__panel {
    display: flex;
    flex-direction: column;
    gap: clamp(1rem, 2vw, 1.5rem);
    background: rgba(0, 0, 0, 0.03);
    border-radius: clamp(12px, 2vw, 16px);
    padding: clamp(1rem, 2.5vw, 1.5rem);
}

.tetris__stat {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    font-weight: 600;
}

.tetris__stat-value {
    font-size: clamp(1.25rem, 3.5vw, 1.75rem);
}

.tetris__preview {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.tetris__preview h2 {
    margin: 0;
    font-size: 1rem;
    color: var(--muted);
}

.tetris__mini-grid {
    width: 100%;
    aspect-ratio: 1 / 1;
    border-radius: 8px;
    background: var(--surface);
    border: 1px solid var(--outline);
}

.tetris__settings .switch {
    justify-content: flex-start;
}

.tetris__help dl {
    display: grid;
    gap: 0.35rem;
    margin: 0;
}

.tetris__help div {
    display: flex;
    gap: 0.5rem;
    align-items: baseline;
}

.tetris__stage-wrapper {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: clamp(0.5rem, 2vw, 1rem);
    border-radius: clamp(12px, 2vw, 16px);
    background: var(--surface);
    box-shadow: 0 20px 45px rgba(0, 0, 0, 0.08);
}

.tetris__overlay {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    backdrop-filter: blur(4px);
    background: rgba(17, 28, 24, 0.55);
}

.tetris__overlay-content {
    background: var(--surface);
    color: var(--text);
    padding: clamp(1.25rem, 3vw, 1.75rem);
    border-radius: clamp(12px, 2vw, 16px);
    max-width: 320px;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.tetris__overlay-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    flex-wrap: wrap;
}

.tetris__mobile-controls {
    display: none;
    gap: 0.75rem;
    justify-content: space-between;
    margin-top: 0.5rem;
}

.tetris__control {
    flex: 1 1 0;
    min-height: 48px;
    border-radius: 12px;
    border: 1px solid var(--outline);
    background: rgba(0, 0, 0, 0.06);
    font-size: 1.25rem;
    font-weight: 600;
}

.tetris__leaderboard {
    display: flex;
    flex-direction: column;
    gap: clamp(0.75rem, 2vw, 1.25rem);
    background: var(--surface);
    padding: clamp(1rem, 2.5vw, 1.5rem);
    border-radius: clamp(12px, 2vw, 16px);
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.08);
}

.tetris__leaderboard-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

.tetris__leaderboard-table {
    min-height: 120px;
}

.tetris__leaderboard-empty {
    text-align: center;
    color: var(--muted);
    padding: 1rem;
}

/* --- Navigation rebuild -------------------------------------------------- */

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: clamp(0.75rem, 2vw, 1.5rem);
    padding: clamp(0.75rem, 2vw, 1.1rem) clamp(1rem, 3vw, 2.25rem);
    background: var(--surface);
    border-bottom: 1px solid var(--outline);
    position: sticky;
    top: 0;
    z-index: 40;
}

.menu-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    width: 42px;
    height: 42px;
    border-radius: 999px;
    border: 1px solid var(--outline);
    background: var(--surface);
    cursor: pointer;
    transition: transform 0.2s ease, background 0.2s ease;
}

.menu-toggle:hover {
    background: rgba(0, 0, 0, 0.05);
}

.menu-toggle__bar {
    width: 20px;
    height: 2px;
    border-radius: 999px;
    background: var(--text);
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.menu-toggle__bar + .menu-toggle__bar {
    margin-top: 5px;
}

.menu-toggle--open .menu-toggle__bar:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
}

.menu-toggle--open .menu-toggle__bar:nth-child(2) {
    opacity: 0;
}

.menu-toggle--open .menu-toggle__bar:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
}

body.menu-open {
    overflow: hidden;
}

.menu {
    display: flex;
    align-items: center;
    gap: clamp(0.75rem, 1.8vw, 1.4rem);
    margin-left: auto;
}

.menu__panel {
    display: flex;
    align-items: center;
    gap: clamp(0.75rem, 1.8vw, 1.4rem);
    flex-wrap: wrap;
}

.menu__links {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.menu__link,
.menu__auth button {
    padding: 0.4rem 0.9rem;
    border-radius: 999px;
    font-weight: 600;
    font: inherit;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
    border: 1px solid var(--outline);
    background: rgba(52, 91, 69, 0.12);
    color: var(--text);
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
    text-decoration: none;
}

.menu__link:hover,
.menu__link:focus-visible,
.menu__auth button:hover,
.menu__auth button:focus-visible {
    background: rgba(52, 91, 69, 0.22);
    border-color: rgba(52, 91, 69, 0.4);
    color: var(--text);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.08);
}

.menu__link:active,
.menu__auth button:active {
    transform: translateY(1px);
}

.menu__link--ghost,
.menu__auth button {
    background: var(--surface);
    border-color: var(--outline);
    color: var(--primary);
}

.menu__link--ghost:hover,
.menu__link--ghost:focus-visible,
.menu__auth button:hover,
.menu__auth button:focus-visible {
    color: var(--primary);
}

.menu__link--primary {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
    box-shadow: 0 10px 22px rgba(52, 91, 69, 0.25);
}

.menu__link--primary:hover,
.menu__link--primary:focus-visible {
    background: #3b6a51;
    border-color: var(--primary);
    color: #fff;
    box-shadow: 0 12px 26px rgba(52, 91, 69, 0.3);
}

.menu__auth {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    flex-wrap: wrap;
}

.menu__logout {
    margin: 0;
}

.menu__toggles {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    flex-wrap: wrap;
    color: var(--muted);
}

.menu__toggles .toggle {
    gap: 0.35rem;
}

@media (min-width: 901px) {
    .menu {
        position: static;
    }

    .menu__panel {
        background: none;
        padding: 0;
        box-shadow: none;
    }
}

@media (max-width: 900px) {
    .menu-toggle {
        display: inline-flex;
    }

    .topbar {
        flex-direction: row;
        align-items: center;
        padding: clamp(0.65rem, 4vw, 0.9rem) clamp(1rem, 5vw, 1.75rem);
    }

    .menu {
        position: fixed;
        inset: 0;
        padding: calc(4.75rem + env(safe-area-inset-top)) 1.5rem 2rem;
        background: rgba(17, 28, 24, 0.62);
        display: none;
        align-items: flex-start;
        justify-content: center;
        margin: 0;
        z-index: 160;
    }

    .menu[data-open="true"],
    .menu.menu--open {
        display: flex;
    }

    .menu__panel {
        width: min(92vw, 360px);
        background: var(--surface);
        border-radius: 18px;
        padding: 1.5rem;
        box-shadow: 0 24px 60px rgba(0, 0, 0, 0.22);
        display: flex;
        flex-direction: column;
        align-items: stretch;
        gap: 1.25rem;
    }

    .menu__links,
    .menu__toggles,
    .menu__auth {
        flex-direction: column;
        align-items: stretch;
        gap: 0.85rem;
    }

    .menu__link,
    .menu__auth button {
        width: 100%;
        font-size: 1.05rem;
        padding: 0.75rem 1rem;
        justify-content: center;
        text-align: center;
        border-width: 1.5px;
        border-radius: 14px;
        box-shadow: 0 10px 28px rgba(17, 28, 24, 0.18);
    }

    .menu__link {
        background: rgba(52, 91, 69, 0.22);
        border-color: rgba(52, 91, 69, 0.45);
        color: var(--text);
    }

    .menu__link:hover,
    .menu__link:focus-visible {
        background: rgba(52, 91, 69, 0.3);
        border-color: rgba(52, 91, 69, 0.55);
    }

    .menu__toggles label {
        justify-content: space-between;
    }
}


@media (max-width: 900px) {
    .topbar {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
        padding: 0.85rem 1.4rem;
    }

    .topbar__left {
        width: 100%;
        justify-content: space-between;
        flex-wrap: wrap;
        gap: 0.65rem;
    }

    .menu {
        flex-wrap: wrap;
    }

    .menu__actions {
        margin-left: auto;
    }

    .tetris__layout {
        grid-template-columns: 1fr;
    }

    .tetris__panel {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 1rem;
    }

    .tetris__panel > * {
        flex: 1 1 180px;
    }
}

@media (max-width: 768px) {
    .menu-toggle {
        display: inline-flex;
    }

    .menu {
        position: absolute;
        top: calc(100% + 0.5rem);
        left: 1rem;
        right: 1rem;
        background: var(--surface);
        border-radius: 12px;
        box-shadow: 0 18px 45px rgba(0, 0, 0, 0.12);
        border: 1px solid var(--outline);
        padding: 0.75rem 1rem;
        flex-direction: column;
        gap: 0.75rem;
        display: none;
        z-index: 15;
    }

    .menu.menu--open {
        display: flex;
    }

    .menu__links,
    .menu__actions {
        width: 100%;
        flex-direction: column;
        align-items: stretch;
        gap: 0.6rem;
    }

    .menu__actions {
        margin-left: 0;
    }

    .menu__toggles {
        width: 100%;
        justify-content: flex-start;
    }

    .menu__link,
    .menu__auth {
        width: 100%;
    }

    .menu__auth {
        justify-content: stretch;
    }

    .menu__auth button {
        width: 100%;
        justify-content: center;
        background: var(--surface);
        border-color: var(--outline);
        color: var(--primary);
    }

    .page {
        width: min(100%, 100vw - 1.5rem);
        margin: 1rem auto 2rem;
    }

    .game__options {
        flex-direction: column;
        align-items: stretch;
    }

    .game__buttons {
        width: 100%;
        justify-content: stretch;
        gap: 0.6rem;
    }

    .game__buttons .btn {
        flex: 1 1 calc(50% - 0.6rem);
        min-width: 0;
    }

    .field {
        flex: 1 1 calc(50% - 0.6rem);
    }

    .keyboard {
        position: sticky;
        bottom: 0;
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
        background: linear-gradient(180deg, rgba(246, 245, 242, 0) 0%, var(--bg) 40%);
        border-top: 1px solid var(--outline);
    }

    .tetris__layout {
        display: flex;
        flex-direction: column;
        gap: 1.25rem;
    }

    .game {
        padding: 1rem 1.25rem;
        gap: 1rem;
    }

    .tetris__panel {
        order: 1;
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.75rem;
    }

    .tetris__panel .tetris__stat {
        grid-column: span 2;
    }

    .tetris__preview {
        grid-column: span 1;
    }

    .tetris__settings,
    .tetris__help {
        grid-column: span 2;
    }

    .tetris__stage-wrapper {
        order: 2;
        align-self: center;
    }

    .tetris__stage {
        --stage-width: min(92vw, 22rem);
        width: var(--stage-width);
        height: min(60vh, calc(var(--stage-width) * 2));
    }

    .tetris__mobile-controls {
        display: grid;
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 0.5rem;
        order: 3;
    }

    .tetris__leaderboard {
        order: 4;
    }
}

:root {
    color-scheme: light dark;
    --cols: 5;
    --tile: clamp(44px, 9vw, 72px);
    --gap: clamp(2px, 1.2vw, 6px);
    --radius: 12px;
    --font-stack: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

    --bg: #f6f5f2;
    --surface: #ffffff;
    --text: #1f2a24;
    --muted: #5d6a63;
    --outline: rgba(31, 42, 36, 0.1);
    --primary: #345b45;
    --accent: #d59f52;
    --tile-correct: #2f8f4e;
    --tile-present: #d6a200;
    --tile-absent: #b5bab7;
    --focus: rgba(52, 91, 69, 0.35);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #111c18;
        --surface: #16241f;
        --text: #f1f5f3;
        --muted: #9db1a6;
        --outline: rgba(240, 250, 245, 0.15);
        --primary: #7dd3a6;
        --accent: #f4c77c;
        --tile-correct: #47d986;
        --tile-present: #f2c84a;
        --tile-absent: #4f5a55;
        --focus: rgba(125, 211, 166, 0.35);
    }
}

body[data-theme="dark"] {
    --bg: #111c18;
    --surface: #16241f;
    --text: #f1f5f3;
    --muted: #9db1a6;
    --outline: rgba(240, 250, 245, 0.15);
    --primary: #7dd3a6;
    --accent: #f4c77c;
    --tile-correct: #47d986;
    --tile-present: #f2c84a;
    --tile-absent: #4f5a55;
    --focus: rgba(125, 211, 166, 0.35);
}

body[data-theme="light"] {
    --bg: #f6f5f2;
    --surface: #ffffff;
    --text: #1f2a24;
    --muted: #5d6a63;
    --outline: rgba(31, 42, 36, 0.1);
    --primary: #345b45;
    --accent: #d59f52;
    --tile-correct: #2f8f4e;
    --tile-present: #d6a200;
    --tile-absent: #b5bab7;
    --focus: rgba(52, 91, 69, 0.35);
}

body.high-contrast {
    --bg: #ffffff;
    --surface: #ffffff;
    --text: #000000;
    --muted: #2b2b2b;
    --outline: #000000;
    --primary: #003366;
    --accent: #cc5500;
    --tile-correct: #007f00;
    --tile-present: #cc9200;
    --tile-absent: #555555;
    --focus: rgba(0, 51, 102, 0.35);
}

[hidden] {
    display: none !important;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: var(--font-stack);
    background: var(--bg);
    color: var(--text);
    display: flex;
    flex-direction: column;
    padding-bottom: env(safe-area-inset-bottom);
}

a {
    color: inherit;
    text-decoration: none;
}

a:focus-visible,
button:focus-visible,
select:focus-visible,
input:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
    border-radius: 6px;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.9rem clamp(1rem, 3vw, 2.25rem);
    background: var(--surface);
    border-bottom: 1px solid var(--outline);
    gap: 1rem;
    position: sticky;
    top: 0;
    z-index: 20;
}

.menu-toggle {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    width: 44px;
    height: 44px;
    border-radius: 999px;
    border: 1px solid var(--outline);
    background: transparent;
    cursor: pointer;
}

.menu-toggle__bar {
    width: 20px;
    height: 2px;
    background: var(--text);
    border-radius: 999px;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.topbar__left {
    display: flex;
    align-items: center;
    gap: clamp(0.5rem, 1.8vw, 1.25rem);
    flex: 1 1 auto;
    min-width: 0;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 700;
    font-size: clamp(1.1rem, 2.5vw, 1.4rem);
}

.brand__logo {
    width: 32px;
    height: 32px;
}

.menu {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

.menu.menu--open {
    display: flex;
}

.menu__link {
    padding: 0.35rem 0.7rem;
    border-radius: 999px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
}

.menu__link:hover,
.menu__link:focus-visible {
    background: var(--outline);
}

.menu__link--action {
    border: 1px solid var(--outline);
    background: transparent;
    color: var(--primary);
}

.menu__link--primary {
    background: var(--primary);
    color: #fff;
}

.menu__auth {
    display: inline-flex;
    margin: 0;
}

.menu__auth button {
    border: none;
    background: none;
    padding: 0;
    font: inherit;
    color: inherit;
    cursor: pointer;
}

.topbar__actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.toggles {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    flex-wrap: wrap;
}

.toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.9rem;
    color: var(--muted);
}

.toggle input {
    appearance: none;
    width: 38px;
    height: 20px;
    border-radius: 999px;
    border: 1px solid var(--outline);
    background: rgba(0, 0, 0, 0.08);
    position: relative;
    transition: background 0.2s ease, border-color 0.2s ease;
    cursor: pointer;
}

.toggle input::after {
    content: "";
    position: absolute;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--surface);
    top: 50%;
    left: 4px;
    transform: translateY(-50%);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18);
    transition: transform 0.2s ease, background 0.2s ease;
}

.toggle input:checked {
    background: var(--primary);
    border-color: transparent;
}

.toggle input:checked::after {
    transform: translate(14px, -50%);
    background: #fff;
}

.switch {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.9rem;
    color: var(--muted);
}

.switch input {
    accent-color: var(--primary);
}




.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    padding: 0.65rem 1.4rem;
    border-radius: 999px;
    border: 1px solid transparent;
    background: var(--primary);
    color: #fff;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.btn:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.08);
}

.btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.btn--ghost {
    background: rgba(0, 0, 0, 0.03);
    color: var(--primary);
    border-color: var(--outline);
}

.page {
    width: min(960px, 95vw);
    margin: clamp(1rem, 3vw, 2.5rem) auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: clamp(1.5rem, 4vw, 2.5rem);
}

.game {
    background: var(--surface);
    border-radius: clamp(12px, 2vw, 18px);
    padding: clamp(1rem, 4vw, 2.5rem);
    box-shadow: 0 20px 45px rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    gap: clamp(1rem, 3vw, 1.75rem);
}

.game__header {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.game__options {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: flex-end;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    font-size: 0.95rem;
}

.field__label {
    font-weight: 600;
    color: var(--muted);
}

.field select {
    padding: 0.55rem 0.75rem;
    border-radius: 8px;
    border: 1px solid var(--outline);
    background: rgba(0, 0, 0, 0.03);
    color: inherit;
}

.game__buttons {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.game__meta {
    margin: 0;
    color: var(--muted);
    font-size: 0.95rem;
    min-height: 1.4rem;
}

.board-wrapper {
    display: flex;
    justify-content: center;
}

.board {
    --cols: 5;
    display: grid;
    gap: var(--gap);
    justify-content: center;
    margin: 0 auto;
    width: min(calc(var(--cols) * var(--tile) + (var(--cols) - 1) * var(--gap)), 100%);
}

.board__row {
    display: grid;
    grid-template-columns: repeat(var(--cols), var(--tile));
    gap: var(--gap);
}

.tile {
    width: var(--tile);
    aspect-ratio: 1 / 1;
    border-radius: clamp(6px, 1.4vw, var(--radius));
    border: 2px solid var(--outline);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-transform: uppercase;
    font-weight: 700;
    font-size: clamp(1.1rem, 4vw, 1.75rem);
    line-height: 1;
    background: var(--surface);
    transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

.tile--filled {
    border-color: var(--primary);
}

.tile--green {
    background: var(--tile-correct);
    color: #1f2a24;
    border-color: var(--tile-correct);
}

.tile--yellow {
    background: var(--tile-present);
    color: #1f2a24;
    border-color: var(--tile-present);
}

.tile--grey {
    background: var(--tile-absent);
    color: #1f2a24;
    border-color: var(--tile-absent);
}

.tile--active {
    box-shadow: 0 0 0 3px var(--focus);
}

.tile--flip {
    animation: flip 0.45s ease forwards;
}

.tile--bounce {
    animation: bounce 380ms ease forwards;
}

@keyframes flip {
    0% { transform: rotateX(0); }
    45% { transform: rotateX(-90deg); }
    55% { transform: rotateX(-90deg); }
    100% { transform: rotateX(-180deg); }
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    35% { transform: translateY(-10%); }
    65% { transform: translateY(4%); }
}

.keyboard {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 0 0.5rem clamp(0.75rem, 4vw, 1.5rem);
    background: rgba(0, 0, 0, 0.03);
}

.keyboard__row {
    display: flex;
    justify-content: center;
    gap: 0.4rem;
}

.key {
    flex: 1 1 0;
    max-width: 3.25rem;
    min-height: 44px;
    padding: 0.65rem 0.35rem;
    border-radius: 8px;
    border: 1px solid var(--outline);
    background: rgba(0, 0, 0, 0.06);
    color: var(--text);
    font-weight: 600;
    text-transform: uppercase;
    cursor: pointer;
    transition: transform 0.1s ease, background 0.1s ease;
}

.key[data-key="ENTER"],
.key[data-key="↵"] {
    flex: 1.5 1 0;
    max-width: none;
}

.key[data-key="⌫"] {
    flex: 1.3 1 0;
    max-width: none;
}

.key:hover,
.key:focus-visible {
    background: rgba(0, 0, 0, 0.12);
}

.key[data-state="correct"] {
    background: var(--tile-correct);
    color: #fff;
}

.key[data-state="present"] {
    background: var(--tile-present);
    color: #1a1300;
}

.key[data-state="absent"] {
    background: var(--tile-absent);
    color: #fff;
}

.mobile-input {
    position: fixed;
    left: 50%;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 12px);
    transform: translateX(-50%);
    opacity: 0;
    pointer-events: auto;
    width: 2px;
    height: 2px;
    border: 0;
    background: rgba(0, 0, 0, 0.03);
    color: transparent;
    caret-color: transparent;
    z-index: -1;
}

.game__actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    justify-content: center;
}

.game__status {
    text-align: center;
    min-height: 1.5rem;
    font-weight: 600;
}

.game__status[data-variant="warning"] {
    color: var(--tile-present);
}

.game__status[data-variant="error"] {
    color: #c04747;
}

.footer {
    text-align: center;
    color: var(--muted);
    padding: 1.5rem clamp(1rem, 3vw, 2rem);
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* --- Tetris --- */
.tetris {
    display: flex;
    flex-direction: column;
    gap: clamp(1rem, 3vw, 1.75rem);
}

.tetris__header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 1rem;
    align-items: flex-end;
}

.tetris__heading h1 {
    margin: 0;
    font-size: clamp(1.75rem, 4vw, 2.5rem);
}

.tetris__subtitle {
    margin: 0.35rem 0 0;
    color: var(--muted);
}

.tetris__controls {
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
    flex-wrap: wrap;
}

.tetris__mode {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    font-size: 0.95rem;
}

.tetris__mode select {
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    border: 1px solid var(--outline);
    background: rgba(0, 0, 0, 0.03);
    color: inherit;
}

.tetris__layout {
    display: grid;
    grid-template-columns: minmax(0, 260px) minmax(0, 1fr);
    gap: clamp(1rem, 3vw, 2rem);
}

.tetris__panel {
    display: flex;
    flex-direction: column;
    gap: clamp(1rem, 2vw, 1.5rem);
    background: rgba(0, 0, 0, 0.03);
    border-radius: clamp(12px, 2vw, 16px);
    padding: clamp(1rem, 2.5vw, 1.5rem);
}

.tetris__stat {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    font-weight: 600;
}

.tetris__stat-value {
    font-size: clamp(1.25rem, 3.5vw, 1.75rem);
}

.tetris__preview {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.tetris__preview h2 {
    margin: 0;
    font-size: 1rem;
    color: var(--muted);
}

.tetris__mini-grid {
    width: 100%;
    aspect-ratio: 1 / 1;
    border-radius: 8px;
    background: var(--surface);
    border: 1px solid var(--outline);
}

.tetris__settings .switch {
    justify-content: flex-start;
}

.tetris__help dl {
    display: grid;
    gap: 0.35rem;
    margin: 0;
}

.tetris__help div {
    display: flex;
    gap: 0.5rem;
    align-items: baseline;
}

.tetris__stage-wrapper {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: clamp(0.5rem, 2vw, 1rem);
    border-radius: clamp(12px, 2vw, 16px);
    background: var(--surface);
    box-shadow: 0 20px 45px rgba(0, 0, 0, 0.08);
}

.tetris__overlay {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    backdrop-filter: blur(4px);
    background: rgba(17, 28, 24, 0.55);
}

.tetris__overlay-content {
    background: var(--surface);
    color: var(--text);
    padding: clamp(1.25rem, 3vw, 1.75rem);
    border-radius: clamp(12px, 2vw, 16px);
    max-width: 320px;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.tetris__overlay-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    flex-wrap: wrap;
}

.tetris__mobile-controls {
    display: none;
    gap: 0.75rem;
    justify-content: space-between;
    margin-top: 0.5rem;
}

.tetris__control {
    flex: 1 1 0;
    min-height: 48px;
    border-radius: 12px;
    border: 1px solid var(--outline);
    background: rgba(0, 0, 0, 0.06);
    font-size: 1.25rem;
    font-weight: 600;
}

.tetris__leaderboard {
    display: flex;
    flex-direction: column;
    gap: clamp(0.75rem, 2vw, 1.25rem);
    background: var(--surface);
    padding: clamp(1rem, 2.5vw, 1.5rem);
    border-radius: clamp(12px, 2vw, 16px);
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.08);
}

.tetris__leaderboard-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

.tetris__leaderboard-table {
    min-height: 120px;
}

.tetris__leaderboard-empty {
    text-align: center;
    color: var(--muted);
    padding: 1rem;
}

@media (max-width: 900px) {
    .topbar {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
        padding: 0.85rem 1.4rem;
    }

    .topbar__left {
        width: 100%;
        justify-content: space-between;
        flex-wrap: wrap;
        gap: 0.65rem;
    }

    .menu {
        flex-wrap: wrap;
    }

    .menu__actions {
        margin-left: auto;
    }

    .tetris__layout {
        grid-template-columns: 1fr;
    }

    .tetris__panel {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 1rem;
    }

    .tetris__panel > * {
        flex: 1 1 180px;
    }
}

@media (max-width: 600px) {
    :root {
        --tile: clamp(44px, 11vw, 56px);
        --gap: clamp(2px, 1vw, 5px);
    }

    .topbar {
        align-items: flex-start;
        padding: 0.7rem 1rem;
    }

    .topbar__brand {
        width: 100%;
        flex-direction: column;
        align-items: flex-start;
        gap: 0.7rem;
    }

    .nav {
        width: 100%;
        gap: 0.55rem;
        justify-content: flex-start;
    }

    .topbar__actions {
        width: 100%;
        flex-direction: column;
        align-items: flex-start;
        gap: 0.65rem;
    }

    .auth-actions {
        width: 100%;
        justify-content: flex-start;
        gap: 0.55rem;
    }

    .auth-actions .btn,
    .auth-actions button {
        padding: 0.45rem 0.95rem;
    }
}

@media (max-width: 480px) {
    :root {
        --tile: clamp(42px, 12vw, 52px);
        --gap: clamp(2px, 0.9vw, 4px);
    }

    .keyboard {
        gap: 0.35rem;
        padding-left: 0.25rem;
        padding-right: 0.25rem;
    }

    .keyboard__row {
        gap: 0.3rem;
    }

    .key {
        font-size: 0.95rem;
    }

    .tetris__controls {
        width: 100%;
        justify-content: space-between;
    }

    .tetris__stage {
        --stage-width: min(90vw, 18rem);
        width: var(--stage-width);
        height: min(60vh, calc(var(--stage-width) * 2));
    }
}

/* --- Tetris Colours --- */
:root {
    --piece-i: #33c6ff;
    --piece-j: #4c62ff;
    --piece-l: #ff8a3c;
    --piece-o: #f2d94e;
    --piece-s: #2ecc71;
    --piece-t: #b075ff;
    --piece-z: #ff5f6d;
    --piece-ghost: rgba(255, 255, 255, 0.35);
}

body[data-theme="dark"] {
    --piece-i: #29a9e6;
    --piece-j: #7d89ff;
    --piece-l: #ff9966;
    --piece-o: #f4d976;
    --piece-s: #44d98d;
    --piece-t: #c39cff;
    --piece-z: #ff707d;
    --piece-ghost: rgba(255, 255, 255, 0.25);
}
.tetris__stage {
    position: relative;
    width: min(420px, 82vw);
    aspect-ratio: 1 / 2;
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    grid-template-rows: repeat(20, 1fr);
    gap: 1px;
    background: var(--outline);
    border-radius: clamp(8px, 2vw, 12px);
    overflow: hidden;
}

.tetris__cell {
    position: relative;
    background: rgba(0, 0, 0, 0.04);
    transition: background 0.08s ease;
}

.tetris__cell::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: clamp(2px, 1vw, 6px);
    background: rgba(0, 0, 0, 0.06);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.15);
    transition: background 0.08s ease, box-shadow 0.08s ease, border 0.08s ease;
}

.tetris__cell--filled::after {
    background: rgba(0, 0, 0, 0.15);
}

.tetris__cell[class*="tetris__cell--"]:not(.tetris__cell--ghost)::after {
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.22), inset 0 -1px 0 rgba(0, 0, 0, 0.18);
}

.tetris__cell--active::after {
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.35) inset;
}

.tetris__cell--ghost::after {
    background: rgba(0, 0, 0, 0.03);
    border: 1px dashed var(--piece-ghost);
}

.tetris__cell--i::after { background: var(--piece-i); }
.tetris__cell--j::after { background: var(--piece-j); }
.tetris__cell--l::after { background: var(--piece-l); }
.tetris__cell--o::after { background: var(--piece-o); }
.tetris__cell--s::after { background: var(--piece-s); }
.tetris__cell--t::after { background: var(--piece-t); }
.tetris__cell--z::after { background: var(--piece-z); }

.tetris__mini-grid {
    display: grid;
    grid-template-columns: repeat(var(--mini-cols, 4), 1fr);
    gap: 3px;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 10px;
    padding: 6px;
}

.tetris__mini-cell {
    position: relative;
    width: 100%;
    padding-top: 100%;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.03);
}

.tetris__mini-cell::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: rgba(0, 0, 0, 0.03);
}

.tetris__mini-cell--i::after { background: var(--piece-i); }
.tetris__mini-cell--j::after { background: var(--piece-j); }
.tetris__mini-cell--l::after { background: var(--piece-l); }
.tetris__mini-cell--o::after { background: var(--piece-o); }
.tetris__mini-cell--s::after { background: var(--piece-s); }
.tetris__mini-cell--t::after { background: var(--piece-t); }
.tetris__mini-cell--z::after { background: var(--piece-z); }

.tetris__leaderboard-grid {
    width: 100%;
    border-collapse: collapse;
}

.tetris__leaderboard-grid th,
.tetris__leaderboard-grid td {
    padding: 0.5rem;
    border-bottom: 1px solid var(--outline);
    text-align: left;
    font-size: 0.95rem;
}

.tetris__leaderboard-grid th {
    font-weight: 700;
    color: var(--muted);
}

.tetris__leaderboard-grid tbody tr:nth-child(even) {
    background: rgba(0, 0, 0, 0.03);
}

.tetris__leaderboard-grid tbody tr:hover {
    background: rgba(0, 0, 0, 0.04);
}
body[data-theme="dark"] .tetris__leaderboard-grid tbody tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.05);
}

/* Global header refresh */
.topbar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    padding: 0.85rem clamp(1rem, 3.2vw, 2.4rem);
    background: var(--surface);
    border-bottom: 1px solid var(--outline);
    position: sticky;
    top: 0;
    z-index: 30;
}

.topbar__brand {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    flex: 1 1 auto;
    min-width: 0;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 700;
    font-size: clamp(1.1rem, 2.5vw, 1.4rem);
    color: var(--text);
}

.nav {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.nav__link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.45rem 0.9rem;
    border-radius: 999px;
    font-weight: 600;
    background: transparent;
    color: var(--muted);
    transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}

.nav__link:hover,
.nav__link:focus-visible {
    background: rgba(52, 91, 69, 0.12);
    color: var(--text);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.06);
}

.topbar__actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 1.1rem;
    flex-wrap: wrap;
}

.toggles {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    flex-wrap: wrap;
    color: var(--muted);
}

.switch {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.9rem;
}

.switch input {
    accent-color: var(--primary);
    width: 1.05rem;
    height: 1.05rem;
    margin: 0;
}

.auth-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.auth-actions__form {
    margin: 0;
}

@media (max-width: 900px) {
    .topbar {
        position: static;
        align-items: flex-start;
        padding: 0.75rem clamp(1rem, 4vw, 1.6rem);
    }

    .topbar__brand {
        width: 100%;
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .nav {
        width: 100%;
        justify-content: flex-start;
        gap: 0.55rem;
    }

    .topbar__actions {
        width: 100%;
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .auth-actions {
        width: 100%;
        justify-content: flex-start;
        gap: 0.55rem;
    }

    .auth-actions .btn,
    .auth-actions button {
        width: auto;
    }
}

@media (max-width: 768px) {
    .nav {
        width: 100%;
    }
}

@media (max-width: 600px) {
    .topbar {
        padding: 0.55rem 0.75rem;
        gap: 0.5rem;
    }

    .topbar__brand {
        flex-direction: row;
        align-items: center;
        gap: 0.55rem;
    }

    .brand__logo {
        width: 28px;
        height: 28px;
    }

    .nav {
        gap: 0.25rem;
    }

    .nav__link {
        padding: 0.35rem 0.5rem;
        font-size: 0.9rem;
    }

    .topbar__actions {
        flex-direction: row;
        align-items: center;
        gap: 0.55rem;
    }

    .toggles {
        gap: 0.45rem;
    }

    .toggles .switch span {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        margin: -1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
        border: 0;
    }

    .auth-actions {
        gap: 0.45rem;
    }

    .auth-actions .btn {
        padding: 0.42rem 0.7rem;
        font-size: 0.9rem;
    }

    .page {
        width: min(100%, 100vw - 1rem);
        margin: 0.6rem auto 1.25rem;
    }

    .tetris {
        gap: 0.75rem;
    }

    .tetris__header {
        gap: 0.65rem;
        align-items: flex-start;
    }

    .tetris__heading h1 {
        font-size: 1.45rem;
    }

    .tetris__subtitle {
        display: none;
    }

    .tetris__controls {
        width: 100%;
        gap: 0.45rem;
    }

    .tetris__mode {
        flex: 1 1 100%;
    }

    .tetris__controls .btn {
        flex: 1 1 0;
        min-width: 0;
        padding: 0.55rem 0.45rem;
    }

    .tetris__layout {
        display: contents;
    }

    .tetris__stage-wrapper {
        order: 1;
        width: 100%;
        padding: 0.5rem;
    }

    .tetris__stage {
        width: min(68vw, 12.5rem);
        height: auto;
        aspect-ratio: 1 / 2;
    }

    .tetris__mobile-controls {
        display: grid;
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 0.4rem;
        order: 2;
        padding: 0.35rem;
        border-radius: 12px;
        background: var(--bg);
        border: 1px solid var(--outline);
    }

    .tetris__control {
        min-height: 48px;
        border-radius: 8px;
        touch-action: manipulation;
    }

    .tetris__panel {
        order: 3;
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 0.6rem;
        padding: 0.8rem;
    }

    .tetris__stat {
        grid-column: auto;
        flex-direction: column;
        gap: 0.15rem;
        align-items: flex-start;
    }

    .tetris__preview,
    .tetris__settings,
    .tetris__help {
        grid-column: 1 / -1;
    }

    .tetris__help dl {
        grid-template-columns: 1fr;
    }

    .tetris__leaderboard {
        order: 4;
    }
}

/* --- Modern app shell and page surfaces --- */
:root {
    --bg: #f7f8f5;
    --surface: #ffffff;
    --surface-soft: #eef6f1;
    --surface-cool: #eef4f8;
    --text: #18231f;
    --muted: #61706a;
    --outline: rgba(24, 35, 31, 0.12);
    --primary: #2f6b4f;
    --primary-strong: #194b36;
    --accent: #cf7b3d;
    --accent-cool: #327c8c;
    --shadow-soft: 0 18px 45px rgba(24, 35, 31, 0.08);
}

body[data-theme="dark"] {
    --bg: #0f1715;
    --surface: #17211f;
    --surface-soft: #1b2b25;
    --surface-cool: #182832;
    --text: #eef5f1;
    --muted: #a9bbb3;
    --outline: rgba(238, 245, 241, 0.16);
    --primary: #7bd1a5;
    --primary-strong: #a8e5c5;
    --accent: #f0a667;
    --accent-cool: #7fc8d5;
    --shadow-soft: 0 18px 45px rgba(0, 0, 0, 0.28);
}

.content {
    width: min(1120px, calc(100vw - 2rem));
    margin: clamp(1rem, 3vw, 2.25rem) auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: clamp(1rem, 3vw, 1.75rem);
}

.hero,
.howto,
.leaderboard,
.stats,
.card {
    background: var(--surface);
    border: 1px solid var(--outline);
    border-radius: 8px;
    box-shadow: var(--shadow-soft);
}

.hero {
    position: relative;
    overflow: hidden;
    padding: clamp(2rem, 7vw, 4.5rem);
    background:
        linear-gradient(135deg, rgba(47, 107, 79, 0.94), rgba(50, 124, 140, 0.9)),
        url("/assets/logo.svg") right clamp(1.5rem, 7vw, 5rem) center / min(34vw, 17rem) no-repeat;
    color: #ffffff;
}

.hero__content {
    max-width: 44rem;
}

.hero h1,
.game__header h1,
.tetris__heading h1,
.leaderboard h1,
.leaderboard h2,
.stats h1,
.auth-card h1 {
    letter-spacing: 0;
    line-height: 1.05;
}

.hero h1 {
    margin: 0;
    font-size: clamp(2.25rem, 6vw, 4.5rem);
}

.hero p {
    max-width: 42rem;
    margin: 1rem 0 0;
    color: rgba(255, 255, 255, 0.86);
    font-size: clamp(1rem, 2.2vw, 1.2rem);
}

.hero__actions,
.game__options,
.leaderboard__filters,
.tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.65rem;
}

.hero__actions {
    margin-top: 1.4rem;
}

.features,
.stats__grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1rem;
}

.feature,
.stat {
    background: var(--surface);
    border: 1px solid var(--outline);
    border-radius: 8px;
    padding: clamp(1rem, 2.5vw, 1.35rem);
    box-shadow: 0 10px 28px rgba(24, 35, 31, 0.06);
}

.feature h2,
.stat h2 {
    margin: 0 0 0.5rem;
    font-size: 1rem;
}

.feature p,
.howto li,
.stat p {
    color: var(--muted);
}

.howto,
.leaderboard,
.stats,
.auth-card {
    padding: clamp(1rem, 3vw, 1.6rem);
}

.howto h2,
.leaderboard h1,
.leaderboard h2,
.stats h1,
.auth-card h1 {
    margin-top: 0;
}

.tabs__item,
.nav__link {
    border: 1px solid transparent;
}

.tabs__item {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 0.45rem 0.85rem;
    border-radius: 999px;
    color: var(--muted);
    font-weight: 700;
}

.tabs__item.is-active,
.tabs__item:hover,
.tabs__item:focus-visible {
    background: var(--surface-soft);
    border-color: var(--outline);
    color: var(--primary-strong);
}

.leaderboard__header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.85rem;
    margin-bottom: 1rem;
}

.leaderboard__table {
    width: 100%;
    border-collapse: collapse;
    overflow: hidden;
    border-radius: 8px;
}

.leaderboard__table th,
.leaderboard__table td {
    padding: 0.75rem;
    border-bottom: 1px solid var(--outline);
    text-align: left;
}

.leaderboard__table th {
    color: var(--muted);
    font-size: 0.9rem;
}

.form {
    display: grid;
    gap: 1rem;
}

.form label {
    display: grid;
    gap: 0.4rem;
    color: var(--muted);
    font-weight: 700;
}

.form input,
.select select,
.tetris__mode select {
    width: 100%;
    min-height: 44px;
    border: 1px solid var(--outline);
    border-radius: 8px;
    padding: 0.65rem 0.75rem;
    background: var(--surface);
    color: var(--text);
}

.alert {
    border-radius: 8px;
    padding: 0.75rem 0.9rem;
}

.alert--error {
    background: #fff0ed;
    color: #94341f;
    border: 1px solid rgba(148, 52, 31, 0.22);
}

.game,
.tetris__stage-wrapper,
.tetris__leaderboard {
    border: 1px solid var(--outline);
    border-radius: 8px;
    box-shadow: var(--shadow-soft);
}

.btn {
    border-radius: 8px;
    min-height: 42px;
    background: var(--primary);
}

.btn--ghost {
    background: var(--surface-cool);
    color: var(--primary-strong);
    border-color: var(--outline);
}

@media (max-width: 720px) {
    .content {
        width: min(100%, calc(100vw - 1rem));
        margin: 0.6rem auto 1.25rem;
    }

    .hero {
        padding: 1.4rem;
        background:
            linear-gradient(135deg, rgba(47, 107, 79, 0.95), rgba(50, 124, 140, 0.92)),
            url("/assets/logo.svg") right 1rem bottom 1rem / 6.5rem no-repeat;
    }

    .features,
    .stats__grid {
        grid-template-columns: 1fr;
    }

    .leaderboard {
        overflow-x: auto;
    }

    .leaderboard__table {
        min-width: 34rem;
    }

    .auth-card {
        width: 100%;
    }
}

/* --- UI/UX responsive hardening pass --- */
html,
body {
    max-width: 100%;
    overflow-x: hidden;
}

body {
    line-height: 1.5;
}

.content,
.topbar,
.topbar__brand,
.topbar__actions,
.nav,
.hero,
.game,
.tetris,
.leaderboard,
.stats,
.card,
.feature,
.stat,
.howto,
.auth-card,
.form,
.game__header,
.game__options,
.game__actions,
.tetris__header,
.tetris__controls,
.tetris__panel,
.tetris__leaderboard,
.leaderboard__header,
.tabs,
.leaderboard__filters {
    min-width: 0;
}

h1,
h2,
h3,
p,
li,
dt,
dd,
label,
button,
a,
span,
td,
th {
    overflow-wrap: anywhere;
}

button,
.btn,
.nav__link,
.tabs__item,
.key,
.tetris__control {
    min-width: 0;
    white-space: normal;
    line-height: 1.15;
}

.content {
    width: min(1040px, calc(100vw - 2rem));
}

.topbar {
    align-items: center;
    gap: 0.75rem;
}

.brand {
    flex: 0 0 auto;
}

.brand__title {
    white-space: nowrap;
}

.nav {
    gap: 0.4rem;
}

.nav__link {
    min-height: 38px;
    padding: 0.42rem 0.7rem;
}

.toggles,
.auth-actions {
    gap: 0.45rem;
}

.game {
    width: min(100%, 54rem);
    margin-inline: auto;
    padding: 1.4rem;
    gap: 1.25rem;
}

.game__header {
    gap: 0.85rem;
}

.game__header p {
    max-width: 44rem;
    margin-bottom: 0;
}

.game__options {
    display: grid;
    grid-template-columns: repeat(3, minmax(8.5rem, 1fr)) repeat(2, minmax(9.5rem, 1.05fr));
    align-items: end;
    gap: 0.65rem;
}

.game__options .btn,
.game__buttons .btn,
.game__actions .btn {
    min-height: 44px;
    padding-inline: 0.7rem;
}

.select,
.field {
    min-width: 0;
}

.select select,
.field select,
.tetris__mode select,
.form input {
    min-width: 0;
}

.game__meta,
.game__status {
    overflow-wrap: anywhere;
}

.board {
    max-width: 100%;
}

.keyboard {
    width: min(100%, 41rem);
    align-self: center;
    gap: 0.45rem;
    padding: 0.55rem;
    border-radius: 8px;
    overflow: hidden;
}

.keyboard__row {
    width: 100%;
    gap: 0.35rem;
}

.key {
    flex: 1 1 0;
    max-width: none;
    min-height: 44px;
    padding: 0.55rem 0.25rem;
    font-size: 0.88rem;
}

.key[data-key="enter"],
.key[data-key="eff"] {
    flex: 1.15 1 0;
    font-size: 1.05rem;
}

.game__actions {
    align-items: center;
}

.game__status {
    flex: 1 1 12rem;
    min-width: 0;
    text-align: left;
}

.game__legend ul,
.howto ol,
.howto ul {
    padding-left: 1.2rem;
}

.tetris__layout {
    grid-template-columns: minmax(13.5rem, 16rem) minmax(0, 1fr);
}

.tetris__panel {
    gap: 1rem;
}

.tetris__help dl {
    display: grid;
    gap: 0.55rem;
}

.tetris__help div {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.1rem;
    align-items: start;
}

.tetris__help dt {
    font-weight: 700;
    line-height: 1.25;
}

.tetris__help dd {
    margin: 0;
    color: var(--muted);
    line-height: 1.25;
}

.tetris__leaderboard-table,
.leaderboard {
    overflow-x: auto;
}

.leaderboard__table,
.tetris__leaderboard-grid {
    table-layout: fixed;
}

.leaderboard__table th,
.leaderboard__table td,
.tetris__leaderboard-grid th,
.tetris__leaderboard-grid td {
    vertical-align: top;
    overflow-wrap: anywhere;
}

.hero h1,
.game__header h1,
.tetris__heading h1,
.leaderboard h1,
.leaderboard h2,
.stats h1,
.auth-card h1 {
    font-size: 2rem;
    line-height: 1.12;
}

.hero h1 {
    font-size: 3.25rem;
}

.hero p {
    font-size: 1.08rem;
}

@media (max-width: 980px) {
    .content {
        width: min(100%, calc(100vw - 1.25rem));
    }

    .topbar {
        position: static;
    }

    .topbar__brand,
    .topbar__actions {
        width: 100%;
    }

    .topbar__brand {
        gap: 0.75rem;
    }

    .nav {
        flex: 1 1 auto;
    }

    .game__options {
        grid-template-columns: repeat(3, minmax(8rem, 1fr));
    }

    .select {
        grid-column: span 1;
    }

    .tetris__layout {
        grid-template-columns: 1fr;
    }

    .tetris__panel {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .tetris__preview,
    .tetris__settings,
    .tetris__help {
        grid-column: 1 / -1;
    }
}

@media (max-width: 720px) {
    .content {
        width: min(100%, calc(100vw - 0.9rem));
        margin: 0.55rem auto 1rem;
        gap: 0.9rem;
    }

    .topbar {
        padding: 0.55rem 0.65rem;
    }

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

    .brand__title {
        font-size: 1rem;
    }

    .nav {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        width: 100%;
    }

    .nav__link {
        padding: 0.42rem 0.3rem;
        font-size: 0.86rem;
        border-radius: 8px;
    }

    .topbar__actions {
        flex-direction: row;
        align-items: center;
        gap: 0.5rem;
    }

    .toggles .switch span {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        margin: -1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
        border: 0;
    }

    .auth-actions {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        width: 100%;
    }

    .auth-actions .btn,
    .auth-actions button {
        width: 100%;
        padding-inline: 0.45rem;
    }

    .hero {
        padding: 1.25rem;
        background: linear-gradient(135deg, rgba(47, 107, 79, 0.96), rgba(50, 124, 140, 0.92));
    }

    .hero h1,
    .game__header h1,
    .tetris__heading h1,
    .leaderboard h1,
    .leaderboard h2,
    .stats h1,
    .auth-card h1 {
        font-size: 1.55rem;
    }

    .hero p {
        font-size: 1rem;
    }

    .game,
    .howto,
    .leaderboard,
    .stats,
    .auth-card {
        padding: 0.95rem;
    }

    .game__options {
        grid-template-columns: 1fr;
        gap: 0.55rem;
    }

    .game__options .btn,
    .game__options .select {
        width: 100%;
    }

    .game__meta {
        font-size: 0.88rem;
    }

    .keyboard {
        width: 100%;
        gap: 0.32rem;
        padding: 0.4rem;
    }

    .keyboard__row {
        gap: 0.26rem;
    }

    .key {
        min-height: 42px;
        padding: 0.45rem 0.12rem;
        border-radius: 7px;
        font-size: 0.8rem;
    }

    .key[data-key="enter"],
    .key[data-key="eff"] {
        font-size: 0.95rem;
    }

    .game__actions {
        justify-content: stretch;
    }

    .game__actions .btn {
        flex: 1 1 8rem;
    }

    .game__status {
        flex-basis: 100%;
        text-align: center;
    }

    .tetris__panel {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        padding: 0.75rem;
    }

    .tetris__stat {
        align-items: flex-start;
    }

    .tetris__leaderboard-header,
    .leaderboard__header {
        align-items: stretch;
    }

    .tabs,
    .leaderboard__filters,
    .tetris__leaderboard-modes {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        width: 100%;
    }

    .tabs__item,
    .leaderboard__filters .btn,
    .tetris__leaderboard-modes .btn {
        padding-inline: 0.35rem;
        font-size: 0.86rem;
    }
}

@media (max-width: 430px) {
    :root {
        --tile: 42px;
        --gap: 4px;
    }

    .content {
        width: min(100%, calc(100vw - 0.5rem));
    }

    .game {
        padding-inline: 0.6rem;
    }

    .board__row {
        grid-template-columns: repeat(var(--cols), minmax(0, var(--tile)));
    }

    .tile {
        font-size: 1.2rem;
    }

    .keyboard {
        padding-inline: 0.25rem;
    }

    .keyboard__row {
        gap: 0.18rem;
    }

    .key {
        min-height: 40px;
        font-size: 0.72rem;
    }

    .tetris__stage {
        width: min(66vw, 12rem);
    }
}

@media (max-width: 720px) {
    .leaderboard,
    .tetris__leaderboard-table {
        overflow-x: visible;
    }

    .leaderboard__table,
    .tetris__leaderboard-grid {
        display: block;
        width: 100%;
        min-width: 0;
        table-layout: auto;
        border-collapse: separate;
        border-spacing: 0;
    }

    .leaderboard__table thead,
    .tetris__leaderboard-grid thead {
        display: none;
    }

    .leaderboard__table tbody,
    .leaderboard__table tr,
    .leaderboard__table td,
    .tetris__leaderboard-grid tbody,
    .tetris__leaderboard-grid tr,
    .tetris__leaderboard-grid td {
        display: block;
        width: 100%;
    }

    .leaderboard__table tr,
    .tetris__leaderboard-grid tr {
        padding: 0.65rem;
        border: 1px solid var(--outline);
        border-radius: 8px;
        background: var(--surface);
    }

    .leaderboard__table tr + tr,
    .tetris__leaderboard-grid tr + tr {
        margin-top: 0.65rem;
    }

    .leaderboard__table td,
    .tetris__leaderboard-grid td {
        display: flex;
        justify-content: space-between;
        gap: 0.85rem;
        padding: 0.35rem 0;
        border: 0;
        text-align: right;
    }

    .leaderboard__table td::before,
    .tetris__leaderboard-grid td::before {
        content: attr(data-label);
        flex: 0 0 auto;
        max-width: 45%;
        color: var(--muted);
        font-weight: 700;
        text-align: left;
    }

    .leaderboard__table td:nth-child(2):not([data-label])::before {
        content: "Joueur";
    }

    .tetris__leaderboard-grid td:nth-child(1)::before { content: "#"; }
    .tetris__leaderboard-grid td:nth-child(2)::before { content: "Joueur"; }
    .tetris__leaderboard-grid td:nth-child(3)::before { content: "Score"; }
    .tetris__leaderboard-grid td:nth-child(4)::before { content: "Lignes"; }
    .tetris__leaderboard-grid td:nth-child(5)::before { content: "Niveau"; }
    .tetris__leaderboard-grid td:nth-child(6)::before { content: "Temps"; }
    .tetris__leaderboard-grid td:nth-child(7)::before { content: "Date"; }

    .leaderboard__table td[colspan],
    .tetris__leaderboard-grid td[colspan],
    .leaderboard__message {
        display: block;
        text-align: center;
        color: var(--muted);
    }

    .leaderboard__table td[colspan]::before,
    .tetris__leaderboard-grid td[colspan]::before,
    .leaderboard__message::before {
        content: none;
    }
}

@media (max-width: 720px) {
    .topbar {
        gap: 0.4rem;
        padding: 0.45rem 0.55rem;
    }

    .topbar__brand {
        flex-direction: row;
        align-items: center;
        flex-wrap: wrap;
        gap: 0.45rem 0.65rem;
    }

    .brand__logo {
        width: 26px;
        height: 26px;
    }

    .nav {
        order: 2;
        gap: 0.25rem;
    }

    .nav__link {
        min-height: 34px;
        padding: 0.34rem 0.25rem;
        font-size: 0.8rem;
    }

    .topbar__actions {
        order: 3;
        justify-content: space-between;
        flex-wrap: nowrap;
        gap: 0.4rem;
    }

    .toggles {
        flex: 0 0 auto;
    }

    .switch input {
        width: 0.95rem;
        height: 0.95rem;
    }

    .auth-actions {
        width: auto;
        flex: 1 1 auto;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.35rem;
    }

    .auth-actions .btn,
    .auth-actions button {
        min-height: 34px;
        padding: 0.32rem 0.35rem;
        font-size: 0.78rem;
    }

    .game {
        padding: 0.75rem;
        gap: 0.75rem;
    }

    .game__header {
        gap: 0.55rem;
    }

    .game__header p {
        display: none;
    }

    .game__options {
        grid-template-columns: repeat(6, minmax(0, 1fr));
        gap: 0.4rem;
    }

    .game__options .btn {
        grid-column: span 2;
        min-height: 38px;
        padding: 0.38rem 0.25rem;
        font-size: 0.78rem;
    }

    .game__options .select {
        grid-column: span 3;
    }

    .select span {
        font-size: 0.78rem;
    }

    .select select {
        min-height: 38px;
        padding: 0.42rem 0.5rem;
        font-size: 0.86rem;
    }

    .game__meta {
        min-height: 1.1rem;
        font-size: 0.8rem;
    }

    .board {
        --tile: 40px;
        --gap: 4px;
    }

    .keyboard {
        gap: 0.25rem;
        padding: 0.3rem;
    }

    .key {
        min-height: 36px;
    }

    .tetris {
        gap: 0.55rem;
    }

    .tetris__header {
        gap: 0.45rem;
    }

    .tetris__controls .btn,
    .tetris__mode select {
        min-height: 38px;
    }
}

@media (max-width: 430px) {
    .board {
        --tile: 36px;
        --gap: 4px;
    }

    .key {
        min-height: 34px;
    }

    .tetris__stage {
        width: min(56vw, 11rem);
    }

    .tetris__mobile-controls {
        min-height: 0;
        gap: 0.25rem;
        padding: 0.25rem;
    }

    .tetris__control {
        min-height: 38px;
    }
}




















