/* style.css — 移动优先单列布局；≥768px 桌面适配 */

:root {
  --surface: #ffffff;
  --text: #1c2126;
  --muted: #6b7480;
  --border: #d8dee4;
  --accent: #15803d;
  --accent-soft: #e7f6ee;
  --red: #d1332e;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  /* 牌桌毛毡：中央受光、四周渐暗，叠加极淡的编织纹理 */
  background:
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.015) 0 2px, transparent 2px 4px),
    repeating-linear-gradient(-45deg, rgba(0, 0, 0, 0.02) 0 2px, transparent 2px 4px),
    radial-gradient(ellipse 130% 100% at 50% 30%, #2f6e50 0%, #245742 45%, #19402f 100%);
  background-color: #19402f;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button {
  font-family: inherit;
  touch-action: manipulation; /* 防双击缩放 */
  -webkit-tap-highlight-color: transparent;
}

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top));
  background: linear-gradient(180deg, #4a3327 0%, #33221a 100%); /* 皮质围栏 */
  border-bottom: 2px solid rgba(0, 0, 0, 0.35);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
  color: #fff;
}

.topbar h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.badge {
  flex-shrink: 0;
  font-size: 12px;
  line-height: 1;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
  color: #eaf7ef;
  max-width: 60vw;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lang-btn {
  flex-shrink: 0;
  min-height: 44px;
  min-width: 44px;
  padding: 0 10px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: rgba(255, 255, 255, 0.85);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.lang-btn:active { background: rgba(255, 255, 255, 0.12); }

/* ---------- 主体 ---------- */

.container {
  max-width: 520px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}

.panel { margin-bottom: 20px; }

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.section-head h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.78);
  letter-spacing: 0.05em;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

/* 公牌区 = 牌桌主区：毛毡台面 + 木质围栏 */
.table-felt {
  background: radial-gradient(ellipse at 50% 40%, #3b8060 0%, #2d6549 55%, #245239 100%);
  border: 3px solid #61412c;
  border-radius: 16px;
  padding: 12px;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.08),
    inset 0 4px 16px rgba(0, 0, 0, 0.30),
    0 6px 18px rgba(0, 0, 0, 0.35);
}

.table-felt .ghost-btn {
  color: rgba(255, 255, 255, 0.85);
}

.table-felt .ghost-btn:active { background: rgba(255, 255, 255, 0.12); }

/* 毛毡上的空牌位：半透明凹陷轮廓 */
.table-felt .card-slot:not(.filled) {
  border-color: rgba(255, 255, 255, 0.35);
  background: rgba(0, 0, 0, 0.14);
  box-shadow: inset 0 1px 4px rgba(0, 0, 0, 0.25);
}

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

.card-row {
  display: flex;
  gap: 8px;
}

.board-row { justify-content: center; }
.board-row .card-slot { flex: 1; max-width: 50px; height: 64px; }

/* 街道分隔线：翻牌 | 转牌 | 河牌 */
.street-sep {
  flex-shrink: 0;
  align-self: center;
  width: 1px;
  height: 46px;
  margin: 0 4px;
  background: rgba(255, 255, 255, 0.28);
}

.card-slot {
  position: relative;
  height: 68px;
  border: 1.5px dashed var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  font-size: 20px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 1px;
  cursor: pointer;
  padding: 0;
  transition: border-color 0.15s ease, background 0.15s ease,
    box-shadow 0.15s ease, transform 0.12s ease;
}

.card-slot:active { border-color: var(--accent); }

/* 亮出的牌：白卡面 + 左上点数 + 右下花色（略小） */
.card-slot.filled {
  border: 1px solid #dfe4e8;
  background: linear-gradient(160deg, #ffffff 0%, #f1f4f6 100%);
  box-shadow: 0 1px 2px rgba(16, 24, 32, 0.16), 0 4px 10px rgba(16, 24, 32, 0.10);
  color: var(--text);
}

.card-slot.filled:active { transform: scale(0.97); }

.card-slot.placeholder {
  font-size: 13px;
  font-weight: 400;
  color: #9aa4ad;
}

.card-corner {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #232a31;
  pointer-events: none;
}

/* 点数/花色各自居中于对角区域（左上/右下偏中间），字号撑满区域 */
.card-corner.rank {
  top: 0; left: 0;
  width: 64%; height: 54%;
  font-size: 28px;
}

.card-corner.suit {
  bottom: 0; right: 0;
  width: 64%; height: 54%;
  font-size: 24px;
}
.card-corner.red { color: var(--red); }

/* 小尺寸牌面的角标缩放：手牌 40×56、公牌 ~50×64、弹层 ~40×56（默认 28/24 给大牌面） */
.hole-cards .card-corner.rank { font-size: 16px; }
.hole-cards .card-corner.suit { font-size: 13px; }
.board-row .card-corner.rank { font-size: 18px; }
.board-row .card-corner.suit { font-size: 15px; }
.picker-card .card-corner.rank { font-size: 19px; }
.picker-card .card-corner.suit { font-size: 16px; }

/* ---------- 玩家 ---------- */

.player {
  background: rgba(255, 255, 255, 0.96);
  border-radius: 10px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.28);
  padding: 10px;
  margin-bottom: 8px;
}

/* 主行：手牌 ×2 + 进度条 + 胜率 + 删除 */
.player-main {
  display: flex;
  align-items: center;
  gap: 8px;
}

.hole-cards {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.hole-cards .card-slot {
  width: 40px;
  height: 56px;
}

.remove-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: #eef1f3;
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
}

.remove-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

/* 副行：玩家名 + 平/负（或未参与提示） */
.player-sub {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-top: 5px;
  font-size: 11px;
  color: var(--muted);
}

.p-name { font-weight: 600; }
.p-detail { font-variant-numeric: tabular-nums; text-align: right; }

/* ---------- 结果 ---------- */

.bar {
  display: flex;
  flex: 1;
  height: 8px;
  border-radius: 4px;
  background: #e8ecef; /* 负 = 底色段 */
  overflow: hidden;
}

.bar-win {
  height: 100%;
  background: linear-gradient(90deg, #1a9a4b, var(--accent));
  transition: width 0.25s ease;
}

.bar-tie {
  height: 100%;
  background: #d9a514;
  transition: width 0.25s ease;
}

.win-pct {
  flex-shrink: 0;
  min-width: 52px;
  text-align: right;
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* ---------- 按钮 ---------- */

.ghost-btn {
  border: none;
  background: transparent;
  color: var(--accent);
  font-size: 16px;
  padding: 8px 10px;
  min-height: 44px;
  cursor: pointer;
  border-radius: 8px;
}

.ghost-btn:active { background: var(--accent-soft); }

.add-btn {
  width: 100%;
  min-height: 48px;
  border: 1.5px dashed rgba(255, 255, 255, 0.45);
  border-radius: 12px;
  background: transparent;
  color: #eaf7ef;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}

.add-btn:active { background: rgba(255, 255, 255, 0.10); }

.add-btn:disabled {
  color: rgba(255, 255, 255, 0.35);
  border-color: rgba(255, 255, 255, 0.20);
  cursor: default;
  background: transparent;
}

.foot {
  text-align: center;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.5);
}

/* ---------- 底部弹层选择器 ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(10, 16, 22, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.overlay[hidden] { display: none; }

.sheet {
  width: 100%;
  max-width: 520px;
  max-height: 85vh;
  max-height: 85dvh; /* dvh 支持时动态视口，避免移动端地址栏遮挡 */
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px 6px 16px;
}

.sheet-title {
  font-size: 16px;
  font-weight: 600;
}

/* 8 列 = 每行 2 个点数（4 花色对齐），13 个点数共 7 行，手机竖屏一屏可见全部 52 张。
   第 5 列是 12px 空列，作左右两半的中缝；中缝正好落在内容区水平中点，用背景渐变画分隔线 */
.picker-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr) 12px repeat(4, 1fr);
  justify-items: center;
  gap: 5px;
  padding: 6px 10px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background-image: linear-gradient(
    to right,
    transparent calc(50% - 0.5px),
    var(--border) calc(50% - 0.5px),
    var(--border) calc(50% + 0.5px),
    transparent calc(50% + 0.5px)
  );
}

/* 每行右半边的首张牌跳过中缝列（稀疏排布不回填，第 5 列保持为空） */
.picker-card:nth-child(8n + 5) { grid-column: 6; }

.picker-card {
  position: relative;
  width: 100%;
  max-width: 52px;
  aspect-ratio: 5 / 7;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: linear-gradient(160deg, #ffffff 0%, #f6f8f9 100%);
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
}

.picker-card:disabled {
  opacity: 0.3;
  cursor: default;
}

.picker-card.selected {
  border: 2px solid var(--accent);
  background: var(--accent-soft);
}

.sheet-foot {
  display: flex;
  justify-content: flex-end;
  padding: 4px 12px 8px;
}

/* ---------- 桌面适配 ---------- */

@media (min-width: 768px) {
  .container { padding-top: 24px; }

  .overlay { align-items: center; }

  .sheet {
    width: 420px;
    border-radius: 16px;
    max-height: 80vh;
  }
}

@media (prefers-reduced-motion: reduce) {
  .bar-win, .bar-tie, .card-slot { transition: none; }
}
