:root {
  color-scheme: dark;
  --felt: #1c6b4c;
  --felt-deep: #0d3d2b;
  --page: #08150f;
  --panel: #10241b;
  --line: rgba(255, 255, 255, 0.12);
  --ink: #f4f1e8;
  --muted: #9db3a6;
  --gold: #f0c36a;
  --red: #e05a4f;
  --mine: #4aa3c4;
  --theirs: #d4737a;
  font-family: "Iowan Old Style", Palatino, "Songti SC", "PingFang SC", serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 50% -20%, #14362a, transparent 55%),
    var(--page);
}

main {
  width: min(1080px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 14px 14px 28px;
  display: flex;
  flex-direction: column;
}

/* ---------- 顶栏 ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 2px 2px 10px;
}

.brand {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 0.06em;
  line-height: 1;
}

.meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-left: auto;
}

.who { font-size: 14px; color: var(--muted); }

.chip {
  font: 600 13px/1 ui-monospace, "SF Mono", Menlo, monospace;
  letter-spacing: 0.08em;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--line);
  color: var(--ink);
}

.chip.gold {
  background: rgba(240, 195, 106, 0.16);
  border-color: rgba(240, 195, 106, 0.5);
  color: var(--gold);
}

.chip.watching { background: rgba(74, 163, 196, 0.2); border-color: var(--mine); color: #bfe6f5; }

.score {
  font-size: 13px;
  color: var(--muted);
  margin: 0 0 10px;
}

.score b { color: var(--ink); font-weight: 600; }
.score .ours { color: var(--mine); }
.score .theirs { color: var(--theirs); }

/* ---------- 牌桌 ---------- */

.table {
  position: relative;
  display: grid;
  grid-template-columns: 132px 1fr 132px;
  grid-template-rows: auto 1fr auto;
  gap: 10px;
  margin-top: 12px;
  padding: 16px;
  /* 桌面上一屏放得下就把中间的空白让给牌桌，别在手牌下面留一条空带 */
  flex: 1 1 auto;
  border-radius: 26px;
  background:
    radial-gradient(ellipse at 50% 42%, #2a8560 0%, var(--felt) 42%, var(--felt-deep) 100%);
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, 0.07),
    inset 0 0 60px rgba(0, 0, 0, 0.45),
    0 20px 44px rgba(0, 0, 0, 0.4);
}

.table::after {
  content: "";
  position: absolute;
  inset: 10px;
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  pointer-events: none;
}

/* 座位牌 */

.seat {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 9px;
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.32);
  border: 1px solid transparent;
  white-space: nowrap;
}

.seat.north { grid-column: 1 / -1; grid-row: 1; justify-self: center; }
.seat.west { grid-column: 1; grid-row: 2; align-self: center; }
.seat.east { grid-column: 3; grid-row: 2; align-self: center; justify-self: end; }
.seat.south { grid-column: 1 / -1; grid-row: 3; justify-self: center; }

/* 两侧座位窄，改成竖排，牌背放在文字下面，不压字 */
.seat.west, .seat.east {
  flex-direction: column;
  align-items: flex-start;
  gap: 5px;
  padding: 9px 10px;
}
.seat.east { align-items: flex-end; }
.seat.west .dir, .seat.east .dir { margin-left: 0; }
.seat.west .backs, .seat.east .backs { margin-left: 0; }

.avatar {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 15px;
  color: #101f18;
}

