:root {
    --table-green: #0f6b45;
    --table-dark: #09462d;
    --panel: rgba(245, 247, 250, 0.94);
    --ink: #132019;
    --accent: #2c7be5;
    --accent-2: #ffb648;
    --danger: #e34b4b;
    --success: #34a853;
    --shadow: 0 16px 36px rgba(0,0,0,.25);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    color: var(--ink);
    font-family: "Segoe UI", Tahoma, Arial, sans-serif;
    background:
        radial-gradient(circle at top, rgba(255,255,255,.12), transparent 35%),
        linear-gradient(180deg, #143d28 0%, #0c281a 100%);
    min-height: 100vh;
}

.app-shell {
    min-height: 100vh;
    padding: 16px;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    color: #fff;
    margin-bottom: 14px;
}

.topbar h1 { margin: 0; font-size: clamp(1.5rem, 3vw, 2.5rem); }
.topbar p { margin: 4px 0 0; opacity: .8; }
.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.primary-btn, .secondary-btn, #controls button, .modal button {
    appearance: none;
    border: 0;
    border-radius: 12px;
    padding: 10px 14px;
    font-weight: 700;
    cursor: pointer;
    transition: transform .15s ease, box-shadow .15s ease, opacity .15s ease;
}

.primary-btn, #controls button {
    color: white;
    background: linear-gradient(180deg, #3d9cff, #2563eb);
    box-shadow: 0 8px 20px rgba(37,99,235,.25);
}

.secondary-btn {
    color: #fff;
    background: rgba(255,255,255,.16);
    backdrop-filter: blur(8px);
}

button:hover:not(:disabled) { transform: translateY(-1px); }
button:disabled { opacity: .5; cursor: not-allowed; }

.game-shell {
    display: grid;
    gap: 14px;
}

#table-layout {
    position: relative;
    display: grid;
    grid-template-columns: 1fr 1.7fr 1fr;
    grid-template-rows: auto 1fr auto;
    gap: 12px;
    min-height: min(72vh, 760px);
    padding: 18px;
    border-radius: 28px;
    background:
        radial-gradient(circle at center, rgba(255,255,255,.08), transparent 38%),
        radial-gradient(circle at center, #1d8b5a 0%, var(--table-green) 42%, var(--table-dark) 100%);
    box-shadow: var(--shadow);
    border: 2px solid rgba(255,255,255,.08);
    overflow: hidden;
}

#table-layout::before {
    content: "";
    position: absolute;
    inset: 18px;
    border-radius: 22px;
    border: 2px solid rgba(255,255,255,.18);
    pointer-events: none;
}

.player-seat { align-self: center; }
.seat-top { grid-column: 2; grid-row: 1; justify-self: center; }
.seat-left { grid-column: 1; grid-row: 2; justify-self: start; }
.seat-right { grid-column: 3; grid-row: 2; justify-self: end; }
.seat-bottom { grid-column: 2; grid-row: 3; justify-self: center; }

#center-area {
    grid-column: 2;
    grid-row: 2;
    display: flex;
    align-items: center;
    justify-content: center;
}

.board-panel {
    width: min(100%, 430px);
    padding: 16px;
    border-radius: 24px;
    background: rgba(8, 31, 20, 0.38);
    box-shadow: inset 0 1px 0 rgba(255,255,255,.08);
    backdrop-filter: blur(6px);
}

.turn-banner, .board-info {
    margin-bottom: 10px;
    padding: 10px 12px;
    border-radius: 14px;
    background: rgba(255,255,255,.12);
    color: #fff;
}

.turn-banner.active { outline: 2px solid rgba(255,255,255,.3); }

#deck-discard-row {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 28px;
    min-height: 160px;
}

.card-slot {
    width: 96px;
    height: 140px;
    border-radius: 18px;
    background: rgba(255,255,255,.08);
    border: 2px dashed rgba(255,255,255,.3);
    display: grid;
    place-items: center;
    position: relative;
}

.card-slot.has-card { border-style: solid; }

.player-box {
    width: min(100%, 300px);
    min-height: 170px;
    padding: 12px;
    border-radius: 22px;
    background: var(--panel);
    box-shadow: 0 8px 24px rgba(0,0,0,.18);
    border: 2px solid rgba(0,0,0,.12);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.player-box.active {
    box-shadow: 0 0 0 3px rgba(255,182,72,.45), 0 16px 32px rgba(0,0,0,.22);
    transform: translateY(-2px);
}

.player-box .player-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 800;
}

.player-box .score-pill {
    padding: 4px 8px;
    border-radius: 999px;
    background: rgba(44,123,229,.12);
    color: var(--accent);
    font-size: .85rem;
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(60px, 1fr));
    gap: 10px;
    position: relative;
}

.playing-card {
    width: 100%;
    aspect-ratio: 2 / 3;
    border-radius: 14px;
    position: relative;
    display: grid;
    place-items: center;
    font-size: clamp(1rem, 2vw, 1.4rem);
    font-weight: 900;
    border: 2px solid rgba(0,0,0,.18);
    box-shadow: 0 8px 16px rgba(0,0,0,.16);
    background:
        radial-gradient(circle at top left, rgba(255,255,255,.95), rgba(255,255,255,.78) 48%, rgba(238,241,245,.96) 100%);
    overflow: hidden;
    transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}

