/* 干瞪眼 · 木质写实牌桌（移动优先）
   没有图片资源：木纹、灯晕、牌面纸感全部用 CSS 渐变叠出来。
   牌宽用 CSS 变量 + aspect-ratio，字号跟着牌宽缩放。 */

:root {
  --wood-1: #5a3620;
  --wood-2: #3a2211;
  --wood-3: #221306;
  --felt: #17583f;
  --felt-deep: #0d3626;
  --ink: #f4ece1;
  --muted: #bda98f;
  --brass: #d9a441;
  --brass-hi: #ffd98a;
  --danger: #b3261e;
  --panel: rgba(28, 16, 8, 0.72);
  --radius: 12px;

  --card-w: clamp(46px, 14vw, 64px);
  --card-r: calc(var(--card-w) * 0.09);
  --gap: clamp(5px, 1.8vw, 10px);
  --tap: 46px;
}

* { box-sizing: border-box; }

.hidden { display: none !important; }

html { -webkit-text-size-adjust: 100%; height: 100%; }

body {
  margin: 0;
  min-height: 100%;
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
  color: var(--ink);
  overscroll-behavior: none;
  background-color: var(--wood-3);
}

button, .as-button, select, input {
  font: inherit;
  -webkit-tap-highlight-color: transparent;
}

button, .as-button {
  min-height: var(--tap);
  padding: 0 18px;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.1s ease, filter 0.15s ease, opacity 0.15s ease;
}

button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: 0.4; cursor: not-allowed; }

/* 黄铜按钮：暖色金属，像牌桌上的实木/铜件 */
.primary {
  background: linear-gradient(180deg, #f6d488 0%, #dcae4f 42%, #b9822c 100%);
  color: #2b1a06;
  font-weight: 700;
  border-color: #8a5c17;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.45) inset, 0 4px 10px rgba(0, 0, 0, 0.4);
}

.ghost {
  background: linear-gradient(180deg, rgba(255, 240, 220, 0.1), rgba(255, 240, 220, 0.03));
  color: var(--ink);
  border-color: rgba(255, 220, 170, 0.22);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.08) inset;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ===================== 木纹底 ===================== */

.wood-bg {
  background-color: var(--wood-2);
  background-image:
    radial-gradient(110% 70% at 50% -12%, rgba(255, 206, 140, 0.16), transparent 62%),
    repeating-linear-gradient(91deg, rgba(0, 0, 0, 0.1) 0 2px, transparent 2px 6px),
    repeating-linear-gradient(89.4deg, rgba(255, 226, 180, 0.035) 0 1px, transparent 1px 13px),
    linear-gradient(180deg, var(--wood-1), var(--wood-2) 46%, var(--wood-3));
}

/* ===================== 首页 ===================== */

body.home {
  display: flex;
  justify-content: center;
  padding: 22px 16px 44px;
  background-color: var(--wood-2);
  background-image:
    radial-gradient(110% 70% at 50% -12%, rgba(255, 206, 140, 0.14), transparent 62%),
    repeating-linear-gradient(91deg, rgba(0, 0, 0, 0.1) 0 2px, transparent 2px 6px),
    repeating-linear-gradient(89.4deg, rgba(255, 226, 180, 0.035) 0 1px, transparent 1px 13px),
    linear-gradient(180deg, var(--wood-1), var(--wood-2) 46%, var(--wood-3));
}

.home-wrap { width: 100%; max-width: 540px; }

.logo {
  margin: 10px 0 4px;
  font-size: clamp(34px, 12vw, 48px);
  letter-spacing: 0.16em;
  text-indent: 0.16em;
  text-align: center;
  color: #ffe6b0;
  text-shadow: 0 2px 0 #6b4419, 0 0 24px rgba(255, 190, 90, 0.35);
}

.tagline {
  margin: 0 0 22px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

/* 木框里的深色内衬面板，像桌面上嵌的一块板 */
.panel {
  background: linear-gradient(180deg, rgba(24, 13, 5, 0.86), rgba(18, 10, 4, 0.92));
  border: 1px solid rgba(255, 214, 150, 0.16);
  border-radius: var(--radius);
  padding: 16px 18px 18px;
  margin-bottom: 14px;
  box-shadow: 0 1px 0 rgba(255, 220, 170, 0.12) inset, 0 10px 24px rgba(0, 0, 0, 0.35);
}

.panel h2 {
  margin: 0 0 12px;
  font-size: 16px;
  font-weight: 600;
  color: #ffe6b0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel h2::before {
  content: "";
  width: 4px;
  height: 15px;
  border-radius: 2px;
  background: linear-gradient(180deg, var(--brass-hi), var(--brass));
}

.panel.muted p { color: var(--muted); font-size: 13px; line-height: 1.7; margin: 0 0 12px; }

.form { display: grid; gap: 12px; }

.field { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }

select, input[type="text"] {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  min-height: var(--tap);
  padding: 0 34px 0 12px;
  color: var(--ink);
  background-color: rgba(255, 240, 220, 0.06);
  border: 1px solid rgba(255, 214, 150, 0.2);
  border-radius: 9px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35) inset;
}

input[type="text"] { padding-right: 12px; }

select {
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%23bda98f' stroke-width='1.8' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 11px 8px;
}

.code-input {
  letter-spacing: 0.5em;
  text-indent: 0.5em;
  text-align: center;
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.rules {
  background: linear-gradient(180deg, rgba(24, 13, 5, 0.86), rgba(18, 10, 4, 0.92));
  border: 1px solid rgba(255, 214, 150, 0.16);
  border-radius: var(--radius);
  padding: 14px 18px;
}

.rules summary {
  cursor: pointer;
  font-weight: 600;
  min-height: 28px;
  display: flex;
  align-items: center;
  list-style: none;
  color: #ffe6b0;
}

.rules summary::-webkit-details-marker { display: none; }
.rules summary::after { content: "▾"; margin-left: auto; color: var(--muted); font-size: 12px; }
.rules[open] summary::after { content: "▴"; }

.rules-body { margin-top: 10px; font-size: 13px; line-height: 1.8; color: var(--muted); }
.rules-body p { margin: 0 0 6px; }
.rules-body b { color: var(--ink); }

.note { font-size: 12px; color: var(--muted); margin: 8px 0 0; line-height: 1.6; }

/* ===================== 牌桌骨架 ===================== */

body.table-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background-color: var(--wood-2);
  background-image:
    radial-gradient(120% 60% at 50% -8%, rgba(255, 206, 140, 0.16), transparent 60%),
    repeating-linear-gradient(91deg, rgba(0, 0, 0, 0.1) 0 2px, transparent 2px 6px),
    repeating-linear-gradient(89.4deg, rgba(255, 226, 180, 0.03) 0 1px, transparent 1px 13px),
    linear-gradient(180deg, var(--wood-1), var(--wood-2) 46%, var(--wood-3));
}

.hud {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(7px + env(safe-area-inset-top)) 12px 7px;
  font-size: 12px;
  color: var(--muted);
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.34), rgba(0, 0, 0, 0.12));
  border-bottom: 1px solid rgba(255, 214, 150, 0.14);
  flex: none;
}

