:root {
  --felt-1: #12664a;
  --felt-2: #0a3b2a;
  --felt-3: #05231a;
  --gold: #e8c66a;
  --team-a: #4a90d9;
  --team-b: #d9534f;
  --cw: 54px;
  --ch: 76px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", system-ui, -apple-system, sans-serif;
  background: var(--felt-3);
  color: #eef5f1;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button {
  font-family: inherit;
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, .25);
  background: rgba(255, 255, 255, .1);
  color: #eef5f1;
  padding: 7px 14px;
  font-size: 14px;
  transition: background .15s, transform .1s, opacity .15s;
}
button:hover { background: rgba(255, 255, 255, .2); }
button:active { transform: translateY(1px); }
button:disabled { opacity: .4; cursor: not-allowed; }
button.primary { background: linear-gradient(180deg, #e8c66a, #cfa63f); color: #3a2a05; border: none; font-weight: 700; }
button.primary:hover { background: linear-gradient(180deg, #f2d47e, #d9b04a); }
button.warn { background: rgba(217, 83, 79, .8); border-color: rgba(255, 255, 255, .3); }
button.warn:hover { background: rgba(217, 83, 79, 1); }
button.ghost { padding: 6px 12px; font-size: 13px; }

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ---------- top bar ---------- */
.topbar {
  height: 54px;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  background: linear-gradient(180deg, #0d3a2a, #092b20);
  border-bottom: 1px solid rgba(232, 198, 106, .25);
  z-index: 20;
}
.brand {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 2px;
  color: var(--gold);
  text-shadow: 0 2px 6px rgba(0, 0, 0, .6);
}
.brand span { color: #fff; }
.stats { display: flex; gap: 10px; margin-left: 8px; }
.stat {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  border-radius: 20px;
  background: rgba(0, 0, 0, .28);
  border: 1px solid rgba(255, 255, 255, .1);
  font-size: 13px;
}
.stat .label { opacity: .75; }
.stat .value { font-weight: 800; font-size: 16px; }
.stat.team-a { border-color: rgba(74, 144, 217, .6); }
.stat.team-a .value { color: #8fc1f2; }
.stat.team-b { border-color: rgba(217, 83, 79, .6); }
.stat.team-b .value { color: #f0938f; }
.actions { margin-left: auto; display: flex; gap: 8px; }

/* ---------- table ---------- */
.table {
  position: relative;
  flex: 1 1 auto;
  margin: 10px;
  border-radius: 24px;
  background:
    radial-gradient(ellipse at 50% 42%, var(--felt-1) 0%, var(--felt-2) 55%, var(--felt-3) 100%);
  box-shadow: inset 0 0 80px rgba(0, 0, 0, .55), 0 10px 30px rgba(0, 0, 0, .5);
  border: 2px solid rgba(232, 198, 106, .18);
  overflow: hidden;
}
.table::after {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(45deg, rgba(255,255,255,.012) 0 2px, transparent 2px 4px);
  pointer-events: none;
}

/* ---------- seats ---------- */
.seat {
  position: absolute;
  width: 104px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transform: translate(-50%, -50%);
  z-index: 5;
  transition: opacity .3s;
}
.seat .avatar {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 19px;
  font-weight: 800;
  background: radial-gradient(circle at 35% 30%, #1d4c39, #0e2c20);
  border: 2px solid rgba(255, 255, 255, .3);
}
.seat.team-a .avatar { border-color: var(--team-a); color: #a9cdf5; }
.seat.team-b .avatar { border-color: var(--team-b); color: #f3a6a2; }
.seat.turn .avatar {
  box-shadow: 0 0 0 3px rgba(232, 198, 106, .85), 0 0 18px rgba(232, 198, 106, .8);
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(232, 198, 106, .85), 0 0 12px rgba(232, 198, 106, .6); }
  50% { box-shadow: 0 0 0 3px rgba(232, 198, 106, 1), 0 0 22px rgba(232, 198, 106, .95); }
}
.seat .name { font-size: 13px; font-weight: 700; text-shadow: 0 1px 4px #000; }
.seat .count {
  font-size: 11px;
  padding: 1px 8px;
  border-radius: 10px;
  background: rgba(0, 0, 0, .4);
  border: 1px solid rgba(255, 255, 255, .15);
}
.seat .badges { display: flex; gap: 4px; }
.badge {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 8px;
  background: rgba(0, 0, 0, .45);
  border: 1px solid rgba(255, 255, 255, .2);
  white-space: nowrap;
}
.badge.open { background: rgba(232, 198, 106, .9); color: #3a2a05; border-color: transparent; font-weight: 700; }
.badge.four { background: rgba(217, 83, 79, .92); color: #fff; border-color: transparent; font-weight: 700; }
.badge.pass { background: rgba(120, 120, 120, .6); }
.badge.finish { background: rgba(74, 144, 217, .9); border-color: transparent; font-weight: 700; }
.seat.team-b .badge.finish { background: rgba(217, 83, 79, .9); }
.seat.done { opacity: .62; }

/* seat positions */
.seat.pos-0 { left: 50%; top: 90%; }
.seat.pos-1 { left: 86%; top: 73%; }
.seat.pos-2 { left: 86%; top: 27%; }
.seat.pos-3 { left: 50%; top: 10%; }
.seat.pos-4 { left: 14%; top: 27%; }
.seat.pos-5 { left: 14%; top: 73%; }

/* ---------- play slots ---------- */
.play-area { position: absolute; inset: 0; pointer-events: none; z-index: 4; }
.play-slot {
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-height: 20px;
}
.play-slot .pile { display: flex; justify-content: center; }
.play-slot .pile .card { --cw: 34px; --ch: 48px; margin-left: -16px; }
.play-slot .pile .card:first-child { margin-left: 0; }
.play-slot .slot-label {
  font-size: 10px;
  color: rgba(255, 255, 255, .75);
  text-shadow: 0 1px 3px #000;
}
.tag {
  font-size: 12px;
  font-weight: 700;
  padding: 2px 10px;
  border-radius: 10px;
  background: rgba(0, 0, 0, .45);
  border: 1px solid rgba(255, 255, 255, .2);
}
.tag.pass { color: #cccccc; }
.tag.finish { background: rgba(232, 198, 106, .9); color: #3a2a05; border-color: transparent; }
.play-slot.standing .pile .card { box-shadow: 0 0 0 2px rgba(232, 198, 106, .9), 0 3px 10px rgba(0,0,0,.5); }

.slot-0 { left: 50%; top: 70%; }
.slot-1 { left: 72%; top: 58%; }
.slot-2 { left: 72%; top: 42%; }
.slot-3 { left: 50%; top: 30%; }
.slot-4 { left: 28%; top: 42%; }
.slot-5 { left: 28%; top: 58%; }

/* ---------- log ---------- */
.log-panel {
  position: absolute;
  right: 12px;
  bottom: 12px;
  width: 218px;
  height: 190px;
  display: flex;
  flex-direction: column;
  background: rgba(4, 18, 13, .9);
  border: 1px solid rgba(255, 255, 255, .16);
  border-radius: 10px;
  overflow: hidden;
  z-index: 30;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .5);
}
.log-panel.collapsed { display: none; }
.log-title {
  font-size: 11px;
  letter-spacing: 1px;
  padding: 5px 10px;
  color: var(--gold);
  border-bottom: 1px solid rgba(255, 255, 255, .1);
  flex: 0 0 auto;
}
.log-list {
  padding: 6px 10px;
  overflow-y: auto;
  font-size: 11.5px;
  line-height: 1.55;
  color: rgba(235, 245, 240, .9);
}
.log-list div { margin-bottom: 2px; }
.log-list div:last-child { color: #fff; font-weight: 600; }

/* ---------- toast ---------- */
.toast {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) scale(.9);
  padding: 10px 22px;
  border-radius: 10px;
  background: rgba(0, 0, 0, .8);
  border: 1px solid var(--gold);
  color: var(--gold);
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 15;
}
.toast.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }

/* ---------- cards ---------- */
.card {
  position: relative;
  width: var(--cw);
  height: var(--ch);
  flex: 0 0 auto;
  border-radius: 6px;
  background: linear-gradient(160deg, #ffffff, #eef0f2);
  border: 1px solid rgba(0, 0, 0, .28);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .45);
  color: #1b1b1b;
  overflow: hidden;
}
.card.red { color: #cf2b28; }
.card .c-rank {
  position: absolute;
  top: 3px;
  left: 4px;
  font-size: calc(var(--cw) * 0.30);
  font-weight: 800;
  line-height: 1;
}
.card .c-suit {
  position: absolute;
  top: calc(var(--cw) * 0.32 + 3px);
  left: 4px;
  font-size: calc(var(--cw) * 0.26);
  line-height: 1;
}
.card .c-big {
  position: absolute;
  right: 3px;
  bottom: 1px;
  font-size: calc(var(--cw) * 0.66);
  opacity: .3;
  line-height: 1;
}
.card.joker .c-joker {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--cw) * 0.30);
  font-weight: 800;
  letter-spacing: 1px;
  writing-mode: vertical-rl;
}
.card.joker { background: linear-gradient(160deg, #fffdf3, #f3ead0); }
.card.joker.sj { color: #2b2b2b; }
.card.joker.bj { color: #cf2b28; }
.card .c-wild {
  position: absolute;
  top: 2px;
  right: 2px;
  font-size: 9px;
  line-height: 12px;
  padding: 0 3px;
  border-radius: 4px;
  background: linear-gradient(180deg, #d9a72e, #b8860b);
  color: #fff;
  font-weight: 700;
}
.card.wild { box-shadow: 0 1px 3px rgba(0, 0, 0, .45), inset 0 0 0 1px rgba(184, 134, 11, .8); }
.hand .card.locked { opacity: .38; cursor: not-allowed; }
.hand .card.force-four { box-shadow: 0 0 0 2px var(--gold), 0 0 14px rgba(232, 198, 106, .9); }
.card.back {
  background:
    repeating-linear-gradient(45deg, #1a3f6b 0 5px, #12304f 5px 10px);
  border: 1px solid var(--gold);
}

/* ---------- hand bar ---------- */
.hand-bar {
  flex: 0 0 auto;
  height: 182px;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, rgba(9, 43, 32, .2), rgba(5, 23, 17, .95));
  border-top: 1px solid rgba(232, 198, 106, .2);
  padding: 4px 12px 10px;
}
.hand-meta {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 2px 4px;
  font-size: 12.5px;
  min-height: 22px;
}
.hand-count { color: var(--gold); font-weight: 700; }
.tip { color: rgba(255, 255, 255, .8); }
.sel-preview { margin-left: auto; font-size: 12.5px; font-weight: 600; color: rgba(255, 255, 255, .85); }
.sel-preview.good { color: var(--gold); }
.sel-preview.bad { color: #f0938f; }
.hand {
  flex: 1 1 auto;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  overflow-x: auto;
  overflow-y: visible;
  padding: 26px 8px 6px;
  scrollbar-width: thin;
}
.hand .card {
  margin-left: -28px;
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease;
}
.hand .card:first-child { margin-left: 0; }
.hand .card:hover { transform: translateY(-10px); }
.hand .card.selected {
  transform: translateY(-20px);
  box-shadow: 0 0 0 2px var(--gold), 0 8px 16px rgba(0, 0, 0, .55);
}
.hand .card.selected:hover { transform: translateY(-20px); }
.hand .card.dim { opacity: .55; }
.controls {
  display: flex;
  justify-content: center;
  gap: 10px;
  padding-top: 4px;
}
.controls button { min-width: 84px; }

/* ---------- modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .66);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.modal.hidden { display: none; }
.modal-box {
  width: min(560px, 92vw);
  max-height: 84vh;
  overflow-y: auto;
  background: linear-gradient(180deg, #103526, #0a2319);
  border: 1px solid rgba(232, 198, 106, .45);
  border-radius: 16px;
  padding: 22px 24px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .6);
}
.modal-box h2 {
  margin: 0 0 14px;
  color: var(--gold);
  font-size: 21px;
  letter-spacing: 1px;
}
.modal-body { font-size: 14px; line-height: 1.75; color: rgba(240, 247, 243, .95); }
.modal-body h3 { color: var(--gold); font-size: 15px; margin: 16px 0 6px; }
.modal-body ul { margin: 6px 0; padding-left: 20px; }
.modal-body p { margin: 6px 0; }
.modal-body .rank-row { display: flex; justify-content: space-between; padding: 6px 10px; border-radius: 8px; margin-bottom: 4px; background: rgba(255,255,255,.05); }
.modal-body .rank-row.win { background: rgba(232, 198, 106, .18); border: 1px solid rgba(232, 198, 106, .5); }
.modal-body .rank-row .who { font-weight: 700; }
.modal-body .team-a-text { color: #8fc1f2; }
.modal-body .team-b-text { color: #f0938f; }
.modal-body label { display: flex; align-items: center; gap: 10px; margin: 10px 0; cursor: pointer; }
.modal-body input[type="range"] { flex: 1; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

@media (max-width: 900px) {
  :root { --cw: 46px; --ch: 64px; }
  .log-panel { display: none; }
  .seat.pos-1 { left: 88%; }
  .seat.pos-2 { left: 88%; }
  .seat.pos-4 { left: 12%; }
  .seat.pos-5 { left: 12%; }
}
@media (max-width: 640px) {
  :root { --cw: 40px; --ch: 56px; }
  .brand { font-size: 16px; }
  .stat { padding: 4px 8px; }
  .actions button { padding: 5px 8px; font-size: 12px; }
  .seat { width: 76px; }
  .seat .avatar { width: 40px; height: 40px; font-size: 15px; }
  .controls button { min-width: 62px; padding: 6px 8px; }
}
