:root {
  color-scheme: dark;
  --felt: #0f6a40;
  --felt-deep: #08482b;
  --gold: #e6c98a;
  --gold-deep: #a67c3d;
  --ink: #24180f;
  --cream: #fbf6ea;
  --burgundy: #6e1824;
  --paper: #fffdf8;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", sans-serif;
  background:
    radial-gradient(circle at 50% 0%, #4a2b22 0%, #1a100d 42%, #0c0908 100%);
  color: var(--cream);
}

button { font: inherit; }

.text-button,
.primary {
  cursor: pointer;
  border-radius: 999px;
  padding: 8px 16px;
}

.text-button {
  color: var(--gold);
  background: transparent;
  border: 1px solid rgba(230, 201, 138, 0.7);
}

.text-button.dark {
  color: var(--burgundy);
  border-color: var(--gold-deep);
}

.primary {
  border: 1px solid #8d6a2e;
  background: linear-gradient(#f4dd9f, #c49645);
  color: #3a2710;
  font-weight: 700;
}

.primary.xl {
  padding: 14px 42px;
  font-size: 22px;
  letter-spacing: 0.08em;
}

button:disabled { opacity: 0.5; cursor: default; }

#title-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  background:
    radial-gradient(circle at 50% 40%, rgba(140, 42, 52, 0.45), transparent 36%),
    radial-gradient(circle at 50% 100%, #2a0d12, #10080a 70%);
}

.corner-help {
  position: absolute;
  top: 22px;
  right: 22px;
}

.title-wrap {
  text-align: center;
  padding: 24px;
}

.fan {
  position: relative;
  height: 118px;
  margin-bottom: 8px;
}

.fan .card {
  position: absolute;
  left: 50%;
  top: 10px;
}

.tilt-a { transform: translateX(-78px) rotate(-16deg); }
.tilt-b { transform: translateX(-28px) rotate(-2deg); }
.tilt-c { transform: translateX(22px) rotate(14deg); }

.eyebrow {
  margin: 0;
  letter-spacing: 0.42em;
  color: var(--gold);
}

h1 {
  margin: 8px 0 0;
  font-family: "PMingLiU", "Palatino Linotype", "Microsoft JhengHei", serif;
  font-size: 68px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.tagline {
  margin: 8px 0 28px;
  color: #f0dcb8;
}

#game-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 18px 0;
}

.brand {
  font-family: "PMingLiU", "Microsoft JhengHei", serif;
  font-size: 28px;
  letter-spacing: 0.12em;
  color: var(--gold);
}

.top-actions { display: flex; gap: 8px; }

#pause-banner {
  align-self: center;
  margin-top: 8px;
  padding: 4px 14px;
  border: 1px solid var(--gold);
  border-radius: 999px;
  color: var(--gold);
  background: rgba(0, 0, 0, 0.35);
}

#status-line {
  min-height: 28px;
  text-align: center;
  padding: 8px 16px 0;
  color: #f7edd8;
}

.stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 12px 0;
}

.table {
  position: relative;
  width: min(1080px, 100%);
  height: min(640px, calc(100vh - 230px));
  min-height: 560px;
  border-radius: 220px / 170px;
  background:
    radial-gradient(ellipse at 50% 45%, #1d8a55 0%, var(--felt) 42%, var(--felt-deep) 78%);
  border: 12px solid #6b3e22;
  box-shadow:
    inset 0 0 0 4px #d7b56a,
    inset 0 0 80px rgba(0, 0, 0, 0.28),
    0 18px 40px rgba(0, 0, 0, 0.35);
}

.seat {
  position: absolute;
  color: #f7f1e4;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.55);
}

.seat-top { top: 16px; left: 50%; width: 430px; transform: translateX(-50%); }
.seat-bottom { bottom: 14px; left: 50%; width: 460px; transform: translateX(-50%); }
.seat-left { left: 16px; top: 50%; width: 236px; transform: translateY(-50%); }
.seat-right { right: 16px; top: 50%; width: 236px; transform: translateY(-50%); }

.meta, .who {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
}

.chips {
  text-align: center;
  font-size: 14px;
  color: #ffe7a8;
}

.dealer {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--gold);
  color: #4a3010;
  font-size: 13px;
  text-shadow: none;
}

.badge {
  padding: 0 6px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.35);
  font-size: 12px;
}

.card-box {
  margin-top: 4px;
  padding: 6px 6px 4px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.16);
}

.stake {
  text-align: center;
  font-size: 13px;
  color: #fff4d2;
}

.hand, .pile-cards, .piles {
  display: flex;
  justify-content: center;
  gap: 6px;
}

.hand { min-height: 68px; }

.piles { align-items: flex-end; }

.pile {
  padding: 4px;
  border-radius: 10px;
}

.pile.won {
  box-shadow: inset 0 0 0 2px var(--gold);
  background: rgba(230, 201, 138, 0.16);
}

