@import url('admin_styles.css');

: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}

.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}

.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:16px 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;max-height:calc(100dvh - 110px - var(--safe-top) - var(--safe-bottom));overflow:auto}
.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-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);
}

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

.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;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{border-color:#ffd54a; box-shadow:0 0 0 2px rgba(255,213,74,.35), 0 0 14px rgba(255,213,74,.2)}
.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}

/* 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);
}

.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-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}

.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));
  }
  .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 > *{order:5}
  .score-panel > h3:nth-of-type(4){order:1;margin-top:0}
  #hand-history{order:2}
  .score-panel > hr{order:3}
  #end-hand{order:4}
  .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.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%)}
  .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}
  .table-layout > .center{gap:6px}
  .mobile-turn-tracker.show{
    display:flex;
    padding:6px calc(10px + var(--safe-right)) calc(6px + var(--safe-bottom)) calc(10px + var(--safe-left));
  }
  .tracker-item{
    font-size:12px;
  }
  .tracker-value{
    font-size:13px;
    padding:3px 6px;
    min-width:54px;
  }
  .table{min-height:clamp(380px, 52dvh, 520px)}
  .table.phase-play{min-height:clamp(460px, 62dvh, 640px)}
  .seat .seat-name{min-width:96px;max-width:116px;font-size:10px;padding:5px 8px}
  .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 > *{order:5}
  .score-panel > h3:nth-of-type(4){order:1;margin-top:0}
  #hand-history{order:2}
  .score-panel > hr{order:3}
  #end-hand{order:4}
  .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;
}
