:root {
    color-scheme: dark;
    font-family: Georgia, "Times New Roman", serif;
    --felt: #155c36;
    --felt-dark: #0b4227;
    --cream: #fffdf5;
    --gold: #f2c94c;
    --red: #c72d29;
    --blue-back: #243b78;
    --red-back: #9e2931;
    --ink: #171918;
    --muted: #c9d8cf;
    --panel: rgba(6, 35, 21, .82);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; background: var(--felt-dark); }
body {
    min-height: 100dvh;
    color: white;
    background:
        radial-gradient(circle at 50% 40%, rgba(255,255,255,.055), transparent 48%),
        linear-gradient(145deg, var(--felt), var(--felt-dark));
}
button, input, select { font: inherit; }
button { touch-action: manipulation; }

.shell {
    width: min(100%, 520px);
    min-height: 100dvh;
    margin: 0 auto;
    padding: max(12px, env(safe-area-inset-top)) 12px max(14px, env(safe-area-inset-bottom));
}
.center { display: grid; place-items: center; }
.stack { display: grid; gap: 14px; width: 100%; }
.lobby { max-width: 390px; }
.brand {
    margin: 0;
    text-align: center;
    font-size: clamp(2.25rem, 12vw, 4.2rem);
    line-height: .9;
    letter-spacing: .04em;
    font-weight: 500;
}
.eyebrow {
    margin-bottom: 8px;
    color: var(--gold);
    text-align: center;
    text-transform: uppercase;
    letter-spacing: .18em;
    font-family: ui-sans-serif, system-ui, sans-serif;
    font-size: .78rem;
    font-weight: 500;
}
.subtle, .statusline {
    color: var(--muted);
    text-align: center;
    font-family: ui-sans-serif, system-ui, sans-serif;
}
.panel {
    padding: 18px;
    border: 1px solid rgba(255,255,255,.11);
    border-radius: 16px;
    background: var(--panel);
    box-shadow: 0 16px 42px rgba(0,0,0,.22);
}
.button {
    min-height: 50px;
    width: 100%;
    padding: 11px 16px;
    border: 0;
    border-radius: 12px;
    background: var(--gold);
    color: var(--ink);
    font-family: ui-sans-serif, system-ui, sans-serif;
    font-weight: 500;
    cursor: pointer;
}
.button.secondary {
    border: 1px solid rgba(255,255,255,.18);
    background: rgba(255,255,255,.1);
    color: white;
}
.button.compact { width: min(100%, 220px); margin: 0 auto; }
.button:disabled { opacity: .45; cursor: default; }
.quiet-button {
    min-height: 38px;
    border: 0;
    background: transparent;
    color: var(--muted);
    font-family: ui-sans-serif, system-ui, sans-serif;
    font-size: .85rem;
    text-decoration: underline;
    text-underline-offset: 3px;
    cursor: pointer;
}
.quiet-button:disabled { opacity: .4; cursor: default; }
.connection-note {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
    min-height: 34px;
    padding: 7px 10px;
    border: 1px solid rgba(242,201,76,.32);
    border-radius: 10px;
    background: rgba(0,0,0,.18);
    color: #ffe6a6;
    text-align: center;
    font-family: ui-sans-serif, system-ui, sans-serif;
    font-size: .8rem;
}
.connection-note button {
    padding: 3px 0;
    border: 0;
    background: transparent;
    color: white;
    font-family: inherit;
    font-size: inherit;
    text-decoration: underline;
    text-underline-offset: 3px;
    cursor: pointer;
}
.error {
    padding: 10px 12px;
    border-radius: 10px;
    background: rgba(142,41,48,.82);
    color: #fff1f1;
    text-align: center;
    font-family: ui-sans-serif, system-ui, sans-serif;
}
.score-choice {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}
.score-choice button {
    min-height: 52px;
    border: 1px solid rgba(255,255,255,.17);
    border-radius: 11px;
    background: rgba(255,255,255,.08);
    color: white;
    font-family: ui-sans-serif, system-ui, sans-serif;
    font-weight: 500;
    cursor: pointer;
}
.score-choice button[aria-pressed="true"] {
    border-color: var(--gold);
    background: var(--gold);
    color: var(--ink);
}
.invite-target {
    text-align: center;
    color: var(--gold);
    font-family: ui-sans-serif, system-ui, sans-serif;
    font-size: 2.3rem;
    font-weight: 500;
}

.game-shell { padding-left: 8px; padding-right: 8px; }
.table {
    min-height: calc(100dvh - max(26px, env(safe-area-inset-top) + env(safe-area-inset-bottom)));
    display: grid;
    grid-template-rows: auto auto minmax(250px, 1fr) auto;
    gap: 8px;
}
.table.is-animating { pointer-events: none; }