.back {
  color: var(--muted);
  text-decoration: none;
  min-height: 30px;
  display: flex;
  align-items: center;
  flex: none;
}

.hud-item { white-space: nowrap; }
.hud-turn {
  margin-left: auto;
  color: var(--brass-hi);
  font-weight: 600;
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 牌桌桌面：木框里嵌一块绿绒 */
.table {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px 10px 2px;
  min-height: 0;
  position: relative;
}

.table::before {
  content: "";
  position: absolute;
  left: 8px;
  right: 8px;
  top: 6px;
  bottom: 0;
  border-radius: 18px;
  background:
    radial-gradient(120% 90% at 50% 0%, rgba(255, 236, 200, 0.1), transparent 55%),
    radial-gradient(90% 70% at 50% 40%, var(--felt), var(--felt-deep) 78%),
    var(--felt-deep);
  border: 1px solid rgba(0, 0, 0, 0.45);
  box-shadow:
    0 2px 0 rgba(255, 220, 170, 0.1) inset,
    0 -14px 40px rgba(0, 0, 0, 0.45) inset;
  z-index: 0;
}

.table > * { position: relative; z-index: 1; }

/* ===================== 座位 ===================== */

.seats {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  flex: none;
}

.seat {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px 6px 6px;
  background: linear-gradient(180deg, rgba(28, 16, 8, 0.78), rgba(16, 9, 3, 0.86));
  border: 1px solid rgba(255, 214, 150, 0.14);
  border-radius: 999px;
  box-shadow: 0 1px 0 rgba(255, 220, 170, 0.1) inset, 0 4px 10px rgba(0, 0, 0, 0.35);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  max-width: 46vw;
}

.seat.active {
  border-color: rgba(255, 217, 138, 0.7);
  box-shadow: 0 0 0 1px rgba(255, 217, 138, 0.35), 0 0 20px rgba(255, 190, 80, 0.28);
}

.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: #1c1005;
  background: linear-gradient(160deg, #f3d79c, #c99b45);
  border: 1px solid rgba(255, 240, 210, 0.5);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.5) inset;
  position: relative;
}

.seat.speaking .avatar::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid var(--brass-hi);
  animation: speak-pulse 1s ease-out infinite;
}

@keyframes speak-pulse {
  0% { transform: scale(0.92); opacity: 0.95; }
  100% { transform: scale(1.35); opacity: 0; }
}

