/* ═══════════════════════════════════════════
   KARMA CARD GAME — Main Stylesheet
   ═══════════════════════════════════════════ */

:root {
    --karma-bg: #1a0a2e;
    --karma-surface: #2d1b4e;
    --karma-accent: #9b59b6;
    --karma-gold: #f39c12;
    --karma-green: #27ae60;
    --karma-red: #e74c3c;
    --karma-text: #f0e6ff;
    --card-radius: 10px;
    --card-shadow: 0 4px 12px rgba(0,0,0,0.5);
    --font-card: 'Boogaloo', cursive;
    --font-ui: 'Nunito', sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    background: var(--karma-bg);
    color: var(--karma-text);
    font-family: var(--font-ui);
    min-height: 100vh;
    overflow-x: hidden;
}

.karma-app { min-height: 100vh; }

/* ─── Utility ─── */
.karma-center { display: flex; align-items: center; justify-content: center; min-height: 80vh; }
.karma-error { color: var(--karma-red); padding: 8px; font-size: 0.9rem; }
.karma-input {
    width: 100%; padding: 10px 14px;
    background: rgba(255,255,255,0.1); border: 1px solid rgba(255,255,255,0.25);
    border-radius: 8px; color: var(--karma-text); font-size: 1rem; font-family: var(--font-ui);
    outline: none; margin-bottom: 10px;
}
.karma-input::placeholder { color: rgba(255,255,255,0.4); }
.karma-input:focus { border-color: var(--karma-accent); }