.seat.ours .avatar { background: var(--mine); }
.seat.theirs .avatar { background: var(--theirs); }
.seat.watching .avatar { background: #d9c9a6; color: #23301f; }
.seat.empty .avatar { background: rgba(255, 255, 255, 0.16); color: rgba(255, 255, 255, 0.5); }

.seat .seat-text { display: block; min-width: 0; }
.seat .who-name { font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 5px; }
.seat .count { font-size: 12px; color: var(--muted); display: block; }
.seat .dir { font-size: 11px; color: var(--muted); margin-left: auto; }
.seat .me-badge {
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 5px;
  background: var(--gold);
  color: #2b2113;
  font-weight: 700;
}
.seat .last-mark {
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.14);
  color: var(--muted);
}
.seat .act-mark {
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 5px;
  background: #fff;
  color: #16301f;
  font-weight: 700;
}
.seat.active { border-color: rgba(255, 255, 255, 0.75); background: rgba(255, 255, 255, 0.14); }
.seat.active .avatar { box-shadow: 0 0 0 2px #fff; }
.seat.offline { opacity: 0.5; }
.seat.done .avatar { box-shadow: 0 0 0 2px var(--gold); }

/* 桌沿的牌背 */

.backs { display: flex; margin-left: 4px; }
.back {
  width: 13px;
  height: 19px;
  margin-left: -6px;
  border-radius: 3px;
  background: linear-gradient(135deg, #2b4a6b, #16283f);
  border: 1px solid rgba(255, 255, 255, 0.22);
}
.back:first-child { margin-left: 0; }

/* 桌面中央：出牌堆 */

.pile {
  grid-column: 2;
  grid-row: 2;
  position: relative;
  z-index: 1;
  justify-self: center;
  align-self: center;
  width: 100%;
  max-width: 380px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
  min-height: 150px;
  padding: 10px;
  border-radius: 18px;
  background: rgba(0, 0, 0, 0.13);
  border: 1px dashed rgba(255, 255, 255, 0.14);
}

/* 观战的时候没有手牌，牌桌撑满中间那块空白 */
.table.watch { flex: 1; }

.pile-label { font-size: 12px; color: var(--gold); letter-spacing: 0.04em; white-space: nowrap; }
.pile-empty { font-size: 13px; color: rgba(255, 255, 255, 0.42); }
.pile-cards { display: flex; justify-content: center; }
.pile-cards .card + .card { margin-left: -22px; }
/* 上一手：淡一点，别跟桌上现在压着的牌混起来 */
.pile-cards.dim { opacity: 0.42; }

/* ---------- 出牌流水 ---------- */

.logrow {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  align-items: center;
  margin-top: 10px;
  padding: 8px 12px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.24);
  border: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
}
.logitem { display: inline-flex; align-items: center; gap: 4px; }
.logitem b { color: var(--ink); font-weight: 600; }
.logitem.pass { opacity: 0.55; }
.logtag {
  font-size: 10px;
  padding: 0 4px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.12);
  color: var(--muted);
}
.logkind { color: var(--gold); }
/* 这几条要压得住后面的 .card.mini（34×48），不然流水行能把手机一屏撑爆：
   同特异度时写在后面的赢，所以这里写得更具体。 */
.logrow .logitem .card { width: 24px; height: 34px; border-radius: 4px; }
.logrow .logitem .card .rank { font-size: 10px; }
.logrow .logitem .card .corner-suit { font-size: 8px; }
.logrow .logitem .card .center-suit { font-size: 14px; }
.logrow .logitem .card .corner-flip { right: 2px; bottom: 2px; }
.logrow .logitem .card .corner-flip .rank { font-size: 8px; }
.logrow .logitem .card .corner-flip .corner-suit { font-size: 6px; }

.turn {
  font-size: 15px;
  font-weight: 600;
  color: var(--gold);
  text-align: center;
}

/* ---------- 牌 ---------- */

.card {
  position: relative;
  width: 46px;
  height: 66px;
  flex: 0 0 auto;
  border: 0;
  border-radius: 7px;
  background: #fffdf8;
  color: #1b2430;
  box-shadow: 0 3px 7px rgba(0, 0, 0, 0.28);
  padding: 4px 5px;
  text-align: left;
}