.seat-info { display: grid; gap: 1px; min-width: 0; }
.seat-name {
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 26vw;
}
.seat-count { font-size: 10px; color: var(--muted); }

.seat-tag {
  font-size: 10px;
  color: #ffbfae;
  border: 1px solid rgba(255, 160, 140, 0.45);
  border-radius: 20px;
  padding: 0 6px;
  line-height: 1.7;
  flex: none;
}

.seat-tag.muted { color: #9ec3ae; border-color: rgba(158, 195, 174, 0.45); }

/* 中央出牌区 */
.center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 0;
}

.last-play { display: flex; gap: var(--gap); flex-wrap: wrap; justify-content: center; }

.last-label {
  font-size: 12px;
  color: #cbe3d5;
  min-height: 18px;
  text-align: center;
  padding: 3px 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.28);
}

/* ===================== 牌面（写实纸牌） ===================== */

.card {
  position: relative;
  width: var(--card-w);
  aspect-ratio: 5 / 7;
  padding: 0;
  flex: none;
  border-radius: var(--card-r);
  background:
    linear-gradient(157deg, #fffefa 0%, #fbf7ee 46%, #efe7d5 100%);
  border: 1px solid #cfc6b2;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.9) inset,
    0 -1px 0 rgba(150, 130, 100, 0.25) inset,
    0 1px 2px rgba(0, 0, 0, 0.3),
    0 7px 12px -6px rgba(0, 0, 0, 0.7);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  color: #1d1a16;
  transition: transform 0.13s ease, box-shadow 0.13s ease, border-color 0.13s ease;
  overflow: hidden;
}

.card .corner {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 0.92;
  font-weight: 700;
}

.card .corner.tl { top: 3px; left: 4px; }
.card .corner.br { bottom: 3px; right: 4px; transform: rotate(180deg); }

.card .corner b { font-size: calc(var(--card-w) * 0.3); letter-spacing: -0.02em; }
.card .corner i { font-size: calc(var(--card-w) * 0.24); font-style: normal; }

/* 中央大花色，带一点纸面压印感 */
.card .pip {
  position: absolute;
  left: 50%;
  top: 54%;
  transform: translate(-50%, -50%);
  font-size: calc(var(--card-w) * 0.52);
  opacity: 0.9;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.7);
}

.card.red { color: var(--danger); }

