:root {
    color-scheme: dark;
    --ink: #11151d;
    --ink-deep: #090c11;
    --console: #181d27;
    --console-raised: #202632;
    --canvas: #f2e5cf;
    --canvas-line: rgba(30, 37, 48, 0.085);
    --text: #fff2df;
    --text-muted: #bdb3a5;
    --line: rgba(255, 242, 223, 0.14);
    --line-strong: rgba(255, 242, 223, 0.25);
    --apple: #ed4d3f;
    --apple-dark: #b72e26;
    --leaf: #53d68c;
    --gold: #f4d43e;
    --radius: 14px;
    font-family: "Avenir Next", Avenir, "Segoe UI", Helvetica, Arial, sans-serif;
}

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

html {
    min-width: 320px;
    background: var(--ink);
    scroll-behavior: smooth;
}

body {
    min-height: 100svh;
    margin: 0;
    padding: 0 clamp(20px, 4vw, 64px);
    color: var(--text);
    background: linear-gradient(112deg, rgba(255, 255, 255, 0.025), transparent 32%), var(--ink);
    accent-color: var(--apple);
}

::selection { color: #fff; background: var(--apple-dark); }

.skip-link {
    position: fixed;
    z-index: 20;
    top: 12px;
    left: 12px;
    padding: 10px 14px;
    border-radius: 8px;
    color: var(--ink-deep);
    background: var(--gold);
    font-weight: 800;
    transform: translateY(-160%);
    transition: transform 140ms ease-out;
}

.skip-link:focus { transform: translateY(0); }

.site-header, .site-footer, .landing {
    width: min(100%, 1180px);
    margin-inline: auto;
}

.site-header {
    min-height: 92px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--line);
}

.wordmark {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    gap: 11px;
    color: var(--text);
    text-decoration: none;
}

.wordmark img {
    width: 42px;
    height: 42px;
    object-fit: contain;
    filter: drop-shadow(0 8px 12px rgba(0, 0, 0, 0.28));
}

.wordmark span {
    font-size: 1.15rem;
    font-weight: 900;
    letter-spacing: -0.025em;
}

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