.card .rank {
  display: block;
  font: 700 15px/1 ui-monospace, "SF Mono", Menlo, monospace;
}
.card .corner-suit {
  display: block;
  font-size: 12px;
  line-height: 1;
  margin-top: 1px;
}
.card .center-suit {
  position: absolute;
  left: 50%;
  top: 52%;
  transform: translate(-50%, -50%);
  font-size: 27px;
  line-height: 1;
  opacity: 0.3;
}
/* 右下角倒过来的点数，跟真牌一样，缩到小尺寸也认得出花色 */
.card .corner-flip {
  position: absolute;
  right: 4px;
  bottom: 3px;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1;
  transform: rotate(180deg);
}
.card .corner-flip .rank { font-size: 12px; }
.card .corner-flip .corner-suit { font-size: 9px; margin-top: 1px; }
.card .wild-mark {
  position: absolute;
  right: 3px;
  top: 3px;
  font-size: 10px;
  font-weight: 700;
  color: #2b2113;
  background: var(--gold);
  border-radius: 4px;
  padding: 0 3px;
}
.card.red { color: var(--red); }
.card.wild { box-shadow: 0 0 0 2px var(--gold), 0 3px 7px rgba(0, 0, 0, 0.28); }
/* 大王小王两个字，牌面小，得缩一号才排得开 */
.card.joker .rank { font-size: 13px; letter-spacing: -0.5px; }
.card.mini.joker .rank { font-size: 9px; }
.card.mini { width: 34px; height: 48px; }
.card.mini .rank { font-size: 12px; }
.card.mini .corner-suit { font-size: 10px; }
.card.mini .center-suit { font-size: 18px; }
.card.mini .corner-flip { right: 2px; bottom: 2px; }
.card.mini .corner-flip .rank { font-size: 9px; }
.card.mini .corner-flip .corner-suit { font-size: 7px; }
.card.mini .wild-mark { font-size: 8px; padding: 0 2px; }
.card.flat { cursor: default; }

/* ---------- 手牌 ---------- */

.handwrap {
  margin-top: 12px;
  padding: 16px 12px 22px;
  border-radius: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
}

.handwrap.mine {
  border-color: rgba(240, 195, 106, 0.55);
  box-shadow: 0 0 0 1px rgba(240, 195, 106, 0.25);
}

.handhead {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 10px;
}

.handhead b { font-size: 14px; font-weight: 600; }
.handhead span { font-size: 12px; color: var(--muted); }

.hand {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(46px, 1fr));
  gap: 6px;
  justify-items: center;
  padding-top: 16px;
  margin-top: -10px;
  /* 后面不能再写一条 .hand，否则这条留白会被盖掉，最后一行又贴到按钮上。 */
  padding-bottom: 120px;
}

.hand .card { width: 46px; cursor: pointer; }
.hand .card:hover { transform: translateY(-4px); }
.hand .card.selected {
  transform: translateY(-14px);
  box-shadow: 0 0 0 2px #7fc4e0, 0 10px 16px rgba(0, 0, 0, 0.4);
}

/* ---------- 操作 ---------- */

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
  position: sticky;
  bottom: 0;
  padding: 12px 0 10px;
  /* 吸在底下的按钮条别把最后一手牌盖成半截，底色压实一点 */
  background: linear-gradient(to top, var(--page) 93%, transparent);
}

/* 提示语、错误语、结算语跟按钮一起吸在底下，手牌再多也盖不住 */
.actions .note {
  flex: 1 0 100%;
  order: -1;
  margin: 0 0 2px;
  min-height: 0;
}

.actions button {
  flex: 1;
  padding: 15px 12px;
  border: 0;
  border-radius: 14px;
  font: 600 16px/1 inherit;
  cursor: pointer;
}

