:root {
    --bg-deep: #082426;
    --bg-table: #116052;
    --ink: #f8f3e7;
    --muted: rgba(248, 243, 231, 0.72);
    --line: rgba(255, 255, 255, 0.15);
    --gold: #f4bd4f;
    --tile-width: min(15vw, 210px);
    --tile-height: calc(var(--tile-width) * 0.5);
    --app-height: 100vh;
}

@supports (height: -webkit-fill-available) {
    :root {
        --app-height: -webkit-fill-available;
    }
}

@supports (height: 100dvh) {
    :root {
        --app-height: 100dvh;
    }
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    height: var(--app-height);
    min-height: var(--app-height);
    overflow: hidden;
    background:
        radial-gradient(circle at 16% 18%, rgba(244, 189, 79, 0.17), transparent 20%),
        radial-gradient(circle at 86% 82%, rgba(61, 117, 177, 0.2), transparent 24%),
        linear-gradient(145deg, #031517 0%, var(--bg-deep) 32%, #143b38 72%, #081719 100%);
    color: var(--ink);
    font-family: "Trebuchet MS", "Avenir Next", "Segoe UI", sans-serif;
}

html {
    height: -webkit-fill-available;
}

body {
    position: relative;
}

.texture-layer {
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(115deg, rgba(255, 255, 255, 0.035) 0, transparent 28%, rgba(255, 255, 255, 0.02) 54%, transparent 74%),
        radial-gradient(circle at center, rgba(255, 255, 255, 0.05) 0.08rem, transparent 0.1rem);
    background-size: 22rem 22rem, 1.1rem 1.1rem;
    opacity: 0.35;
    pointer-events: none;
}

.screen-shell {
    position: relative;
    z-index: 1;
    height: var(--app-height);
    max-height: var(--app-height);
    padding: 1rem;
    display: grid;
    grid-template-columns: minmax(18rem, 23rem) minmax(0, 1fr);
    gap: 1rem;
    overflow: hidden;
}

.info-sidebar {
    min-height: 0;
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr);
    gap: 1rem;
}

.topbar,
.join-panel,
.bottom-zone,
.table-core {
    border: 1px solid var(--line);
    background: linear-gradient(180deg, rgba(12, 31, 34, 0.86), rgba(5, 16, 18, 0.76));
    box-shadow: 0 1rem 3rem rgba(0, 0, 0, 0.24);
    backdrop-filter: blur(14px);
}

.topbar {
    display: grid;
    gap: 0.95rem;
    min-width: 0;
    padding: 1rem;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
    border-radius: 12px;
}

.brand-block {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
        "eyebrow room"
        "title title"
        "status status";
    align-items: start;
    gap: 0.18rem 0.65rem;
    min-width: 0;
}

.brand-block .eyebrow {
    grid-area: eyebrow;
}

.brand-block h1 {
    grid-area: title;
    margin: 0.12rem 0 0.28rem;
    font-size: clamp(2rem, 3vw, 3.25rem);
    line-height: 0.96;
    white-space: nowrap;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.brand-block .status-line {
    grid-area: status;
}

.eyebrow {
    color: rgba(255, 255, 255, 0.72);
    font-size: 0.78rem;
    letter-spacing: 0.22em;
    text-transform: uppercase;
}

.status-line,
.join-copy {
    margin: 0;
    color: var(--muted);
    line-height: 1.45;
}

.pill-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.55rem;
}

.pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 2.4rem;
    padding: 0.5rem 0.82rem;
    border-radius: 999px;
    background: rgba(5, 18, 20, 0.64);
    border: 1px solid rgba(255, 255, 255, 0.14);
    color: var(--ink);
    font-size: 0.92rem;
}

.room-pill {
    grid-area: room;
    justify-self: end;
    min-height: 1.45rem;
    max-width: 4.5rem;
    padding: 0.18rem 0.4rem;
    font-size: 0.62rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.join-panel,
.bottom-zone {
    border-radius: 12px;
    padding: 0.95rem;
}

.join-panel {
    display: grid;
    align-content: start;
    gap: 0.7rem;
}

.qr-link {
    display: inline-grid;
    place-items: center;
    justify-self: center;
    width: fit-content;
    max-width: 100%;
    aspect-ratio: 1 / 1;
    padding: 0.65rem;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.06), 0 1rem 2rem rgba(0, 0, 0, 0.16);
}

.qr-code,
.qr-code canvas,
.qr-code img,
.qr-code svg,
.qr-link canvas,
.qr-link img,
.qr-link svg {
    display: block;
    line-height: 0;
}