.server-state {
    margin: 0;
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: 9px;
    color: var(--text-muted);
    font-size: 0.7rem;
    font-weight: 750;
    line-height: 1;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.server-beacon {
    flex: 0 0 auto;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #8f877d;
}

.server-state[data-state="live"] .server-beacon {
    background: var(--leaf);
    box-shadow: 0 0 0 4px rgba(83, 214, 140, 0.1);
}

.server-state-label {
    color: var(--text-muted);
    font-size: 0.64rem;
    font-weight: 850;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.server-count {
    min-width: 86px;
    display: inline-flex;
    align-items: baseline;
    gap: 4px;
    letter-spacing: 0.015em;
}

.server-count strong {
    min-width: 4.5ch;
    color: var(--text);
    font-size: 0.82rem;
    font-weight: 900;
    letter-spacing: -0.02em;
    text-align: right;
}

.server-state[data-state="loading"] .server-count strong,
.server-state[data-state="retrying"] .server-count strong {
    color: var(--text-muted);
}

.landing {
    min-height: calc(100svh - 160px);
    padding-block: clamp(42px, 7vh, 82px);
    display: grid;
    grid-template-columns: minmax(0, 1.08fr) minmax(380px, 0.92fr);
    align-items: center;
    gap: clamp(54px, 7vw, 104px);
}

.arena-intro, .play-console { min-width: 0; }

.intro-copy h1 {
    max-width: 9ch;
    margin: 0;
    font-size: clamp(4rem, 8.2vw, 6rem);
    font-weight: 900;
    line-height: 0.85;
    letter-spacing: -0.04em;
    text-wrap: balance;
}

.intro-copy p {
    max-width: 48ch;
    margin: 24px 0 0;
    color: var(--text-muted);
    font-size: clamp(0.98rem, 1.4vw, 1.1rem);
    line-height: 1.65;
}

.arena-window {
    width: min(100%, 540px);
    margin-top: clamp(34px, 5vw, 52px);
    overflow: hidden;
    border-radius: var(--radius);
    background: var(--canvas);
    box-shadow: 0 28px 70px rgba(0, 0, 0, 0.32);
}

.arena-bar {
    height: 38px;
    padding-inline: 15px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: var(--text-muted);
    background: var(--console-raised);
    font-size: 0.66rem;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.arena-readout {
    color: var(--leaf);
    font-variant-numeric: tabular-nums;
}

.board-preview {
    position: relative;
    min-height: 220px;
    background-color: var(--canvas);
    background-image:
        linear-gradient(var(--canvas-line) 1px, transparent 1px),
        linear-gradient(90deg, var(--canvas-line) 1px, transparent 1px);
    background-size: 22px 22px;
    box-shadow: inset 0 0 0 1px rgba(17, 21, 29, 0.12);
}

.snake-cell {
    position: absolute;
    z-index: 1;
    width: 22px;
    height: 22px;
    border: 2px solid #216d46;
    background: #49ca7e;
}

.snake-head { top: 66px; left: 154px; border-radius: 8px 3px 3px 8px; }

.snake-head::before, .snake-head::after {
    content: "";
    position: absolute;
    left: 3px;
    width: 3px;
    height: 3px;
    border-radius: 50%;
    background: var(--ink-deep);
}

.snake-head::before { top: 3px; }
.snake-head::after { bottom: 3px; }
.snake-2 { top: 66px; left: 176px; }
.snake-3 { top: 66px; left: 198px; }
.snake-4 { top: 88px; left: 198px; }
.snake-5 { top: 110px; left: 198px; }
.snake-6 { top: 132px; left: 198px; border-radius: 3px 3px 8px 8px; }

.pickup {
    position: absolute;
    z-index: 2;
    width: 42px;
    height: 42px;
    object-fit: contain;
}

.pickup-apple { top: 27px; right: 12%; }
.pickup-crate { right: 29%; bottom: 20px; }
.pickup-golden { left: 7%; bottom: 30px; width: 36px; height: 36px; }

.game-notes {
    width: min(100%, 540px);
    margin: 0;
    padding: 20px 0 0;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 18px;
    list-style: none;
}

.game-notes li { min-width: 0; }
.game-notes strong, .game-notes span { display: block; }

.game-notes strong {
    color: var(--text);
    font-size: 0.74rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.game-notes span {
    margin-top: 5px;
    color: var(--text-muted);
    font-size: 0.76rem;
    line-height: 1.4;
}

.play-console {
    position: relative;
    overflow: hidden;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    background: var(--console);
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.34);
}

.console-header {
    padding: 28px 30px 24px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 24px;
    border-bottom: 1px solid var(--line);
}

.console-header > div {
    min-width: 0;
}

.console-header h2 {
    margin: 0;
    font-size: clamp(1.6rem, 3vw, 2rem);
    line-height: 1.1;
    letter-spacing: -0.03em;
}

.console-header p {
    margin: 8px 0 0;
    color: var(--text-muted);
    font-size: 0.88rem;
    line-height: 1.5;
}

.console-mark {
    flex: 0 0 auto;
    padding-top: 3px;
    color: var(--apple);
    font-size: 0.62rem;
    font-weight: 900;
    letter-spacing: 0.13em;
    text-transform: uppercase;
}

.form-error {
    margin: 22px 30px 0;
    padding: 11px 13px;
    border-radius: 9px;
    color: #ffd9d5;
    background: rgba(237, 77, 63, 0.14);
    font-size: 0.84rem;
    font-weight: 700;
    line-height: 1.45;
    overflow-wrap: anywhere;
}

.form-error[hidden] { display: none; }

.quick-join-form {
    padding: 22px 30px;
}

.button.button-quick {
    min-height: 62px;
    margin-top: 0;
    color: var(--ink-deep);
    background: var(--gold);
    box-shadow: 0 10px 24px rgba(109, 86, 6, 0.24);
    text-align: left;
    text-transform: none;
}

.button-quick:hover {
    background: #ffe05c;
    box-shadow: 0 13px 29px rgba(109, 86, 6, 0.31);
}

.button-copy {
    min-width: 0;
    display: grid;
    gap: 3px;
}

.button-copy strong {
    font-size: 0.83rem;
    font-weight: 900;
    letter-spacing: 0.08em;
    line-height: 1.2;
    text-transform: uppercase;
}

.button-copy small {
    font-size: 0.72rem;
    font-weight: 650;
    letter-spacing: 0;
    line-height: 1.35;
}

.console-form { padding: 26px 30px; }

.console-form fieldset {
    min-width: 0;
    margin: 0;
    padding: 0;
    border: 0;
}

.console-form legend {
    width: 100%;
    margin-bottom: 18px;
    padding: 0;
    color: var(--text);
    font-size: 0.72rem;
    font-weight: 850;
    letter-spacing: 0.11em;
    text-transform: uppercase;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.field { min-width: 0; }

.field label {
    display: block;
    margin-bottom: 7px;
    color: var(--text-muted);
    font-size: 0.78rem;
    font-weight: 750;
}

.field label span { font-weight: 500; }
input, button { font: inherit; }

.field input,
.field select {
    display: block;
    width: 100%;
    min-height: 46px;
    padding: 10px 12px;
    border: 1px solid var(--line-strong);
    border-radius: 9px;
    outline: none;
    color: var(--text);
    background: var(--ink-deep);
    caret-color: var(--gold);
    font-size: 0.93rem;
    font-variant-numeric: tabular-nums;
    transition: border-color 150ms ease-out, background-color 150ms ease-out, box-shadow 150ms ease-out;
}

.field input::placeholder { color: #847d73; opacity: 1; }
.field input:hover,
.field select:hover { border-color: rgba(255, 242, 223, 0.38); }

.field input:focus,
.field select:focus {
    border-color: var(--apple);
    background: #0c1016;
    box-shadow: 0 0 0 3px rgba(237, 77, 63, 0.14);
}

.field select {
    padding-right: 38px;
    appearance: none;
    background-image:
        linear-gradient(45deg, transparent 50%, var(--text-muted) 50%),
        linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
    background-position:
        calc(100% - 17px) calc(50% - 2px),
        calc(100% - 12px) calc(50% - 2px);
    background-repeat: no-repeat;
    background-size: 5px 5px, 5px 5px;
}

.field select:disabled {
    color: #8f877d;
    border-color: var(--line);
    cursor: not-allowed;
    opacity: 0.72;
}

.room-settings {
    margin-top: 14px;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.field-help {
    display: block;
    margin-top: 7px;
    color: var(--text-muted);
    font-size: 0.69rem;
    line-height: 1.45;
}

.button {
    width: 100%;
    min-height: 48px;
    margin-top: 14px;
    padding: 11px 16px;
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border: 0;
    border-radius: 9px;
    cursor: pointer;
    font-size: 0.78rem;
    font-weight: 850;
    letter-spacing: 0.09em;
    line-height: 1.2;
    text-transform: uppercase;
    transition: transform 130ms ease-out, background-color 150ms ease-out, color 150ms ease-out, box-shadow 150ms ease-out;
}

.button svg {
    flex: 0 0 auto;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.button-primary {
    color: #fff;
    background: var(--apple-dark);
    box-shadow: 0 9px 22px rgba(183, 46, 38, 0.28);
}

.button-primary:hover { background: var(--apple); box-shadow: 0 12px 26px rgba(183, 46, 38, 0.36); }

.button-secondary {
    color: var(--ink-deep);
    background: var(--leaf);
    box-shadow: 0 9px 22px rgba(25, 111, 66, 0.2);
}

.button-secondary:hover { background: #6be19e; box-shadow: 0 12px 26px rgba(25, 111, 66, 0.29); }
.button:active { transform: translateY(1px); }
.button:disabled { cursor: not-allowed; opacity: 0.48; box-shadow: none; }

.console-divider {
    position: relative;
    height: 1px;
    margin-inline: 30px;
    background: var(--line);
}

.console-divider span {
    position: absolute;
    top: 0;
    left: 50%;
    padding-inline: 12px;
    color: #8f877d;
    background: var(--console);
    font-size: 0.64rem;
    font-weight: 800;
    letter-spacing: 0.11em;
    text-transform: uppercase;
    transform: translate(-50%, -50%);
}

.console-form .mode-picker {
    margin-top: 16px;
}

.console-form .mode-picker > legend {
    margin-bottom: 8px;
    color: var(--text-muted);
    font-size: 0.78rem;
    font-weight: 750;
    letter-spacing: 0;
    text-transform: none;
}

.mode-options {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
}

.mode-option {
    position: relative;
    min-width: 0;
    cursor: pointer;
}

.mode-option input {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    opacity: 0;
}

.mode-surface {
    height: 100%;
    min-height: 102px;
    padding: 11px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    border: 1px solid var(--line-strong);
    border-radius: 9px;
    background: var(--console-raised);
    transition: border-color 150ms ease-out, background-color 150ms ease-out, box-shadow 150ms ease-out;
}

.mode-option:hover .mode-surface { background: #252c39; }

.mode-heading {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 5px;
    color: var(--text);
    font-size: 0.8rem;
    font-weight: 820;
    line-height: 1.25;
}

.radio-mark {
    grid-column: 2;
    grid-row: 1;
    width: 16px;
    height: 16px;
    border: 1px solid var(--line-strong);
    border-radius: 50%;
    background: var(--ink-deep);
    box-shadow: inset 0 0 0 4px var(--ink-deep);
    transition: border-color 150ms ease-out, background-color 150ms ease-out;
}

.mode-surface small {
    color: var(--text-muted);
    font-size: 0.69rem;
    line-height: 1.42;
}

.mode-option input:checked + .mode-surface {
    border-color: var(--leaf);
    background: #202d2b;
}

.mode-option input:checked + .mode-surface .radio-mark {
    border-color: var(--leaf);
    background: var(--leaf);
}

.mode-option input:focus-visible + .mode-surface {
    outline: 3px solid var(--gold);
    outline-offset: 3px;
}

.form-note {
    margin: 9px 0 0;
    color: var(--text-muted);
    font-size: 0.72rem;
    line-height: 1.4;
    text-align: center;
}

.button:focus-visible, .field input:focus-visible, .field select:focus-visible, .wordmark:focus-visible {
    outline: 3px solid var(--gold);
    outline-offset: 3px;
}

.site-footer {
    min-height: 68px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    border-top: 1px solid var(--line);
    color: #8f877d;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
}

@media (max-width: 920px) {
    .landing {
        width: min(100%, 620px);
        grid-template-columns: 1fr;
        gap: 48px;
    }

    .arena-intro { display: grid; justify-items: center; text-align: center; }
    .intro-copy h1 { max-width: 10ch; }
    .intro-copy p { margin-inline: auto; }
}

@media (min-width: 921px) and (max-height: 800px) {
    .landing {
        padding-block: 24px;
    }

    .intro-copy p {
        margin-top: 18px;
    }

    .arena-window {
        margin-top: 28px;
    }

    .console-header {
        padding: 20px 26px 18px;
    }

    .console-header p {
        margin-top: 5px;
    }

    .console-form {
        padding: 18px 26px;
    }

    .quick-join-form { padding: 16px 26px; }

    .console-form legend {
        margin-bottom: 12px;
    }

    .field label {
        margin-bottom: 5px;
    }

    .field input,
    .field select {
        min-height: 42px;
        padding-block: 8px;
    }

    .button {
        min-height: 44px;
        margin-top: 11px;
    }

    .console-divider {
        margin-inline: 26px;
    }

    .console-form .mode-picker {
        margin-top: 11px;
    }

    .mode-surface {
        min-height: 90px;
        padding: 9px 10px;
        gap: 5px;
    }

    .form-note {
        margin-top: 6px;
    }
}

@media (max-width: 560px) {
    body { padding-inline: 14px; }
    .site-header { min-height: 76px; }
    .wordmark { flex: 0 0 auto; }
    .server-state { min-width: 0; flex: 0 1 auto; gap: 7px; font-size: 0.64rem; }
    .server-state-label { display: none; }
    .server-count { min-width: 0; flex: 0 0 auto; gap: 3px; }
    .server-count strong { min-width: 1.5ch; font-size: 0.74rem; }
    .landing { padding-block: 34px 48px; gap: 38px; }
    .intro-copy h1 { font-size: clamp(3.4rem, 17vw, 4.6rem); }
    .intro-copy p { margin-top: 19px; font-size: 0.94rem; }
    .arena-window { margin-top: 28px; }
    .board-preview { min-height: 176px; background-size: 18px 18px; }
    .snake-cell { width: 18px; height: 18px; }
    .snake-head { top: 54px; left: 88px; }
    .snake-2 { top: 54px; left: 106px; }
    .snake-3 { top: 54px; left: 124px; }
    .snake-4 { top: 72px; left: 124px; }
    .snake-5 { top: 90px; left: 124px; }
    .snake-6 { top: 108px; left: 124px; }
    .pickup { width: 34px; height: 34px; }
    .pickup-golden { width: 30px; height: 30px; }
    .game-notes { gap: 10px; }
    .game-notes strong { font-size: 0.66rem; }
    .game-notes span { font-size: 0.68rem; }
    .console-header, .console-form, .quick-join-form { padding-inline: 20px; }
    .console-mark { display: none; }
    .form-error { margin-inline: 20px; }
    .console-divider { margin-inline: 20px; }
    .form-row { grid-template-columns: 1fr; }
    .room-settings { grid-template-columns: 1fr; }
    .mode-options { grid-template-columns: 1fr; }
    .mode-surface { min-height: 0; }
    .site-footer { min-height: 60px; font-size: 0.62rem; }
}

@media (max-width: 920px) and (max-height: 600px) and (orientation: landscape) {
    .landing {
        min-height: auto;
        padding-block: 24px;
        gap: 0;
    }

    .arena-intro {
        display: none;
    }

    .console-header {
        padding-block: 20px 18px;
    }

    .console-header p {
        margin-top: 5px;
    }

    .console-form {
        padding-block: 18px;
    }

    .quick-join-form { padding-block: 16px; }

    .console-form legend {
        margin-bottom: 12px;
    }

    .field label {
        margin-bottom: 5px;
    }

    .field input,
    .field select {
        min-height: 44px;
        padding-block: 9px;
    }

    .button {
        min-height: 44px;
        margin-top: 11px;
    }

    .console-form .mode-picker {
        margin-top: 11px;
    }

    .form-note {
        margin-top: 6px;
    }
}

@media (max-width: 370px) {
    .server-state { gap: 5px; font-size: 0.59rem; }
    .server-count strong { font-size: 0.7rem; }
    .game-notes { grid-template-columns: 1fr; text-align: left; }
    .game-notes li { display: grid; grid-template-columns: 72px 1fr; align-items: baseline; gap: 8px; }
    .game-notes span { margin-top: 0; }
}

@media (prefers-reduced-motion: no-preference) {
    .arena-window { animation: arena-arrive 620ms cubic-bezier(0.16, 1, 0.3, 1) both; }

    @keyframes arena-arrive {
        from {
            opacity: 0.5;
            filter: blur(4px);
            clip-path: inset(0 100% 0 0 round var(--radius));
        }
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        scroll-behavior: auto !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