.actions .primary { background: var(--gold); color: #2b2113; }
.actions .secondary { background: rgba(255, 255, 255, 0.1); color: var(--ink); }
.actions button:disabled { background: rgba(255, 255, 255, 0.06); color: rgba(255, 255, 255, 0.3); cursor: not-allowed; }

.tablebar { display: flex; justify-content: flex-end; margin-bottom: 8px; }
.tablebar button {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  border-radius: 999px;
  padding: 7px 16px;
  font: 600 13px/1 inherit;
  cursor: pointer;
}
.tablebar button:disabled { opacity: 0.35; cursor: not-allowed; }
.replay-btn {
  display: inline-block;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  border-radius: 999px;
  padding: 7px 16px;
  font: 600 13px/1 inherit;
  text-decoration: none;
}

.note { min-height: 1.3em; margin: 10px 2px 0; font-size: 13px; color: var(--muted); }
.note.err { color: #ffb4ac; }
.note a, .chip { text-decoration: none; }

/* 回放：四家的牌都亮出来，一步一步看 */
.replay { display: grid; gap: 12px; margin-top: 8px; }
.replay-seat {
  padding: 8px 10px;
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--line);
}
.replay-seat.done { opacity: 0.55; }
.replay-who { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 6px; }
.replay-who span { color: var(--muted); }
.replay-cards { display: flex; flex-wrap: wrap; gap: 4px; }
.replay-cards .card { width: 28px; height: 40px; }
.replay-cards .card .rank { font-size: 11px; }
.replay-cards .card .corner-suit { font-size: 9px; }
.replay-cards .card .center-suit { font-size: 16px; }
.replay-cards .card .corner-flip { display: none; }
.replay .pile { min-height: 84px; }
.wild-note { color: var(--gold); }

/* ---------- 大厅 ---------- */

.lobby {
  max-width: 560px;
  margin: 6vh auto 0;
  display: grid;
  gap: 12px;
}

.lobby h1 { font-size: 30px; margin: 0 0 4px; letter-spacing: 0.06em; }
.lobby .lede { margin: 0 0 6px; color: var(--muted); font-size: 14px; line-height: 1.6; }

.entry {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
}

.entry.primary { border-color: rgba(240, 195, 106, 0.45); }
.entry h2 { margin: 0 0 4px; font-size: 16px; font-weight: 650; }
.entry p { margin: 0 0 12px; font-size: 13px; color: var(--muted); }
.entry form { display: flex; gap: 8px; flex-wrap: wrap; }
.entry input {
  flex: 1 1 140px;
  min-width: 0;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.28);
  color: var(--ink);
  border-radius: 11px;
  padding: 12px 14px;
  font: inherit;
}
.entry button {
  border: 0;
  border-radius: 11px;
  padding: 12px 20px;
  font: 600 15px/1 inherit;
  background: var(--gold);
  color: #2b2113;
  cursor: pointer;
}
.entry.secondary button { background: rgba(255, 255, 255, 0.12); color: var(--ink); }

@media (max-width: 640px) {
  main { padding: 12px 12px 24px; }
  .brand { font-size: 22px; }
  .meta { margin-left: 0; width: 100%; }
  .table { grid-template-columns: 104px 1fr 104px; padding: 12px; border-radius: 20px; }
  /* 手机上一屏要放得下牌桌、流水和 27 张手牌，别让最后一张掉到屏幕外 */
  .pile { min-height: 84px; padding: 6px; }
  .table { gap: 8px; }
  .logrow { margin-top: 8px; padding: 6px 10px; }
  .handwrap { padding: 12px 10px 14px; }
  .card { width: 44px; height: 52px; }
  .card .center-suit { font-size: 22px; }
  .hand { grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 5px; }
  .hand .card { width: 44px; }
  /* 按钮的点击目标别小于 44px */
  .tablebar button { padding: 12px 18px; }
  .pile-label { font-size: 11px; }
  .seat { padding: 6px 7px; gap: 6px; }
  .seat .dir { display: none; }
  .avatar { width: 30px; height: 30px; font-size: 13px; }
  .entry button { flex: 1 1 100%; }
}