.scoreboard {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    min-height: 48px;
    padding: 0 12px;
    border-radius: 11px;
    background: rgba(0,0,0,.18);
    font-family: ui-sans-serif, system-ui, sans-serif;
}
.score-player {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}
.score-player.right { justify-content: flex-end; }
.score-player strong { color: var(--gold); font-weight: 500; font-variant-numeric: tabular-nums; }
.score-add {
    padding: 2px 5px;
    border-radius: 999px;
    background: rgba(242,201,76,.16);
    color: #ffe6a6;
    font-size: .68rem;
    font-style: normal;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
}
.score-player.turn::before {
    content: "";
    width: 8px;
    height: 8px;
    flex: 0 0 8px;
    border-radius: 50%;
    background: var(--gold);
    box-shadow: 0 0 0 4px rgba(242,201,76,.13);
}
.score-player.right.turn::before { order: 3; }
.score-target {
    min-width: 66px;
    text-align: center;
    color: rgba(255,255,255,.82);
    font-variant-numeric: tabular-nums;
}
.score-target small { margin-right: 4px; color: var(--muted); }

.opponent-hand {
    min-height: 60px;
    display: grid;
    align-content: start;
    gap: 3px;
}
.back-row {
    display: flex;
    justify-content: center;
    min-height: 51px;
}
.mini-back {
    width: 36px;
    height: 51px;
    flex: 0 0 36px;
    margin-left: -10px;
    border: 2px solid var(--cream);
    border-radius: 5px;
    box-shadow: 0 3px 6px rgba(0,0,0,.22);
}
.mini-back:first-child { margin-left: 0; }

.middle {
    display: grid;
    align-content: center;
    justify-items: stretch;
    gap: 10px;
}
.middle .statusline { font-size: .78rem; }
.piles {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 28px;
}
.card {
    position: relative;
    width: 70px;
    height: 100px;
    flex: 0 0 auto;
    padding: 0;
    border: 1px solid #d8d1c5;
    border-radius: 7px;
    background: var(--cream);
    color: var(--ink);
    box-shadow: 0 6px 13px rgba(0,0,0,.24);
    user-select: none;
}
button.card { cursor: pointer; }
.card.red { color: var(--red); }
.card-corner {
    position: absolute;
    left: 6px;
    top: 5px;
    display: grid;
    place-items: center;
    font-size: 1.05rem;
    line-height: .9;
    font-weight: 500;
}
.card-corner small { font-size: .92rem; }
.card-suit {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    padding-top: 6px;
    font-size: 2.4rem;
}
.joker-star { font-size: 2.2rem; }
.draw-pile {
    position: absolute;
    inset: 0;
    z-index: 10;
    border: 4px solid var(--cream);
    box-shadow: 0 7px 13px rgba(0,0,0,.24);
}
.draw-pile-wrap {
    position: relative;
    display: block;
    width: 70px;
    height: 100px;
}
.draw-stack-layer {
    position: absolute;
    inset: 0;
    z-index: var(--layer);
    border: 4px solid var(--cream);
    border-radius: 7px;
    transform: translate(calc(var(--layer) * -1px), calc(var(--layer) * 1px));
    box-shadow: 0 2px 2px rgba(0,0,0,.16);
    transition: transform .22s ease, opacity .22s ease;
}
.back-red {
    color: white;
    background:
        repeating-linear-gradient(45deg, rgba(255,255,255,.13) 0 5px, transparent 5px 10px),
        var(--red-back);
}
.back-blue {
    color: white;
    background:
        repeating-linear-gradient(45deg, rgba(255,255,255,.13) 0 5px, transparent 5px 10px),
        var(--blue-back);
}
.draw-pile:disabled { opacity: 1; filter: saturate(.8) brightness(.88); cursor: default; }
.pile-count {
    position: absolute;
    right: -11px;
    top: -11px;
    min-width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
    padding: 0 5px;
    border-radius: 50%;
    background: var(--cream);
    color: var(--ink);
    font-family: ui-sans-serif, system-ui, sans-serif;
    font-size: .75rem;
    font-weight: 500;
}
.center-field {
    width: 70px;
    height: 100px;
    padding: 0;
    border: 0;
    border-radius: 7px;
    background: transparent;
}
.center-pile-wrap {
    position: relative;
    display: block;
    width: 70px;
    height: 100px;
}
.center-pile-wrap::before {
    content: "";
    position: absolute;
    inset: 2px 0 -2px 0;
    border-radius: 7px;
    background: #c8c1b5;
    transform: translate(calc(var(--discard-depth) * -1px), calc(var(--discard-depth) * 1px));
    box-shadow: 0 5px 9px rgba(0,0,0,.2);
}
.requested-suit {
    position: absolute;
    left: calc(100% + 10px);
    top: 50%;
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    border: 2px solid rgba(255,255,255,.8);
    border-radius: 50%;
    background: var(--cream);
    color: var(--ink);
    box-shadow: 0 5px 12px rgba(0,0,0,.24);
    font-size: 1.65rem;
    line-height: 1;
    transform: translateY(-50%);
    z-index: 20;
}
.requested-suit.red { color: var(--red); }
.center-field:disabled { opacity: 1; }
.table-card {
    position: absolute;
    inset: 0;
    z-index: var(--pile-layer);
    display: block;
    width: 100%;
    height: 100%;
    transform: translate(var(--pile-x), var(--pile-y)) rotate(var(--pile-turn));
    transition: transform .2s ease;
}
.center-ready, .effect-target {
    box-shadow: 0 0 0 3px var(--gold), 0 0 22px rgba(242,201,76,.38), 0 7px 13px rgba(0,0,0,.24);
}
.message {
    min-height: 24px;
    color: #ffe6a6;
    text-align: center;
    font-family: ui-sans-serif, system-ui, sans-serif;
    font-size: .9rem;
    font-weight: 500;
}
.wish {
    width: min(100%, 270px);
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 7px;
    margin: 0 auto;
}
.wish button {
    min-height: 44px;
    border: 1px solid rgba(255,255,255,.2);
    border-radius: 9px;
    background: rgba(255,255,255,.09);
    color: white;
    font-size: 1.35rem;
    cursor: pointer;
}
.wish button.active { border-color: var(--gold); background: var(--gold); color: var(--ink); }