.table-stage {
    min-height: 0;
}

.table-core {
    position: relative;
    height: 100%;
    width: 100%;
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto;
    gap: 0.55rem;
    padding: 1rem;
    border-radius: 14px;
    overflow: hidden;
}

.table-aura,
.felt-shadow {
    position: absolute;
    inset: 1rem;
    border-radius: 12px;
    pointer-events: none;
}

.felt-shadow {
    background:
        radial-gradient(circle at 32% 38%, rgba(244, 189, 79, 0.16), transparent 25%),
        radial-gradient(circle at 70% 68%, rgba(73, 138, 197, 0.16), transparent 26%),
        linear-gradient(180deg, rgba(20, 109, 91, 0.96), rgba(9, 65, 57, 0.98));
    box-shadow:
        inset 0 0 0 1px rgba(255, 255, 255, 0.08),
        inset 0 -1rem 3rem rgba(0, 0, 0, 0.24);
}

.table-aura {
    background: radial-gradient(circle at center, rgba(255, 226, 162, 0.15), transparent 62%);
    filter: blur(12px);
    opacity: 0.8;
}

.table-aura.is-live {
    background:
        radial-gradient(circle at 40% 54%, rgba(244, 189, 79, 0.22), transparent 34%),
        radial-gradient(circle at 70% 46%, rgba(49, 94, 159, 0.2), transparent 32%);
}

.table-top,
.table-middle,
.table-bottom {
    position: relative;
    z-index: 2;
}

.table-top {
    position: absolute;
    left: 1.8rem;
    right: 1.8rem;
    top: 1.8rem;
    z-index: 5;
    display: grid;
    grid-template-columns: minmax(13rem, 22rem) auto;
    gap: 0.85rem;
    align-items: start;
    pointer-events: none;
}

.turn-panel {
    justify-self: start;
    width: 100%;
    padding: 0.62rem 0.82rem 0.72rem;
    border-radius: 10px;
    background: rgba(7, 24, 25, 0.58);
    border: 1px solid rgba(255, 255, 255, 0.12);
    text-align: left;
    box-shadow: 0 0.8rem 2rem rgba(0, 0, 0, 0.16);
    pointer-events: auto;
}

.turn-label {
    color: rgba(255, 255, 255, 0.64);
    font-size: 0.7rem;
    letter-spacing: 0.22em;
    text-transform: uppercase;
}

.turn-name {
    margin-top: 0.12rem;
    font-size: clamp(1.05rem, 1.55vw, 1.45rem);
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.turn-hint {
    margin-top: 0.16rem;
    color: var(--muted);
    font-size: 0.82rem;
    line-height: 1.25;
}

.boneyard-panel {
    justify-self: end;
    display: grid;
    justify-items: center;
    grid-template-rows: auto auto;
    gap: 0.38rem;
    min-width: 10.25rem;
    padding: 0.5rem;
    border-radius: 12px;
    background: rgba(6, 22, 23, 0.46);
    border: 1px solid rgba(255, 255, 255, 0.11);
    pointer-events: auto;
}

.pile-caption {
    color: rgba(255, 255, 255, 0.78);
    font-size: 0.76rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    text-align: center;
    line-height: 1.25;
    min-height: 1.45rem;
    max-width: 9.5rem;
    display: grid;
    place-items: center;
}

.boneyard-pile {
    position: relative;
    width: 8.6rem;
    height: 5rem;
}

.stack-tile {
    position: absolute;
    left: 1.35rem;
    top: 0.1rem;
    width: 6.6rem;
    aspect-ratio: 2 / 1;
    filter: drop-shadow(0 0.65rem 1.2rem rgba(0, 0, 0, 0.24));
}

.stack-tile.is-ghost {
    opacity: 0.68;
}

.stack-tile svg,
.board-tile svg,
.motion-tile svg {
    width: 100%;
    height: 100%;
    display: block;
}

.boneyard-empty {
    display: grid;
    place-items: center;
    width: 100%;
    height: 100%;
    border-radius: 8px;
    border: 1px dashed rgba(255, 255, 255, 0.18);
    color: rgba(255, 255, 255, 0.54);
    font-size: 0.78rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.table-middle {
    grid-row: 1;
    min-height: 0;
    display: grid;
    place-items: stretch;
}

.board-surface {
    position: relative;
    min-height: 0;
    height: 100%;
    padding: 0;
    border-radius: 12px;
    overflow: hidden;
    background:
        linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px),
        linear-gradient(0deg, rgba(255, 255, 255, 0.028) 1px, transparent 1px),
        rgba(2, 33, 31, 0.18);
    background-size: 3.2rem 3.2rem;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.07);
}

