/* ============================================================
   style.css v2 — 麻将记牌器「牌桌风」重构
   移动优先 · 适配 320px 小屏 → 桌面宽屏
   深色牌桌绿 + 米白麻将牌 + 金色点缀
   ============================================================ */
:root {
  /* 牌桌 */
  --felt-1: #0a3629;
  --felt-2: #0e4a36;
  --felt-3: #166346;
  --ink: #f2f7f3;
  --muted: #a3beb0;
  --faint: rgba(255, 255, 255, .55);
  --panel: rgba(255, 255, 255, .075);
  --panel-2: rgba(10, 44, 34, .72);
  --line: rgba(255, 255, 255, .13);
  --gold: #ffcf6e;
  --gold-deep: #e8a33d;

  /* 牌面颜色 */
  --wan: #e2594f;
  --tiao: #35a45c;
  --tong: #2f7fc0;
  --honor: #8a5a2b;
  --hua: #c2698f;
  --zero-ink: #a3a89f;

  --danger: #ff6b5e;
  --brand: linear-gradient(135deg, #ffcf6e, #f2a93b);
  --brand-ink: #3d2a05;

  --tile-bg: linear-gradient(168deg, #fffaf1 0%, #f6ecd6 55%, #efe0c2 100%);
  --tile-ink: #43371f;
  --tile-shadow: 0 3px 6px rgba(0, 0, 0, .38), inset 0 1px 0 rgba(255, 255, 255, .85);

  --radius: 16px;
  --radius-sm: 10px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; overflow-x: clip; }
html { -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  background:
    radial-gradient(1200px 600px at 85% -10%, rgba(255, 207, 110, .14), transparent 55%),
    radial-gradient(900px 500px at -10% 30%, rgba(53, 164, 92, .16), transparent 55%),
    radial-gradient(700px 700px at 50% 120%, rgba(255, 107, 94, .08), transparent 60%),
    linear-gradient(160deg, var(--felt-1) 0%, var(--felt-2) 45%, var(--felt-3) 100%);
  background-attachment: fixed;
}

#app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 12px 12px calc(96px + env(safe-area-inset-bottom));
}

/* ---------- 通用控件 ---------- */
.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform .1s, filter .15s;
  user-select: none;
  min-height: 44px;
}
.btn:active { transform: scale(.96); }
.btn-block { display: block; width: 100%; }

.btn-primary {
  background: var(--brand);
  color: var(--brand-ink);
  border: none;
  font-size: 16px;
  box-shadow: 0 6px 18px rgba(242, 169, 59, .35);
}
.btn-primary:active { filter: brightness(1.05); }

.btn-add {
  background: var(--brand);
  color: var(--brand-ink);
  border: none;
  font-size: 17px;
  min-width: 64px;
}

.field { display: flex; flex-direction: column; gap: 7px; margin-bottom: 16px; }
.field > label { font-size: 13px; color: var(--muted); font-weight: 600; }

.select-wrap { position: relative; }
.select-wrap::after {
  content: '▾';
  position: absolute; right: 14px; top: 50%;
  transform: translateY(-50%);
  color: var(--muted); pointer-events: none; font-size: 14px;
}
select {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--ink);
  border-radius: 12px;
  padding: 12px 38px 12px 13px;
  font-size: 15px;
  min-height: 46px;
}
select option { color: #222; background: #fff; }

/* 面板卡片（毛玻璃） */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: 14px;
  margin-bottom: 12px;
  min-width: 0;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .18);
}

/* ---------- 初始化界面 ---------- */
.setup { max-width: 430px; margin: 6vh auto 0; padding: 0; border: none; background: none; box-shadow: none; }

.setup-hero { text-align: center; margin-bottom: 20px; }
.setup-hero .logo {
  width: 64px; height: 64px;
  margin: 0 auto 12px;
  display: flex; align-items: center; justify-content: center;
  background: var(--tile-bg);
  color: var(--tile-ink);
  font-size: 32px; font-weight: 800;
  border-radius: 16px;
  box-shadow: var(--tile-shadow);
  transform: rotate(-3deg);
}
.setup-hero h1 { margin: 0 0 6px; font-size: 24px; letter-spacing: 1px; }
.setup-hero p { margin: 0; color: var(--muted); font-size: 14px; }

