:root {
  --cw: 56px;
  --ch: 78px;
  --mw: 34px;
  --mh: 47px;
  --glass: rgba(255, 255, 255, .09);
  --glass-b: rgba(255, 255, 255, .16);
  --gold: #ffd36b;
  --accent: #3aa0ff;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none;
  background: radial-gradient(ellipse at 50% 40%, #1d3b57 0%, #10213a 45%, #0a1024 100%) fixed;
  color: #eef3ff;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  touch-action: manipulation;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; }
a { color: inherit; }

#app {
  position: fixed; inset: 0; display: flex; flex-direction: column; overflow: hidden;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.topbar { display: flex; align-items: center; gap: 8px; padding: 8px 10px 4px; font-size: 13px; }
.pill {
  background: var(--glass); border: 1px solid var(--glass-b); border-radius: 999px;
  padding: 5px 11px; white-space: nowrap; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.pill b { color: var(--gold); }
.topbar .spacer { flex: 1; }
.topbar a.pill { text-decoration: none; }

.table { position: relative; flex: 1; min-height: 0; }

.bottom-cards {
  position: absolute; top: 4px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 4px; padding: 5px 8px; border-radius: 12px;
  background: rgba(0, 0, 0, .18); border: 1px solid rgba(255, 255, 255, .08);
}

.seat {
  position: absolute; top: 4px; width: 84px; display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 7px 4px 8px; border-radius: 16px; background: var(--glass); border: 1px solid var(--glass-b);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); transition: box-shadow .25s, border-color .25s;
}
.seat.left { left: 8px; }
.seat.right { right: 8px; }
.seat.active { border-color: var(--gold); box-shadow: 0 0 0 2px rgba(255, 211, 107, .35), 0 0 18px rgba(255, 211, 107, .35); }
.seat .name { font-size: 12px; opacity: .9; }
.badge { font-size: 11px; padding: 1px 7px; border-radius: 999px; background: rgba(255, 255, 255, .14); }
.badge.lord { background: linear-gradient(180deg, #ffcf5a, #e59a12); color: #3a2400; font-weight: 700; }
.badge.farmer { background: linear-gradient(180deg, #62d38a, #23945a); color: #04200f; font-weight: 700; }
.stack { position: relative; width: 38px; height: 52px; }
.stack .back { position: absolute; width: 34px; height: 48px; }
.stack .back:nth-child(2) { left: 2px; top: 2px; }
.stack .back:nth-child(3) { left: 4px; top: 4px; }
.count { font-size: 18px; font-weight: 800; color: var(--gold); line-height: 1; }
.count.warn { color: #ff6b6b; animation: pulse 1s infinite; }
@keyframes pulse { 50% { transform: scale(1.18); } }

.slot {
  position: absolute; display: flex; align-items: center; min-height: var(--mh);
  pointer-events: none;
}
.slot.s1 { right: 8px; top: 150px; justify-content: flex-end; width: 48%; }
.slot.s2 { left: 8px; top: 150px; justify-content: flex-start; width: 48%; }
.slot.s0 { left: 2%; bottom: 8px; justify-content: center; width: 96%; }
.slot .word {
  font-size: 17px; font-weight: 700; padding: 6px 14px; border-radius: 999px;
  background: rgba(0, 0, 0, .28); color: #cfe0ff; letter-spacing: 2px;
}
.slot .word.bid { color: var(--gold); }
.slot .mini-row { display: flex; }
.slot .tag { font-size: 11px; margin: 0 6px; padding: 2px 6px; border-radius: 6px; background: rgba(255, 211, 107, .9); color: #3a2400; font-weight: 700; white-space: nowrap; }
.pop { animation: pop .22s ease-out; }
@keyframes pop { from { transform: scale(.7); opacity: 0; } }
.slot.s0 .pop { animation: pop0 .22s ease-out; }
@keyframes pop0 { from { transform: translateY(20px); opacity: 0; } }

.center-info {
  position: absolute; left: 50%; top: 58%; transform: translate(-50%, -50%);
  text-align: center; font-size: 14px; opacity: .85; pointer-events: none; white-space: nowrap;
}

.card {
  position: relative; width: var(--cw); height: var(--ch); border-radius: calc(var(--cw) * .12);
  background: linear-gradient(180deg, #ffffff, #eef1f6); color: #1b1f2a;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .35), inset 0 0 0 1px rgba(0, 0, 0, .12);
  flex: none;
}
.card.red { color: #d3262e; }
.card .corner {
  position: absolute; left: 3px; top: 2px; display: flex; flex-direction: column; align-items: center;
  line-height: 1; font-weight: 800; font-size: calc(var(--cw) * .3);
}
.card .corner .s { font-size: calc(var(--cw) * .24); margin-top: 1px; }
.card .pip { position: absolute; right: 8%; bottom: 6%; font-size: calc(var(--cw) * .5); line-height: 1; }
.card.ten .corner { letter-spacing: -2px; font-size: calc(var(--cw) * .26); }
.card.joker .corner { font-size: calc(var(--cw) * .2); letter-spacing: 0; }
.card.joker .corner span { display: block; line-height: 1.05; }
.card.joker .pip { font-size: calc(var(--cw) * .56); }
.card.joker.big { color: #d3262e; }
.card.joker.small { color: #1b1f2a; }
.card.mini { width: var(--mw); height: var(--mh); border-radius: 5px; }
.card.mini .corner { font-size: calc(var(--mw) * .34); left: 2px; }
.card.mini .corner .s { font-size: calc(var(--mw) * .28); }
.card.mini.ten .corner { font-size: calc(var(--mw) * .3); }
.card.mini.joker .corner { font-size: calc(var(--mw) * .24); }
.card.mini .pip { font-size: calc(var(--mw) * .46); }
.back {
  border-radius: 5px; border: 2px solid #fff;
  background: repeating-linear-gradient(45deg, #2f6fd6 0 4px, #2559b3 4px 8px);
  box-shadow: 0 1px 4px rgba(0, 0, 0, .4);
}
.bottom-cards .back, .bottom-cards .card { width: 30px; height: 42px; }
.bottom-cards .card { --mw: 30px; }

.actions { display: flex; justify-content: center; gap: 10px; padding: 6px 10px; min-height: 52px; flex-wrap: wrap; }
.btn {
  min-width: 76px; padding: 10px 18px; border-radius: 999px; font-weight: 700; font-size: 16px;
  background: rgba(255, 255, 255, .14); border: 1px solid rgba(255, 255, 255, .22);
  box-shadow: 0 4px 12px rgba(0, 0, 0, .3), inset 0 1px 0 rgba(255, 255, 255, .25);
  transition: transform .08s, opacity .2s;
}
.btn:active { transform: scale(.95); }
.btn.primary { background: linear-gradient(180deg, #3aa0ff, #0a6cff); border-color: transparent; box-shadow: 0 4px 14px rgba(10, 108, 255, .4), inset 0 1px 0 rgba(255, 255, 255, .4); }
.btn.gold { background: linear-gradient(180deg, #ffcf5a, #e59a12); color: #3a2400; border-color: transparent; }
.btn:disabled { opacity: .35; pointer-events: none; }

.hand-wrap { position: relative; height: calc(var(--ch) + 26px); margin-bottom: 6px; touch-action: none; }
.hand-wrap .card { position: absolute; bottom: 4px; transition: transform .12s, left .2s; cursor: pointer; }
.hand-wrap .card.sel { transform: translateY(-18px); box-shadow: 0 6px 14px rgba(0, 0, 0, .45), inset 0 0 0 2px var(--accent); }
.hand-wrap .card.fresh { animation: fresh .6s ease-out; }
@keyframes fresh { 0% { transform: translateY(-26px); box-shadow: 0 0 0 3px var(--gold); } }
.hand-wrap.shake { animation: shake .3s; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

.toast {
  position: fixed; left: 50%; top: 38%; transform: translate(-50%, -50%); z-index: 50;
  background: rgba(10, 12, 30, .82); border: 1px solid var(--glass-b); padding: 10px 18px; border-radius: 14px;
  font-size: 15px; pointer-events: none; opacity: 0; transition: opacity .2s;
}
.toast.show { opacity: 1; }

.overlay {
  position: fixed; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center; padding: 16px;
  background: rgba(4, 8, 20, .55); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.overlay[hidden] { display: none; }
.panel {
  width: min(420px, 100%); max-height: 100%; overflow: auto; text-align: center;
  background: rgba(22, 30, 58, .78); border: 1px solid var(--glass-b); border-radius: 22px;
  padding: 22px 20px; box-shadow: 0 20px 50px rgba(0, 0, 0, .45);
}
.panel h1 { margin: 4px 0 2px; font-size: 30px; letter-spacing: 4px; }
.panel h2 { margin: 2px 0 8px; font-size: 24px; }
.panel .sub { opacity: .75; font-size: 13px; margin-bottom: 12px; }
.panel .rules { text-align: left; font-size: 13px; line-height: 1.65; background: rgba(0, 0, 0, .2); border-radius: 14px; padding: 10px 14px; margin: 10px 0 14px; }
.panel .rules b { color: var(--gold); }
.panel .rec { font-size: 13px; opacity: .85; margin-bottom: 12px; }
.panel .btns { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 8px; }
.panel .link { display: inline-block; margin-top: 12px; font-size: 13px; opacity: .8; }
.panel .small-btn { background: none; font-size: 12px; opacity: .6; text-decoration: underline; margin-top: 8px; }
.result-table { width: 100%; border-collapse: collapse; margin: 8px 0 6px; font-size: 14px; }
.result-table td { padding: 5px 4px; border-bottom: 1px solid rgba(255, 255, 255, .08); }
.result-table td:first-child { text-align: left; }
.result-table td:last-child { text-align: right; font-weight: 700; }
.plus { color: #6be39b; }
.minus { color: #ff7a7a; }
.big-emoji { font-size: 44px; }
.breakdown { font-size: 13px; opacity: .85; }

@media (min-width: 700px) {
  .seat { width: 100px; top: 12px; }
  .seat.left { left: 24px; }
  .seat.right { right: 24px; }
  .slot.s1 { right: 140px; top: 70px; width: calc(50% - 150px); }
  .slot.s2 { left: 140px; top: 70px; width: calc(50% - 150px); }
  .btn { min-width: 96px; }
}
@media (max-height: 520px) {
  .seat { flex-direction: row; width: auto; padding: 4px 8px; }
  .stack { display: none; }
  .slot.s1, .slot.s2 { top: 50px; width: 45%; }
  .slot.s1 { right: 8px; }
  .slot.s2 { left: 8px; }
  .center-info { top: 50%; }
  .panel { padding: 12px 16px; }
  .panel .big-emoji { display: none; }
  .panel .rules { font-size: 12px; line-height: 1.5; margin: 6px 0 8px; }
  .actions { min-height: 44px; padding: 3px; }
  .btn { padding: 7px 14px; }
}
