:root{
  --bg:#0e0f12;
  --panel:#151820;
  --muted:#8892a6;
  --text:#e8ecf1;
  --accent:#7aa2ff;
  --accent-2:#55d2a6;
  --danger:#ff6482;
  --yellow:#ffd166;
  --red:#ff5c5c;
  --green:#34d399;
  --black:#111;
  --safe-top:env(safe-area-inset-top, 0px);
  --safe-right:env(safe-area-inset-right, 0px);
  --safe-bottom:env(safe-area-inset-bottom, 0px);
  --safe-left:env(safe-area-inset-left, 0px);
  --card-w:64px;
  --card-ratio:1.42;
  --play-card-w:72px;
}

@media (max-width: 800px){
  :root{
    --card-w:clamp(60px, 18vw, 82px);
    --play-card-w:clamp(54px, calc((100vw - 56px) / 5), 74px);
  }
}

@media (max-width: 520px){
  :root{
    --card-w:clamp(56px, 19vw, 74px);
    --play-card-w:clamp(50px, calc((100vw - 42px) / 5), 68px);
  }
}

@media (max-height: 500px) and (orientation: landscape){
  :root{
    --card-w:clamp(44px, 12vw, 60px);
    --play-card-w:clamp(42px, calc((100vw - 34px) / 6), 56px);
  }
}

*{box-sizing:border-box}
html,body,#app{height:100%;min-height:100%}
body{
  margin:0;
  font-family:Inter,system-ui,Segoe UI,Roboto,Arial,Helvetica,sans-serif;
  color:var(--text);
  background:radial-gradient(1400px 900px at 50% -20%, #10161a 0%, #0b0e10 60%);
  min-height:100dvh;
  -webkit-text-size-adjust:100%;
}
.view{display:none}
.view.active{display:block}

.build-version-inline{
  font-size:11px;
  letter-spacing:.2px;
  color:#b9c4d8;
  background:rgba(9, 12, 18, 0.78);
  border:1px solid rgba(122, 162, 255, 0.35);
}

.app-header,.room-header{
  display:flex;align-items:center;justify-content:space-between;
  padding:calc(16px + var(--safe-top)) calc(20px + var(--safe-right)) 16px calc(20px + var(--safe-left));border-bottom:1px solid #232839;background:#0f1218cc;backdrop-filter:blur(6px);
  position:sticky;top:0;z-index:5
}
.brand,.room-title{display:flex;gap:12px;align-items:center}
.header-left{display:flex;gap:10px;align-items:center;min-width:0}
.logo{font-size:22px}
h1{font-size:20px;margin:0}
.header-right{display:flex;gap:8px;align-items:center;justify-content:flex-end;flex-wrap:wrap}

#resume-live-room{
  box-shadow:0 0 0 1px rgba(255,213,74,.35), 0 0 14px rgba(255,213,74,.16);
}
#resume-live-room.hidden{display:none}

.lobby-grid{
  display:grid;grid-template-columns:repeat(3, minmax(260px, 1fr));
  gap:20px;padding:20px;max-width:1200px;margin:0 auto;
}
.panel{
  background:var(--panel);border:1px solid #232839;border-radius:12px;padding:16px;
  box-shadow:0 10px 30px rgba(0,0,0,.25);
}
.panel h2{margin:6px 0 12px;font-size:16px}

