:root {
  --felt: #178a48;
  --felt-2: #0d6b36;
  --felt-3: #0a552b;
  --wood-1: #c4894c;
  --wood-2: #8a5328;
  --wood-3: #5c3216;
  --card-w: 68px;
  --card-h: 96px;
  --font: "Noto Sans SC", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --display: "ZCOOL QingKe HuangYou", "Noto Sans SC", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  color: #f6e7cf;
  font-family: var(--font);
  background: #1a110c;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 80% 45% at 50% 0%, rgba(180,110,50,.28), transparent 60%),
    repeating-linear-gradient(
      95deg,
      rgba(255,255,255,.02) 0 1px,
      transparent 1px 9px
    ),
    linear-gradient(#26180f, #120c09);
  z-index: -1;
}

#app {
  width: min(430px, 100%);
  margin: 0 auto;
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  gap: 6px;
}

.topbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: end;
  gap: 8px;
  padding: 4px 2px;
}
.room-tag {
  font-size: 11px;
  line-height: 1.2;
  color: #e2c39a;
  background: #3a2415;
  border: 1px solid #7a5230;
  padding: 5px 8px;
  border-radius: 3px;
}
.brand {
  margin: 0;
  font-family: var(--display);
  font-size: 30px;
  line-height: 1;
  letter-spacing: 4px;
  color: #ffd76a;
  text-align: center;
  text-shadow: 0 2px 0 #4a2a0e, 0 0 12px rgba(255,180,40,.25);
}
.scoreboard {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 11px;
}
.scoreboard span {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 72px;
  background: #2b1a10;
  border: 1px solid #5d3b22;
  border-radius: 3px;
  padding: 2px 6px;
  color: #cbb396;
}
.scoreboard i { font-style: normal; color: #f0d2a0; }
.scoreboard b {
  color: #ffcc4d;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.table-wrap { min-height: 0; }

/* 木框椭圆桌 */
.table-rail {
  height: 100%;
  min-height: min(620px, calc(100dvh - 150px));
  padding: 14px 12px;
  border-radius: 48% / 28%;
  background:
    repeating-linear-gradient(
      120deg,
      rgba(255,220,170,.12) 0 2px,
      transparent 2px 7px
    ),
    linear-gradient(160deg, var(--wood-1), var(--wood-2) 42%, var(--wood-3));
  box-shadow:
    inset 0 2px 0 rgba(255,230,190,.35),
    inset 0 -3px 0 rgba(0,0,0,.28),
    0 14px 28px rgba(0,0,0,.45);
}

.felt {
  position: relative;
  height: 100%;
  min-height: min(590px, calc(100dvh - 170px));
  border-radius: 48% / 28%;
  overflow: hidden;
  background:
    radial-gradient(ellipse 70% 55% at 50% 42%, rgba(255,255,255,.08), transparent 60%),
    radial-gradient(ellipse 90% 80% at 50% 50%, var(--felt), var(--felt-2) 55%, var(--felt-3)),
    var(--felt-2);
  box-shadow:
    inset 0 0 0 3px rgba(20, 60, 30, .45),
    inset 0 0 50px rgba(0,0,0,.28);
}

.felt::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='120' height='120' filter='url(%23n)' opacity='.08'/%3E%3C/svg%3E");
  opacity: .45;
  pointer-events: none;
  mix-blend-mode: soft-light;
}

.felt-mark {
  position: absolute;
  left: 50%;
  top: 48%;
  transform: translate(-50%, -50%);
  font-family: var(--display);
  font-size: 58px;
  color: rgba(0,0,0,.1);
  letter-spacing: 10px;
  pointer-events: none;
  z-index: 0;
}

.pot {
  position: absolute;
  left: 50%;
  top: 45%;
  transform: translate(-50%, -50%);
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  min-width: 78px;
  padding: 7px 14px 8px;
  background: rgba(8, 36, 20, .78);
  border: 1px solid rgba(255, 205, 100, .4);
  border-radius: 4px;
}
.pot-label {
  font-size: 11px;
  color: #c7e6d2;
  letter-spacing: 3px;
}
.pot strong {
  font-size: 22px;
  color: #ffe082;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
}

.seat {
  position: absolute;
  z-index: 3;
  width: 128px;
}
.seat-bot0 { left: 6px; top: 8%; }
.seat-bot1 { right: 6px; top: 8%; }
.seat-you {
  left: 50%;
  bottom: 3%;
  transform: translateX(-50%);
  width: min(320px, 92%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.you-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 100%;
}

.plate {
  display: grid;
  grid-template-columns: 36px 1fr;
  column-gap: 6px;
  row-gap: 1px;
  align-items: center;
  background: rgba(16, 10, 6, .62);
  border: 1px solid rgba(255,220,160,.14);
  border-radius: 4px;
  padding: 4px 6px;
  margin-bottom: 6px;
  backdrop-filter: blur(2px);
}
.plate.self { margin: 0; width: 148px; }
.seat-bot1 .plate { direction: rtl; }
.seat-bot1 .plate .meta,
.seat-bot1 .plate .status { direction: ltr; text-align: right; }

.face {
  width: 36px;
  height: 36px;
  border-radius: 4px;
  grid-row: 1 / span 2;
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(0,0,0,.35);
}
.face::before {
  content: "";
  position: absolute;
  inset: 0;
}
.face::after {
  position: absolute;
  left: 0; right: 0; bottom: 2px;
  text-align: center;
  font-size: 11px;
  font-weight: 800;
  color: #fff8e7;
  text-shadow: 0 1px 0 rgba(0,0,0,.45);
}
.face-a::before {
  background:
    radial-gradient(circle at 50% 42%, #f0c7a0 0 38%, transparent 39%),
    linear-gradient(#5d4037 0 38%, #6d4c41 38% 100%);
}
.face-a::after { content: "强"; }
.face-b::before {
  background:
    radial-gradient(circle at 50% 42%, #e8b992 0 38%, transparent 39%),
    linear-gradient(#37474f 0 38%, #455a64 38% 100%);
}
.face-b::after { content: "王"; }
.face-you::before {
  background:
    radial-gradient(circle at 50% 42%, #f3c9a4 0 38%, transparent 39%),
    linear-gradient(#bf360c 0 38%, #d84315 38% 100%);
}
.face-you::after { content: "我"; }

.meta .name { font-size: 13px; font-weight: 800; color: #fff1d6; }
.meta .chips {
  font-size: 12px;
  color: #ffd54f;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}
.meta .chips::before {
  content: "币";
  display: inline-block;
  margin-right: 3px;
  font-size: 10px;
  color: #ffe082;
  background: #8d6e14;
  border-radius: 2px;
  padding: 0 3px;
  vertical-align: 1px;
}
.status {
  grid-column: 2;
  font-size: 11px;
  color: #a5d6a7;
  min-height: 14px;
}

.hand {
  display: flex;
  justify-content: center;
  gap: 3px;
  min-height: calc(var(--card-h) * 0.72);
  perspective: 700px;
}
.seat-you .hand {
  gap: 5px;
  min-height: var(--card-h);
}

.card {
  width: var(--card-w);
  height: var(--card-h);
  border-radius: 4px;
  position: relative;
  transform-style: preserve-3d;
  transition: transform .28s ease;
  box-shadow: 0 3px 7px rgba(0,0,0,.38);
}
.card.small {
  --card-w: 46px;
  --card-h: 66px;
  width: var(--card-w);
  height: var(--card-h);
}
.card .face, .card .back {
  position: absolute;
  inset: 0;
  border-radius: 4px;
  backface-visibility: hidden;
  overflow: hidden;
}
.card .back {
  background:
    radial-gradient(circle at 50% 50%, rgba(255,255,255,.12), transparent 45%),
    repeating-linear-gradient(45deg, #1a237e 0 5px, #303f9f 5px 10px);
  border: 1px solid #c9a227;
}
.card .back::before {
  content: "";
  position: absolute;
  inset: 4px;
  border: 1px solid rgba(255, 213, 79, .4);
  border-radius: 2px;
}
.card .face {
  background: #fffdf7;
  color: #212121;
  transform: rotateY(180deg);
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: 4px 5px;
  border: 1px solid #d2c5ad;
}
.card.red .face { color: #c62828; }
.card.black .face { color: #212121; }
.card .corner {
  font-size: 11px;
  font-weight: 800;
  line-height: 1.05;
}
.card .corner .suit { display: block; font-size: 11px; }
.card .center-suit {
  display: grid;
  place-items: center;
  font-size: 22px;
}
.card .corner.br {
  justify-self: end;
  align-self: end;
  transform: rotate(180deg);
}
.card.flipped { transform: rotateY(180deg); }
.card.folded { filter: grayscale(.85) brightness(.72); opacity: .58; }
.card.winner-glow { box-shadow: 0 0 0 2px #ffeb3b, 0 3px 7px rgba(0,0,0,.38); }

.bet-chip {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  min-width: 38px;
  padding: 1px 7px;
  border-radius: 10px;
  background: #b71c1c;
  border: 1px solid #ffcc80;
  color: #fff8e1;
  font-size: 11px;
  text-align: center;
  font-weight: 800;
}
.seat-bot0 .bet-chip,
.seat-bot1 .bet-chip { top: calc(100% + 2px); }
.seat-you .bet-chip { bottom: 50px; }

.deck-pile {
  position: absolute;
  left: 50%;
  top: 17%;
  width: 40px;
  height: 56px;
  transform: translateX(-50%);
  border-radius: 3px;
  background: repeating-linear-gradient(45deg, #1a237e 0 5px, #303f9f 5px 10px);
  border: 1px solid #c9a227;
  box-shadow: 3px 3px 0 rgba(0,0,0,.22), 6px 6px 0 rgba(0,0,0,.12);
  z-index: 1;
}

.fly-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 20;
}
.fly-card {
  position: absolute;
  width: 46px;
  height: 66px;
  border-radius: 3px;
  background: repeating-linear-gradient(45deg, #1a237e 0 5px, #303f9f 5px 10px);
  border: 1px solid #c9a227;
  box-shadow: 0 6px 12px rgba(0,0,0,.35);
  transition: transform .4s cubic-bezier(.2,.75,.2,1), opacity .18s ease;
  will-change: transform;
}

.hint {
  position: absolute;
  left: 50%;
  top: 58%;
  transform: translate(-50%, -50%);
  z-index: 4;
  margin: 0;
  text-align: center;
  color: rgba(230, 245, 232, .9);
  font-size: 12px;
  text-shadow: 0 1px 2px rgba(0,0,0,.45);
  pointer-events: none;
  max-width: 80%;
}

.dock {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 5px;
  width: 100%;
  max-width: 300px;
  padding: 5px;
  background: rgba(20, 12, 8, .72);
  border: 1px solid rgba(255, 210, 140, .28);
  border-radius: 6px;
  box-shadow: 0 4px 10px rgba(0,0,0,.28);
  z-index: 16;
}

.act {
  appearance: none;
  border: 0;
  border-radius: 4px;
  min-height: 36px;
  min-width: 56px;
  padding: 7px 10px;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 800;
  color: #fff;
  background: #5d4037;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.12), inset 0 -2px 0 rgba(0,0,0,.28);
  cursor: pointer;
}
.act:active { transform: translateY(1px); filter: brightness(.96); }
.act:disabled { opacity: .4; cursor: not-allowed; }
.act.start {
  background: linear-gradient(#ffd54f, #f9a825);
  color: #4e342e;
}
.act.call { background: linear-gradient(#66bb6a, #2e7d32); }
.act.raise { background: linear-gradient(#ffa726, #ef6c00); }
.act.compare { background: linear-gradient(#42a5f5, #1565c0); }
.act.fold { background: linear-gradient(#ef5350, #c62828); }
.act.wide { width: 100%; }

.rub-overlay,
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(12, 6, 2, .78);
  display: grid;
  place-items: center;
  padding: 16px;
}
.rub-overlay[hidden],
.modal[hidden] { display: none !important; }

.rub-panel,
.modal-card {
  width: min(390px, 100%);
  background: #3e2723;
  border: 1px solid #8d6e63;
  border-radius: 8px;
  padding: 12px;
  box-shadow: 0 12px 28px rgba(0,0,0,.5);
}
.rub-title,
.modal-card h2 {
  margin: 0 0 10px;
  text-align: center;
  font-family: var(--display);
  font-size: 22px;
  color: #ffe082;
  font-weight: 400;
}
.rub-stage {
  height: 250px;
  display: grid;
  place-items: center;
  touch-action: none;
  background: #1b5e20;
  border-radius: 6px;
  border: 1px solid rgba(0,0,0,.25);
}
.rub-card {
  width: 148px;
  height: 210px;
  position: relative;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 10px 22px rgba(0,0,0,.4);
}
.rub-face, .rub-back {
  position: absolute;
  inset: 0;
  border-radius: 6px;
}
.rub-face {
  background: #fffdf7;
  color: #212121;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: 12px 14px;
  z-index: 1;
}
.rub-face.red { color: #c62828; }
.rub-face .big {
  display: grid;
  place-items: center;
  font-size: 52px;
}
.rub-face .corner { font-size: 18px; font-weight: 800; line-height: 1.1; }
.rub-face .corner .suit { display: block; }
.rub-face .br { justify-self: end; align-self: end; transform: rotate(180deg); }
.rub-back {
  z-index: 2;
  background: repeating-linear-gradient(45deg, #1a237e 0 7px, #303f9f 7px 14px);
  border: 2px solid #c9a227;
  clip-path: inset(0 0 0 0);
}
.rub-back::after {
  content: "搓";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: var(--display);
  font-size: 44px;
  color: rgba(255, 224, 130, .9);
}
.rub-progress {
  height: 6px;
  border-radius: 2px;
  background: rgba(0,0,0,.35);
  margin: 10px 2px;
  overflow: hidden;
}
.rub-progress i {
  display: block;
  height: 100%;
  width: 0%;
  background: #ffca28;
}
.rub-actions {
  display: grid;
  grid-template-columns: 1fr 1.35fr 1fr;
  gap: 6px;
}

.settle-list {
  list-style: none;
  margin: 0 0 12px;
  padding: 0;
  display: grid;
  gap: 6px;
}
.settle-list li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 4px;
  background: rgba(0,0,0,.28);
}
.settle-list .delta.pos { color: #81c784; font-weight: 800; }
.settle-list .delta.neg { color: #ef9a9a; font-weight: 800; }
.settle-list .meta { color: #bcaaa4; font-size: 12px; margin-top: 2px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 92px;
  transform: translateX(-50%);
  z-index: 120;
  background: rgba(30, 18, 10, .94);
  border: 1px solid #8d6e63;
  color: #fff3e0;
  padding: 8px 14px;
  border-radius: 4px;
  font-size: 13px;
  pointer-events: none;
  white-space: nowrap;
}
.toast[hidden] { display: none !important; }

@media (min-width: 640px) and (orientation: portrait) {
  :root {
    --card-w: 74px;
    --card-h: 104px;
  }
}

/* 横屏手机：按钮贴在自己牌旁，不占右侧栏 */
@media (orientation: landscape) and (max-height: 520px) {
  :root {
    --card-w: 50px;
    --card-h: 70px;
  }

  html, body {
    height: 100%;
    overflow: hidden;
  }

  #app {
    width: 100%;
    max-width: none;
    height: 100dvh;
    min-height: 100dvh;
    max-height: 100dvh;
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    padding:
      max(4px, env(safe-area-inset-top))
      max(8px, env(safe-area-inset-right))
      max(4px, env(safe-area-inset-bottom))
      max(8px, env(safe-area-inset-left));
    gap: 4px;
  }

  .topbar {
    grid-template-columns: auto auto 1fr;
    align-items: center;
    gap: 10px;
    padding: 0 2px;
  }
  .brand {
    font-size: 22px;
    letter-spacing: 2px;
  }
  .room-tag {
    padding: 3px 6px;
    font-size: 10px;
  }
  .scoreboard {
    flex-direction: row;
    justify-self: end;
    gap: 6px;
  }
  .scoreboard span { min-width: 0; }

  .table-wrap {
    min-height: 0;
    height: 100%;
  }

  .table-rail {
    min-height: 0;
    height: 100%;
    padding: 8px 10px;
    border-radius: 36% / 48%;
  }
  .felt {
    min-height: 0;
    height: 100%;
    border-radius: 36% / 48%;
  }
  .felt-mark {
    font-size: 40px;
    letter-spacing: 8px;
    top: 40%;
  }

  .pot {
    top: 36%;
    min-width: 64px;
    padding: 4px 10px 5px;
  }
  .pot strong { font-size: 16px; }
  .pot-label { font-size: 10px; }

  .deck-pile {
    top: 10%;
    width: 32px;
    height: 46px;
  }

  .hint {
    top: 52%;
    font-size: 11px;
  }

  .seat {
    width: 118px;
  }
  .seat-bot0 {
    left: 3%;
    top: 42%;
    transform: translateY(-50%);
  }
  .seat-bot1 {
    right: 3%;
    top: 42%;
    transform: translateY(-50%);
  }

  /* 自己的牌在下，按钮紧贴牌面下方（不在屏幕右侧） */
  .seat-you {
    left: 50%;
    bottom: 1%;
    top: auto;
    transform: translateX(-50%);
    width: min(420px, 78%);
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
  }
  .you-zone {
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    width: 100%;
  }
  .seat-you .hand {
    min-height: var(--card-h);
  }
  .seat-you .dock {
    width: auto;
    max-width: 100%;
    padding: 3px 4px;
    gap: 3px;
    background: rgba(12, 8, 4, .78);
  }
  .seat-you .plate.self {
    position: absolute;
    left: -4px;
    bottom: 36px;
    width: auto;
    margin: 0;
  }
  .seat-you .bet-chip {
    bottom: auto;
    top: -14px;
    left: 50%;
  }

  .act {
    min-height: 30px;
    min-width: 44px;
    padding: 4px 7px;
    font-size: 12px;
  }

  .plate {
    margin-bottom: 4px;
    padding: 3px 5px;
  }
  .face {
    width: 28px;
    height: 28px;
  }
  .meta .name { font-size: 12px; }
  .meta .chips { font-size: 11px; }

  .card.small {
    --card-w: 40px;
    --card-h: 56px;
  }
  .fly-card {
    width: 40px;
    height: 56px;
  }

  .rub-overlay,
  .modal { padding: 8px; }
  .rub-panel {
    width: min(640px, 100%);
    max-height: calc(100dvh - 16px);
    display: grid;
    grid-template-columns: 1fr 160px;
    grid-template-rows: auto 1fr auto;
    gap: 8px 10px;
    padding: 10px;
  }
  .rub-title {
    grid-column: 1 / -1;
    margin: 0;
    font-size: 18px;
  }
  .rub-stage {
    grid-column: 1;
    grid-row: 2;
    height: auto;
    min-height: 0;
  }
  .rub-card {
    width: min(120px, 28vh);
    height: min(170px, 40vh);
  }
  .rub-progress {
    grid-column: 1;
    grid-row: 3;
    margin: 0;
  }
  .rub-actions {
    grid-column: 2;
    grid-row: 2 / 4;
    display: flex;
    flex-direction: column;
    gap: 6px;
  }
  .rub-actions .act {
    flex: 1;
    min-height: 40px;
  }

  .modal-card {
    width: min(420px, 92vw);
    max-height: calc(100dvh - 20px);
    overflow: auto;
  }

  .toast {
    bottom: 10px;
    left: 50%;
  }
}

/* 较宽横屏（平板横放 / 大屏手机） */
@media (orientation: landscape) and (min-height: 521px) {
  #app {
    width: min(920px, 100%);
  }
  .table-rail,
  .felt {
    border-radius: 40% / 42%;
    min-height: min(520px, calc(100dvh - 100px));
  }
  .seat-bot0 { left: 4%; top: 28%; }
  .seat-bot1 { right: 4%; top: 28%; }
  .seat-you {
    width: min(420px, 70%);
  }
  .you-zone {
    flex-direction: column;
    align-items: center;
    gap: 6px;
  }
  .dock {
    max-width: 360px;
    width: auto;
  }
}