.end-strip {
    position: absolute;
    left: 1rem;
    right: 1rem;
    top: auto;
    bottom: 0.85rem;
    z-index: 3;
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    pointer-events: none;
}

.end-cap {
    min-width: 5.5rem;
    padding: 0.5rem 0.65rem;
    border-radius: 8px;
    background: rgba(4, 18, 20, 0.48);
    border: 1px solid rgba(255, 255, 255, 0.11);
    color: rgba(255, 255, 255, 0.62);
    display: grid;
    grid-template-columns: auto auto;
    gap: 0.45rem;
    align-items: center;
}

.end-cap.is-live {
    color: var(--ink);
    border-color: rgba(244, 189, 79, 0.32);
}

.end-cap span {
    font-size: 0.68rem;
    letter-spacing: 0.16em;
    text-transform: uppercase;
}

.end-cap strong {
    font-size: 1.25rem;
    line-height: 1;
}

.board-empty {
    position: absolute;
    left: 50%;
    top: 52%;
    transform: translate(-50%, -50%);
    width: min(26rem, calc(100% - 2rem));
    text-align: center;
    color: var(--muted);
}

.board-empty-title {
    color: var(--ink);
    font-size: clamp(2rem, 5vw, 4rem);
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.board-empty-copy {
    margin-top: 0.45rem;
    line-height: 1.4;
}

.board-track {
    position: absolute;
    left: 1.2rem;
    right: 1.2rem;
    top: 6.25rem;
    bottom: 3.75rem;
    z-index: 1;
    min-height: 0;
    display: block;
    padding: 0;
}

.board-tile {
    position: absolute;
    filter: drop-shadow(0 0.8rem 1.4rem rgba(0, 0, 0, 0.25));
    transform-origin: center center;
}

.board-tile.is-double {
    z-index: 2;
}

.table-core.is-celebrating .board-surface,
.table-core.is-celebrating .table-top,
.table-core.is-celebrating .table-bottom {
    opacity: 0.28;
}

.celebration-panel {
    position: absolute;
    left: 50%;
    top: 50%;
    z-index: 3;
    width: min(34rem, calc(100% - 2rem));
    padding: 1.25rem 1.4rem 1.4rem;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    background:
        radial-gradient(circle at top, rgba(244, 189, 79, 0.24), transparent 48%),
        linear-gradient(180deg, rgba(8, 24, 25, 0.94), rgba(8, 29, 27, 0.9));
    box-shadow: 0 1.4rem 3rem rgba(0, 0, 0, 0.28);
    text-align: center;
    transform: translate(-50%, -50%);
    backdrop-filter: blur(14px);
}

.celebration-name {
    margin-top: 0.4rem;
    font-size: clamp(2rem, 4vw, 3.4rem);
    font-weight: 800;
    line-height: 0.96;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.celebration-eyebrow,
.celebration-timer-label {
    color: rgba(255, 232, 180, 0.9);
    font-size: 0.76rem;
    letter-spacing: 0.24em;
    text-transform: uppercase;
}

.celebration-copy {
    margin-top: 0.6rem;
    color: rgba(248, 243, 231, 0.8);
    line-height: 1.4;
}

.celebration-timer-wrap {
    margin-top: 1rem;
    display: inline-grid;
    gap: 0.35rem;
    justify-items: center;
    min-width: 9rem;
    padding: 0.7rem 0.95rem;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.11);
}

.celebration-timer {
    color: #ffe0a2;
    font-size: clamp(1.5rem, 3vw, 2.4rem);
    font-weight: 800;
    line-height: 1;
    font-variant-numeric: tabular-nums;
}

.table-bottom {
    grid-row: 2;
    display: flex;
    justify-content: center;
}

.action-burst {
    min-width: 11rem;
    max-width: min(100%, 44rem);
    padding: 0.62rem 0.82rem;
    border-radius: 8px;
    text-align: center;
    color: rgba(255, 255, 255, 0.88);
    background: rgba(8, 24, 25, 0.58);
    border: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: 0 0.8rem 1.8rem rgba(0, 0, 0, 0.18);
}

.action-burst.is-special {
    border-color: rgba(244, 189, 79, 0.44);
}

.motion-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
    z-index: 4;
}