.playing-card::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255,255,255,.55), transparent 40%);
    pointer-events: none;
}

.playing-card.red { color: #c62828; }
.playing-card.black { color: #17212b; }
.playing-card.special { border-color: var(--accent-2); box-shadow: 0 0 0 2px rgba(255,182,72,.18), 0 8px 16px rgba(0,0,0,.16); }
.playing-card.moving { z-index: 50; }
.playing-card.selected { transform: translateY(-4px) scale(1.04); border-color: var(--accent); box-shadow: 0 0 0 3px rgba(44,123,229,.2), 0 10px 20px rgba(0,0,0,.18); }

.card-face { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; }
.card-corner { position: absolute; font-size: .72em; font-weight: 900; }
.card-corner.top { top: 7px; left: 8px; }
.card-corner.bottom { right: 8px; bottom: 7px; transform: rotate(180deg); }

.deck-card-back {
    width: 84px;
    height: 124px;
    border-radius: 16px;
    border: 2px solid rgba(255,255,255,.35);
    background:
        linear-gradient(135deg, #1846a8 0%, #0e2f77 60%, #091c4d 100%);
    position: relative;
    box-shadow: 0 10px 18px rgba(0,0,0,.22);
}

.deck-card-back::before {
    content: "WIN";
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    color: rgba(255,255,255,.92);
    font-weight: 900;
    letter-spacing: .22em;
}

.deck-card-back::after {
    content: "";
    position: absolute;
    inset: 10px;
    border-radius: 12px;
    border: 1px solid rgba(255,255,255,.18);
}

.selected-card-area {
    grid-column: 1 / -1;
    min-height: 34px;
    display: flex;
    justify-content: center;
}

.controls-panel {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    justify-content: center;
    padding: 14px;
    border-radius: 20px;
    background: rgba(255,255,255,.1);
    color: #fff;
}

.controls-panel .status-text { flex: 1 1 100%; text-align: center; font-weight: 700; }

.stats-row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.stat-chip {
    padding: 7px 10px;
    border-radius: 999px;
    background: rgba(255,255,255,.12);
}

.decision-popup, .modal {
    position: fixed;
    inset: auto 50% 50% auto;
    transform: translate(50%, 50%);
    width: min(92vw, 540px);
    max-height: min(82vh, 760px);
    overflow: auto;
    z-index: 40;
    padding: 18px;
    border-radius: 18px;
    background: rgba(255,255,255,.98);
    box-shadow: var(--shadow);
    border: 1px solid rgba(0,0,0,.12);
}

.decision-popup h3, .modal h2 { margin-top: 0; }
.decision-popup .row, .modal .row { display: flex; flex-wrap: wrap; gap: 8px; }
.decision-popup button, .modal button { background: linear-gradient(180deg, #eff6ff, #dbeafe); }
.decision-popup button.primary, .modal button.primary { background: linear-gradient(180deg, #4da3ff, #2563eb); color: #fff; }
.decision-popup button.warn { background: linear-gradient(180deg, #fff7ed, #fed7aa); }
.decision-popup::before, .modal::before {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.42);
    z-index: -1;
}

.end-screen {
    margin-top: 6px;
    padding: 18px;
    border-radius: 22px;
    background: rgba(255,255,255,.96);
    box-shadow: var(--shadow);
}

#toast-root {
    position: fixed;
    right: 16px;
    bottom: 16px;
    display: grid;
    gap: 8px;
    z-index: 60;
}

.toast {
    padding: 10px 12px;
    border-radius: 12px;
    color: #fff;
    background: rgba(19, 32, 25, .95);
    box-shadow: 0 8px 18px rgba(0,0,0,.2);
}
.toast.success { background: rgba(52,168,83,.95); }
.toast.warn { background: rgba(255,182,72,.95); color: #222; }
.toast.danger { background: rgba(227,75,75,.95); }

.highlight-pulse { animation: pulse .9s ease-in-out 2; }
@keyframes pulse { 0%,100% { box-shadow: inherit; } 50% { filter: brightness(1.08); } }

@media (max-width: 900px) {
    #table-layout {
        grid-template-columns: 1fr 1fr;
        grid-template-rows: auto auto auto auto;
    }
    .seat-top { grid-column: 1 / -1; grid-row: 1; }
    .seat-left { grid-column: 1; grid-row: 2; }
    .seat-right { grid-column: 2; grid-row: 2; }
    #center-area { grid-column: 1 / -1; grid-row: 3; }
    .seat-bottom { grid-column: 1 / -1; grid-row: 4; }
    .player-box { width: 100%; }
}

@media (max-width: 640px) {
    .topbar { flex-direction: column; align-items: flex-start; }
    #table-layout { padding: 12px; border-radius: 20px; }
    .board-panel { padding: 12px; }
    #deck-discard-row { gap: 16px; }
    .card-slot { width: 84px; height: 124px; }
    .deck-card-back { width: 74px; height: 108px; }
    .player-box { min-height: 145px; border-radius: 18px; }
}