.card.wild {
  border-color: #b8862c;
  background:
    linear-gradient(150deg, #fff8e2 0%, #ffe9b4 45%, #f4d189 62%, #fff3cf 78%, #e9c574 100%);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.85) inset,
    0 0 0 1px rgba(184, 134, 44, 0.55) inset,
    0 1px 2px rgba(0, 0, 0, 0.3),
    0 7px 12px -6px rgba(0, 0, 0, 0.7);
}

.card.wild .corner b { font-size: calc(var(--card-w) * 0.26); color: #7a5410; }
.card.wild .corner i { font-size: calc(var(--card-w) * 0.2); color: #8a6114; }
.card.wild .pip {
  font-size: calc(var(--card-w) * 0.34);
  color: #8a6114;
  font-weight: 700;
  opacity: 0.95;
  line-height: 1.05;
  text-align: center;
  width: 100%;
}

.card.selected {
  transform: translateY(-11px);
  border-color: var(--brass-hi);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.9) inset,
    0 0 0 2px rgba(255, 217, 138, 0.85),
    0 12px 20px -8px rgba(0, 0, 0, 0.8),
    0 0 22px rgba(255, 190, 80, 0.35);
}

/* 桌面中央的牌：小一号，只展示，不点 */
.card.mini {
  width: calc(var(--card-w) * 0.8);
  cursor: default;
}
.card.mini:disabled { opacity: 1; }

/* ===================== 手牌区 ===================== */

.handbar {
  flex: none;
  padding: 6px 10px calc(9px + env(safe-area-inset-bottom));
  background: linear-gradient(0deg, rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.16));
  border-top: 1px solid rgba(255, 214, 150, 0.14);
}

.handbar > * {
  width: 100%;
  max-width: 620px;
  margin-left: auto;
  margin-right: auto;
}

.hint {
  min-height: 17px;
  margin-bottom: 2px;
  font-size: 12px;
  color: var(--brass-hi);
  text-align: center;
  line-height: 1.4;
}

.hand {
  display: flex;
  gap: var(--gap);
  justify-content: center;
  align-items: flex-end;
  padding: 12px 2px 13px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.hand::-webkit-scrollbar { display: none; }
.hand .card:disabled { opacity: 0.86; }

.actions {
  display: grid;
  grid-template-columns: 1.2fr 1fr 0.9fr;
  gap: 8px;
}

.actions button { padding: 0 6px; white-space: nowrap; }

/* ===================== 语音 ===================== */

.mic-btn {
  flex: none;
  min-height: 30px;
  height: 30px;
  width: 30px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid rgba(255, 214, 150, 0.28);
  background: rgba(255, 240, 220, 0.08);
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  line-height: 1;
}

.mic-btn.on {
  color: #2b1a06;
  background: linear-gradient(180deg, #f6d488, #cf9c3f);
  border-color: #8a5c17;
  box-shadow: 0 0 0 2px rgba(255, 217, 138, 0.22);
}

.mic-btn.off { color: #d99b8f; }
.mic-btn:disabled { opacity: 0.4; }

.voice-note {
  position: absolute;
  left: 50%;
  bottom: 8px;
  transform: translateX(-50%);
  font-size: 11px;
  color: #ffcfc4;
  background: rgba(0, 0, 0, 0.55);
  border-radius: 999px;
  padding: 2px 10px;
  z-index: 3;
  white-space: nowrap;
}

/* ===================== 弹层 ===================== */

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  z-index: 20;
}

.overlay.hidden { display: none; }

.dialog {
  width: 100%;
  max-width: 420px;
  max-height: 88dvh;
  overflow-y: auto;
  background: linear-gradient(180deg, #2a1a0c, #1a0f05);
  border: 1px solid rgba(255, 214, 150, 0.24);
  border-radius: 16px;
  padding: 18px;
  box-shadow: 0 1px 0 rgba(255, 220, 170, 0.12) inset, 0 24px 60px rgba(0, 0, 0, 0.6);
}

.dialog h3 { margin: 0 0 12px; font-size: 16px; color: #ffe6b0; }

.decl-options { display: grid; gap: 8px; margin-bottom: 12px; }
.decl-options button {
  text-align: left;
  background: rgba(255, 240, 220, 0.08);
  color: var(--ink);
  border-color: rgba(255, 214, 150, 0.2);
  padding: 0 14px;
  white-space: normal;
  line-height: 1.4;
  min-height: 52px;
}

.dialog-actions { display: flex; gap: 10px; margin-top: 14px; }
.dialog-actions > * { flex: 1; }

/* 结算 */
.result-body { display: grid; gap: 8px; font-size: 14px; }

.result-row {
  padding: 9px 12px;
  border-radius: 10px;
  background: rgba(255, 240, 220, 0.06);
  border: 1px solid rgba(255, 214, 150, 0.1);
}

.result-row.winner {
  background: linear-gradient(180deg, rgba(255, 217, 138, 0.18), rgba(255, 190, 80, 0.1));
  border-color: rgba(255, 217, 138, 0.5);
}

.result-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.result-top .name { font-weight: 600; }
.result-detail {
  margin-top: 3px;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.result-top .score { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 16px; }
.result-top .score.neg { color: #ff9b8a; }
.result-top .score.pos { color: var(--brass-hi); }

/* 房间等待面板 */
.seat-list { display: grid; gap: 8px; margin: 12px 0; }
.seat-line {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(255, 240, 220, 0.06);
  border: 1px solid rgba(255, 214, 150, 0.12);
}
.seat-line .grow { flex: 1; min-width: 0; }
.seat-line .tag { font-size: 11px; color: var(--muted); }

.room-code {
  font-size: 34px;
  font-weight: 700;
  letter-spacing: 0.28em;
  text-indent: 0.28em;
  text-align: center;
  color: #ffe6b0;
  margin: 6px 0 2px;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 20px rgba(255, 190, 90, 0.35);
}

/* ===================== 手机细节 ===================== */

@media (max-width: 640px) {
  .overlay { align-items: flex-end; padding: 0; }
  .dialog {
    max-width: none;
    max-height: 90dvh;
    border-radius: 18px 18px 0 0;
    padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
    animation: sheet-up 0.18s ease-out;
  }
  @keyframes sheet-up {
    from { transform: translateY(12px); opacity: 0.6; }
    to { transform: translateY(0); opacity: 1; }
  }
  .table { gap: 8px; }
  .card .corner.br { display: none; }
}

@media (max-height: 620px) {
  .hand { padding: 8px 2px 9px; }
  .card.selected { transform: translateY(-7px); }
  .center { gap: 6px; }
  .card .pip { font-size: calc(var(--card-w) * 0.44); }
}

@media (min-width: 900px) and (min-height: 700px) {
  :root { --card-w: 66px; --gap: 10px; }
  .table { gap: 18px; padding: 16px; }
  .center { flex: 0 1 auto; min-height: 150px; }
  .seat { padding: 8px 14px 8px 8px; }
  .avatar { width: 36px; height: 36px; font-size: 15px; }
  .handbar { padding: 10px 16px 16px; }
  .hand { padding: 14px 4px 16px; }
  .actions { display: flex; justify-content: center; gap: 10px; }
  .actions button { min-width: 100px; }
  .overlay { align-items: center; padding: 24px; }
  .dialog { border-radius: 16px; }
}