.motion-tile {
    position: absolute;
    aspect-ratio: 2 / 1;
    filter: drop-shadow(0 1.1rem 2rem rgba(0, 0, 0, 0.3));
    transform-origin: center center;
    will-change: transform, opacity;
}

.bottom-zone {
    display: grid;
    min-height: 0;
    overflow-y: auto;
    padding-right: 0.1rem;
    align-content: start;
}

.player-rail {
    display: grid;
    gap: 0.52rem;
}

.player-chip {
    padding: 0.62rem 0.7rem;
    border-radius: 8px;
    background: rgba(8, 24, 25, 0.56);
    border: 1px solid rgba(255, 255, 255, 0.09);
}

.player-chip.is-current {
    border-color: rgba(244, 189, 79, 0.44);
    background: linear-gradient(180deg, rgba(244, 189, 79, 0.18), rgba(244, 189, 79, 0.06));
}

.player-chip.is-waiting {
    opacity: 0.72;
}

.player-chip.is-disconnected {
    opacity: 0.54;
}

.player-name-row,
.player-meta-row {
    display: flex;
    justify-content: space-between;
    gap: 0.7rem;
    align-items: center;
}

.player-name-row strong {
    font-size: 0.92rem;
}

.player-seat {
    color: rgba(255, 255, 255, 0.58);
    font-size: 0.66rem;
    letter-spacing: 0.15em;
    text-transform: uppercase;
}

.player-meta-row {
    margin-top: 0.32rem;
    color: var(--muted);
    font-size: 0.82rem;
}

.player-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2.25rem;
    padding: 0.2rem 0.45rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
    color: var(--ink);
}

@media (max-width: 1100px) {
    :root {
        --tile-width: min(18vw, 180px);
    }

    .screen-shell {
        grid-template-columns: minmax(16rem, 20rem) minmax(0, 1fr);
    }

    .table-top {
        grid-template-columns: minmax(12rem, 20rem) auto;
        left: 1.35rem;
        right: 1.35rem;
        top: 1.35rem;
    }

    .boneyard-panel {
        justify-self: end;
        grid-template-columns: 1fr;
        grid-template-rows: auto auto;
        align-items: start;
        min-width: 9.75rem;
    }
}

@media (max-height: 680px) {
    :root {
        --tile-width: min(13vw, 23vh, 170px);
    }

    .screen-shell {
        padding: 0.65rem;
        gap: 0.65rem;
        grid-template-columns: minmax(14rem, 17rem) minmax(0, 1fr);
    }

    .topbar,
    .join-panel,
    .bottom-zone,
    .table-core {
        padding: 0.7rem;
    }

    .brand-block h1 {
        font-size: clamp(1.55rem, 3vw, 2.2rem);
    }

    .eyebrow {
        font-size: 0.68rem;
        letter-spacing: 0.18em;
    }

    .status-line,
    .join-copy,
    .turn-hint {
        font-size: 0.78rem;
    }

    .turn-panel {
        padding: 0.5rem 0.72rem 0.58rem;
    }

    .boneyard-panel {
        padding: 0.5rem;
    }

    .boneyard-pile {
        width: 7.6rem;
        height: 4.55rem;
    }

    .stack-tile {
        left: 1.2rem;
        width: 5.85rem;
    }

    .board-surface {
        padding: 0;
    }

    .board-track {
        left: 0.7rem;
        right: 0.7rem;
        top: 5.55rem;
        bottom: 3.25rem;
    }

    .action-burst {
        padding: 0.48rem 0.65rem;
        font-size: 0.78rem;
    }
}