/* ─── Buttons ─── */
.karma-btn {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 12px 24px; border: none; border-radius: 10px;
    font-family: var(--font-ui); font-size: 1rem; font-weight: 700;
    cursor: pointer; transition: all 0.15s ease;
    touch-action: manipulation; min-height: 44px;
}
.karma-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.karma-btn-primary { background: var(--karma-accent); color: white; }
.karma-btn-primary:hover:not(:disabled) { background: #8e44ad; transform: translateY(-1px); }
.karma-btn-secondary { background: #2980b9; color: white; }
.karma-btn-secondary:hover:not(:disabled) { background: #1a6fa3; }
.karma-btn-danger { background: var(--karma-red); color: white; }
.karma-btn-danger:hover:not(:disabled) { background: #c0392b; }
.karma-btn-ghost { background: rgba(255,255,255,0.1); color: var(--karma-text); border: 1px solid rgba(255,255,255,0.2); }
.karma-btn-ghost:hover:not(:disabled) { background: rgba(255,255,255,0.2); }
.karma-btn-start {
    background: linear-gradient(135deg, var(--karma-green), #219a52);
    color: white; width: 100%; font-size: 1.2rem; padding: 16px;
    margin-top: 12px; letter-spacing: 1px;
}
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }

/* ─── CARDS ─── */
.card {
    width: 64px; height: 96px;
    border-radius: var(--card-radius);
    box-shadow: var(--card-shadow);
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    position: relative; user-select: none;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    border: 2px solid rgba(255,255,255,0.15);
    overflow: hidden; /* keep content (esp. karma text) clipped to card shape */
}

.card-small { width: 44px; height: 66px; border-radius: 7px; }
.card-large { width: 88px; height: 130px; border-radius: 14px; }

.card.clickable { cursor: pointer; }
.card.playable {
    border-color: var(--karma-gold);
    box-shadow: 0 0 12px rgba(243,156,18,0.6), var(--card-shadow);
}
.card.playable:hover { transform: translateY(-6px); box-shadow: 0 8px 20px rgba(243,156,18,0.8); }
.card.unplayable { position: relative; }
.card.unplayable::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    border-radius: inherit;
    pointer-events: none;
}
.card.card-selected {
    border: 2px solid #00e5ff;
    transform: translateY(-10px);
    box-shadow: 0 10px 24px rgba(0,229,255,0.7), var(--card-shadow);
}
.card.card-selected:hover { transform: translateY(-12px); }

/* ─── Card animations ─── */
@keyframes card-play-to-discard {
    0%   { transform: translateY(-80px) rotate(-8deg) scale(0.75); opacity: 0; }
    60%  { transform: translateY(6px)   rotate(2deg)  scale(1.05); opacity: 1; }
    100% { transform: translateY(0)     rotate(0deg)  scale(1);    opacity: 1; }
}
@keyframes card-draw-from-pile {
    0%   { transform: translateY(-60px) scale(0.8); opacity: 0; }
    70%  { transform: translateY(4px)   scale(1.04); opacity: 1; }
    100% { transform: translateY(0)     scale(1);    opacity: 1; }
}
.card-play-animate {
    animation: card-play-to-discard 0.38s cubic-bezier(0.22, 0.61, 0.36, 1) both;
}
.card-draw-animate {
    animation: card-draw-from-pile 0.42s cubic-bezier(0.22, 0.61, 0.36, 1) both;
}

/* Number cards — color by value */
.card-number { background: linear-gradient(145deg, #2c3e50, #34495e); }
.card-num-1 { background: linear-gradient(145deg, #1abc9c, #16a085); }
.card-num-2 { background: linear-gradient(145deg, #3498db, #2980b9); }
.card-num-3 { background: linear-gradient(145deg, #9b59b6, #8e44ad); }
.card-num-4 { background: linear-gradient(145deg, #e67e22, #d35400); }
.card-num-5 { background: linear-gradient(145deg, #e74c3c, #c0392b); }
.card-num-6 { background: linear-gradient(145deg, #f39c12, #e67e22); }
.card-num-7 { background: linear-gradient(145deg, #27ae60, #219a52); }
.card-num-8 { background: linear-gradient(145deg, #2980b9, #1a6fa3); }
.card-num-9 { background: linear-gradient(145deg, #8e44ad, #6c3483); }
.card-num-10 { background: linear-gradient(145deg, #d35400, #b7470a); }
.card-num-11 { background: linear-gradient(145deg, #16a085, #0e7060); }
.card-num-12 { background: linear-gradient(145deg, #2471a3, #1a5276); }
.card-num-13 { background: linear-gradient(145deg, #6c3483, #512e5f); }
.card-num-14 { background: linear-gradient(145deg, #b7770d, #9a6a0a); }
.card-num-15 { background: linear-gradient(145deg, #1e8449, #196f3d); }
.card-num-16 { background: linear-gradient(145deg, #154360, #0e2d4a); }

.card-number-display {
    font-family: var(--font-card);
    font-size: 2rem; color: white;
    text-shadow: 1px 1px 3px rgba(0,0,0,0.5);
    line-height: 1;
}
.card-small .card-number-display { font-size: 1.3rem; }
.card-large .card-number-display { font-size: 2.8rem; }

/* Karma cards */
.card-karma { background: linear-gradient(145deg, #2c2c54, #1a1a3e); border: 2px solid rgba(255,215,0,0.5); }
.card-karma-wild { background: linear-gradient(145deg, #ff6b35, #f7c59f); }
.card-karma-fiveorbelow { background: linear-gradient(145deg, #11998e, #38ef7d); }
.card-karma-bottomsup { background: linear-gradient(145deg, #4e54c8, #8f94fb); }
.card-karma-givetofriend { background: linear-gradient(145deg, #c94b4b, #4b134f); }
.card-karma-playtablecard { background: linear-gradient(145deg, #2193b0, #6dd5ed); }

.card-karma-symbol {
    font-size: 1.6rem; line-height: 1; flex-shrink: 0;
    text-shadow: 0 0 8px rgba(255,255,255,0.8);
    max-width: 100%;
}
.card-small .card-karma-symbol { font-size: 1rem; }
.card-large .card-karma-symbol { font-size: 2.2rem; }

.card-karma-label {
    font-family: var(--font-ui); font-size: 0.52rem; font-weight: 900;
    letter-spacing: 0.3px; text-align: center;
    padding: 0 3px; width: 100%;
    color: rgba(255,255,255,0.9); text-transform: uppercase;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.card-small .card-karma-label { font-size: 0.35rem; letter-spacing: 0; }
.card-large .card-karma-label { font-size: 0.7rem; }

/* Card back */
.card-back {
    background: linear-gradient(135deg, #1a0a2e, #2d1b4e);
    border: 2px solid rgba(255,255,255,0.2);
    background-image: repeating-linear-gradient(
        45deg,
        rgba(155,89,182,0.15) 0px, rgba(155,89,182,0.15) 2px,
        transparent 2px, transparent 8px
    );
}
.draw-pile { cursor: default; }
.pile-count {
    position: absolute; bottom: 4px; right: 6px;
    font-size: 0.75rem; font-weight: 700; color: rgba(255,255,255,0.7);
}

/* ─── CARD COUNT ICON ─── */
.card-count-icon {
    position: relative; width: 40px; height: 56px;
    display: flex; align-items: center; justify-content: center;
}
.card-stack-item {
    position: absolute;
    width: 28px; height: 42px;
    background: linear-gradient(145deg, #2c3e50, #34495e);
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 5px;
    transform: translateX(calc(var(--stack-i) * 5px)) translateY(calc(var(--stack-i) * -3px));
    box-shadow: 1px 1px 3px rgba(0,0,0,0.4);
}
.card-count-label {
    position: absolute; top: -8px; right: -8px;
    background: var(--karma-gold); color: #000;
    border-radius: 50%; width: 20px; height: 20px;
    font-size: 0.7rem; font-weight: 900;
    display: flex; align-items: center; justify-content: center;
}

/* ─── LANDING PAGE ─── */
.karma-landing {
    min-height: 100vh; display: flex; flex-direction: column;
    align-items: center; justify-content: center; padding: 24px;
    background: radial-gradient(ellipse at center, #2d1b4e 0%, #1a0a2e 70%);
}

.landing-header { text-align: center; margin-bottom: 40px; }

.karma-logo {
    font-family: var(--font-card); font-size: 5rem; font-weight: 900;
    color: var(--karma-gold);
    text-shadow: 0 0 30px rgba(243,156,18,0.6), 2px 2px 4px rgba(0,0,0,0.8);
    letter-spacing: 6px;
}

.karma-tagline {
    font-size: 1.1rem; color: rgba(255,255,255,0.6);
    letter-spacing: 3px; text-transform: uppercase;
}

.landing-buttons {
    display: flex; flex-direction: column; gap: 12px;
    width: 100%; max-width: 340px;
}
.landing-name-row { margin-bottom: 8px; }

.landing-panel {
    background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.15);
    border-radius: 16px; padding: 24px; width: 100%; max-width: 400px;
    display: flex; flex-direction: column; gap: 12px;
}
.landing-panel h3 { margin-bottom: 8px; color: var(--karma-gold); }

.table-list { display: flex; flex-direction: column; gap: 8px; max-height: 200px; overflow-y: auto; }

.table-item {
    background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.15);
    border-radius: 8px; padding: 10px 14px; cursor: pointer;
    display: flex; flex-direction: column; transition: border-color 0.15s;
}
.table-item:hover, .table-item.selected {
    border-color: var(--karma-accent);
    background: rgba(155,89,182,0.15);
}
.table-name { font-weight: 700; }
.table-meta { font-size: 0.8rem; color: rgba(255,255,255,0.5); }
.no-tables { text-align: center; color: rgba(255,255,255,0.4); padding: 12px; }

.join-details { display: flex; flex-direction: column; gap: 10px; }

/* ─── LOBBY PAGE ─── */
.lobby-page {
    max-width: 500px; margin: 0 auto; padding: 24px;
    display: flex; flex-direction: column; gap: 20px;
}
.lobby-header h2 { color: var(--karma-gold); font-family: var(--font-card); font-size: 2rem; }
.lobby-subtitle { color: rgba(255,255,255,0.5); }

.player-list { display: flex; flex-direction: column; gap: 8px; }
.player-list h4 { color: rgba(255,255,255,0.6); font-size: 0.85rem; text-transform: uppercase; }
.lobby-player {
    display: flex; align-items: center; gap: 10px;
    background: rgba(255,255,255,0.06); border-radius: 10px;
    padding: 12px 16px; border: 1px solid rgba(255,255,255,0.1);
}
.lobby-player.is-host { border-color: var(--karma-gold); }
.lobby-player.is-bot { opacity: 0.8; }
.player-icon { font-size: 1.2rem; }
.player-name { flex: 1; font-weight: 700; }

.badge { font-size: 0.7rem; font-weight: 700; padding: 3px 8px; border-radius: 20px; text-transform: uppercase; }
.badge-host { background: var(--karma-gold); color: #000; }
.badge-bot { background: #555; color: #fff; }
.badge-spectator { background: #2980b9; color: #fff; }

.host-controls { display: flex; flex-direction: column; gap: 12px; }
.bot-controls { display: flex; gap: 10px; }
.waiting-message { text-align: center; color: rgba(255,255,255,0.5); padding: 16px; }

/* ─── GAME PAGE ─── */
.game-wrapper {
    display: flex; flex-direction: column;
    height: 100vh; height: 100dvh;
    overflow: hidden;
}

.game-banner {
    flex: 0 0 auto;
    display: flex; align-items: center; gap: 8px;
    padding: 6px 14px; background: rgba(0,0,0,0.35);
    border-radius: 10px; margin: 4px 8px;
    font-size: 0.85rem;
}
.banner-title { font-family: var(--font-card); font-size: 1.1rem; color: var(--karma-gold); font-weight: 700; }
.banner-sep { color: rgba(255,255,255,0.25); }
.banner-table { color: var(--karma-text); font-weight: 600; }
.banner-password { color: rgba(255,255,255,0.5); font-size: 0.8rem; }

.game-page {
    flex: 1 1 0; min-height: 0;
    display: flex; flex-direction: column;
    padding: 8px; gap: 0;
    overflow: hidden;
}

.other-players-area {
    flex: 1 1 0; min-height: 0;
    overflow-y: auto;
    padding: 8px; background: rgba(0,0,0,0.2); border-radius: 12px;
}

/* zoom-content is the direct child wrapper — give it the flex layout */
.other-players-area .zoom-content {
    display: flex; flex-wrap: wrap; gap: 8px; align-content: flex-start;
    width: 100%;
}

/* bottom panel zoom-content stays column */
.player-bottom-panel .zoom-content {
    display: flex; flex-direction: column; gap: 10px;
    width: 100%;
}

.panel-splitter {
    flex: 0 0 28px;
    display: flex; align-items: center; justify-content: center;
    cursor: row-resize; touch-action: none; user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}
.panel-splitter-handle {
    width: 64px; height: 6px;
    background: rgba(255,255,255,0.35); border-radius: 3px;
    transition: background 0.15s;
}
.panel-splitter:hover .panel-splitter-handle,
.panel-splitter:active .panel-splitter-handle {
    background: var(--karma-accent);
}

.other-player {
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 10px; padding: 8px 12px;
    display: flex; flex-direction: column; gap: 4px;
    transition: border-color 0.2s;
}
.other-player.is-current {
    border-color: var(--karma-gold);
    background: rgba(243,156,18,0.12);
    box-shadow: 0 0 12px rgba(243,156,18,0.3);
}
.other-player.is-finished { opacity: 0.5; }
.op-self { opacity: 0.6; min-height: unset; justify-content: center; }
.op-self-badge {
    font-size: 0.65rem; color: var(--karma-gold); font-weight: 700;
    font-family: var(--font-ui);
}
.op-name { font-size: 0.8rem; font-weight: 700; }
.op-info-row { display: flex; align-items: flex-start; gap: 6px; }
.op-table-piles { display: flex; gap: 4px; }

.center-piles {
    display: flex; flex-direction: column; align-items: center; gap: 8px;
}

.pile-area {
    display: flex; gap: 24px; align-items: center; justify-content: center;
    padding: 12px;
}

.draw-pile-area, .discard-pile-area {
    display: flex; flex-direction: column; align-items: center; gap: 6px;
}

.discard-empty, .pile-empty {
    width: 88px; height: 130px;
    border: 2px dashed rgba(255,255,255,0.2);
    border-radius: 14px;
    display: flex; align-items: center; justify-content: center;
    color: rgba(255,255,255,0.3); font-size: 0.75rem; text-align: center;
}

.rule-badge {
    padding: 4px 12px; border-radius: 20px;
    font-size: 0.8rem; font-weight: 700; text-align: center;
    animation: pulse 1.5s infinite;
}
.rule-5 { background: #27ae60; color: white; }
.rule-wild { background: var(--karma-gold); color: #000; }
.rule-from { background: #555; color: #ddd; font-style: italic; animation: none; }

.section-label.highlight {
    color: var(--karma-gold);
    text-shadow: 0 0 10px var(--karma-gold);
    font-weight: 900;
    animation: label-pulse 1.5s infinite;
}

@keyframes label-pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.1); opacity: 0.8; }
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.7; transform: scale(0.97); }
}

.game-status { text-align: center; padding: 6px; }
.status-myturn {
    color: var(--karma-gold); font-size: 1.2rem; font-weight: 900;
    font-family: var(--font-card);
    animation: glow 1s ease-in-out infinite alternate;
}
.status-action { color: #f39c12; font-weight: 700; }
.status-waiting { color: rgba(255,255,255,0.5); }

@keyframes glow {
    from { text-shadow: 0 0 5px rgba(243,156,18,0.5); }
    to { text-shadow: 0 0 20px rgba(243,156,18,1); }
}

.player-bottom-panel {
    flex: 1 1 0; min-height: 0;
    display: flex; flex-direction: column; gap: 10px;
    padding: 10px;
    background: rgba(0,0,0,0.2); border-radius: 12px;
    overflow-y: auto;
}

/* ─── BOTTOM PANEL: slightly smaller cards (56×84 regular, 76×112 large) ─── */
.player-bottom-panel .card { width: 56px; height: 84px; border-radius: 9px; }
.player-bottom-panel .card-large { width: 76px; height: 112px; border-radius: 12px; }
.player-bottom-panel .card-number-display { font-size: 1.75rem; }
.player-bottom-panel .card-large .card-number-display { font-size: 2.4rem; }
.player-bottom-panel .card-karma-symbol { font-size: 1.4rem; }
.player-bottom-panel .card-large .card-karma-symbol { font-size: 1.9rem; }
.player-bottom-panel .discard-empty,
.player-bottom-panel .pile-empty { width: 76px; height: 112px; border-radius: 12px; }
.player-bottom-panel .hand-cards-row { min-height: 58px; }

/* Piles + table cards: column on desktop, row on mobile */
.piles-table-row {
    display: flex; flex-direction: column; align-items: center; gap: 8px;
}

/* ─── TABLE PILES (stacked face-down + face-up) ─── */
.table-pile {
    position: relative;
    flex-shrink: 0;
}
.pile-card { position: absolute; }
.pile-fd {
    top: 0; left: 0;
    z-index: 10;
    opacity: 0.8;
}
/* Face-up offset to reveal face-down beneath */
.pile-fu {
    z-index: 20;
}
.pile-both .pile-fu { z-index: 20; }
/* When no face-down, face-up sits flush */
.table-pile:not(.pile-both) .pile-fu { top: 0; left: 0; }

/* Other-player piles (small cards: 44×66) */
.op-table-piles .table-pile { width: 44px; height: 66px; }
.op-table-piles .table-pile.pile-both { height: 82px; }
.op-table-piles .pile-both .pile-fu { top: 16px; left: 2px; }

/* My table card piles — sized to match bottom-panel regular cards (56×84) */
.my-table-cards .table-pile { width: 56px; height: 84px; }
.my-table-cards .table-pile.pile-both { height: 104px; }
.my-table-cards .pile-both .pile-fu { top: 20px; left: 2px; }

.section-label { font-size: 0.75rem; color: rgba(255,255,255,0.5); text-transform: uppercase; }

.my-table-cards, .my-hand { display: flex; flex-direction: column; gap: 6px; }

/* Table cards + action buttons side-by-side on widescreen */
.table-actions-row {
    display: flex; flex-direction: row; align-items: center; gap: 16px;
    justify-content: flex-start; flex-wrap: wrap;
    align-self: stretch;
}

.table-card-row {
    display: flex; flex-wrap: wrap; gap: 6px;
}
.hand-cards-row {
    display: flex; flex-wrap: wrap; gap: 6px;
    min-height: 70px;
}

.action-buttons { display: flex; flex-direction: column; align-items: center; gap: 8px; }

.give-to-friend-panel {
    background: rgba(201,75,75,0.2); border: 1px solid var(--karma-red);
    border-radius: 10px; padding: 12px;
    display: flex; flex-direction: column; gap: 8px;
}
.panel-title { font-weight: 700; color: var(--karma-red); }

.finished-banner {
    text-align: center; padding: 20px; border-radius: 12px;
    font-size: 1.1rem; font-weight: 700;
}
.finished-banner.is-winner { background: rgba(39,174,96,0.2); border: 1px solid var(--karma-green); }
.finished-banner.is-loser { background: rgba(231,76,60,0.2); border: 1px solid var(--karma-red); }

.game-error {
    position: fixed; bottom: 12px; left: 50%; transform: translateX(-50%);
    background: var(--karma-red); color: white; padding: 10px 20px;
    border-radius: 20px; font-size: 0.9rem; z-index: 999;
    animation: fadeout 3s forwards 2s;
}
@keyframes fadeout { to { opacity: 0; } }

/* ─── SWAP PHASE ─── */
.swap-page {
    max-width: 600px; margin: 0 auto; padding: 24px;
    display: flex; flex-direction: column; gap: 16px;
}
.swap-header h2 { color: var(--karma-gold); font-family: var(--font-card); font-size: 2rem; }
.swap-header p { color: rgba(255,255,255,0.6); }
.swap-section { display: flex; flex-direction: column; gap: 8px; }
.swap-section h4 { color: rgba(255,255,255,0.7); font-size: 0.85rem; }
.swap-row { display: flex; flex-wrap: wrap; gap: 8px; }
.swap-arrows { text-align: center; color: var(--karma-accent); font-size: 1.1rem; }
.swap-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.swap-ready-msg { text-align: center; color: var(--karma-green); font-size: 1.1rem; padding: 20px; }

.all-players-swap { display: flex; flex-wrap: wrap; gap: 8px; padding-top: 8px; }
.swap-player-status { padding: 4px 10px; border-radius: 20px; font-size: 0.8rem; }
.swap-player-status.ready { background: rgba(39,174,96,0.2); border: 1px solid var(--karma-green); }
.swap-player-status.waiting { background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.2); }

/* ─── GAME OVER ─── */
.game-over-page {
    min-height: 100vh; display: flex; flex-direction: column;
    align-items: center; justify-content: center; padding: 24px; gap: 24px;
}
.game-over-header {
    font-family: var(--font-card); font-size: 4rem; color: var(--karma-gold);
    text-shadow: 0 0 30px rgba(243,156,18,0.8);
    letter-spacing: 4px;
}
.results-list { display: flex; flex-direction: column; gap: 8px; width: 100%; max-width: 400px; }
.result-row {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 16px; border-radius: 10px;
    background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.1);
}
.result-row.is-me { border-color: var(--karma-accent); }
.result-row.is-loser { border-color: var(--karma-red); background: rgba(231,76,60,0.15); }
.result-pos { font-size: 1.5rem; font-weight: 900; color: rgba(255,255,255,0.4); width: 32px; }
.result-name { flex: 1; font-weight: 700; }
.result-badge { font-size: 0.7rem; font-weight: 700; padding: 3px 8px; border-radius: 20px; }
.badge-loser { background: var(--karma-red); color: white; }
.badge-winner { background: var(--karma-green); color: white; }

.loser-announcement {
    text-align: center; padding: 16px 24px;
    background: rgba(231,76,60,0.2); border: 1px solid var(--karma-red);
    border-radius: 12px; font-size: 1rem;
}
.replay-btn { font-size: 1.2rem; padding: 16px 40px; margin-top: 8px; }
.waiting-host { color: rgba(255,255,255,0.5); text-align: center; }

/* ─── SPECTATE PAGE ─── */
.spectate-page {
    min-height: 100vh; display: grid;
    grid-template-rows: auto 1fr auto auto;
    grid-template-columns: 1fr;
    padding: 12px; gap: 12px;
}

/* ─── WIDESCREEN: give bottom panel more space (25/75 split) ─── */
@media (min-width: 901px) {
    .other-players-area { flex: 1 1 0; }
    .player-bottom-panel { flex: 3 1 0; }
}

@media (min-width: 900px) {
    .spectate-page {
        grid-template-columns: 1fr 200px 250px;
        grid-template-rows: auto 1fr;
    }
    .spectate-header { grid-column: 1 / -1; }
    .spectate-players { grid-column: 1; }
    .spectate-center { grid-column: 2; }
    .spectate-log { grid-column: 3; }
}

.spectate-header {
    display: flex; align-items: center; gap: 16px;
    padding: 8px 16px; background: rgba(0,0,0,0.3); border-radius: 10px;
}
.spectate-title { font-family: var(--font-card); font-size: 1.8rem; color: var(--karma-gold); }
.spectate-status { color: rgba(255,255,255,0.6); }

.spectate-players { display: flex; flex-wrap: wrap; gap: 12px; align-content: start; }

.spectate-player {
    background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.1);
    border-radius: 12px; padding: 12px; min-width: 120px; max-width: 160px;
    display: flex; flex-direction: column; gap: 8px;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.spectate-player.is-current {
    border-color: var(--karma-gold);
    box-shadow: 0 0 16px rgba(243,156,18,0.4);
}
.spectate-player.is-finished { opacity: 0.5; }
.spectate-player.is-loser { border-color: var(--karma-red); }

.sp-header { display: flex; flex-direction: column; gap: 4px; }
.sp-name { font-weight: 700; font-size: 0.9rem; }
.sp-turn-badge { background: var(--karma-gold); color: #000; font-size: 0.65rem; font-weight: 900; padding: 2px 6px; border-radius: 10px; width: fit-content; }
.sp-done-badge { background: var(--karma-green); color: white; font-size: 0.65rem; padding: 2px 6px; border-radius: 10px; width: fit-content; }
.sp-loser-badge { background: var(--karma-red); color: white; font-size: 0.65rem; padding: 2px 6px; border-radius: 10px; width: fit-content; }

.sp-hand-count { display: flex; align-items: center; gap: 6px; }
.sp-hand-label { font-size: 0.7rem; color: rgba(255,255,255,0.5); }
.sp-table-cards { display: flex; flex-direction: column; gap: 4px; }
.sp-faceup, .sp-facedown { display: flex; flex-wrap: wrap; gap: 3px; }

.spectate-center {
    display: flex; flex-direction: column; align-items: center;
    gap: 12px; padding: 12px;
}
.spectate-pile-area { display: flex; gap: 16px; align-items: flex-start; }

.spectate-log {
    background: rgba(0,0,0,0.3); border-radius: 10px; padding: 12px;
    display: flex; flex-direction: column; gap: 4px;
    max-height: 300px; overflow-y: auto;
}
.log-title { font-weight: 700; color: var(--karma-gold); margin-bottom: 6px; font-size: 0.85rem; }
.log-entry { font-size: 0.75rem; color: rgba(255,255,255,0.6); padding: 2px 0; border-bottom: 1px solid rgba(255,255,255,0.05); }

/* ─── MOBILE RESPONSIVE ─── */
@media (max-width: 600px) {
    .karma-logo { font-size: 3.5rem; }
    .card { width: 52px; height: 78px; }
    .card-large { width: 72px; height: 108px; }
    .card-small { width: 36px; height: 54px; }
    .card-number-display { font-size: 1.6rem; }
    .card-large .card-number-display { font-size: 2.2rem; }
    .card-small .card-number-display { font-size: 1rem; }
    .other-players-area { padding: 6px; }
    .other-players-area .zoom-content { gap: 6px; }

    /* 2 other-player panels per row on mobile */
    .other-players-area .other-player { padding: 6px; flex: 0 0 calc(50% - 3px); min-width: 0; }

    /* karma card content sizing for mobile card dimensions */
    .card-karma-symbol { font-size: 1.4rem; }
    .card-karma-label  { font-size: 0.46rem; }
    .card-small .card-karma-symbol { font-size: 0.85rem; }
    .card-small .card-karma-label  { font-size: 0.3rem; }

    .game-over-header { font-size: 2.5rem; }

    /* ── Splitter layout already handles both panels ── */
    .player-bottom-panel {
        padding: 6px;
        gap: 6px;
    }

    /* Piles + table cards side-by-side on mobile */
    .piles-table-row {
        flex-direction: row;
        align-items: flex-start;
        justify-content: center;
        gap: 8px;
    }
    .center-piles {
        flex: 0 0 auto;
    }
    .my-table-cards {
        flex: 0 0 auto;
    }

    /* Stack table cards + action buttons vertically on mobile */
    .table-actions-row {
        flex-direction: column; gap: 8px;
        align-self: center;
    }

    /* Bottom panel: use mobile card sizes (override the desktop bottom-panel reduction) */
    .player-bottom-panel .card { width: 52px; height: 78px; border-radius: 8px; }
    .player-bottom-panel .card-large { width: 62px; height: 92px; border-radius: 10px; }
    .player-bottom-panel .card-number-display { font-size: 1.6rem; }
    .player-bottom-panel .card-large .card-number-display { font-size: 2rem; }
    .player-bottom-panel .discard-empty,
    .player-bottom-panel .pile-empty { width: 62px; height: 92px; border-radius: 10px; }
    .player-bottom-panel .hand-cards-row { min-height: 52px; }

    /* Pile size overrides for mobile card sizes */
    /* My table cards use 52×78 on mobile */
    .my-table-cards .table-pile { width: 52px; height: 78px; }
    .my-table-cards .table-pile.pile-both { height: 98px; }
    .my-table-cards .pile-both .pile-fu { top: 20px; left: 2px; }

    /* Other-player piles use 36×54 on mobile */
    .op-table-piles .table-pile { width: 36px; height: 54px; }
    .op-table-piles .table-pile.pile-both { height: 70px; }
    .op-table-piles .pile-both .pile-fu { top: 16px; left: 2px; }

    /* Compact pile area on mobile */
    .pile-area { gap: 12px; padding: 6px; }
}

/* ─── ANIMATIONS ─── */
@keyframes card-fly-in {
    from { transform: translateY(-30px) scale(0.8); opacity: 0; }
    to { transform: translateY(0) scale(1); opacity: 1; }
}
.card { animation: card-fly-in 0.2s ease; }
/* Prevent fly-in animation replay on table pile cards during Blazor re-renders */
.pile-card .card { animation: none; }

@keyframes pile-clear {
    0% { transform: scale(1); }
    50% { transform: scale(1.2); opacity: 0.5; }
    100% { transform: scale(0); opacity: 0; }
}

/* ─── ERROR BOUNDARY ─── */
.error-boundary-panel {
    margin: 24px auto; max-width: 900px;
    background: #1c0a0a; border: 2px solid var(--karma-red);
    border-radius: 12px; overflow: hidden;
    font-family: var(--font-ui);
}
.eb-header {
    display: flex; align-items: center; gap: 10px;
    background: var(--karma-red); color: white;
    padding: 12px 16px; font-weight: 700; font-size: 1.1rem;
}
.eb-icon { font-size: 1.4rem; }
.eb-body { padding: 16px; display: flex; flex-direction: column; gap: 12px; overflow-x: auto; }

.eb-exception {
    border-left: 3px solid rgba(231,76,60,0.5);
    padding-left: 12px;
}
.eb-exception.depth-1 { border-color: rgba(231,76,60,0.3); margin-left: 16px; }
.eb-exception.depth-2 { border-color: rgba(231,76,60,0.2); margin-left: 32px; }

.eb-ex-type {
    font-size: 0.8rem; color: #f39c12; font-family: monospace;
    font-weight: 700; margin-bottom: 4px;
}
.eb-ex-message {
    font-size: 1rem; color: #fce4e4; margin-bottom: 8px;
    font-weight: 600;
}
.eb-stacktrace {
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: 0.72rem; color: #ccc;
    background: rgba(0,0,0,0.4); padding: 10px;
    border-radius: 6px; overflow-x: auto;
    white-space: pre; max-height: 300px; overflow-y: auto;
    margin-top: 8px;
}
details > summary {
    cursor: pointer; color: rgba(255,255,255,0.6);
    font-size: 0.8rem; user-select: none;
    padding: 4px 0;
}
.eb-inner-label {
    font-size: 0.75rem; color: rgba(255,255,255,0.5);
    text-transform: uppercase; letter-spacing: 1px;
    margin-top: 8px;
}

.eb-footer {
    background: rgba(0,0,0,0.3); padding: 12px 16px;
    display: flex; flex-direction: column; gap: 10px;
}
.eb-logpath { font-size: 0.8rem; color: rgba(255,255,255,0.5); }
.eb-logpath code {
    background: rgba(255,255,255,0.1); padding: 2px 6px;
    border-radius: 4px; font-size: 0.75rem;
}
.eb-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ─── ZOOM CONTROLS ─── */
.zoom-controls {
    position: fixed; top: 50%; left: 12px; z-index: 100;
    transform: translateY(-50%);
    display: flex; flex-direction: column; gap: 4px;
}
.zoom-btn {
    width: 38px; height: 38px; border-radius: 50%;
    background: rgba(45,27,78,0.92); border: 1px solid rgba(255,255,255,0.2);
    color: var(--karma-text); font-size: 1.3rem; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; box-shadow: 0 2px 10px rgba(0,0,0,0.5);
    transition: background 0.15s, transform 0.15s;
    line-height: 1;
}
.zoom-btn:hover:not(:disabled) { background: rgba(155,89,182,0.85); transform: scale(1.08); }
.zoom-btn:disabled { opacity: 0.35; cursor: not-allowed; }

/* ─── GAME LOG OVERLAY ─── */
.log-btn {
    position: fixed; bottom: 16px; right: 16px; z-index: 100;
    width: 44px; height: 44px; border-radius: 50%;
    background: rgba(45,27,78,0.92); border: 1px solid rgba(255,255,255,0.2);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.3rem; cursor: pointer;
    box-shadow: 0 2px 10px rgba(0,0,0,0.5);
    transition: background 0.15s, transform 0.15s;
}
.log-btn:hover { background: rgba(155,89,182,0.85); transform: scale(1.08); }

.chat-btn {
    position: fixed; bottom: 16px; right: 70px; z-index: 100;
    width: 44px; height: 44px; border-radius: 50%;
    background: rgba(45,27,78,0.92); border: 1px solid rgba(255,255,255,0.2);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.3rem; cursor: pointer;
    box-shadow: 0 2px 10px rgba(0,0,0,0.5);
    transition: background 0.15s, transform 0.15s;
}
.chat-btn:hover { background: rgba(155,89,182,0.85); transform: scale(1.08); }

.chat-badge {
    position: absolute; top: -2px; right: -2px;
    background: var(--karma-red); color: white;
    border-radius: 50%; width: 18px; height: 18px;
    font-size: 0.7rem; font-weight: 900;
    display: flex; align-items: center; justify-content: center;
    border: 2px solid var(--karma-surface);
}

.chat-message-item {
    font-size: 0.85rem; padding: 6px 10px; border-radius: 8px;
    background: rgba(255,255,255,0.04); margin-bottom: 4px;
    display: flex; flex-direction: column; gap: 2px;
}
.chat-msg-header { display: flex; justify-content: space-between; align-items: center; }
.chat-msg-name { font-weight: 700; font-size: 0.75rem; opacity: 0.9; }
.chat-msg-time { font-size: 0.65rem; opacity: 0.4; }
.chat-msg-body { word-break: break-word; color: rgba(255,255,255,0.9); }

.chat-input-area {
    padding: 12px; border-top: 1px solid rgba(255,255,255,0.1);
    display: flex; gap: 8px; background: rgba(0,0,0,0.2);
}
.chat-input {
    flex: 1; padding: 8px 12px; border-radius: 20px;
    background: rgba(255,255,255,0.1); border: 1px solid rgba(255,255,255,0.1);
    color: white; font-family: var(--font-ui); outline: none;
}
.chat-input:focus { border-color: var(--karma-accent); }

.log-overlay {
    position: fixed; inset: 0; z-index: 200;
    background: rgba(0,0,0,0.65);
    display: flex; align-items: flex-end; justify-content: center;
}
.log-panel {
    background: var(--karma-surface); border-top: 1px solid rgba(255,255,255,0.15);
    border-radius: 16px 16px 0 0; width: 100%; max-width: 600px;
    max-height: 70vh; display: flex; flex-direction: column; overflow: hidden;
}
.log-panel-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 14px 16px; border-bottom: 1px solid rgba(255,255,255,0.1);
    font-weight: 700; color: var(--karma-gold); font-size: 1rem;
}
.log-close {
    font-size: 1.3rem; cursor: pointer; line-height: 1; opacity: 0.7;
}
.log-close:hover { opacity: 1; }
.log-panel-body {
    overflow-y: auto; padding: 10px 16px;
    display: flex; flex-direction: column-reverse; gap: 2px;
}
.log-item {
    font-size: 0.78rem; color: rgba(255,255,255,0.7);
    padding: 4px 0; border-bottom: 1px solid rgba(255,255,255,0.05);
    font-family: var(--font-ui);
}
.log-empty { text-align: center; color: rgba(255,255,255,0.3); padding: 24px; }

/* ─── DISCARD PILE OVERLAY ─── */
.discard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
    gap: 12px;
    padding: 16px;
    justify-items: center;
}
@media (max-width: 600px) {
    .discard-grid {
        grid-template-columns: repeat(auto-fill, minmax(52px, 1fr));
        gap: 8px;
        padding: 12px;
    }
}

/* ─── FLIP REVEAL OVERLAY ─── */
.flip-reveal-overlay {
    position: fixed; inset: 0; z-index: 300;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    background: rgba(0,0,0,0.72); pointer-events: none;
    animation: flip-reveal-in 0.2s ease;
}
.flip-reveal-label {
    margin-top: 16px;
    font-family: var(--font-card); font-size: 2rem; color: var(--karma-red);
    text-shadow: 0 2px 12px rgba(0,0,0,0.9);
    animation: flip-label-in 0.3s 0.1s ease both;
}
.flip-reveal-label-large {
    font-size: 4rem; color: white; margin-top: 8px;
}
.flip-reveal-label-highlight {
    color: var(--karma-gold);
}
@keyframes flip-reveal-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}
@keyframes flip-label-in {
    from { transform: scale(0.7); opacity: 0; }
    to   { transform: scale(1);   opacity: 1; }
}

/* ─── SPEED MODE ─── */
.speed-mode-bar {
    position: fixed; top: 12px; left: 50%; transform: translateX(-50%);
    z-index: 150; pointer-events: none;
    display: flex; align-items: center; gap: 6px;
    background: rgba(243,156,18,0.15); border: 1px solid rgba(243,156,18,0.45);
    border-radius: 24px; padding: 5px 16px;
    color: var(--karma-gold); font-weight: 700; font-size: 0.82rem;
    backdrop-filter: blur(4px);
}
.spectate-speed-bar { top: 54px; } /* offset below spectate header */

.speed-flash-overlay {
    position: fixed; inset: 0; z-index: 250; pointer-events: none;
    display: flex; align-items: center; justify-content: center;
    animation: speed-flash-anim 2.5s ease forwards;
}
.speed-flash-content {
    background: rgba(26,10,46,0.92); border: 2px solid var(--karma-gold);
    border-radius: 16px; padding: 20px 36px;
    font-family: var(--font-card); font-size: 1.8rem; color: var(--karma-gold);
    text-align: center; box-shadow: 0 0 40px rgba(243,156,18,0.35);
    max-width: 80vw;
}
@keyframes speed-flash-anim {
    0%   { opacity: 0; }
    12%  { opacity: 1; }
    72%  { opacity: 1; }
    100% { opacity: 0; }
}

.speed-up-row {
    display: flex; justify-content: center; padding: 6px 0;
}

/* ─── BLAZOR ERROR UI (circuit-level) ─── */
#blazor-error-ui {
    display: none; /* shown by Blazor JS on circuit failure */
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 9999;
    background: #7b1a1a; color: white;
    padding: 12px 20px; font-family: var(--font-ui); font-size: 0.9rem;
}
.blazor-error-content {
    display: flex; align-items: center; gap: 12px;
    max-width: 900px; margin: 0 auto;
}
.blazor-error-content code {
    background: rgba(255,255,255,0.15); padding: 2px 6px; border-radius: 4px;
}
#blazor-error-ui .reload {
    color: #ffd; text-decoration: underline; margin-left: 8px;
}
#blazor-error-ui .dismiss {
    margin-left: auto; cursor: pointer; font-size: 1.2rem; opacity: 0.7;
}
#blazor-error-ui .dismiss:hover { opacity: 1; }