.pile-name {
  text-align: center;
  font-size: 12px;
  line-height: 1.3;
  margin-bottom: 3px;
}

.seat.is-turn .name { color: #fff1b8; }
.seat.is-folded, .seat.is-out { opacity: 0.72; }

.card {
  position: relative;
  display: block;
  width: 46px;
  height: 66px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: var(--paper);
  color: #1c1c1c;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.28);
  user-select: none;
  appearance: none;
  font: inherit;
  text-align: left;
}

.seat-bottom .card { width: 68px; height: 98px; }
.seat-bottom .hand { min-height: 98px; }

.card.red { color: #c52828; }
.card.selectable { cursor: pointer; }
.card.selected {
  transform: translateY(-8px);
  box-shadow: 0 10px 16px rgba(0, 0, 0, 0.28), 0 0 0 3px #e6c36a;
}

.card.back {
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.16), transparent 40%),
    repeating-linear-gradient(45deg, #8d2432 0 7px, #641722 7px 14px);
  border: 2px solid #f0d48a;
  box-shadow: inset 0 0 0 4px rgba(90, 16, 24, 0.65), 0 2px 4px rgba(0, 0, 0, 0.28);
}

.corner {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1;
  font-weight: 700;
}

.corner b, .corner i { font-style: normal; }
.corner.top { top: 3px; left: 4px; }
.corner.bot { right: 4px; bottom: 3px; transform: rotate(180deg); }
.seat-bottom .corner b { font-size: 16px; }
.card[data-rank="10"] .corner b { font-size: 12px; }

.face { position: absolute; inset: 16px 6px; }
.seat-bottom .face { inset: 22px 8px; }

.pip {
  position: absolute;
  width: 14px;
  height: 14px;
  margin-left: -7px;
  margin-top: -7px;
  text-align: center;
  line-height: 14px;
}

.seat-bottom .pip { width: 18px; height: 18px; margin-left: -9px; margin-top: -9px; line-height: 18px; font-size: 16px; }
.pip.inv { transform: rotate(180deg); }

.ace, .court {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
}

.seat-bottom .ace, .seat-bottom .court { font-size: 34px; }
.court small { font-size: 0.45em; margin-left: 2px; }

.center {
  position: absolute;
  left: 50%;
  top: 46%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  gap: 22px;
}

#dice-anchor {
  position: absolute;
  right: calc(100% + 18px);
  top: 50%;
  transform: translateY(-50%);
}

.dice-row { display: flex; gap: 8px; }

.die {
  width: 48px;
  height: 48px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 6px;
  border-radius: 8px;
  background: #f7f4ef;
  box-shadow: inset 0 0 0 1px #d9d0c3, 0 4px 8px rgba(0, 0, 0, 0.25);
}

.die i {
  width: 8px;
  height: 8px;
  margin: auto;
  border-radius: 50%;
}

.die i.dot { background: #222; }

#pot-box, #deck-box { text-align: center; }
.round, .pot-label, .deck-count { font-size: 13px; color: #f4e5c4; }
.pot-value {
  font-size: 28px;
  color: #fff6d4;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.3);
}

.deck-stack .card { margin: 0 auto; }

#log {
  min-height: 22px;
  padding: 4px 18px 0;
  text-align: center;
  color: rgba(247, 236, 216, 0.8);
  font-size: 13px;
}

#log div { line-height: 1.45; }

#action-bar {
  min-height: 96px;
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  padding: 8px 16px 18px;
}

#action-bar p { margin: 0; }
#action-bar input {
  width: 84px;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid var(--gold);
  background: #fffaf0;
  color: var(--ink);
  font: inherit;
}

.form-error { color: #ffb4b4; }

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(8, 5, 4, 0.46);
}

.overlay.top { z-index: 40; }
#help { z-index: 50; }

.panel {
  width: min(640px, 100%);
  max-height: min(82vh, 820px);
  overflow: auto;
  padding: 22px 24px 18px;
  border-radius: 16px;
  background: var(--cream);
  color: var(--ink);
  border: 2px solid var(--gold-deep);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
}

.help-panel { width: min(760px, 100%); }
.panel h2, .panel h3 { margin: 0 0 8px; font-family: "PMingLiU", "Microsoft JhengHei", serif; }
.panel h3 { margin-top: 16px; }
.panel p, .panel li { line-height: 1.65; }
.panel-head { display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.final-chips { font-size: 22px; font-weight: 700; }

body.is-paused #action-bar button { pointer-events: none; opacity: 0.45; }

@media (max-width: 980px) {
  h1 { font-size: 46px; }
  .table { border-radius: 36px; min-height: 720px; height: auto; }
  .seat-left, .seat-right, .seat-top, .seat-bottom {
    position: static;
    transform: none;
    width: auto;
    margin: 10px auto;
  }
  .center { position: static; transform: none; margin: 12px auto; width: fit-content; }
  #dice-anchor { position: static; transform: none; }
}