@media (max-width: 950px) and (max-height: 560px), (max-height: 520px) {
    :root {
        --tile-width: min(12vw, 19vh, 150px);
    }

    .screen-shell {
        padding: 0.45rem;
        gap: 0.45rem;
        grid-template-columns: minmax(10.5rem, 12.5rem) minmax(0, 1fr);
    }

    .info-sidebar {
        gap: 0.45rem;
    }

    .topbar,
    .join-panel,
    .bottom-zone,
    .table-core {
        padding: 0.45rem;
        border-radius: 8px;
    }

    .table-aura,
    .felt-shadow {
        inset: 0.45rem;
        border-radius: 8px;
    }

    .topbar {
        gap: 0.34rem;
    }

    .brand-block {
        gap: 0.08rem 0.35rem;
    }

    .brand-block h1 {
        margin: 0.04rem 0 0.12rem;
        font-size: 1.28rem;
        line-height: 0.95;
    }

    .eyebrow {
        font-size: 0.54rem;
        letter-spacing: 0.12em;
    }

    .status-line,
    .join-copy,
    .turn-hint {
        font-size: 0.62rem;
        line-height: 1.22;
    }

    .pill-row {
        gap: 0.24rem;
    }

    .pill {
        min-height: 1.55rem;
        padding: 0.22rem 0.4rem;
        font-size: 0.62rem;
    }

    .room-pill {
        max-width: 3.25rem;
        min-height: 1.15rem;
        padding: 0.12rem 0.28rem;
        font-size: 0.52rem;
    }

    .join-panel {
        gap: 0.34rem;
    }

    .qr-link {
        padding: 0.35rem;
        border-radius: 6px;
    }

    .qr-code,
    .qr-code canvas,
    .qr-code img,
    .qr-code svg,
    .qr-link canvas,
    .qr-link img,
    .qr-link svg {
        width: 64px !important;
        height: 64px !important;
    }

    .player-rail {
        gap: 0.28rem;
    }

    .player-chip {
        padding: 0.32rem 0.38rem;
    }

    .player-name-row,
    .player-meta-row {
        gap: 0.35rem;
    }

    .player-name-row strong {
        font-size: 0.68rem;
    }

    .player-seat {
        font-size: 0.48rem;
        letter-spacing: 0.08em;
    }

    .player-meta-row {
        margin-top: 0.12rem;
        font-size: 0.58rem;
    }

    .player-badge {
        min-width: 1.6rem;
        padding: 0.08rem 0.24rem;
    }

    .table-core {
        gap: 0.3rem;
    }

    .table-top {
        left: 0.65rem;
        right: 0.65rem;
        top: 0.65rem;
        grid-template-columns: minmax(8rem, 14rem) auto;
        gap: 0.36rem;
    }

    .turn-panel {
        padding: 0.34rem 0.46rem;
        border-radius: 8px;
    }

    .turn-label {
        font-size: 0.52rem;
        letter-spacing: 0.12em;
    }

    .turn-name {
        font-size: 0.88rem;
    }

    .boneyard-panel {
        min-width: 6.25rem;
        padding: 0.3rem;
        gap: 0.18rem;
        border-radius: 8px;
    }

    .pile-caption {
        min-height: 1rem;
        max-width: 5.8rem;
        font-size: 0.52rem;
        letter-spacing: 0.08em;
    }

    .boneyard-pile {
        width: 5.05rem;
        height: 3rem;
    }

    .stack-tile {
        left: 0.78rem;
        width: 4rem;
        filter: drop-shadow(0 0.45rem 0.8rem rgba(0, 0, 0, 0.22));
    }

    .boneyard-empty {
        font-size: 0.58rem;
        letter-spacing: 0.08em;
    }

    .board-surface {
        border-radius: 8px;
        background-size: 2.55rem 2.55rem;
    }

    .board-track {
        left: 0.36rem;
        right: 0.36rem;
        top: 4.35rem;
        bottom: 2.3rem;
    }

    .end-strip {
        left: 0.5rem;
        right: 0.5rem;
        bottom: 0.45rem;
        gap: 0.5rem;
    }

    .end-cap {
        min-width: 3.9rem;
        padding: 0.28rem 0.38rem;
        gap: 0.28rem;
    }

    .end-cap span {
        font-size: 0.5rem;
        letter-spacing: 0.1em;
    }

    .end-cap strong {
        font-size: 0.92rem;
    }

    .action-burst {
        min-width: 7.5rem;
        padding: 0.34rem 0.5rem;
        font-size: 0.62rem;
    }
}

@media (max-width: 760px) {
    html,
    body {
        overflow: auto;
    }

    .screen-shell {
        height: auto;
        min-height: var(--app-height);
        max-height: none;
        grid-template-columns: 1fr;
    }

    .info-sidebar {
        grid-template-rows: auto auto auto;
    }

    .table-stage {
        min-height: 42rem;
    }

    .table-top {
        left: 1rem;
        right: 1rem;
        top: 1rem;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 0.5rem;
    }

    .turn-panel {
        min-width: 0;
    }

    .turn-hint {
        display: none;
    }

    .boneyard-panel {
        min-width: 8.8rem;
    }

    .pile-caption {
        font-size: 0.66rem;
        letter-spacing: 0.1em;
        max-width: 8rem;
    }

    .brand-block h1 {
        white-space: normal;
    }

    .board-track {
        min-height: 0;
    }
}