.seg { display: flex; gap: 8px; flex-wrap: wrap; }
.seg button {
  flex: 1 1 0;
  min-width: 64px;
  min-height: 46px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  border-radius: 12px;
  padding: 11px 8px;
  font-size: 15px;
  cursor: pointer;
  color: var(--ink);
  transition: .15s;
}
.seg button.active {
  background: var(--brand);
  color: var(--brand-ink);
  border-color: transparent;
  font-weight: 800;
  box-shadow: 0 4px 14px rgba(242, 169, 59, .3);
}
.setup .hint { margin: 14px 0 0; color: var(--faint); font-size: 12px; text-align: center; }

/* ---------- 顶部状态 hero ---------- */
.hero { padding: 16px; }
.hero-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; flex-wrap: wrap; min-width: 0; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  font-size: 12px; font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, .08);
  color: var(--ink);
  white-space: nowrap;
}

.wall { min-width: 0; flex: 1 1 190px; max-width: 100%; }
.wall-num { display: flex; align-items: baseline; gap: 6px; }
.wall-label { font-size: 13px; color: var(--muted); }
.wall-num b {
  font-size: clamp(34px, 9vw, 44px);
  line-height: 1;
  color: var(--gold);
  font-weight: 800;
  letter-spacing: -1px;
}
.wall-total { font-size: 14px; color: var(--muted); }

.wall-bar {
  margin-top: 8px;
  height: 7px;
  border-radius: 4px;
  background: rgba(255, 255, 255, .12);
  overflow: hidden;
}
.wall-bar i {
  display: block; height: 100%;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--gold), var(--gold-deep));
  transition: width .3s ease;
}

.hero-sub {
  margin-top: 12px;
  display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap;
  font-size: 12px; color: var(--muted);
}
.hero-sub b { color: var(--ink); }

/* ---------- 快速登记 ---------- */
.quick-title {
  font-size: 13px; font-weight: 700; margin-bottom: 10px;
  display: flex; align-items: baseline; gap: 8px;
}
.quick-title span { font-size: 12px; color: var(--muted); font-weight: 400; }
.add-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; gap: 8px; align-items: center; }

/* ---------- 牌面 ---------- */
.suit-group { margin-bottom: 14px; }
.suit-group:last-child { margin-bottom: 0; }

.suit-title {
  display: flex; align-items: center; justify-content: space-between;
  margin: 2px 2px 8px;
}
.suit-name { display: flex; align-items: center; gap: 7px; font-size: 14px; font-weight: 800; letter-spacing: 1px; }
.dot { width: 9px; height: 9px; border-radius: 50%; box-shadow: 0 0 6px currentColor; }
.dot-wan  { background: var(--wan);  color: var(--wan); }
.dot-tiao { background: var(--tiao); color: var(--tiao); }
.dot-tong { background: var(--tong); color: var(--tong); }
.dot-feng { background: var(--honor); color: var(--honor); }
.dot-jian { background: var(--honor); color: var(--honor); }
.dot-hua  { background: var(--hua);  color: var(--hua); }
.suit-rem { font-size: 12px; color: var(--muted); }

.tile-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }

.tile {
  position: relative;
  background: var(--tile-bg);
  color: var(--tile-ink);
  border-radius: 9px;
  padding: 9px 2px 7px;
  text-align: center;
  cursor: pointer;
  user-select: none;
  box-shadow: var(--tile-shadow);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 64px; min-width: 0;
  overflow: hidden;
  transition: transform .1s;
}
.tile:active { transform: scale(.93); }

.tile .face { font-size: clamp(15px, 4.8vw, 22px); font-weight: 800; line-height: 1.15; max-width: 100%; }
.tile .meta { font-size: 10px; color: rgba(67, 55, 31, .62); margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }

.tile .minus {
  position: absolute; top: 0; left: 0;
  width: 30px; height: 28px;
  line-height: 27px;
  font-size: 16px; font-weight: 800;
  border-radius: 0 0 9px 0;
  background: rgba(0, 0, 0, .07);
  color: rgba(67, 55, 31, .5);
  z-index: 2;
}
.tile .minus:active { background: rgba(0, 0, 0, .16); }