.seat-panel{margin:0 20px 20px;padding:16px;background:rgba(15,18,24,.95);border:1px solid #232839;border-radius:14px;opacity:1;transform:translateY(0);transition:opacity .18s ease, transform .18s ease}
.seat-panel.fading-out{opacity:0;transform:translateY(-6px);pointer-events:none}
.seat-grid{display:grid;grid-template-columns:repeat(4,1fr);gap:12px;margin-top:12px}
.seat-card{background:#0f1218;border:1px solid #232839;border-radius:14px;padding:14px;display:flex;flex-direction:column;gap:10px;align-items:center;justify-content:center;text-align:center}
.seat-card strong{font-size:14px;color:#e8ecf1}
.seat-card .muted{font-size:12px;color:#8892a6}
.seat-card.taken{opacity:.55}
.seat-card button{width:100%}
.hidden{display:none}

label{display:flex;flex-direction:column;gap:6px;font-size:12px;color:var(--muted)}
input,select{background:#0f1218;border:1px solid #232839;color:var(--text);border-radius:10px;padding:10px 12px;font-size:13px}
.grid-2{display:grid;grid-template-columns:repeat(2, 1fr);gap:10px}

button{cursor:pointer;border:1px solid transparent;border-radius:10px;padding:10px 12px;color:var(--text);background:#212838;font-size:13px;transition:all .15s ease}
button:hover{filter:brightness(1.15)}
button:active{transform:scale(.97)}
button.primary{background:linear-gradient(180deg, #6d8cff, #4c6bff);border-color:#405de6}
button.secondary{background:#23293b;border-color:#2e3550}
button.ghost{background:transparent;border-color:#2a2f45}
button.trump{color:#111;font-weight:700;padding:12px 18px;font-size:14px}
button.trump.red{background:var(--red)}
button.trump.green{background:var(--green)}
button.trump.yellow{background:var(--yellow)}
button.trump.black{background:#444;color:#eee}

.list{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;gap:10px}
.list li{display:flex;align-items:center;justify-content:space-between;padding:8px 10px;border:1px solid #232839;border-radius:10px;background:#0f1218}
.list.compact li{padding:6px 8px;font-size:12px}

.table-layout{display:grid;grid-template-columns:280px 1fr;gap:18px;padding:18px}
.score-panel{background:var(--panel);border:1px solid #232839;border-radius:12px;padding:14px;padding-bottom:70px;max-height:calc(100dvh - 110px - var(--safe-top) - var(--safe-bottom));overflow:auto}
.score-panel-mobile-header{display:none}
.score-panel h3{margin:10px 0 8px;font-size:14px;color:var(--accent);border-bottom:1px solid #1e2436;padding-bottom:4px}
.kv{display:flex;justify-content:space-between;gap:12px;padding:4px 0;color:#c8d0df;font-size:13px}
.kv span{color:var(--muted)}

.table{
  position:relative;min-height:70vh;
  background:
    radial-gradient(800px 400px at 30% 20%, rgba(255,255,255,.05), rgba(0,0,0,0) 60%),
    radial-gradient(900px 500px at 70% 80%, rgba(255,255,255,.05), rgba(0,0,0,0) 60%),
    repeating-linear-gradient(45deg, rgba(0,0,0,.06) 0, rgba(0,0,0,.06) 2px, rgba(0,0,0,0) 2px, rgba(0,0,0,0) 8px),
    linear-gradient(180deg,#1e6a3a,#165630);
  border-radius:20px;
  border:10px solid transparent;
  padding:10px;
  box-shadow:
    0 0 0 12px #6a4b2b inset,
    0 0 0 14px #583e23 inset,
    0 18px 40px rgba(0,0,0,.45);
}
.table:after{content:"";position:absolute;inset:0;border-radius:12px;pointer-events:none;opacity:.35;
  background:
    radial-gradient(1px 1px at 10% 15%, rgba(255,255,255,.06), rgba(0,0,0,0) 2px),
    radial-gradient(1px 1px at 20% 55%, rgba(255,255,255,.06), rgba(0,0,0,0) 2px),
    radial-gradient(1px 1px at 35% 30%, rgba(255,255,255,.06), rgba(0,0,0,0) 2px),
    radial-gradient(1px 1px at 60% 70%, rgba(255,255,255,.06), rgba(0,0,0,0) 2px),
    radial-gradient(1px 1px at 80% 40%, rgba(255,255,255,.06), rgba(0,0,0,0) 2px);
  mix-blend-mode: overlay;
}

.seat{position:absolute;display:flex;flex-direction:column;align-items:center;gap:8px}
.seat .seat-name{padding:8px 12px;background:#0f1218;border:1px solid #232839;border-radius:999px;font-size:13px;color:#cbd5e1;min-width:140px;text-align:center;box-shadow:0 0 0 1px rgba(255,255,255,.06)}
.seat .seat-name::after{content:'';display:block;margin-top:4px;width:100%;height:1px;background:rgba(255,255,255,0.06)}
.seat .hand{display:flex;flex-wrap:nowrap;justify-content:center}
.seat .hand .card:not(:first-child){margin-left:-45px}
.pos-top .hand .card:not(:first-child){margin-left:-25px}
.pos-bottom .hand .card:not(:first-child){margin-left:-25px}
.pos-left .hand, .pos-right .hand { flex-direction: column; }
.pos-left .hand .card, .pos-right .hand .card { transform: rotate(90deg); }
.pos-left .hand .card:not(:first-child), .pos-right .hand .card:not(:first-child) { margin-left: 0; margin-top: -75px; }

.pos-top{top:8px;left:50%;transform:translateX(-50%)}
.pos-bottom{bottom:8px;left:50%;transform:translateX(-50%)}
.pos-right{right:8px;top:50%;transform:translateY(-50%); flex-direction: row-reverse;}
.pos-left{left:8px;top:50%;transform:translateY(-50%); flex-direction: row;}

.seat.active-turn .seat-name {
  border-color: #ffd700;
  background: #2a2000;
  color: #fff;
  box-shadow: 0 0 10px rgba(255,215,0,0.5);
}

/* Show a yellow turn ring around the active player's cards when seat labels are hidden. */
.table.hide-seat-overlay .seat.active-turn .hand{
  border:2px solid rgba(255,215,0,.92);
  border-radius:12px;
  padding:6px 8px;
  background:rgba(42,32,0,.22);
  box-shadow:0 0 0 1px rgba(255,215,0,.45), 0 0 16px rgba(255,215,0,.26);
}

.seat .seat-name.seat-name-joinable{
  cursor:pointer;
  border-color:#4f6fc4;
  box-shadow:0 0 0 1px rgba(122,162,255,.28), 0 0 12px rgba(76,107,255,.24);
}

.seat .seat-name.seat-name-joinable:hover{
  background:#172031;
  color:#e8ecf1;
}

.table-seat-overlay{
  position:absolute;
  inset:0;
  pointer-events:none;
  z-index:6;
}

.table.hide-seat-overlay .table-seat-overlay{display:none}

.table-seat-chip{
  position:absolute;
  padding:7px 11px;
  border-radius:999px;
  border:1px solid #2b3348;
  background:rgba(10,14,22,.92);
  color:#d6deed;
  font-size:12px;
  font-weight:700;
  letter-spacing:.2px;
  white-space:nowrap;
  box-shadow:0 2px 10px rgba(0,0,0,.35);
  max-width:220px;
  overflow:hidden;
  text-overflow:ellipsis;
}

.table-seat-chip.active-turn{
  border-color:#ffd700;
  background:#2a2000;
  color:#fff;
  box-shadow:0 0 10px rgba(255,215,0,.5);
}

.table-seat-chip.seat-chip-joinable{
  pointer-events:auto;
  cursor:pointer;
  border-color:#4f6fc4;
  box-shadow:0 2px 12px rgba(58,92,180,.3);
}

.table-seat-chip.seat-chip-joinable:hover{
  background:rgba(20,30,50,.96);
  color:#e8ecf1;
}

.seat-chip-n{top:14px;left:50%;transform:translateX(-50%)}
.seat-chip-s{bottom:14px;left:50%;transform:translateX(-50%)}
.seat-chip-w{left:14px;top:50%;transform:translateY(-50%)}
.seat-chip-e{right:14px;top:50%;transform:translateY(-50%)}

/* ID-based fallback anchors keep chips positioned even if class mapping is disrupted. */
#table-seat-n,#table-seat-s,#table-seat-e,#table-seat-w{position:absolute}
#table-seat-n{top:14px;left:50%;transform:translateX(-50%)}
#table-seat-s{bottom:14px;left:50%;transform:translateX(-50%)}
#table-seat-w{left:14px;top:50%;transform:translateY(-50%)}
#table-seat-e{right:14px;top:50%;transform:translateY(-50%)}

/* Keep all seat chips visible when explicit table seat info mode is enabled. */
.table.show-seat-info .seat{display:flex !important}
.table.show-seat-info .seat .seat-name{display:none !important}
.table.show-seat-info .pos-top{top:36px}

/* Seat label toggle hides both overlay chips and inline seat names. */
.table.hide-seat-overlay .seat .seat-name{display:none !important}

.center{position:absolute;top:34%;left:50%;transform:translate(-50%, -50%);display:flex;flex-direction:column;gap:12px;align-items:center;z-index:10}
.center.center-bidding{top:50%}

.bidding{display:none;flex-direction:column;gap:10px;align-items:center;background:#0f1218ee;border:1px solid #2f3754;border-radius:12px;padding:14px 16px;backdrop-filter:blur(4px);z-index:10}
.bidding-row{display:flex;gap:10px;align-items:center;justify-content:center;flex-wrap:wrap}
.bidding-info{font-size:13px;color:#cbd5e1;text-align:center;max-width:320px}
.pending-bid-display{background:#1a2030;border:1px solid #2e3550;border-radius:8px;padding:6px 14px;color:var(--yellow);font-size:15px;font-weight:700;min-width:80px;text-align:center}

.trump-select{display:none;flex-direction:column;gap:10px;align-items:center;background:#0f1218ee;border:1px solid #2f3754;border-radius:12px;padding:14px 16px;backdrop-filter:blur(4px);z-index:10}
.trump-buttons{display:flex;gap:8px;flex-wrap:wrap;justify-content:center}

.kitty{display:none;flex-direction:column;gap:8px;align-items:stretch;background:#0f1218ee;border:1px solid #2f3754;border-radius:12px;padding:14px 16px;min-width:520px;backdrop-filter:blur(4px);z-index:10}
.kitty-row{display:flex;gap:10px;align-items:center}
.kitty-row span{min-width:100px;color:#cbd5e1;font-size:13px}
.cards{display:flex;gap:8px;flex-wrap:wrap}
.droppable{min-height:84px;border:1px dashed #2e3550;border-radius:8px;padding:8px}
.kitty .card .center-frame{display:flex;align-items:center;justify-content:center}
.kitty .card .face-rank{display:block;width:100%;text-align:center;transform:translateY(-1px)}

.trick{display:none;position:relative;background:rgba(15,18,24,var(--trick-panel-alpha,0.97));border:1px solid #334067;border-radius:12px;padding:12px;min-width:400px;backdrop-filter:blur(4px);z-index:10;opacity:1;transform:translateY(0);max-height:560px;overflow:hidden;transition:opacity .18s ease, transform .18s ease, max-height .22s ease, padding .22s ease, margin .22s ease, border-width .22s ease}
.trick.turn-hidden{opacity:0;transform:translateY(10px);max-height:0;padding-top:0;padding-bottom:0;margin-top:0;margin-bottom:0;border-width:0;pointer-events:none}
.trick.reveal-trick{box-shadow:0 18px 40px rgba(0,0,0,.4), 0 0 0 1px rgba(122,162,255,.14) inset}
.trump-badge{display:none !important;position:absolute;top:8px;left:8px;width:36px;height:36px;border-radius:6px;border:2px solid rgba(255,255,255,0.25);font-size:9px;font-weight:700;text-align:center;line-height:1.1;padding-top:5px;text-transform:uppercase;letter-spacing:0.5px;box-shadow:0 2px 6px rgba(0,0,0,0.4)}
.trump-badge.red{background:var(--red);color:#fff}
.trump-badge.green{background:var(--green);color:#fff}
.trump-badge.yellow{background:var(--yellow);color:#111}
.trump-badge.black{background:#333;color:#eee}
.trick-grid{display:grid;grid-template-areas:". p-top ." "p-left . p-right" ". p-bottom ."; gap:6px; justify-items:center; align-items:center}
.play{width:110px;height:100px;border:1px solid #2e3550;border-radius:10px;background:#0e1a12;display:flex;flex-direction:column;gap:4px;align-items:center;justify-content:center}
.play.current-turn,
.play.active-turn{border-color:#ffd54a; background:#172412; box-shadow:0 0 0 2px rgba(255,213,74,.42), 0 0 18px rgba(255,213,74,.24)}
.play.active-turn .play-label,
.play.current-turn .play-label{color:#ffe28a}
.play-label{font-size:11px;color:#8892a6;font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:90%}
.play-label.empty{opacity:0.5}
.turn-indicator{margin-top:6px;color:#cbd5e1;font-size:13px;text-align:center}
.trick-message{margin-top:4px;color:var(--accent);font-size:13px;font-weight:600;text-align:center;min-height:16px}
.trick-peek-hint{margin-top:8px;color:#6b7280;font-size:11px;text-align:center;font-style:italic;opacity:0;pointer-events:none;transition:opacity .2s ease}
.trick.reveal-mobile-large .trick-peek-hint[data-peek="true"]{opacity:1}

.card{
  --c:#111;
  width:64px;height:92px;border-radius:8px;border:1px solid #d8d2c4;
  background:
    radial-gradient(120px 90px at 20% 10%, #fffdf7 0%, #f6f1e6 65%, #ece4d3 100%),
    linear-gradient(160deg, #f8f3e9 0%, #f0e8d8 100%);
  display:flex;align-items:center;justify-content:center;position:relative;
  box-shadow:0 2px 8px rgba(0,0,0,.35);
  user-select:none;color:#111;cursor:pointer;transition:transform .12s ease, box-shadow .12s ease;
  overflow:hidden;
}
.card:hover:not(.back):not(.disabled){transform:translateY(-4px);box-shadow:0 6px 16px rgba(0,0,0,.45)}
.card.back{background:repeating-linear-gradient(135deg,#efe9db 0,#efe9db 6px,#e4dcc9 6px,#e4dcc9 12px);border-color:#cfc4ae;cursor:default}
.card[data-color="Red"]{--c:#cc3c3c}
.card[data-color="Green"]{--c:#6f8f2b}
.card[data-color="Yellow"]{--c:#e18f2f}
.card[data-color="Black"]{--c:#111}
.card[data-color="Rook"]{--c:#8b5e3c;background:#f7f0df;border-color:#d8c8a8}
.card .corner{position:absolute;display:flex;flex-direction:column;align-items:center;gap:1px;color:var(--c)}
.card .corner .r{font-weight:700;font-size:13px;line-height:1;letter-spacing:.2px;font-family:Georgia, "Times New Roman", serif}
.card .corner.tl{top:5px;left:5px}
.card .corner.br{bottom:5px;right:5px;transform:rotate(180deg)}
.card .center-mark{color:var(--c);font-weight:800;font-size:22px;opacity:.9}
.card.rook{background:#fff8ec;border-color:#e8d6b7}
.card .card-color-word{position:absolute;font-size:8px;font-weight:700;letter-spacing:.6px;color:var(--c);font-family:Georgia, "Times New Roman", serif;opacity:.95}
.card .card-color-word.top{top:5px;right:8px}
.card .card-color-word.bottom{bottom:5px;left:8px;transform:rotate(180deg)}
.card .center-frame{width:34px;height:48px;border:2px solid #bf7373;display:flex;align-items:center;justify-content:center;background:rgba(255,255,255,.15)}
.card .face-rank{font-size:40px;line-height:1;color:var(--c);font-family:Georgia, "Times New Roman", serif;font-weight:700;transform:translateY(-1px)}
.card .rook-center{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:2px}
.card .rook-title{font-size:7px;letter-spacing:1.2px;color:#7f2e2e;font-family:Georgia, "Times New Roman", serif;font-weight:700}
.card.rook .rook-icon{width:28px;height:28px;color:var(--c)}
.card.selected{outline:3px solid var(--accent);outline-offset:1px}
.card.playable{box-shadow:0 0 0 2px #4c6bff88,0 0 12px 2px rgba(76,107,255,.25)}
.card.disabled{opacity:.45;filter:grayscale(.2);cursor:default;pointer-events:none}

.tag{padding:2px 6px;border-radius:999px;border:1px solid #2e3550;background:#0f1218;color:#cbd5e1;font-size:11px}

.modal{position:fixed;inset:0;background:#00000080;backdrop-filter:blur(3px);display:none;align-items:center;justify-content:center;z-index:20;padding:20px calc(16px + var(--safe-right)) calc(20px + var(--safe-bottom)) calc(16px + var(--safe-left))}
.modal.show{display:flex}
.modal-card{width:min(720px, 92vw);max-height:90vh;overflow-y:auto;background:#141822;border:1px solid #2a2f45;border-radius:12px;box-shadow:0 20px 60px rgba(0,0,0,.5);display:flex;flex-direction:column}
.confirm-modal-card{width:min(520px, 92vw)}
.modal-head{display:flex;align-items:center;gap:12px;padding:12px 14px;border-bottom:1px solid #232839}
.modal-head h3{margin:0;font-size:16px}
.modal-body{padding:14px;gap:10px}
.modal-foot{display:flex;align-items:center;gap:10px;padding:12px 14px;border-top:1px solid #232839}
.muted{color:var(--muted)}
.spacer{flex:1}
.rules-details{margin:10px 0}
.rules-details summary{cursor:pointer;color:var(--accent);font-weight:600;font-size:13px;padding:6px 0}

.mobile-turn-tracker{
  display:none;
  position:fixed;
  top:auto;
  bottom:0;
  left:0;
  right:0;
  background:linear-gradient(180deg, rgba(21,24,32,.95), rgba(15,18,24,.98));
  border-top:2px solid #2a3550;
  backdrop-filter:blur(8px);
  z-index:46;
  padding:8px calc(12px + var(--safe-right)) calc(8px + var(--safe-bottom)) calc(12px + var(--safe-left));
  box-shadow:0 -8px 24px rgba(0,0,0,.4);
}

.mobile-turn-tracker.show{display:flex}
.mobile-turn-tracker.hidden{display:none}
.mobile-turn-tracker.overlay-active{display:flex}


.desktop-turn-tracker{
  display:flex;
  align-items:center;
  justify-content:space-around;
  gap:14px;
  flex-wrap:wrap;
  margin:0 18px 18px;
  padding:10px 14px;
  border:1px solid #253049;
  border-radius:12px;
  background:linear-gradient(180deg, rgba(28,32,42,.96), rgba(19,23,31,.98));
  box-shadow:0 10px 24px rgba(0,0,0,.28), inset 0 1px 0 rgba(255,255,255,.03);
}

.desktop-turn-tracker .tracker-item{
  min-width:0;
}

.desktop-turn-tracker .tracker-value{
  min-width:92px;
}

/* Trick peek scrim — sits in root stacking context (body child), blocks hand
   interaction when user peeks at the overlay during their turn */
.trick-peek-scrim{
  display:none;
  position:fixed;
  inset:0;
  z-index:43;
  background:rgba(5,10,20,.62);
  backdrop-filter:blur(1px);
  pointer-events:all;
  cursor:pointer;
}

/* Trick overlay toggle button — fixed top-right during play phase on mobile */
.trick-overlay-toggle{
  display:none; /* shown via JS only on mobile during play */
  position:fixed;
  top:calc(12px + var(--safe-top, 0px));
  right:calc(12px + var(--safe-right, 0px));
  z-index:50;
  width:40px;
  height:40px;
  border-radius:50%;
  border:2px solid #3a4a75;
  background:rgba(15,18,30,.82);
  backdrop-filter:blur(8px);
  color:#8892a6;
  align-items:center;
  justify-content:center;
  padding:0;
  cursor:pointer;
  box-shadow:0 4px 16px rgba(0,0,0,.45);
  transition:background 0.15s, color 0.15s, border-color 0.15s;
  -webkit-tap-highlight-color:transparent;
}
.trick-overlay-toggle:active{
  background:rgba(40,56,100,.9);
}
.trick-overlay-toggle.active{
  background:rgba(35,55,120,.92);
  border-color:#6b82c8;
  color:#c8d4ff;
  box-shadow:0 4px 18px rgba(50,80,200,.35);
}

.seat-overlay-toggle{
  position:absolute;
  bottom:calc(12px + var(--safe-bottom, 0px));
  right:calc(12px + var(--safe-right, 0px));
  top:auto;
  left:auto;
  /* The .table section is position:relative so this anchors to its corner */
}

body.show-seat-overlay-toggle #seat-overlay-toggle{display:flex !important}

@media (min-width: 801px){
  #view-room .table-layout{
    align-items:start;
    padding-top:8px;
  }
  #view-room .table-layout > .table{
    align-self:start;
  }
  /* Desktop play uses an internal 3x3 grid so seat areas and the trick panel
     respond to viewport height without relying on fixed absolute offsets. */
  .table.phase-play{
    min-height:max(70vh, 640px);
    display:grid;
    grid-template-columns:minmax(120px, 18%) minmax(320px, 1fr) minmax(120px, 18%);
    grid-template-rows:auto minmax(0, 1fr) auto;
    gap:18px 14px;
    align-items:center;
    justify-items:center;
    padding:22px 18px 18px;
  }
  .table.phase-play .seat,
  .table.phase-play .center{
    position:relative;
    top:auto;
    right:auto;
    bottom:auto;
    left:auto;
    transform:none;
    z-index:10;
  }
  .table.phase-play .seat.pos-top{
    grid-column:2;
    grid-row:1;
    align-self:start;
  }
  .table.phase-play .seat.pos-bottom{
    grid-column:2;
    grid-row:3;
    align-self:end;
    width:min(100%, 760px);
    max-width:100%;
  }
  .table.phase-play .seat.pos-left{
    grid-column:1;
    grid-row:2;
    justify-self:start;
    align-self:center;
  }
  .table.phase-play .seat.pos-right{
    grid-column:3;
    grid-row:2;
    justify-self:end;
    align-self:center;
  }
  .table.phase-play .center.center-play,
  .table.phase-play .center.center-reveal{
    grid-column:2;
    grid-row:2;
    width:min(100%, 440px);
    align-self:center;
    justify-self:center;
    pointer-events:none;
  }
  .table.phase-play .center.center-play > .trick,
  .table.phase-play .center.center-reveal > .trick{
    width:min(100%, 440px);
    min-width:0;
    pointer-events:auto;
  }
  .table.phase-play .seat.pos-top .hand{
    max-width:min(100%, 560px);
  }
  .table.phase-play .seat.pos-bottom .hand{
    max-width:min(100%, 760px);
  }
}

.mobile-turn-tracker{
  flex-direction:row;
  justify-content:space-around;
  align-items:center;
  gap:12px;
  flex-wrap:wrap;
}

.tracker-item{
  display:flex;
  align-items:center;
  gap:6px;
  font-size:13px;
}

.tracker-item.wide{
  flex-basis:100%;
  align-items:flex-start;
}

.tracker-item.wide .tracker-value{
  min-width:0;
  flex:1;
  text-align:left;
  white-space:normal;
  line-height:1.15;
}

.tracker-label{
  color:var(--muted);
  font-weight:600;
}

.tracker-value{
  color:var(--accent);
  font-weight:700;
  font-size:14px;
  padding:4px 8px;
  background:rgba(122,162,255,.1);
  border-radius:6px;
  border:1px solid rgba(122,162,255,.2);
  min-width:60px;
  text-align:center;
}

.tracker-value.current-turn{
  color:#ffd54a;
  background:rgba(255,213,74,.15);
  border-color:rgba(255,213,74,.3);
  box-shadow:0 0 8px rgba(255,213,74,.2);
}

.tracker-value.trump-red{
  color:#ffd9d9;
  background:rgba(255,92,92,.2);
  border-color:rgba(255,92,92,.45);
}

.tracker-value.trump-green{
  color:#d9ffec;
  background:rgba(52,211,153,.2);
  border-color:rgba(52,211,153,.45);
}

.tracker-value.trump-yellow{
  color:#2d2300;
  background:rgba(255,209,102,.78);
  border-color:rgba(255,209,102,.95);
}

.tracker-value.trump-black{
  color:#f2f5fb;
  background:rgba(17,17,17,.75);
  border-color:rgba(200,210,230,.38);
}

.tracker-value.lead-red{border-color:rgba(255,92,92,.55);box-shadow:0 0 0 1px rgba(255,92,92,.2) inset}
.tracker-value.lead-green{border-color:rgba(52,211,153,.55);box-shadow:0 0 0 1px rgba(52,211,153,.2) inset}
.tracker-value.lead-yellow{border-color:rgba(255,209,102,.9);box-shadow:0 0 0 1px rgba(255,209,102,.3) inset}
.tracker-value.lead-black{border-color:rgba(200,210,230,.45);box-shadow:0 0 0 1px rgba(200,210,230,.2) inset}

.app-toast{
  position:fixed;
  left:50%;
  bottom:calc(18px + var(--safe-bottom));
  transform:translate(-50%, 12px);
  opacity:0;
  pointer-events:none;
  z-index:40;
  background:rgba(15,18,24,.96);
  border:1px solid #2a3350;
  color:#e8ecf1;
  border-radius:12px;
  padding:10px 14px;
  font-size:13px;
  font-weight:600;
  box-shadow:0 12px 28px rgba(0,0,0,.35);
  transition:opacity .16s ease, transform .16s ease;
  max-width:min(90vw, 460px);
  text-align:center;
}
.app-toast.show{opacity:1;transform:translate(-50%, 0)}
.app-toast.seat{border-color:#365a9a;color:#dce6ff}
.app-toast.warn{border-color:#a07c20;background:rgba(40,30,8,.97);color:#ffd166}

.hand-result{margin:8px 0 10px;padding:8px 10px;border-radius:8px;border:1px solid #2e3550;background:#161d2c;color:#d9e3f6;font-size:12px;font-weight:700;text-align:center}
.hand-result.made{border-color:#2f7d53;background:#0f2a1d;color:#8ef3bf}
.hand-result.set{border-color:#8a2e45;background:#2a0f18;color:#ff9db5}
.room-header .hand-result{margin:0;white-space:nowrap;padding:7px 10px;line-height:1.2}

h4{color:#cbd5e1;font-size:13px;margin:12px 0 6px}

@media (max-width: 1100px){
  .lobby-grid{grid-template-columns:1fr}
  .table-layout{grid-template-columns:1fr}
  .score-panel{max-height:none}
  .seat .hand{max-width:90vw}
  .kitty{min-width:unset}
}

@media (max-width: 800px) {
  @keyframes yourTurnPulse {
    0% { box-shadow: 0 0 0 0 rgba(255,213,74,0.0), 0 0 0 0 rgba(255,213,74,0.0); }
    40% { box-shadow: 0 0 0 2px rgba(255,213,74,0.34), 0 0 20px 2px rgba(255,213,74,0.22); }
    100% { box-shadow: 0 0 0 0 rgba(255,213,74,0.0), 0 0 0 0 rgba(255,213,74,0.0); }
  }

  body{min-height:100svh}
  input,select,button{font-size:16px}
  .app-header,.room-header{
    align-items:flex-start;
    flex-wrap:wrap;
    gap:10px;
    padding:calc(12px + var(--safe-top)) calc(12px + var(--safe-right)) 12px calc(12px + var(--safe-left));
  }
  .build-version-inline{display:none}
  .header-left,.header-right,.room-title{
    width:100%;
  }
  .header-left,.room-title{justify-content:flex-start}
  .header-right{justify-content:stretch}
  .header-right button{flex:1 1 140px}
  .room-header .hand-result{white-space:normal;max-width:none}
  body.hide-mobile-room-header #view-room .room-header{display:none}
  body.hide-mobile-room-header #view-room .table-layout{padding-top:8px}
  .trump-badge{display:none !important}
  .mobile-turn-tracker.show{
    display:flex;
    bottom:calc(20px + var(--safe-bottom));
  }
  .seat-panel{margin:12px;padding:14px}
  .seat-grid{grid-template-columns:repeat(2,minmax(0,1fr))}
  .grid-2{grid-template-columns:1fr}
  .list li{align-items:flex-start;gap:8px;flex-wrap:wrap}
  .table-layout{display:flex;flex-direction:column;gap:14px;padding:12px}
  .table-layout > .center{
    order:1;
    position:relative;
    top:auto;
    left:auto;
    transform:none;
    width:100%;
    padding:0;
    gap:8px;
    align-items:stretch;
  }
  .table > .center.center-play,
  .table > .center.center-reveal{
    position:absolute;
    left:50%;
    padding:0;
    gap:0;
    z-index:12;
    align-items:center;
  }
  .table > .center.center-play{
    top:clamp(28px, 6vh, 44px);
    bottom:clamp(104px, 18vh, 136px);
    transform:translateX(-50%);
    width:min(calc(100% - 20px), 340px);
    max-height:calc(100% - clamp(132px, 24vh, 180px));
  }
  .table > .center.center-reveal{
    top:50%;
    left:50%;
    transform:translate(-50%, -50%);
    width:min(calc(100% - 20px), 340px);
  }
  .score-panel{order:3;padding:12px;border-radius:14px;display:flex;flex-direction:column}
  .score-panel.mobile-score-panel{padding-bottom:12px}
  .score-panel-mobile-header{display:flex;align-items:center;justify-content:space-between;gap:8px;margin-bottom:8px}
  .score-panel-mobile-header #history-heading{margin:0;border-bottom:none;padding-bottom:0}
  .score-panel-mobile-toggle{padding:7px 10px;font-size:12px;border-radius:999px;flex:0 0 auto;white-space:nowrap}
  .score-panel.mobile-score-collapsed > :not(#score-panel-mobile-header):not(#mobile-stats-scroll){display:none !important}
  .score-panel > *{order:5}
  #score-panel-mobile-header{order:0}
  #mobile-stats-scroll{order:1}
  .score-panel > #history-heading{order:2;margin-top:0}
  #hand-history{order:3}
  .score-panel > hr{order:6}
  #end-hand{order:7}
  .table{
    order:2;
    min-height:clamp(420px, 56dvh, 600px);
    padding:8px;
    overflow:hidden;
    margin-bottom:0;
    border-radius:18px;
    box-shadow:0 0 0 10px #6a4b2b inset, 0 0 0 12px #583e23 inset, 0 12px 28px rgba(0,0,0,.42);
  }
  .table.hide-seat-overlay .table-seat-overlay{display:none}
  .table.phase-play{min-height:clamp(500px, 67dvh, 700px)}
  .seat{gap:6px}
  .seat .seat-name{
    min-width:112px;
    max-width:140px;
    padding:6px 10px;
    font-size:11px;
  }
  .pos-top .seat-name,
  .pos-left .seat-name,
  .pos-right .seat-name{display:none}
  .pos-top .hand,
  .pos-left .hand,
  .pos-right .hand{display:none}
  .seat .hand .card:not(:first-child){margin-left:-42px}
  .pos-bottom .hand{flex-wrap:wrap;gap:0 6px;row-gap:8px;justify-content:center}
  .pos-bottom .hand.your-turn-pulse{
    border-radius:12px;
    padding:4px 8px;
    animation:yourTurnPulse 1.15s ease-in-out infinite;
  }
  .pos-bottom .hand .card:not(:first-child){margin-left:-28px}
  .pos-left .hand .card:not(:first-child), .pos-right .hand .card:not(:first-child){margin-top:-68px}
  .card{width:var(--card-w);height:calc(var(--card-w) * var(--card-ratio))}
  .card .corner .r{font-size:13px}
  .card .center-frame{width:33px;height:47px}
  .card .face-rank{font-size:37px}
  .card .card-color-word{font-size:8px}
  .card.rook .rook-icon{width:24px;height:24px}
  .pos-bottom .hand .card{width:var(--card-w);height:calc(var(--card-w) * var(--card-ratio))}
  .pos-bottom .hand .card .corner .r{font-size:13px}
  .pos-bottom .hand .card .center-frame{width:34px;height:48px}
  .pos-bottom .hand .card .face-rank{font-size:38px}
  .pos-bottom .hand .card.rook .rook-icon{width:24px;height:24px}
  .pos-top{top:8px;left:50%;transform:translateX(-50%)}
  .pos-bottom{bottom:8px;left:50%;transform:translateX(-50%);max-width:calc(100% - 16px)}
  .pos-left{left:2px;top:50%;transform:translateY(-50%)}
  .pos-right{right:2px;top:50%;transform:translateY(-50%)}
  .table-seat-chip{
    max-width:min(46vw, 210px);
    font-size:11px;
    padding:6px 9px;
  }
  #table-seat-n{top:10px;left:50%;transform:translateX(-50%)}
  #table-seat-s{bottom:10px;left:50%;transform:translateX(-50%)}
  #table-seat-w{left:10px;top:50%;transform:translateY(-50%)}
  #table-seat-e{right:10px;top:50%;transform:translateY(-50%)}
  .center{
    position:relative;
    top:auto;
    left:auto;
    transform:none;
    width:100%;
    padding:0;
    gap:10px;
  }
  .table > .center.center-play,
  .table > .center.center-reveal{width:min(calc(100% - 18px), 320px)}
  .table > .center.center-play{
    top:24px;
    bottom:clamp(100px, 17vh, 128px);
    max-height:calc(100% - 148px);
  }
  .phase-kitty,.phase-bidding,.phase-trump{display:flex;flex-direction:column;justify-content:flex-start;align-items:center;padding:8px !important;overflow-y:auto;--phase-stack-margin:8px}
  .phase-reveal{overflow:visible}
  .phase-play .pos-bottom{
    top:6px;bottom:6px;left:8px;right:8px;
    z-index:11;transform:none;width:auto;max-width:none;
    display:flex;flex-direction:column;align-items:stretch;
  }
  .phase-play .pos-bottom .seat-name{display:none}
  .phase-play .pos-bottom .hand{
    flex:1;
    min-height:0;
    display:grid;
    grid-template-columns:repeat(5,minmax(0,1fr));
    gap:6px;
    justify-items:center;
    align-items:start;
    align-content:start;
    width:100%;
    overflow-y:auto;
    overflow-x:hidden;
    padding:4px;
    margin:0;
  }
  .phase-play .pos-bottom .hand .card{width:var(--play-card-w);height:calc(var(--play-card-w) * 1.40)}
  .phase-play .pos-bottom .hand .card .center-frame{width:40px;height:56px}
  .phase-play .pos-bottom .hand .card .face-rank{font-size:46px}
  .phase-play .pos-bottom .hand .card .corner .r{font-size:15px}
  .phase-play .pos-bottom .hand .card.rook .rook-icon{width:28px;height:28px}
  .phase-play .pos-bottom .hand .card:not(:first-child){margin-left:0}
  .phase-kitty .seat-n,.phase-kitty .seat-e,.phase-kitty .seat-w,
  .phase-bidding .seat-n,.phase-bidding .seat-e,.phase-bidding .seat-w,
  .phase-trump .seat-n,.phase-trump .seat-e,.phase-trump .seat-w{display:none}
  .phase-kitty .pos-bottom,.phase-bidding .pos-bottom,.phase-trump .pos-bottom{position:relative;bottom:auto;left:auto;top:auto;transform:none;max-width:100%;width:100%;margin-top:var(--phase-stack-margin)}
  .phase-kitty .pos-bottom .hand,.phase-bidding .pos-bottom .hand,.phase-trump .pos-bottom .hand{justify-content:center}
  .kitty-row:first-child{display:none}
  .bidding,.trump-select,.kitty,.trick{
    width:100%;
    min-width:0;
    max-width:100%;
    padding:12px;
  }
  .center.center-play .trick{
    max-height:100%;
    overflow-y:auto;
    overscroll-behavior:contain;
  }
  .bidding-row{gap:8px}
  .bidding-row button{flex:1 1 110px}
  .pending-bid-display{min-width:74px;font-size:14px;padding:6px 10px}
  .trump-buttons{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));width:100%}
  .trump-buttons .trump{width:100%}
  .kitty-row{flex-direction:column;align-items:stretch;gap:4px}
  .kitty-row span{min-width:0;font-size:11px}
  .kitty{padding:6px 8px;gap:4px}
  .cards{gap:3px}
  .droppable{min-height:40px;padding:4px}
  .kitty .confirm-btn,.kitty button#confirm-discard{padding:8px 12px;font-size:13px}
  .trick-grid{display:flex;flex-wrap:nowrap;gap:6px;align-items:stretch;justify-content:space-between;overflow-x:auto}
  .play{flex:0 0 calc((100% - 18px)/4);width:auto;min-width:90px;height:clamp(88px, 19vw, 112px);min-height:88px;border-radius:10px}
  .play .card{width:56px;height:80px}
  .play-label{font-size:12px;font-weight:700}
  .turn-indicator,.trick-message{font-size:15px;line-height:1.3}
  .center.center-play .trick .play-label,
  .center.center-play .trick .turn-indicator,
  .center.center-play .trick .trick-message,
  .center.center-reveal .trick .play-label,
  .center.center-reveal .trick .turn-indicator,
  .center.center-reveal .trick .trick-message{display:none}
  .trick.reveal-trick{
    position:relative;
    left:auto;
    top:auto;
    transform:none;
    width:100%;
    min-width:0;
    padding:12px 10px;
    z-index:35;
    background:rgba(15,18,24,.98);
    border-color:#3a4a75;
    box-shadow:0 18px 46px rgba(0,0,0,.55);
  }
  .trick.reveal-trick .trick-grid{gap:6px}
  .trick.reveal-trick .play{height:auto;min-height:64px;aspect-ratio:2.8/1;background:#102017}
  .trick.reveal-trick .play .card{width:40px;height:58px}
  .trick.reveal-trick .play-label{font-size:12px}
  .trick.reveal-trick .turn-indicator{display:none}
  .trick.reveal-trick .trick-message{margin-top:8px;font-size:13px}
  .trick.reveal-mobile-large{
    position:fixed;
    left:50%;
    top:50%;
    transform:translate(-50%, -50%);
    width:min(94vw, 620px);
    height:min(72vh, 700px);
    min-height:420px;
    padding:16px 14px;
    z-index:45;
    border-color:#4964a3;
    box-shadow:0 0 0 999px rgba(5,10,20,.42), 0 24px 56px rgba(0,0,0,.58);
  }
  .trick.reveal-mobile-large .trick-grid{
    display:grid;
    grid-template-areas:
      ". p-top ."
      "p-left . p-right"
      ". p-bottom .";
    grid-template-columns:minmax(0,1fr) minmax(112px, 1.4fr) minmax(0,1fr);
    grid-template-rows:minmax(104px, 1fr) minmax(112px, 1.1fr) minmax(104px, 1fr);
    gap:12px;
    width:100%;
    height:calc(100% - 46px);
    overflow:visible;
    justify-items:center;
    align-items:center;
  }
  .trick.reveal-mobile-large .play{
    width:min(36vw, 180px);
    min-width:118px;
    height:auto;
    min-height:138px;
    aspect-ratio:0.74;
    border-radius:12px;
    background:#11241a;
    padding:8px 6px;
    justify-content:center;
    gap:0;
  }
  .trick.reveal-mobile-large .play .card{width:min(22vw, 108px);height:auto;aspect-ratio:0.70}
  .trick.reveal-mobile-large .play-label{display:block;font-size:13px;line-height:1.3;text-align:center;max-width:100%;color:#c8d0df;font-weight:700;margin-top:4px}
  .trick.reveal-mobile-large .play-label.empty{opacity:0.45;font-weight:500}
  .trick.reveal-mobile-large .trick-message{font-size:16px;font-weight:700;text-align:center}
  .trick.reveal-mobile-large .turn-indicator{display:none}
  .kitty .card{width:34px;height:48px}
  .kitty .card .center-frame{width:18px;height:26px}
  .kitty .card .face-rank{font-size:22px}
  .kitty .card .corner .r{font-size:8px}
  .kitty .card .card-color-word{font-size:5px}
  .kitty .card.rook .rook-icon{width:14px;height:14px}
  .modal{padding:12px calc(10px + var(--safe-right)) calc(12px + var(--safe-bottom)) calc(10px + var(--safe-left))}
  .modal-card{
    width:100%;
    max-width:none;
    max-height:calc(100dvh - 24px - var(--safe-top) - var(--safe-bottom));
    border-radius:16px;
  }
  .modal-head,.modal-foot{padding:12px}
  .modal-body{padding:12px}
}

@media (max-width: 520px) {
  .lobby-grid{padding:12px}
  .panel{padding:14px}
  .seat-grid{grid-template-columns:1fr}
  .app-header,.room-header{gap:8px;padding:calc(10px + var(--safe-top)) calc(10px + var(--safe-right)) 10px calc(10px + var(--safe-left))}
  .brand,.room-title{gap:8px}
  .logo{font-size:18px}
  h1{font-size:17px;line-height:1.1}
  .header-right{gap:6px}
  .header-right button{flex:1 1 120px;padding:8px 10px}
  .table-layout > .center{gap:6px}
  .mobile-turn-tracker.show{
    display:flex;
    padding:5px calc(8px + var(--safe-right)) calc(5px + var(--safe-bottom)) calc(8px + var(--safe-left));
    gap:8px;
  }
  .tracker-item{
    font-size:12px;
  }
  .tracker-value{
    font-size:12px;
    padding:3px 6px;
    min-width:50px;
  }
  .table{min-height:clamp(380px, 52dvh, 520px)}
  .table.phase-play{min-height:clamp(460px, 62dvh, 640px)}
  .table.hide-seat-overlay .table-seat-overlay{display:none}
  .seat .seat-name{min-width:96px;max-width:116px;font-size:10px;padding:5px 8px}
  .table-seat-chip{
    max-width:min(44vw, 180px);
    font-size:10px;
    padding:5px 8px;
  }
  #table-seat-n{top:8px;left:50%;transform:translateX(-50%)}
  #table-seat-s{bottom:8px;left:50%;transform:translateX(-50%)}
  #table-seat-w{left:8px;top:50%;transform:translateY(-50%)}
  #table-seat-e{right:8px;top:50%;transform:translateY(-50%)}
  .card{width:var(--card-w);height:calc(var(--card-w) * var(--card-ratio))}
  .card .center-frame{width:28px;height:39px}
  .card .face-rank{font-size:31px}
  .seat .hand .card:not(:first-child){margin-left:-32px}
  .pos-bottom .hand{flex-wrap:wrap;gap:0 5px;row-gap:6px;justify-content:center}
  .pos-bottom .hand .card{width:var(--card-w);height:calc(var(--card-w) * var(--card-ratio))}
  .pos-bottom .hand .card .center-frame{width:31px;height:43px}
  .pos-bottom .hand .card .face-rank{font-size:35px}
  .pos-bottom .hand .card .corner .r{font-size:12px}
  .pos-bottom .hand .card:not(:first-child){margin-left:-20px}
  .pos-left .hand .card:not(:first-child), .pos-right .hand .card:not(:first-child){margin-top:-56px}
  .table > .center.center-play,
  .table > .center.center-reveal{width:min(calc(100% - 14px), 300px)}
  .table > .center.center-play{
    top:20px;
    bottom:clamp(94px, 16vh, 118px);
    max-height:calc(100% - 136px);
  }
  .trick-grid{display:flex;flex-wrap:nowrap;gap:5px;align-items:stretch;justify-content:space-between;overflow-x:auto}
  .play{flex:0 0 calc((100% - 15px)/4);width:auto;min-width:82px;height:clamp(82px, 20vw, 96px);min-height:82px}
  .play .card{width:50px;height:72px}
  .play-label{font-size:11px;font-weight:700}
  .phase-kitty,.phase-bidding,.phase-trump{--phase-stack-margin:6px}
  .phase-reveal{overflow:visible}
  .phase-play .pos-bottom{
    top:5px;bottom:5px;left:6px;right:6px;
    z-index:11;transform:none;width:auto;max-width:none;
    display:flex;flex-direction:column;align-items:stretch;
  }
  .phase-play .pos-bottom .seat-name{display:none}
  .phase-play .pos-bottom .hand{
    flex:1;
    min-height:0;
    display:grid;
    grid-template-columns:repeat(5,minmax(0,1fr));
    gap:5px;
    justify-items:center;
    align-items:start;
    align-content:start;
    width:100%;
    overflow-y:auto;
    overflow-x:hidden;
    padding:3px 4px;
    margin:0;
  }
  .phase-play .pos-bottom .hand .card{width:var(--play-card-w);height:calc(var(--play-card-w) * 1.40)}
  .phase-play .pos-bottom .hand .card .center-frame{width:37px;height:52px}
  .phase-play .pos-bottom .hand .card .face-rank{font-size:42px}
  .phase-play .pos-bottom .hand .card .corner .r{font-size:14px}
  .phase-play .pos-bottom .hand .card.rook .rook-icon{width:26px;height:26px}
  .phase-play .pos-bottom .hand .card:not(:first-child){margin-left:0}
  .kitty{padding:5px 6px;gap:3px}
  .kitty-row{gap:3px}
  .cards{gap:2px}
  .droppable{min-height:36px;padding:3px}
  .kitty .card{width:30px;height:43px}
  .kitty .card .center-frame{width:16px;height:24px}
  .kitty .card .face-rank{font-size:19px}
  .kitty .card .corner .r{font-size:7px}
  .kitty .card .card-color-word{font-size:4px}
  .kitty .card.rook .rook-icon{width:12px;height:12px}
  .trick.reveal-trick{
    width:100%;
    padding:10px 8px;
  }
  .trick.reveal-trick .play{min-height:66px;aspect-ratio:3/1}
  .trick.reveal-trick .play .card{width:40px;height:58px}
  .trick.reveal-mobile-large{
    width:min(96vw, 500px);
    height:min(74vh, 620px);
    min-height:400px;
    padding:14px 10px;
  }
  .trick.reveal-mobile-large .trick-grid{
    grid-template-columns:minmax(0,1fr) minmax(102px, 1.3fr) minmax(0,1fr);
    grid-template-rows:minmax(94px, 1fr) minmax(104px, 1.1fr) minmax(94px, 1fr);
    gap:10px;
  }
  .trick.reveal-mobile-large .play{
    width:min(38vw, 152px);
    min-width:104px;
    min-height:120px;
    gap:6px;
  }
  .trick.reveal-mobile-large .play .card{width:min(24vw, 90px)}
  .trick.reveal-mobile-large .play-label{display:block;font-size:12px;color:#c8d0df;font-weight:700;margin-top:3px}
  .trick.reveal-mobile-large .trick-message{font-size:15px}
}

@media (max-height: 500px) and (orientation: landscape) {
  body{min-height:100svh}
  .app-header,.room-header{
    gap:8px;
    padding:calc(8px + var(--safe-top)) calc(10px + var(--safe-right)) 8px calc(10px + var(--safe-left));
  }
  .mobile-turn-tracker.show{
    display:flex;
    padding:6px calc(10px + var(--safe-right)) calc(6px + var(--safe-bottom)) calc(10px + var(--safe-left));
    border-top:1px solid #2a3550;
  }
  .logo{font-size:18px}
  h1{font-size:16px}
  .header-right button,.header-left button{padding:8px 10px;font-size:13px}
  .table-layout{
    display:flex;
    flex-direction:column;
    gap:10px;
    padding:10px;
  }
  .table-layout > .center{order:1;position:relative;top:auto;left:auto;transform:none;width:100%;padding:0;gap:6px;align-items:stretch}
  .table{order:2}
  .score-panel{order:3}
  .score-panel{
    max-height:none;
    padding:10px;
    display:flex;
    flex-direction:column;
  }
  .score-panel.mobile-score-panel{padding-bottom:10px}
  .score-panel > *{order:5}
  #score-panel-mobile-header{order:0}
  #mobile-stats-scroll{order:1}
  .score-panel > #history-heading{order:2;margin-top:0}
  #hand-history{order:3}
  .score-panel > hr{order:6}
  #end-hand{order:7}
  .score-panel h3{margin:8px 0 6px}
  .kv{font-size:12px;padding:3px 0}
  .table{
    min-height:calc(100svh - 84px - var(--safe-top) - var(--safe-bottom));
    border-radius:16px;
    box-shadow:0 0 0 8px #6a4b2b inset, 0 0 0 10px #583e23 inset, 0 10px 24px rgba(0,0,0,.38);
  }
  .seat .seat-name{
    min-width:90px;
    max-width:120px;
    padding:4px 7px;
    font-size:10px;
  }
  .card{width:var(--card-w);height:calc(var(--card-w) * var(--card-ratio))}
  .card .center-frame{width:27px;height:38px}
  .card .face-rank{font-size:30px}
  .card .card-color-word{font-size:6px}
  .card .corner .r{font-size:10px}
  .card.rook .rook-icon{width:18px;height:18px}
  .seat .hand .card:not(:first-child){margin-left:-26px}
  .pos-bottom .hand{flex-wrap:wrap;gap:0 4px;row-gap:4px;justify-content:center}
  .pos-bottom .hand .card{width:var(--card-w);height:calc(var(--card-w) * var(--card-ratio))}
  .pos-bottom .hand .card .center-frame{width:25px;height:35px}
  .pos-bottom .hand .card .face-rank{font-size:27px}
  .pos-bottom .hand .card .corner .r{font-size:10px}
  .pos-bottom .hand .card.rook .rook-icon{width:16px;height:16px}
  .pos-bottom .hand .card:not(:first-child){margin-left:-16px}
  .pos-left .hand .card:not(:first-child), .pos-right .hand .card:not(:first-child){margin-top:-44px}
  .center{
    position:relative;
    top:auto;
    left:auto;
    transform:none;
    width:100%;
    gap:8px;
  }
  .center.center-bidding,.center.center-kitty,.center.center-trump{position:relative;top:auto;left:auto;transform:none;width:100%;padding:0}
  .phase-play .pos-bottom{
    top:4px;bottom:4px;left:5px;right:5px;
    z-index:11;transform:none;width:auto;max-width:none;
    display:flex;flex-direction:column;align-items:stretch;
  }
  .phase-play .pos-bottom .seat-name{display:none}
  .phase-play .pos-bottom .hand{
    flex:1;
    min-height:0;
    display:grid;
    grid-template-columns:repeat(6,minmax(0,1fr));
    gap:4px;
    justify-items:center;
    align-items:start;
    align-content:start;
    width:100%;
    overflow-y:auto;
    overflow-x:hidden;
    padding:2px 3px;
    margin:0;
  }
  .phase-play .pos-bottom .hand .card:not(:first-child){margin-left:0}
  .table > .center.center-play{
    position:absolute;
    left:50%;
    top:14px;
    bottom:80px;
    transform:translateX(-50%);
    width:min(calc(100% - 16px), 280px);
    max-height:calc(100% - 102px);
    padding:0;
    gap:0;
    z-index:12;
    align-items:center;
  }
  .table > .center.center-reveal{
    position:absolute;
    top:50%;
    left:50%;
    transform:translate(-50%, -50%);
    width:min(calc(100% - 16px), 280px);
    padding:0;
    gap:0;
    z-index:12;
    align-items:center;
  }
  .bidding,.trump-select,.kitty,.trick{padding:8px 10px}
  .center.center-play .trick{
    max-height:100%;
    overflow-y:auto;
    overscroll-behavior:contain;
  }
  .bidding-row{gap:6px}
  .bidding-row button{flex:1 1 92px;padding:7px 8px}
  .pending-bid-display{font-size:13px;padding:4px 8px;min-width:66px}
  .trump-buttons{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:6px;width:100%}
  .trump-buttons .trump{padding:8px 10px}
  .kitty-row{gap:4px}
  .cards{gap:2px}
  .droppable{min-height:36px;padding:4px}
  .phase-kitty .pos-bottom{bottom:6px;top:auto}
  .trick-grid{display:flex;flex-wrap:nowrap;gap:5px;align-items:stretch;justify-content:space-between;overflow-x:auto}
  .play{flex:0 0 calc((100% - 15px)/4);width:auto;min-width:76px;height:80px}
  .play .card{width:44px;height:64px}
  .play-label{font-size:11px;font-weight:700}
  .turn-indicator,.trick-message{font-size:13px;line-height:1.3}
  .trick.reveal-mobile-large{
    width:min(96vw, 560px);
    height:min(82vh, 520px);
    min-height:320px;
    padding:10px 10px;
  }
  .trick.reveal-mobile-large .trick-grid{
    grid-template-columns:minmax(0,1fr) minmax(88px, 1.2fr) minmax(0,1fr);
    grid-template-rows:minmax(76px, 1fr) minmax(90px, 1.05fr) minmax(76px, 1fr);
    gap:8px;
  }
  .trick.reveal-mobile-large .play{
    width:min(26vw, 110px);
    min-width:82px;
    min-height:88px;
    gap:4px;
    padding:6px 4px;
  }
  .trick.reveal-mobile-large .play .card{width:min(14vw, 58px)}
  .trick.reveal-mobile-large .play-label{display:block;font-size:10px;color:#c8d0df;font-weight:700;margin-top:2px}
  .trick.reveal-mobile-large .trick-message{font-size:13px}
  .kitty .card{width:34px;height:48px}
  .kitty .card .center-frame{width:20px;height:28px}
  .kitty .card .face-rank{font-size:21px}
  .kitty .card .corner .r{font-size:8px}
  .kitty .card .card-color-word{font-size:5px}
  .kitty .card.rook .rook-icon{width:15px;height:15px}
  .seat-panel{margin:10px;padding:12px}
  .seat-grid{grid-template-columns:repeat(2,minmax(0,1fr))}
  .modal{padding:10px calc(8px + var(--safe-right)) calc(10px + var(--safe-bottom)) calc(8px + var(--safe-left))}
  .modal-card{
    max-height:calc(100svh - 20px - var(--safe-top) - var(--safe-bottom));
    border-radius:12px;
  }
}


/* -- Debug Mode -- */
body.debug-layout .table {
  outline: 3px solid lime !important;
  outline-offset: -3px;
}
body.debug-layout .center {
  outline: 3px solid yellow !important;
  outline-offset: -3px;
}
body.debug-layout .play {
  outline: 2px solid cyan !important;
  outline-offset: -2px;
}
body.debug-layout .trick {
  outline: 2px solid magenta !important;
  outline-offset: -2px;
}
body.debug-layout .seat {
  outline: 1px dashed orange !important;
}


/* Phase 12 deploy-verification styling */
.phase20-deploy-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: 10px;
  padding: 4px 10px;
  border: 1px solid rgba(99, 179, 237, 0.75);
  border-radius: 999px;
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.28), rgba(16, 185, 129, 0.18));
  color: #bfdbfe;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  vertical-align: middle;
  box-shadow: 0 0 14px rgba(37, 99, 235, 0.22);
}
.room-phase-badge {
  margin-left: 12px;
  white-space: nowrap;
}
.phase12-deploy-footer {
  position: fixed;
  right: 14px;
  bottom: 14px;
  z-index: 9999;
  max-width: min(420px, calc(100vw - 28px));
  padding: 9px 12px;
  border: 1px solid rgba(34, 197, 94, 0.45);
  border-radius: 12px;
  background: rgba(2, 6, 23, 0.84);
  color: #bbf7d0;
  font-size: 0.78rem;
  line-height: 1.25;
  backdrop-filter: blur(8px);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.35);
}
@media (max-width: 720px) {
  .phase12-deploy-footer {
    left: 10px;
    right: 10px;
    bottom: 10px;
    text-align: center;
  }
  .phase20-deploy-badge {
    font-size: 0.65rem;
    padding: 3px 8px;
  }
}


/* Phase 19 default Rook rules / AI level helpers */
.live-default-rules-card {
  margin: 10px 0 12px;
  padding: 10px 12px;
  border: 1px solid rgba(96, 165, 250, 0.35);
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.72);
  color: #dbeafe;
  font-size: 12px;
  line-height: 1.45;
}
.live-default-rules-card strong { color:#bfdbfe; }
.live-default-rules-card .rule-points-line { color:#e5e7eb; margin-top:4px; }
.live-ai-help, #rule-ai-level-help, #rm-ai-level-help {
  display:block;
  margin-top:4px;
  color:#93c5fd;
  font-size:11px;
  line-height:1.35;
}
.live-bid-cap-warning {
  display:inline-flex;
  align-items:center;
  gap:6px;
  margin-left:8px;
  padding:3px 8px;
  border-radius:999px;
  border:1px solid rgba(251,191,36,.45);
  background:rgba(251,191,36,.12);
  color:#fde68a;
  font-size:11px;
  font-weight:700;
}
body.rook-live-mode #bidding-panel .live-max-bid-reached button[data-bid-action="up"],
body.rook-live-mode #bidding-panel .live-max-bid-reached button[data-bid-action="bid"] {
  opacity:.55;
}


/* Phase 20 live left-panel hookup */
.live-left-title {
  font-weight: 700;
  color: #dbeafe;
  margin-top: 8px;
}
.live-left-status,
.live-left-summary,
.live-left-points,
.live-left-result {
  line-height: 1.35;
}
.live-left-result {
  border: 1px solid rgba(34, 197, 94, 0.45);
  background: rgba(34, 197, 94, 0.12);
  color: #bbf7d0;
  font-weight: 700;
}
.live-left-card-list-item {
  padding: 6px 4px !important;
  background: transparent !important;
}
.live-left-trick-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.live-left-trick-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  min-height: 78px;
  border-radius: 8px;
  padding: 4px;
  background: rgba(15, 23, 42, 0.48);
  border: 1px solid rgba(148, 163, 184, 0.15);
}
.live-left-trick-card.active {
  border-color: rgba(250, 204, 21, 0.8);
  box-shadow: 0 0 10px rgba(250, 204, 21, 0.35);
}
.live-left-seat-label {
  font-size: 10px;
  color: #94a3b8;
  text-align: center;
  white-space: nowrap;
}
.live-left-card-mini {
  transform: scale(0.52);
  transform-origin: top center;
  margin: -2px -18px -38px -18px;
}
.live-left-empty-card {
  width: 42px;
  height: 56px;
  border: 1px dashed rgba(148, 163, 184, 0.35);
  border-radius: 6px;
  color: #64748b;
  display: grid;
  place-items: center;
  font-size: 11px;
}

/* Phase 21: deeper Colyseus UI wiring / left panel parity */

/* Phase 22: hide kitty cards unless the local player owns the kitty */
.live-waiting-kitty {
  width: 100%;
  padding: 14px 16px;
  border: 1px dashed rgba(148, 163, 184, .45);
  border-radius: 12px;
  color: #cbd5e1;
  background: rgba(15, 23, 42, .55);
  text-align: center;
  font-weight: 700;
}


/* -------------------------------------------------------------------------
   Phase 31 mobile play layout
   Problem fixed: on phones the trick panel and live adapter could cover the
   South/player hand, making it impossible to pick a card. During live play,
   the player's hand becomes a fixed bottom drawer, like a real mobile card
   tray, while the active trick stays on the table above it.
   ------------------------------------------------------------------------- */
@media (max-width: 800px) {
  body:has(#view-room.active) {
    padding-bottom: calc(178px + var(--safe-bottom));
  }

  body:has(#view-room.active) #view-room .room-header {
    position: sticky;
    top: 0;
    z-index: 90;
  }

  body:has(#view-room.active) #view-room .table-layout {
    padding-bottom: calc(190px + var(--safe-bottom));
  }

  .table.phase-play {
    min-height: clamp(390px, 54dvh, 560px) !important;
    overflow: visible !important;
    margin-bottom: calc(150px + var(--safe-bottom));
  }

  .table.phase-play .center.center-play,
  .table.phase-play .center.center-reveal,
  .table > .center.center-play,
  .table > .center.center-reveal {
    top: clamp(16px, 4vh, 34px) !important;
    bottom: 18px !important;
    width: min(calc(100% - 18px), 360px) !important;
    max-height: calc(100% - 32px) !important;
    z-index: 30 !important;
  }

  .table.phase-play .center.center-play > .trick,
  .table.phase-play .center.center-reveal > .trick,
  .table > .center.center-play > .trick,
  .table > .center.center-reveal > .trick {
    width: 100% !important;
    max-height: 100% !important;
  }

  .phase-play .pos-bottom,
  .table.phase-play .seat.pos-bottom {
    position: fixed !important;
    left: calc(8px + var(--safe-left)) !important;
    right: calc(8px + var(--safe-right)) !important;
    bottom: calc(88px + var(--safe-bottom)) !important;
    top: auto !important;
    transform: none !important;
    width: auto !important;
    max-width: none !important;
    min-height: 116px !important;
    max-height: min(32dvh, 220px) !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 6px !important;
    z-index: 999990 !important;
    padding: 10px 10px 12px !important;
    border: 1px solid rgba(85, 210, 166, .55) !important;
    border-radius: 18px !important;
    background: rgba(7, 12, 20, .96) !important;
    box-shadow: 0 -16px 38px rgba(0,0,0,.48), 0 0 0 1px rgba(255,255,255,.05) inset !important;
    backdrop-filter: blur(8px) !important;
  }

  .phase-play .pos-bottom::before,
  .table.phase-play .seat.pos-bottom::before {
    content: "Your Hand — tap a card to play";
    display: block;
    color: #52ff8f;
    font-weight: 800;
    font-size: 13px;
    line-height: 1.15;
    text-align: center;
    letter-spacing: .2px;
    margin-bottom: 2px;
  }

  .phase-play .pos-bottom:not(.active-turn)::before,
  .table.phase-play .seat.pos-bottom:not(.active-turn)::before {
    content: "Your Hand — waiting for your turn";
    color: #a8b3c7;
  }

  .phase-play .pos-bottom .seat-name,
  .table.phase-play .seat.pos-bottom .seat-name {
    display: none !important;
  }

  .phase-play .pos-bottom .hand,
  .table.phase-play .seat.pos-bottom .hand {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    width: 100% !important;
    display: grid !important;
    grid-template-columns: repeat(5, minmax(0, 1fr)) !important;
    gap: 7px !important;
    align-items: start !important;
    justify-items: center !important;
    align-content: start !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    overscroll-behavior: contain !important;
    padding: 2px 3px 4px !important;
    margin: 0 !important;
    -webkit-overflow-scrolling: touch !important;
  }

  .phase-play .pos-bottom .hand .card,
  .table.phase-play .seat.pos-bottom .hand .card {
    width: min(17.5vw, 66px) !important;
    height: auto !important;
    aspect-ratio: .70 !important;
    margin-left: 0 !important;
    touch-action: manipulation !important;
  }

  .phase-play .pos-bottom .hand .card.playable,
  .table.phase-play .seat.pos-bottom .hand .card.playable {
    box-shadow: 0 0 0 3px rgba(82,255,143,.72), 0 0 18px rgba(82,255,143,.34) !important;
  }

  .phase-play .pos-bottom .hand .card .center-frame,
  .table.phase-play .seat.pos-bottom .hand .card .center-frame { width: 34px !important; height: 48px !important; }
  .phase-play .pos-bottom .hand .card .face-rank,
  .table.phase-play .seat.pos-bottom .hand .card .face-rank { font-size: 38px !important; }
  .phase-play .pos-bottom .hand .card .corner .r,
  .table.phase-play .seat.pos-bottom .hand .card .corner .r { font-size: 13px !important; }
  .phase-play .pos-bottom .hand .card.rook .rook-icon,
  .table.phase-play .seat.pos-bottom .hand .card.rook .rook-icon { width: 24px !important; height: 24px !important; }

  #colyseus-live-panel.collapsed {
    left: calc(8px + var(--safe-left));
    right: calc(8px + var(--safe-right));
    bottom: calc(8px + var(--safe-bottom));
    width: auto;
    max-height: 70px;
    overflow: hidden;
    padding: 10px 12px;
    z-index: 999999;
  }

  #colyseus-live-panel.collapsed h3 {
    font-size: clamp(16px, 4.3vw, 20px);
    line-height: 1.15;
  }
}

@media (max-width: 430px) {
  .phase-play .pos-bottom,
  .table.phase-play .seat.pos-bottom {
    bottom: calc(82px + var(--safe-bottom)) !important;
    max-height: min(34dvh, 230px) !important;
    padding: 9px 8px 10px !important;
  }
  .phase-play .pos-bottom .hand,
  .table.phase-play .seat.pos-bottom .hand {
    grid-template-columns: repeat(5, minmax(0, 1fr)) !important;
    gap: 5px !important;
  }
  .phase-play .pos-bottom .hand .card,
  .table.phase-play .seat.pos-bottom .hand .card {
    width: min(17.8vw, 62px) !important;
  }
  .phase-play .pos-bottom .hand .card .center-frame,
  .table.phase-play .seat.pos-bottom .hand .card .center-frame { width: 30px !important; height: 42px !important; }
  .phase-play .pos-bottom .hand .card .face-rank,
  .table.phase-play .seat.pos-bottom .hand .card .face-rank { font-size: 34px !important; }
}

@media (max-height: 500px) and (orientation: landscape) {
  body:has(#view-room.active) #view-room .table-layout {
    padding-bottom: calc(128px + var(--safe-bottom));
  }
  .table.phase-play { margin-bottom: calc(112px + var(--safe-bottom)); }
  .phase-play .pos-bottom,
  .table.phase-play .seat.pos-bottom {
    bottom: calc(64px + var(--safe-bottom)) !important;
    min-height: 86px !important;
    max-height: min(34dvh, 140px) !important;
  }
  .phase-play .pos-bottom .hand,
  .table.phase-play .seat.pos-bottom .hand {
    grid-template-columns: repeat(10, minmax(0, 1fr)) !important;
  }
  .phase-play .pos-bottom .hand .card,
  .table.phase-play .seat.pos-bottom .hand .card {
    width: min(8.8vw, 52px) !important;
  }
}

/* -------------------------------------------------------------------------
   Phase 31 mobile table mode
   Deep mobile revamp: phones now use a stacked game-app layout instead of
   trying to show the desktop table, hand, adapter, and history all at once.
   The player's hand becomes a single-row horizontal tray above the adapter so
   every card can be reached with a side-swipe instead of a cramped two-row grid.
   ------------------------------------------------------------------------- */
@media (max-width: 800px) {
  html,
  body {
    overflow-x: hidden !important;
    background: #080d14 !important;
  }

  body:has(#view-room.active) {
    padding-bottom: calc(220px + var(--safe-bottom)) !important;
  }

  body:has(#view-room.active) #view-room {
    min-height: 100svh !important;
  }

  body:has(#view-room.active) #view-room .room-header {
    position: sticky !important;
    top: 0 !important;
    z-index: 200 !important;
    display: grid !important;
    grid-template-columns: 1fr auto !important;
    gap: 8px 10px !important;
    align-items: center !important;
    padding: calc(8px + var(--safe-top)) 10px 8px !important;
    background: rgba(8, 13, 20, .96) !important;
    border-bottom: 1px solid rgba(64, 205, 150, .16) !important;
    backdrop-filter: blur(10px) !important;
  }

  body:has(#view-room.active) #view-room .room-header h1,
  body:has(#view-room.active) #view-room .room-title,
  body:has(#view-room.active) #room-title {
    font-size: clamp(20px, 6vw, 28px) !important;
    line-height: 1.05 !important;
    margin: 0 !important;
    min-width: 0 !important;
  }

  body:has(#view-room.active) #view-room .room-actions,
  body:has(#view-room.active) #view-room .top-actions {
    grid-column: 1 / -1 !important;
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 8px !important;
    width: 100% !important;
  }

  body:has(#view-room.active) #view-room .room-actions button,
  body:has(#view-room.active) #view-room .top-actions button,
  body:has(#view-room.active) #view-room .room-actions .btn,
  body:has(#view-room.active) #view-room .top-actions .btn {
    min-height: 42px !important;
    padding: 10px 8px !important;
    font-size: clamp(13px, 3.8vw, 16px) !important;
  }

  body:has(#view-room.active) #view-room .table-layout {
    display: block !important;
    padding: 8px 8px calc(142px + var(--safe-bottom)) !important;
  }

  body:has(#view-room.active) #view-room .sidebar,
  body:has(#view-room.active) #view-room .left-panel,
  body:has(#view-room.active) #history-panel {
    order: 3 !important;
    margin-top: 10px !important;
    max-height: none !important;
  }

  .table.phase-play {
    height: min(50svh, 430px) !important;
    min-height: 360px !important;
    max-height: 430px !important;
    margin: 0 0 10px !important;
    padding: 6px !important;
    overflow: hidden !important;
    border-width: 6px !important;
    border-radius: 16px !important;
  }

  .table.phase-play .seat.pos-top,
  .table.phase-play .seat.pos-left,
  .table.phase-play .seat.pos-right {
    transform: scale(.78) !important;
    transform-origin: center !important;
    opacity: .92 !important;
  }

  .table.phase-play .seat.pos-left { left: -12px !important; }
  .table.phase-play .seat.pos-right { right: -12px !important; }
  .table.phase-play .seat.pos-top { top: 4px !important; }

  .table.phase-play .center.center-play,
  .table.phase-play .center.center-reveal,
  .table > .center.center-play,
  .table > .center.center-reveal {
    position: absolute !important;
    top: 54px !important;
    left: 50% !important;
    bottom: auto !important;
    width: min(calc(100% - 18px), 360px) !important;
    max-height: calc(100% - 68px) !important;
    transform: translateX(-50%) !important;
    z-index: 28 !important;
  }

  .table.phase-play .center.center-play > .trick,
  .table.phase-play .center.center-reveal > .trick,
  .table > .center.center-play > .trick,
  .table > .center.center-reveal > .trick {
    padding: 9px !important;
    border-radius: 14px !important;
  }

  .trick.reveal-mobile-large .trick-grid,
  .table.phase-play .trick-grid {
    gap: 7px !important;
  }

  .table.phase-play .play .card,
  .trick.reveal-mobile-large .play .card {
    width: min(18vw, 62px) !important;
    height: auto !important;
    aspect-ratio: .70 !important;
  }

  .table.phase-play .play-label {
    font-size: 11px !important;
  }

  /* Replace the cramped two-row hand grid with a single-row swipe tray. */
  .phase-play .pos-bottom,
  .table.phase-play .seat.pos-bottom {
    position: fixed !important;
    left: calc(8px + var(--safe-left)) !important;
    right: calc(8px + var(--safe-right)) !important;
    bottom: calc(78px + var(--safe-bottom)) !important;
    top: auto !important;
    transform: none !important;
    width: auto !important;
    max-width: none !important;
    min-height: 116px !important;
    max-height: 132px !important;
    z-index: 999990 !important;
    padding: 8px 8px 10px !important;
    border: 1px solid rgba(85, 210, 166, .68) !important;
    border-radius: 18px !important;
    background: linear-gradient(180deg, rgba(7, 12, 20, .98), rgba(5, 10, 18, .98)) !important;
    box-shadow: 0 -16px 34px rgba(0,0,0,.52), 0 0 0 1px rgba(255,255,255,.05) inset !important;
    backdrop-filter: blur(10px) !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
  }

  .phase-play .pos-bottom::before,
  .table.phase-play .seat.pos-bottom::before {
    content: "Your Hand — swipe sideways, tap highlighted card" !important;
    flex: 0 0 auto !important;
    display: block !important;
    color: #52ff8f !important;
    font-weight: 900 !important;
    font-size: clamp(12px, 3.8vw, 16px) !important;
    line-height: 1.05 !important;
    text-align: center !important;
    letter-spacing: .1px !important;
    margin: 0 0 7px !important;
  }

  .phase-play .pos-bottom:not(.active-turn)::before,
  .table.phase-play .seat.pos-bottom:not(.active-turn)::before {
    content: "Your Hand — waiting for your turn" !important;
    color: #aab6c8 !important;
  }

  .phase-play .pos-bottom .seat-name,
  .table.phase-play .seat.pos-bottom .seat-name {
    display: none !important;
  }

  .phase-play .pos-bottom .hand,
  .table.phase-play .seat.pos-bottom .hand {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    width: 100% !important;
    display: flex !important;
    flex-wrap: nowrap !important;
    align-items: flex-start !important;
    justify-content: flex-start !important;
    gap: 8px !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    overscroll-behavior-x: contain !important;
    padding: 2px 8px 8px !important;
    margin: 0 !important;
    scroll-snap-type: x proximity !important;
    -webkit-overflow-scrolling: touch !important;
    scrollbar-width: thin !important;
  }

  .phase-play .pos-bottom .hand .card,
  .table.phase-play .seat.pos-bottom .hand .card {
    flex: 0 0 auto !important;
    width: clamp(50px, 15.2vw, 62px) !important;
    height: auto !important;
    aspect-ratio: .70 !important;
    margin: 0 !important;
    scroll-snap-align: center !important;
    touch-action: manipulation !important;
    border-radius: 7px !important;
  }

  .phase-play .pos-bottom .hand .card.disabled,
  .table.phase-play .seat.pos-bottom .hand .card.disabled {
    opacity: .38 !important;
    filter: grayscale(.45) brightness(.72) !important;
  }

  .phase-play .pos-bottom .hand .card.playable,
  .table.phase-play .seat.pos-bottom .hand .card.playable {
    opacity: 1 !important;
    box-shadow: 0 0 0 3px rgba(82,255,143,.82), 0 0 18px rgba(82,255,143,.45) !important;
  }

  .phase-play .pos-bottom .hand .card .center-frame,
  .table.phase-play .seat.pos-bottom .hand .card .center-frame { width: 26px !important; height: 36px !important; }
  .phase-play .pos-bottom .hand .card .face-rank,
  .table.phase-play .seat.pos-bottom .hand .card .face-rank { font-size: 30px !important; }
  .phase-play .pos-bottom .hand .card .corner .r,
  .table.phase-play .seat.pos-bottom .hand .card .corner .r { font-size: 11px !important; }
  .phase-play .pos-bottom .hand .card .card-color-word,
  .table.phase-play .seat.pos-bottom .hand .card .card-color-word { font-size: 6px !important; }

  /* The adapter should not compete with the card tray on phones. */
  #colyseus-live-panel.collapsed {
    left: calc(8px + var(--safe-left)) !important;
    right: calc(8px + var(--safe-right)) !important;
    bottom: calc(8px + var(--safe-bottom)) !important;
    width: auto !important;
    max-height: 58px !important;
    min-height: 58px !important;
    overflow: hidden !important;
    padding: 8px 10px !important;
    border-radius: 16px !important;
    z-index: 999999 !important;
  }

  #colyseus-live-panel.collapsed h3 {
    font-size: clamp(14px, 4vw, 18px) !important;
    line-height: 1.05 !important;
  }

  #colyseus-live-panel.collapsed .live-panel-toggle {
    min-height: 40px !important;
    min-width: 74px !important;
    font-size: 16px !important;
  }
}

@media (max-width: 430px) {
  body:has(#view-room.active) {
    padding-bottom: calc(210px + var(--safe-bottom)) !important;
  }

  .table.phase-play {
    height: min(46svh, 390px) !important;
    min-height: 330px !important;
  }

  .table.phase-play .center.center-play,
  .table.phase-play .center.center-reveal,
  .table > .center.center-play,
  .table > .center.center-reveal {
    top: 44px !important;
    width: min(calc(100% - 12px), 330px) !important;
  }

  .phase-play .pos-bottom,
  .table.phase-play .seat.pos-bottom {
    bottom: calc(70px + var(--safe-bottom)) !important;
    max-height: 124px !important;
    min-height: 110px !important;
    padding: 7px 7px 9px !important;
  }

  .phase-play .pos-bottom .hand,
  .table.phase-play .seat.pos-bottom .hand {
    gap: 7px !important;
    padding-bottom: 6px !important;
  }

  .phase-play .pos-bottom .hand .card,
  .table.phase-play .seat.pos-bottom .hand .card {
    width: clamp(48px, 14.4vw, 58px) !important;
  }
}

@media (max-height: 720px) and (max-width: 800px) {
  .table.phase-play {
    height: min(42svh, 340px) !important;
    min-height: 310px !important;
  }

  .table.phase-play .play .card,
  .trick.reveal-mobile-large .play .card {
    width: min(16vw, 54px) !important;
  }
}

/* -------------------------------------------------------------------------
   Phase 31 mobile app layout
   The phone view now stops trying to show the desktop layout. The important
   layers are: compact header, table/trick stage, action panel, fixed hand tray.
   ------------------------------------------------------------------------- */
@media (max-width: 800px) {
  body:has(#view-room.active) {
    padding: 0 !important;
    min-height: 100svh !important;
    overflow-x: hidden !important;
    background: #070c13 !important;
  }

  body:has(#view-room.active) #view-room {
    min-height: 100svh !important;
    display: block !important;
    padding: 0 !important;
  }

  body:has(#view-room.active) #view-room .room-header {
    position: sticky !important;
    top: 0 !important;
    z-index: 1000000 !important;
    display: grid !important;
    grid-template-columns: auto 1fr auto !important;
    grid-template-areas:
      "back title phase"
      "sound title rules" !important;
    gap: 6px 8px !important;
    align-items: center !important;
    padding: calc(6px + var(--safe-top)) 8px 7px !important;
    min-height: 0 !important;
    background: rgba(7, 12, 19, .98) !important;
    border-bottom: 1px solid rgba(45, 212, 133, .18) !important;
    backdrop-filter: blur(10px) !important;
  }

  body:has(#view-room.active) #view-room .header-left { grid-area: back !important; display: contents !important; }
  body:has(#view-room.active) #view-room #back-to-lobby {
    grid-area: back !important;
    width: 58px !important;
    min-width: 58px !important;
    height: 44px !important;
    min-height: 44px !important;
    padding: 0 !important;
    border-radius: 12px !important;
    font-size: 0 !important;
  }
  body:has(#view-room.active) #view-room #back-to-lobby::before {
    content: "←" !important;
    font-size: 25px !important;
    line-height: 1 !important;
  }
  body:has(#view-room.active) #view-room #hand-result-indicator { display: none !important; }

  body:has(#view-room.active) #view-room .room-title {
    grid-area: title !important;
    min-width: 0 !important;
    display: grid !important;
    grid-template-columns: auto 1fr !important;
    gap: 5px 7px !important;
    align-items: center !important;
    justify-content: start !important;
  }
  body:has(#view-room.active) #view-room .room-title .logo {
    font-size: 20px !important;
    grid-row: 1 / span 2 !important;
  }
  body:has(#view-room.active) #room-title,
  body:has(#view-room.active) #view-room .room-title h1 {
    font-size: clamp(17px, 5.2vw, 24px) !important;
    line-height: 1.02 !important;
    margin: 0 !important;
    white-space: normal !important;
  }
  body:has(#view-room.active) #view-room .room-title h1::after {
    content: "" !important;
    display: none !important;
  }
  body:has(#view-room.active) #view-room .room-phase-badge {
    grid-area: phase !important;
    align-self: start !important;
    margin-top: 3px !important;
    padding: 4px 8px !important;
    font-size: 11px !important;
  }

  body:has(#view-room.active) #view-room .header-right { display: contents !important; }
  body:has(#view-room.active) #toggle-turn-sound,
  body:has(#view-room.active) #toggle-rules {
    width: 58px !important;
    min-width: 58px !important;
    height: 36px !important;
    min-height: 36px !important;
    padding: 0 4px !important;
    font-size: 0 !important;
    border-radius: 12px !important;
  }
  body:has(#view-room.active) #toggle-turn-sound { grid-area: sound !important; }
  body:has(#view-room.active) #toggle-turn-sound::before { content: "🔔"; font-size: 20px; }
  body:has(#view-room.active) #toggle-rules { grid-area: rules !important; justify-self: end !important; }
  body:has(#view-room.active) #toggle-rules::before { content: "Rules"; font-size: 13px; font-weight: 800; }
  body:has(#view-room.active) #new-hand { display: none !important; }

  body:has(#view-room.active) #mobile-turn-tracker.show {
    position: sticky !important;
    top: 88px !important;
    z-index: 999999 !important;
    margin: 0 !important;
    border-radius: 0 !important;
    padding: 5px 8px !important;
    background: rgba(9, 15, 24, .96) !important;
    border-left: 0 !important;
    border-right: 0 !important;
  }

  body:has(#view-room.active) #view-room .table-layout {
    display: block !important;
    padding: 6px 6px calc(168px + var(--safe-bottom)) !important;
  }

  body:has(#view-room.active) #view-room .score-panel,
  body:has(#view-room.active) #history-panel {
    display: none !important;
  }

  .table.phase-bidding,
  .table.phase-kitty,
  .table.phase-play {
    position: relative !important;
    height: calc(100svh - 278px - var(--safe-top) - var(--safe-bottom)) !important;
    min-height: 230px !important;
    max-height: 390px !important;
    margin: 0 !important;
    padding: 4px !important;
    border-width: 5px !important;
    border-radius: 15px !important;
    overflow: hidden !important;
  }

  .table.phase-bidding .seat.pos-top,
  .table.phase-bidding .seat.pos-left,
  .table.phase-bidding .seat.pos-right,
  .table.phase-kitty .seat.pos-top,
  .table.phase-kitty .seat.pos-left,
  .table.phase-kitty .seat.pos-right,
  .table.phase-play .seat.pos-top,
  .table.phase-play .seat.pos-left,
  .table.phase-play .seat.pos-right {
    transform: scale(.66) !important;
    opacity: .72 !important;
    pointer-events: none !important;
  }
  .table.phase-bidding .seat.pos-top,
  .table.phase-kitty .seat.pos-top,
  .table.phase-play .seat.pos-top { top: 0 !important; }
  .table.phase-bidding .seat.pos-left,
  .table.phase-kitty .seat.pos-left,
  .table.phase-play .seat.pos-left { left: -28px !important; }
  .table.phase-bidding .seat.pos-right,
  .table.phase-kitty .seat.pos-right,
  .table.phase-play .seat.pos-right { right: -28px !important; }

  /* Bidding/kitty action panels become fixed bars above your hand. */
  .table.phase-bidding .center,
  .table.phase-kitty .center {
    position: fixed !important;
    left: calc(8px + var(--safe-left)) !important;
    right: calc(8px + var(--safe-right)) !important;
    bottom: calc(112px + var(--safe-bottom)) !important;
    top: auto !important;
    width: auto !important;
    max-width: none !important;
    transform: none !important;
    z-index: 999992 !important;
    pointer-events: none !important;
  }
  .table.phase-bidding .center > *,
  .table.phase-kitty .center > * { pointer-events: auto !important; }

  .table.phase-bidding #bidding-panel {
    width: 100% !important;
    padding: 8px !important;
    border-radius: 16px !important;
    background: rgba(7, 12, 20, .98) !important;
    box-shadow: 0 -10px 28px rgba(0,0,0,.55) !important;
  }
  .table.phase-bidding #bidding-panel .bidding-row {
    display: grid !important;
    grid-template-columns: 1fr .8fr 1fr .8fr 1.4fr !important;
    gap: 5px !important;
    align-items: center !important;
  }
  .table.phase-bidding #bidding-panel button,
  .table.phase-bidding #bidding-panel .pending-bid-display {
    min-height: 36px !important;
    padding: 6px 5px !important;
    font-size: 12px !important;
    border-radius: 9px !important;
    text-align: center !important;
  }
  .table.phase-bidding #bidding-panel .bidding-info {
    margin-top: 5px !important;
    font-size: 12px !important;
    text-align: center !important;
  }

  .table.phase-play .center.center-play,
  .table.phase-play .center.center-reveal,
  .table > .center.center-play,
  .table > .center.center-reveal {
    top: 18px !important;
    width: min(calc(100% - 10px), 330px) !important;
    max-height: calc(100% - 28px) !important;
  }
  .table.phase-play .center.center-play > .trick,
  .table.phase-play .center.center-reveal > .trick,
  .table > .center.center-play > .trick,
  .table > .center.center-reveal > .trick {
    padding: 7px !important;
    border-radius: 13px !important;
  }
  .table.phase-play .play .card,
  .trick.reveal-mobile-large .play .card {
    width: min(17vw, 56px) !important;
  }

  /* Your hand is always the bottom-most game control. */
  .phase-bidding .pos-bottom,
  .phase-kitty .pos-bottom,
  .phase-play .pos-bottom,
  .table.phase-bidding .seat.pos-bottom,
  .table.phase-kitty .seat.pos-bottom,
  .table.phase-play .seat.pos-bottom {
    position: fixed !important;
    left: calc(8px + var(--safe-left)) !important;
    right: calc(8px + var(--safe-right)) !important;
    bottom: calc(8px + var(--safe-bottom)) !important;
    top: auto !important;
    transform: none !important;
    width: auto !important;
    max-width: none !important;
    min-height: 96px !important;
    max-height: 104px !important;
    z-index: 999991 !important;
    margin: 0 !important;
    padding: 6px 7px 8px !important;
    border: 1px solid rgba(80, 220, 170, .72) !important;
    border-radius: 16px !important;
    background: linear-gradient(180deg, rgba(7,12,20,.99), rgba(4,8,15,.99)) !important;
    box-shadow: 0 -12px 30px rgba(0,0,0,.55) !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
  }

  .phase-bidding .pos-bottom::before,
  .phase-kitty .pos-bottom::before,
  .phase-play .pos-bottom::before,
  .table.phase-bidding .seat.pos-bottom::before,
  .table.phase-kitty .seat.pos-bottom::before,
  .table.phase-play .seat.pos-bottom::before {
    content: "Your cards" !important;
    display: block !important;
    flex: 0 0 auto !important;
    color: #52ff8f !important;
    font-size: 12px !important;
    font-weight: 900 !important;
    line-height: 1 !important;
    margin: 0 0 5px !important;
    text-align: center !important;
  }
  .phase-play .pos-bottom.active-turn::before,
  .table.phase-play .seat.pos-bottom.active-turn::before { content: "Your turn — tap a highlighted card" !important; }
  .phase-bidding .pos-bottom.active-turn::before,
  .table.phase-bidding .seat.pos-bottom.active-turn::before { content: "Your cards — choose bid or pass" !important; }

  .phase-bidding .pos-bottom .seat-name,
  .phase-kitty .pos-bottom .seat-name,
  .phase-play .pos-bottom .seat-name,
  .table.phase-bidding .seat.pos-bottom .seat-name,
  .table.phase-kitty .seat.pos-bottom .seat-name,
  .table.phase-play .seat.pos-bottom .seat-name { display: none !important; }

  .phase-bidding .pos-bottom .hand,
  .phase-kitty .pos-bottom .hand,
  .phase-play .pos-bottom .hand,
  .table.phase-bidding .seat.pos-bottom .hand,
  .table.phase-kitty .seat.pos-bottom .hand,
  .table.phase-play .seat.pos-bottom .hand {
    display: flex !important;
    flex-wrap: nowrap !important;
    align-items: flex-start !important;
    justify-content: flex-start !important;
    gap: 6px !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    width: 100% !important;
    min-height: 0 !important;
    flex: 1 1 auto !important;
    padding: 1px 5px 8px !important;
    margin: 0 !important;
    -webkit-overflow-scrolling: touch !important;
    scroll-snap-type: x proximity !important;
  }

  .phase-bidding .pos-bottom .hand .card,
  .phase-kitty .pos-bottom .hand .card,
  .phase-play .pos-bottom .hand .card,
  .table.phase-bidding .seat.pos-bottom .hand .card,
  .table.phase-kitty .seat.pos-bottom .hand .card,
  .table.phase-play .seat.pos-bottom .hand .card {
    flex: 0 0 auto !important;
    width: clamp(43px, 12.3vw, 52px) !important;
    height: auto !important;
    aspect-ratio: .70 !important;
    margin: 0 !important;
    scroll-snap-align: center !important;
    border-radius: 7px !important;
  }
  .phase-bidding .pos-bottom .hand .card .center-frame,
  .phase-kitty .pos-bottom .hand .card .center-frame,
  .phase-play .pos-bottom .hand .card .center-frame,
  .table.phase-bidding .seat.pos-bottom .hand .card .center-frame,
  .table.phase-kitty .seat.pos-bottom .hand .card .center-frame,
  .table.phase-play .seat.pos-bottom .hand .card .center-frame { width: 24px !important; height: 33px !important; }
  .phase-bidding .pos-bottom .hand .card .face-rank,
  .phase-kitty .pos-bottom .hand .card .face-rank,
  .phase-play .pos-bottom .hand .card .face-rank,
  .table.phase-bidding .seat.pos-bottom .hand .card .face-rank,
  .table.phase-kitty .seat.pos-bottom .hand .card .face-rank,
  .table.phase-play .seat.pos-bottom .hand .card .face-rank { font-size: 27px !important; }
  .phase-bidding .pos-bottom .hand .card .corner .r,
  .phase-kitty .pos-bottom .hand .card .corner .r,
  .phase-play .pos-bottom .hand .card .corner .r,
  .table.phase-bidding .seat.pos-bottom .hand .card .corner .r,
  .table.phase-kitty .seat.pos-bottom .hand .card .corner .r,
  .table.phase-play .seat.pos-bottom .hand .card .corner .r { font-size: 9px !important; }

  /* Hide the debug adapter on phones unless explicitly expanded. It was taking
     the most valuable tap space away from the hand. */
  #colyseus-live-panel.collapsed {
    display: none !important;
  }
  #colyseus-live-panel:not(.collapsed) {
    left: calc(6px + var(--safe-left)) !important;
    right: calc(6px + var(--safe-right)) !important;
    top: calc(6px + var(--safe-top)) !important;
    bottom: auto !important;
    width: auto !important;
    max-height: calc(100svh - 16px - var(--safe-top)) !important;
    z-index: 2000000 !important;
  }
}

@media (max-width: 430px) {
  .table.phase-bidding,
  .table.phase-kitty,
  .table.phase-play {
    height: calc(100svh - 262px - var(--safe-top) - var(--safe-bottom)) !important;
    min-height: 220px !important;
  }
  .table.phase-bidding .center,
  .table.phase-kitty .center {
    bottom: calc(104px + var(--safe-bottom)) !important;
  }
  .phase-bidding .pos-bottom,
  .phase-kitty .pos-bottom,
  .phase-play .pos-bottom,
  .table.phase-bidding .seat.pos-bottom,
  .table.phase-kitty .seat.pos-bottom,
  .table.phase-play .seat.pos-bottom {
    min-height: 88px !important;
    max-height: 96px !important;
  }
  .phase-bidding .pos-bottom .hand .card,
  .phase-kitty .pos-bottom .hand .card,
  .phase-play .pos-bottom .hand .card,
  .table.phase-bidding .seat.pos-bottom .hand .card,
  .table.phase-kitty .seat.pos-bottom .hand .card,
  .table.phase-play .seat.pos-bottom .hand .card {
    width: clamp(40px, 11.6vw, 49px) !important;
  }
}


/* -------------------------------------------------------------------------
   Phase 31 lobby + mobile deal cleanup
   ------------------------------------------------------------------------- */
.live-room-toolbar { display:flex; flex-direction:column; gap:8px; margin:0 0 12px; }
.live-room-toolbar small { color:#9aa6bd; line-height:1.35; }
.live-room-toolbar .secondary { width:100%; font-weight:700; }
.live-room-list-item { align-items:stretch !important; gap:10px !important; }
.live-room-info { display:flex; flex-direction:column; gap:3px; min-width:0; }
.live-room-info strong { color:#f7fbff; }
.live-room-info small { color:#9aa6bd; line-height:1.25; }
.live-room-actions { display:flex; align-items:center; }
.live-leaderboard-panel #leaderboard { gap:8px; }
.live-leaderboard-panel #leaderboard li.leaderboard-row {
  display:grid;
  grid-template-columns:auto 1fr;
  gap:4px 10px;
  align-items:center;
}
.leaderboard-rank {
  grid-row:1 / span 2;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  width:34px;
  height:34px;
  border-radius:999px;
  background:rgba(109,140,255,.22);
  border:1px solid rgba(132,166,255,.45);
  color:#dbeafe;
  font-weight:800;
  font-size:12px;
}
.leaderboard-team { color:#f1f5ff; font-weight:800; }
.leaderboard-metric { color:#a9b7d3; font-size:12px; }

@media (max-width: 800px) {
  body:has(#view-lobby.active) .lobby-grid {
    display:grid !important;
    grid-template-columns:1fr !important;
    gap:10px !important;
  }
  body:has(#view-lobby.active) .live-leaderboard-panel {
    display:block !important;
  }
  body:has(#view-lobby.active) .panel {
    padding:12px !important;
  }
  body:has(#view-lobby.active) #create-room-form button[type="submit"],
  body:has(#view-lobby.active) .live-room-actions .primary {
    min-height:44px !important;
    font-size:15px !important;
  }

  /* Phase 28 hid the main deal button on phones. Phase 31 shows it only when
     it is actually useful: lobby/ready-to-deal/hand-over. */
  body:has(#view-room.active) #new-hand:not([data-live-phase="bidding"]):not([data-live-phase="kitty"]):not([data-live-phase="playing"]):not([data-live-phase="trick-complete"]) {
    display:block !important;
    position:sticky !important;
    top:72px !important;
    z-index:1000001 !important;
    grid-column:1 / -1 !important;
    width:100% !important;
    min-height:42px !important;
    border-radius:14px !important;
    font-size:14px !important;
    font-weight:900 !important;
    padding:8px 10px !important;
  }
  body:has(#view-room.active) #new-hand[data-live-phase="bidding"],
  body:has(#view-room.active) #new-hand[data-live-phase="kitty"],
  body:has(#view-room.active) #new-hand[data-live-phase="playing"],
  body:has(#view-room.active) #new-hand[data-live-phase="trick-complete"] {
    display:none !important;
  }
}

/* -------------------------------------------------------------------------
   Phase 31 mobile/lobby cleanup
   ------------------------------------------------------------------------- */
.mobile-live-deal { display:none; }
.live-room-list li small { display:block; margin-top:4px; color:#9aa6bd; }
.live-room-list-item .live-room-actions button { white-space:nowrap; }

@media (max-width: 800px) {
  /* Reliable phone-only deal/start button. This is separate from the desktop
     header button because the desktop control is heavily rearranged on phones. */
  body:has(#view-room.active).rook-live-mode #mobile-live-deal.show {
    display:flex !important;
    align-items:center !important;
    justify-content:center !important;
    position:fixed !important;
    left:14px !important;
    right:14px !important;
    bottom:calc(env(safe-area-inset-bottom, 0px) + 18px) !important;
    z-index:2147483640 !important;
    min-height:54px !important;
    border-radius:18px !important;
    font-size:17px !important;
    font-weight:950 !important;
    letter-spacing:.01em !important;
    box-shadow:0 16px 45px rgba(0,0,0,.55), 0 0 0 2px rgba(33, 255, 142, .35) inset !important;
  }

  /* Give the phone hand cards more height and tap area. Keep one horizontal
     swipe row so the cards do not stack and hide behind Safari controls. */
  .phase-bidding .pos-bottom .hand .card,
  .phase-kitty .pos-bottom .hand .card,
  .phase-play .pos-bottom .hand .card,
  .table.phase-bidding .seat.pos-bottom .hand .card,
  .table.phase-kitty .seat.pos-bottom .hand .card,
  .table.phase-play .seat.pos-bottom .hand .card {
    width:clamp(56px, 16.5vw, 72px) !important;
    aspect-ratio:.66 !important;
    border-radius:9px !important;
  }
  .phase-bidding .pos-bottom .hand .card .center-frame,
  .phase-kitty .pos-bottom .hand .card .center-frame,
  .phase-play .pos-bottom .hand .card .center-frame,
  .table.phase-bidding .seat.pos-bottom .hand .card .center-frame,
  .table.phase-kitty .seat.pos-bottom .hand .card .center-frame,
  .table.phase-play .seat.pos-bottom .hand .card .center-frame {
    width:31px !important;
    height:44px !important;
  }
  .phase-bidding .pos-bottom .hand .card .face-rank,
  .phase-kitty .pos-bottom .hand .card .face-rank,
  .phase-play .pos-bottom .hand .card .face-rank,
  .table.phase-bidding .seat.pos-bottom .hand .card .face-rank,
  .table.phase-kitty .seat.pos-bottom .hand .card .face-rank,
  .table.phase-play .seat.pos-bottom .hand .card .face-rank {
    font-size:36px !important;
  }
  .phase-bidding .pos-bottom .hand .card .corner .r,
  .phase-kitty .pos-bottom .hand .card .corner .r,
  .phase-play .pos-bottom .hand .card .corner .r,
  .table.phase-bidding .seat.pos-bottom .hand .card .corner .r,
  .table.phase-kitty .seat.pos-bottom .hand .card .corner .r,
  .table.phase-play .seat.pos-bottom .hand .card .corner .r {
    font-size:12px !important;
  }
  .phase-bidding .pos-bottom .hand,
  .phase-kitty .pos-bottom .hand,
  .phase-play .pos-bottom .hand,
  .table.phase-bidding .seat.pos-bottom .hand,
  .table.phase-kitty .seat.pos-bottom .hand,
  .table.phase-play .seat.pos-bottom .hand {
    gap:8px !important;
    padding-bottom:10px !important;
  }

  /* Lobby cleanup: live room list should be the primary middle panel. */
  body:has(#view-lobby.active) .live-room-list-item {
    display:flex !important;
    flex-direction:column !important;
  }
  body:has(#view-lobby.active) .live-room-actions .primary {
    width:100% !important;
  }
}


/* Phase 33 live lobby polish */
.live-seat-grid{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:6px;margin-top:10px}
.live-seat-pick{border:1px solid rgba(96,165,250,.45);border-radius:10px;background:rgba(15,23,42,.75);color:#dbeafe;padding:8px 6px;display:flex;flex-direction:column;align-items:center;gap:2px;min-height:48px;cursor:pointer}
.live-seat-pick.open{box-shadow:0 0 0 1px rgba(34,197,94,.25) inset}
.live-seat-pick.open:hover{border-color:#22c55e;background:rgba(20,83,45,.45)}
.live-seat-pick.taken{opacity:.55;cursor:not-allowed;border-color:rgba(148,163,184,.3)}
.live-seat-pick span{font-size:11px;max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.live-room-list-item.warn{border-color:#fbbf24}
.live-leaderboard-panel #leaderboard li{opacity:.96}
@media(max-width:760px){.live-seat-grid{grid-template-columns:repeat(2,minmax(0,1fr))}.live-seat-pick{min-height:54px;font-size:14px}}
.live-seat-pick.ai-open{box-shadow:0 0 0 1px rgba(250,204,21,.28) inset;border-color:rgba(250,204,21,.55);background:rgba(113,63,18,.34)}
.live-seat-pick.ai-open:hover{border-color:#facc15;background:rgba(113,63,18,.55)}


/* Phase 36 Colyseus-native lobby helpers */
.live-room-list-item.maybe-stale{outline:1px dashed rgba(255,209,102,.45);outline-offset:2px}


/* -------------------------------------------------------------------------
   Phase 37 mobile card size presets
   User-selectable phone hand cards: Normal / Large / XL. This only changes
   the South/player hand dock on phones; center table trick cards stay smaller.
   ------------------------------------------------------------------------- */
.mobile-card-size-control{
  display:none;
}
.mobile-card-size-control button.active{
  background:#4f7cff;
  color:white;
  border-color:#84a6ff;
  box-shadow:0 0 0 1px rgba(255,255,255,.14) inset,0 0 18px rgba(79,124,255,.28);
}

@media (max-width:800px){
  body.mobile-card-normal{
    --rook-mobile-hand-dock-h:128px;
    --rook-mobile-table-bottom:146px;
    --rook-mobile-card-min:56px;
    --rook-mobile-card-vw:16.2vw;
    --rook-mobile-card-max:70px;
    --rook-mobile-card-ratio:.66;
    --rook-mobile-card-gap:8px;
    --rook-mobile-frame-w:31px;
    --rook-mobile-frame-h:44px;
    --rook-mobile-rank-font:36px;
    --rook-mobile-corner-font:12px;
    --rook-mobile-color-font:6px;
    --rook-mobile-hand-label:12px;
  }
  body.mobile-card-large{
    --rook-mobile-hand-dock-h:162px;
    --rook-mobile-table-bottom:184px;
    --rook-mobile-card-min:70px;
    --rook-mobile-card-vw:20vw;
    --rook-mobile-card-max:88px;
    --rook-mobile-card-ratio:.65;
    --rook-mobile-card-gap:10px;
    --rook-mobile-frame-w:40px;
    --rook-mobile-frame-h:56px;
    --rook-mobile-rank-font:46px;
    --rook-mobile-corner-font:15px;
    --rook-mobile-color-font:8px;
    --rook-mobile-hand-label:14px;
  }
  body.mobile-card-xl{
    --rook-mobile-hand-dock-h:194px;
    --rook-mobile-table-bottom:218px;
    --rook-mobile-card-min:82px;
    --rook-mobile-card-vw:24vw;
    --rook-mobile-card-max:104px;
    --rook-mobile-card-ratio:.64;
    --rook-mobile-card-gap:12px;
    --rook-mobile-frame-w:48px;
    --rook-mobile-frame-h:66px;
    --rook-mobile-rank-font:54px;
    --rook-mobile-corner-font:17px;
    --rook-mobile-color-font:9px;
    --rook-mobile-hand-label:15px;
  }

  body:has(#view-room.active){
    padding-bottom:calc(var(--rook-mobile-table-bottom, 184px) + var(--safe-bottom)) !important;
  }
  body:has(#view-room.active) #view-room .table-layout{
    padding-bottom:calc(var(--rook-mobile-table-bottom, 184px) + var(--safe-bottom)) !important;
  }

  .mobile-card-size-control{
    display:flex !important;
    grid-column:1 / -1 !important;
    align-items:center !important;
    justify-content:center !important;
    gap:6px !important;
    margin-top:6px !important;
    padding:5px !important;
    border:1px solid rgba(96,165,250,.28) !important;
    border-radius:14px !important;
    background:rgba(10,16,27,.72) !important;
  }
  .mobile-card-size-control span{
    color:#9fb4d6 !important;
    font-size:12px !important;
    font-weight:800 !important;
    margin-right:2px !important;
  }
  .mobile-card-size-control button{
    min-height:28px !important;
    padding:5px 8px !important;
    border-radius:10px !important;
    border:1px solid rgba(96,165,250,.38) !important;
    background:rgba(15,23,42,.86) !important;
    color:#dbeafe !important;
    font-size:12px !important;
    font-weight:850 !important;
    line-height:1 !important;
  }

  .phase-bidding .pos-bottom,
  .phase-kitty .pos-bottom,
  .phase-play .pos-bottom,
  .table.phase-bidding .seat.pos-bottom,
  .table.phase-kitty .seat.pos-bottom,
  .table.phase-play .seat.pos-bottom{
    min-height:var(--rook-mobile-hand-dock-h, 162px) !important;
    max-height:var(--rook-mobile-hand-dock-h, 162px) !important;
    padding:8px 8px 10px !important;
    bottom:calc(8px + var(--safe-bottom)) !important;
  }

  .table.phase-bidding .center,
  .table.phase-kitty .center{
    bottom:calc(var(--rook-mobile-hand-dock-h, 162px) + 16px + var(--safe-bottom)) !important;
  }

  .phase-bidding .pos-bottom::before,
  .phase-kitty .pos-bottom::before,
  .phase-play .pos-bottom::before,
  .table.phase-bidding .seat.pos-bottom::before,
  .table.phase-kitty .seat.pos-bottom::before,
  .table.phase-play .seat.pos-bottom::before{
    font-size:var(--rook-mobile-hand-label, 14px) !important;
    margin-bottom:7px !important;
  }

  .phase-bidding .pos-bottom .hand,
  .phase-kitty .pos-bottom .hand,
  .phase-play .pos-bottom .hand,
  .table.phase-bidding .seat.pos-bottom .hand,
  .table.phase-kitty .seat.pos-bottom .hand,
  .table.phase-play .seat.pos-bottom .hand{
    gap:var(--rook-mobile-card-gap, 10px) !important;
    padding:2px 8px 12px !important;
    overflow-x:auto !important;
    overflow-y:hidden !important;
    align-items:flex-start !important;
  }

  .phase-bidding .pos-bottom .hand .card,
  .phase-kitty .pos-bottom .hand .card,
  .phase-play .pos-bottom .hand .card,
  .table.phase-bidding .seat.pos-bottom .hand .card,
  .table.phase-kitty .seat.pos-bottom .hand .card,
  .table.phase-play .seat.pos-bottom .hand .card{
    width:clamp(var(--rook-mobile-card-min, 70px), var(--rook-mobile-card-vw, 20vw), var(--rook-mobile-card-max, 88px)) !important;
    height:auto !important;
    aspect-ratio:var(--rook-mobile-card-ratio, .65) !important;
    border-radius:10px !important;
    margin:0 !important;
  }
  .phase-bidding .pos-bottom .hand .card .center-frame,
  .phase-kitty .pos-bottom .hand .card .center-frame,
  .phase-play .pos-bottom .hand .card .center-frame,
  .table.phase-bidding .seat.pos-bottom .hand .card .center-frame,
  .table.phase-kitty .seat.pos-bottom .hand .card .center-frame,
  .table.phase-play .seat.pos-bottom .hand .card .center-frame{
    width:var(--rook-mobile-frame-w, 40px) !important;
    height:var(--rook-mobile-frame-h, 56px) !important;
  }
  .phase-bidding .pos-bottom .hand .card .face-rank,
  .phase-kitty .pos-bottom .hand .card .face-rank,
  .phase-play .pos-bottom .hand .card .face-rank,
  .table.phase-bidding .seat.pos-bottom .hand .card .face-rank,
  .table.phase-kitty .seat.pos-bottom .hand .card .face-rank,
  .table.phase-play .seat.pos-bottom .hand .card .face-rank{
    font-size:var(--rook-mobile-rank-font, 46px) !important;
  }
  .phase-bidding .pos-bottom .hand .card .corner .r,
  .phase-kitty .pos-bottom .hand .card .corner .r,
  .phase-play .pos-bottom .hand .card .corner .r,
  .table.phase-bidding .seat.pos-bottom .hand .card .corner .r,
  .table.phase-kitty .seat.pos-bottom .hand .card .corner .r,
  .table.phase-play .seat.pos-bottom .hand .card .corner .r{
    font-size:var(--rook-mobile-corner-font, 15px) !important;
  }
  .phase-bidding .pos-bottom .hand .card .card-color-word,
  .phase-kitty .pos-bottom .hand .card .card-color-word,
  .phase-play .pos-bottom .hand .card .card-color-word,
  .table.phase-bidding .seat.pos-bottom .hand .card .card-color-word,
  .table.phase-kitty .seat.pos-bottom .hand .card .card-color-word,
  .table.phase-play .seat.pos-bottom .hand .card .card-color-word{
    font-size:var(--rook-mobile-color-font, 8px) !important;
  }
  .phase-bidding .pos-bottom .hand .card.rook .rook-icon,
  .phase-kitty .pos-bottom .hand .card.rook .rook-icon,
  .phase-play .pos-bottom .hand .card.rook .rook-icon,
  .table.phase-bidding .seat.pos-bottom .hand .card.rook .rook-icon,
  .table.phase-kitty .seat.pos-bottom .hand .card.rook .rook-icon,
  .table.phase-play .seat.pos-bottom .hand .card.rook .rook-icon{
    width:calc(var(--rook-mobile-frame-w, 40px) * .75) !important;
    height:calc(var(--rook-mobile-frame-w, 40px) * .75) !important;
  }

  /* Keep trick/played cards readable but smaller than your hand. */
  .table.phase-play .play .card,
  .trick.reveal-mobile-large .play .card{
    width:min(17vw, 58px) !important;
    height:auto !important;
    aspect-ratio:.70 !important;
  }
}

@media (max-width:430px){
  body.mobile-card-normal{
    --rook-mobile-hand-dock-h:132px;
    --rook-mobile-table-bottom:150px;
    --rook-mobile-card-min:58px;
    --rook-mobile-card-vw:17vw;
    --rook-mobile-card-max:72px;
  }
  body.mobile-card-large{
    --rook-mobile-hand-dock-h:168px;
    --rook-mobile-table-bottom:190px;
    --rook-mobile-card-min:72px;
    --rook-mobile-card-vw:21.5vw;
    --rook-mobile-card-max:90px;
  }
  body.mobile-card-xl{
    --rook-mobile-hand-dock-h:202px;
    --rook-mobile-table-bottom:226px;
    --rook-mobile-card-min:86px;
    --rook-mobile-card-vw:25.5vw;
    --rook-mobile-card-max:106px;
  }
  .mobile-card-size-control{
    gap:4px !important;
    padding:4px !important;
  }
  .mobile-card-size-control span{font-size:11px !important;}
  .mobile-card-size-control button{
    min-height:26px !important;
    padding:4px 6px !important;
    font-size:11px !important;
  }
}

@media (max-height:620px) and (max-width:800px){
  /* Keep very short phone screens playable. XL remains large, but not so tall
     that Safari hides the whole table. */
  body.mobile-card-xl{
    --rook-mobile-hand-dock-h:182px;
    --rook-mobile-table-bottom:204px;
    --rook-mobile-card-min:78px;
    --rook-mobile-card-vw:23vw;
    --rook-mobile-card-max:96px;
  }
}


/* Phase 44 mobile last trick + hand stats scroll fix */
@media (max-width: 800px) {
  body:has(#view-room.active) #view-room .table-layout,
  body.rook-live-mode #view-room.active .table-layout {
    display: flex !important;
    flex-direction: column !important;
    gap: 10px !important;
    padding: 6px 6px calc(var(--rook-mobile-table-bottom, 184px) + 28px + var(--safe-bottom)) !important;
  }

  body:has(#view-room.active) #view-room .table,
  body.rook-live-mode #view-room.active .table {
    order: 2 !important;
    width: 100% !important;
  }

  body:has(#view-room.active) #view-room .score-panel,
  body.rook-live-mode #view-room.active .score-panel {
    display: flex !important;
    order: 3 !important;
    width: 100% !important;
    max-height: none !important;
    overflow: visible !important;
    margin: 10px 0 12px !important;
    padding: 12px !important;
    padding-bottom: 12px !important;
    border-radius: 16px !important;
    background: rgba(15, 18, 24, .98) !important;
    border: 1px solid rgba(82, 255, 143, .18) !important;
    box-shadow: 0 14px 28px rgba(0, 0, 0, .28) !important;
  }

  body:has(#view-room.active) #view-room .score-panel.mobile-score-collapsed > :not(#score-panel-mobile-header):not(#mobile-stats-scroll),
  body.rook-live-mode #view-room.active .score-panel.mobile-score-collapsed > :not(#score-panel-mobile-header):not(#mobile-stats-scroll) {
    display: none !important;
  }

  body:has(#view-room.active) #view-room #mobile-stats-scroll,
  body.rook-live-mode #view-room.active #mobile-stats-scroll {
    display: block !important;
    width: 100% !important;
    margin: 0 0 10px !important;
  }

  body:has(#view-room.active) #view-room .mobile-stats-scroll.hidden,
  body.rook-live-mode #view-room.active .mobile-stats-scroll.hidden {
    display: none !important;
  }

  body:has(#view-room.active) #view-room .mobile-stats-trick-row,
  body.rook-live-mode #view-room.active .mobile-stats-trick-row {
    display: grid !important;
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
    gap: 6px !important;
    align-items: start !important;
  }

  body:has(#view-room.active) #view-room .mobile-stats-trick-seat,
  body.rook-live-mode #view-room.active .mobile-stats-trick-seat {
    min-width: 0 !important;
    padding: 6px 3px !important;
    border: 1px solid rgba(96, 165, 250, .16) !important;
    border-radius: 10px !important;
    background: rgba(9, 16, 27, .52) !important;
  }

  body:has(#view-room.active) #view-room .mobile-stats-trick-seat .card,
  body.rook-live-mode #view-room.active .mobile-stats-trick-seat .card {
    width: clamp(46px, 15vw, 62px) !important;
    height: auto !important;
    aspect-ratio: .70 !important;
    margin: 0 auto !important;
    transform: none !important;
  }

  body:has(#view-room.active) #view-room .mobile-stats-hand-summary,
  body.rook-live-mode #view-room.active .mobile-stats-hand-summary {
    grid-template-columns: 1fr 1fr !important;
    gap: 6px 10px !important;
  }
}

/* Phase 49 live UI privacy/name polish */
body.rook-live-mode .table-seat-overlay { z-index: 28; }
body.rook-live-mode .table.phase-play #table-seat-s { bottom: 80px; }
body.rook-live-mode .table.phase-play #table-seat-n { top: 54px; }
body.rook-live-mode .table.phase-play #table-seat-w { left: 70px; }
body.rook-live-mode .table.phase-play #table-seat-e { right: 70px; }
body.rook-live-mode .table-seat-chip {
  background: rgba(2, 6, 23, .86);
  border-color: rgba(125,165,255,.35);
}