.hand {
    display: grid;
    align-content: end;
    gap: 7px;
    min-height: 98px;
    padding: 4px 0 2px;
}
.hand-row {
    display: flex;
    align-items: end;
    justify-content: center;
    min-width: 0;
}
.hand-row .hand-card {
    width: 62px;
    height: 89px;
    flex: 0 0 62px;
    transition: transform .16s ease, box-shadow .16s ease, filter .16s ease;
}
.hand-row .hand-card + .hand-card { margin-left: 4px; }
.hand-row[data-count="8"] .hand-card + .hand-card { margin-left: -2px; }
.hand-row[data-count="9"] .hand-card + .hand-card { margin-left: -9px; }
.hand-row[data-count="10"] .hand-card + .hand-card { margin-left: -15px; }
.hand-card:disabled {
    opacity: 1;
    filter: saturate(.5) brightness(.74) contrast(.9);
    cursor: default;
}
.hand-card.counter:not(:disabled) {
    opacity: 1;
    box-shadow: 0 0 0 2px var(--gold), 0 0 16px rgba(242,201,76,.42), 0 5px 10px rgba(0,0,0,.22);
}
.hand-card.selected {
    z-index: 10;
    opacity: 1;
    transform: translateY(-9px);
    box-shadow: 0 0 0 3px var(--gold), 0 9px 17px rgba(0,0,0,.28);
}

.flying-card {
    position: fixed !important;
    z-index: 9999 !important;
    margin: 0 !important;
    pointer-events: none !important;
    transform-origin: center;
}

@media (prefers-reduced-motion: reduce) {
    .hand-row .hand-card { transition: none; }
}

@media (max-width: 430px) {
    .shell { padding-left: 7px; padding-right: 7px; }
    .game-shell { padding-left: 5px; padding-right: 5px; }
    .card { width: 64px; height: 92px; }
    .draw-pile-wrap { width: 64px; height: 92px; }
    .center-field { width: 64px; height: 92px; }
    .center-pile-wrap { width: 64px; height: 92px; }
    .requested-suit { left: calc(100% + 8px); width: 34px; height: 34px; font-size: 1.45rem; }
    .hand-row .hand-card { width: 52px; height: 75px; flex-basis: 52px; }
    .hand-row .hand-card + .hand-card { margin-left: 4px; }
    .hand-row[data-count="7"] .hand-card + .hand-card { margin-left: -4px; }
    .hand-row[data-count="8"] .hand-card + .hand-card { margin-left: -11px; }
    .hand-row[data-count="9"] .hand-card + .hand-card { margin-left: -16px; }
    .hand-row[data-count="10"] .hand-card + .hand-card { margin-left: -20px; }
    .hand-row .card-corner { left: 4px; top: 4px; font-size: .92rem; }
    .hand-row .card-corner small { font-size: .8rem; }
    .hand-row .card-suit { font-size: 1.75rem; }
    .scoreboard { padding: 0 9px; }
    .score-target { min-width: 58px; }
}

@media (max-width: 340px) {
    .hand-row .hand-card { width: 48px; height: 69px; flex-basis: 48px; }
    .hand-row[data-count="7"] .hand-card + .hand-card { margin-left: -5px; }
    .hand-row[data-count="8"] .hand-card + .hand-card { margin-left: -11px; }
    .hand-row[data-count="9"] .hand-card + .hand-card { margin-left: -16px; }
    .hand-row[data-count="10"] .hand-card + .hand-card { margin-left: -20px; }
}