/* 花色字色 */
.tile.s-wan  .face { color: var(--wan); }
.tile.s-tiao .face { color: var(--tiao); }
.tile.s-tong .face { color: var(--tong); }
.tile.s-feng .face, .tile.s-jian .face { color: var(--honor); }
.tile.s-hua  .face { color: var(--hua); }

/* 绝张：暗化 + 斜纹 */
.tile.exhausted {
  background: repeating-linear-gradient(-45deg, rgba(255, 255, 255, .5) 0 5px, rgba(255, 255, 255, .18) 5px 10px), linear-gradient(168deg, #e9e4d5, #ddd5c0);
  box-shadow: inset 0 0 0 2px rgba(163, 160, 143, .55), 0 2px 4px rgba(0, 0, 0, .25);
  opacity: .82;
}
.tile.exhausted .face { color: var(--zero-ink); }
.tile.exhausted .meta { color: var(--danger); font-weight: 800; }
.tile.exhausted .minus { color: rgba(163, 160, 143, .6); }

/* 抖动反馈：超过上限点 +1 时触发 */
@keyframes tileShake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-4px); }
  40%, 80% { transform: translateX(4px); }
}
.tile.shake { animation: tileShake .4s ease; }

/* Toast 提示 */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(86px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px);
  background: rgba(8, 36, 28, .94);
  color: #fff;
  border: 1px solid rgba(255, 207, 110, .4);
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .4);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 200;
  max-width: calc(100vw - 48px);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- 汇总折叠 ---------- */
.summary-fold { padding: 0; overflow: hidden; }
.summary-fold > summary {
  list-style: none;
  cursor: pointer;
  padding: 13px 16px;
  font-size: 14px; font-weight: 700;
  display: flex; align-items: center; justify-content: space-between;
}
.summary-fold > summary::-webkit-details-marker { display: none; }
.summary-fold > summary::after { content: '▾'; color: var(--gold); font-size: 13px; transition: transform .2s; }
.summary-fold:not([open]) > summary::after { transform: rotate(-90deg); }
.summary-body { padding: 2px 16px 14px; }
.summary-body table { width: 100%; border-collapse: collapse; font-size: 13px; }
.summary-body th, .summary-body td {
  padding: 7px 6px;
  border-bottom: 1px solid var(--line);
  text-align: center;
}
.summary-body th { color: var(--muted); font-weight: 600; font-size: 12px; }
.summary-body th:first-child, .summary-body td:first-child { text-align: left; }
.summary-body tr:last-child td { border-bottom: none; }
.summary-body .zero { color: var(--danger); font-weight: 800; }

/* ---------- 底部悬浮操作栏 ---------- */
.bottom-bar {
  position: fixed;
  left: 12px; right: 12px;
  bottom: calc(10px + env(safe-area-inset-bottom));
  z-index: 100;
  display: flex; gap: 8px;
  background: rgba(8, 36, 28, .85);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(255, 255, 255, .16);
  border-radius: 20px;
  padding: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .4);
  max-width: 1076px;
  margin: 0 auto;
}
.bar-btn {
  flex: 1 1 0;
  min-width: 0;
  min-height: 46px;
  border: none;
  border-radius: 14px;
  font-size: 15px; font-weight: 700;
  cursor: pointer;
  color: var(--ink);
  background: rgba(255, 255, 255, .1);
  transition: transform .1s, filter .15s;
  user-select: none;
}
.bar-btn:active { transform: scale(.95); }
.bar-btn.bar-gold { background: var(--brand); color: var(--brand-ink); }
.bar-btn.bar-danger { color: var(--danger); background: rgba(255, 107, 94, .12); }
.bar-btn.bar-ghost { background: transparent; border: 1px solid var(--line); }

/* ---------- 分档适配（320px → 桌面） ---------- */
@media (min-width: 360px) {
  .tile-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (min-width: 520px) {
  .tile-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .tile { min-height: 70px; }
}
@media (min-width: 760px) {
  .tile-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .tile { min-height: 76px; }
  .tile .face { font-size: 24px; }
  .tile .meta { font-size: 12px; }
}
@media (min-width: 1080px) {
  .tile-grid { grid-template-columns: repeat(auto-fill, minmax(98px, 1fr)); }
  #app { padding: 18px 18px calc(100px + env(safe-area-inset-bottom)); }
  .panel { padding: 18px; }
}
