:root {
  --wood: #3a1c16;
  --felt-1: #6b2f26;
  --felt-2: #401b18;
  --gold: #ffd27a;
  --gold-deep: #d69f3c;
  --cream: #f6ead2;
  --ink: #22303a;
  --red: #c62b2b;
  --line: rgba(255, 235, 205, .16);
  --shadow: 0 10px 24px rgba(0, 0, 0, .45);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", system-ui, sans-serif;
  background: #1b0d0b; color: var(--cream); overflow: hidden; user-select: none;
}
button { font-family: inherit; cursor: pointer; }
#app { height: 100%; padding: 10px; }
.table {
  position: relative; height: 100%; border-radius: 20px; overflow: hidden;
  border: 7px solid var(--wood);
  box-shadow: inset 0 0 0 2px #7a4630, inset 0 0 100px rgba(0, 0, 0, .6), 0 18px 50px rgba(0, 0, 0, .6);
  background:
    radial-gradient(ellipse 80% 65% at 50% 44%, rgba(255, 220, 170, .09), transparent 72%),
    radial-gradient(ellipse at 50% 42%, var(--felt-1), var(--felt-2) 72%, #210e0d 100%);
}

/* 顶栏 */
.topbar {
  height: 62px; display: flex; align-items: center; gap: 14px; padding: 0 18px;
  background: linear-gradient(180deg, rgba(0, 0, 0, .36), rgba(0, 0, 0, .06));
  border-bottom: 1px solid var(--line); position: relative; z-index: 6;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 190px; }
.logo { font-size: 29px; filter: drop-shadow(0 2px 4px rgba(0, 0, 0, .5)); }
.brand-txt b { display: block; font-size: 17px; letter-spacing: 2px; color: var(--gold); line-height: 1.15; }
.brand-txt small { font-size: 9px; letter-spacing: 1.2px; color: #d9b9a3; }
.chips { display: flex; gap: 8px; flex: 1; flex-wrap: wrap; }
.chip { display: flex; align-items: center; gap: 6px; background: rgba(0, 0, 0, .28); border: 1px solid var(--line); border-radius: 20px; padding: 5px 12px; font-size: 12px; color: #e3cab2; white-space: nowrap; }
.chip b { color: #fff; font-size: 14px; font-variant-numeric: tabular-nums; }
.chip.coins b { color: #ffe08a; }
.chip.streak { background: rgba(255, 120, 90, .18); border-color: rgba(255, 140, 100, .45); }
.chip.bump { animation: bump .4s ease; }
@keyframes bump { 40% { transform: scale(1.2); } }
.tools { display: flex; gap: 6px; }
.tool { background: rgba(255, 255, 255, .08); border: 1px solid var(--line); color: #f6e6d2; border-radius: 10px; height: 34px; min-width: 34px; padding: 0 10px; font-size: 14px; transition: .16s; }
.tool span { font-size: 11px; }
.tool:hover { background: rgba(255, 255, 255, .2); transform: translateY(-1px); }
.tool.off { opacity: .42; }

/* 主区 */
.board { position: relative; height: calc(100% - 62px); display: flex; flex-direction: column; gap: 8px; padding: 10px 18px 10px; }

/* 对手 */
.opponents { flex: 0 0 auto; height: 84px; display: flex; gap: 16px; justify-content: center; align-items: flex-start; }
.opp { position: relative; width: 150px; text-align: center; padding-top: 2px; }
.opp .avatar { width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; font-size: 25px; margin: 0 auto; background: linear-gradient(145deg, #ffe0ac, #d79a45); border: 2px solid rgba(255, 255, 255, .75); box-shadow: var(--shadow); }
.opp:nth-child(2) .avatar { background: linear-gradient(145deg, #ffd0e0, #df87ab); }
.opp.turn .avatar { box-shadow: 0 0 0 4px rgba(255, 210, 122, .55), 0 0 22px rgba(255, 210, 122, .8); }
.opp-name { font-size: 12px; margin-top: 4px; color: #f8e8d2; }
.opp-name b { color: var(--gold); }
.opp-backs { display: flex; justify-content: center; gap: 0; margin-top: 3px; height: 22px; }
.opp-backs .tile.back { width: 14px; height: 20px; margin-left: -6px; }
.opp-backs .tile.back:first-child { margin-left: 0; }
.opp .bubble { position: absolute; top: -10px; left: 100%; margin-left: 4px; background: #fff8e8; color: #3a2a20; font-size: 11px; font-weight: 700; padding: 6px 10px; border-radius: 12px 12px 12px 2px; white-space: nowrap; box-shadow: var(--shadow); opacity: 0; transform: scale(.7); transition: .2s; pointer-events: none; z-index: 9; }
.opp .bubble.show { opacity: 1; transform: scale(1); }

/* 接龙区 */
.chain-zone { flex: 1 1 auto; min-height: 170px; position: relative; }
.chain-zone::before {
  content: '牌九'; position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  font-size: 130px; font-weight: 900; letter-spacing: 22px;
  color: rgba(255, 228, 185, .035); pointer-events: none; white-space: nowrap;
}
.chain-zone::after {
  content: ''; position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: 320px; height: 320px; max-width: 70vw; max-height: 38vh;
  border: 1px solid rgba(255, 228, 185, .045); border-radius: 50%; pointer-events: none;
}
.chain-caption { font-size: 12px; letter-spacing: 2px; color: #d8b89c; text-align: center; }
.chain-scroll {
  position: absolute; top: 34px; left: 0; right: 96px; bottom: 8px;
  display: flex; align-items: center; justify-content: flex-start; gap: 0;
  overflow-x: auto; overflow-y: hidden; padding: 8px 4px;
  scrollbar-width: thin; scrollbar-color: rgba(255, 210, 122, .5) transparent;
}
.chain-scroll::-webkit-scrollbar { height: 7px; }
.chain-scroll::-webkit-scrollbar-thumb { background: rgba(255, 210, 122, .45); border-radius: 6px; }
.chain-scroll::before, .chain-scroll::after { content: ''; flex: 1 1 0; }
.chain { display: flex; align-items: center; flex: 0 0 auto; }
.chain .tile.newtile { animation: tileIn .3s cubic-bezier(.2, .9, .3, 1) both; }
@keyframes tileIn { from { opacity: 0; transform: translateY(-24px) scale(.7) rotate(-8deg); } to { opacity: 1; transform: none; } }
.joint { flex: 0 0 auto; width: 14px; text-align: center; font-size: 10px; font-weight: 800; color: #ffd27a; position: relative; }
.joint::before { content: ''; position: absolute; left: 0; right: 0; top: 50%; border-top: 1px dashed rgba(255, 210, 122, .55); }
.joint span { position: relative; background: #4a211c; padding: 0 2px; }
.endcap {
  flex: 0 0 auto; width: 62px; height: 74px; margin: 0 8px;
  border: 2px dashed rgba(255, 235, 205, .3); border-radius: 12px;
  display: grid; place-items: center; align-content: center; gap: 2px;
  color: #e6c9a9; transition: .18s;
}
.endcap b { font-size: 24px; line-height: 1; }
.endcap small { font-size: 10px; letter-spacing: 1px; }
.endcap.can { border-color: var(--gold); background: rgba(255, 210, 122, .16); color: var(--gold); cursor: pointer; animation: endPulse .9s ease-in-out infinite alternate; }
.endcap.can:hover { transform: scale(1.07); }
.endcap.dim { opacity: .35; }
@keyframes endPulse { from { box-shadow: 0 0 0 0 rgba(255, 210, 122, .28); } to { box-shadow: 0 0 0 9px rgba(255, 210, 122, 0); } }
.chain-scroll.compact .tile { width: 68px; height: 44px; }
.chain-scroll.compact .half { width: 31px; }
.chain-scroll.compact .pips { width: 24px; height: 24px; gap: 1px; }
.chain-scroll.compact .pips i.on { width: 5px; height: 5px; }
.chain-scroll.compact .tile-name { font-size: 7px; }
.chain-scroll.compact .joint { width: 9px; }

/* 摸牌堆 */
.pile { position: absolute; right: 0; top: 50%; transform: translateY(-50%); width: 84px; height: 106px; border: none; background: none; padding: 0; color: var(--cream); }
.pile-stack { position: relative; width: 100%; height: 76px; }
.pile-stack .tile.back { width: 40px; height: 62px; position: absolute; top: 4px; left: 50%; margin-left: -20px; }
.pile-stack .tile.back:nth-child(1) { transform: translate(-7px, 3px) rotate(-7deg); }
.pile-stack .tile.back:nth-child(2) { transform: translate(5px, 1px) rotate(5deg); }
.pile-stack .tile.back:nth-child(3) { transform: none; }
.pile-num { position: absolute; top: 20px; left: 50%; transform: translateX(-50%); font-size: 19px; font-weight: 900; color: #fff; text-shadow: 0 2px 6px #000; }
.pile small { display: block; font-size: 11px; color: #d9b89a; letter-spacing: 2px; }
.pile:hover .pile-stack { transform: translateY(-3px); }
.pile.empty { opacity: .4; cursor: default; }

/* 骨牌 */
.tile {
  position: relative; flex: 0 0 auto; width: 92px; height: 56px;
  display: flex; align-items: center; border-radius: 7px;
  background: linear-gradient(155deg, #fffdf4, #ece2c9);
  border: 1px solid #c9b894; box-shadow: 0 4px 10px rgba(0, 0, 0, .4), inset 0 1px 0 #fff;
  color: var(--ink);
}
.tile.pair { border: 2px solid var(--gold-deep); box-shadow: 0 0 0 1px rgba(255, 210, 122, .5), 0 5px 12px rgba(0, 0, 0, .42); }
.tile .half { width: 42px; display: grid; place-items: center; }
.tile .sep { width: 2px; height: 76%; background: repeating-linear-gradient(180deg, #b9a883 0 3px, transparent 3px 6px); opacity: .8; }
.pips { display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); width: 30px; height: 30px; gap: 2px; place-items: center; }
.pips i { display: block; }
.pips i.on { width: 6px; height: 6px; border-radius: 50%; }
.pips i.on.black { background: #202d38; box-shadow: inset 0 -1px 1px rgba(255, 255, 255, .35); }
.pips i.on.red { background: var(--red); box-shadow: inset 0 -1px 1px rgba(255, 255, 255, .35); }
.tile-name { position: absolute; right: 3px; bottom: 1px; font-size: 8px; color: #a2916f; letter-spacing: 1px; pointer-events: none; }
.tile.pair .tile-name { color: #a87516; font-weight: 700; }
.tile.back { width: 40px; height: 62px; display: grid; place-items: center; background: repeating-linear-gradient(45deg, #8d2b2b 0 5px, #f0dfc0 5px 10px); border: 2px solid #fff8e8; border-radius: 5px; }
.back-grid { width: 70%; height: 78%; border: 2px solid rgba(255, 248, 232, .85); border-radius: 3px; }
.tile.playable::after { content: ''; position: absolute; top: -5px; right: -5px; width: 10px; height: 10px; border-radius: 50%; background: #76e08e; border: 2px solid #1c3b28; box-shadow: 0 0 8px rgba(118, 224, 142, .8); }
.tile.hint { animation: hintPulse .65s ease-in-out infinite alternate; }
@keyframes hintPulse { from { box-shadow: 0 0 0 2px rgba(124, 196, 255, .55); } to { box-shadow: 0 0 0 5px rgba(124, 196, 255, .95); } }
.tile.selected { transform: translateY(-14px); box-shadow: 0 0 0 3px var(--gold), 0 14px 22px rgba(0, 0, 0, .5); z-index: 4; }
.tile.just-drawn { animation: drawPop .45s ease both; }
@keyframes drawPop { from { opacity: 0; transform: translate(-120px, -60px) rotate(-20deg) scale(.6); } to { opacity: 1; transform: none; } }

/* 我的手牌 */
.my-bar { flex: 0 0 auto; height: 132px; }
.me-info { height: 24px; text-align: center; font-size: 12px; color: #e6c9a9; }
.me-info b { color: var(--gold); font-size: 14px; }
.me-avatar { font-size: 15px; }
.swipe-tip { display: none; }
.me-count { margin: 0 6px; }
.hand-scroll { height: 106px; overflow-x: auto; overflow-y: hidden; display: flex; align-items: center; scrollbar-width: thin; }
.hand-scroll::-webkit-scrollbar { height: 6px; }
.hand-scroll::-webkit-scrollbar-thumb { background: rgba(255, 210, 122, .4); border-radius: 6px; }
.hand { display: flex; gap: 9px; margin: auto; padding: 18px 10px 6px; }
.hand .tile { cursor: pointer; transition: transform .14s, box-shadow .14s; }
.hand .tile:hover { transform: translateY(-7px); }
.hand .tile.selected:hover { transform: translateY(-17px); }
.hand .tile.dealing { animation: dealIn .36s cubic-bezier(.2, .8, .3, 1) both; }
@keyframes dealIn { from { opacity: 0; transform: translate(-180px, -110px) rotate(22deg) scale(.6); } to { opacity: 1; transform: none; } }

/* 状态与按钮 */
.status { flex: 0 0 auto; height: 22px; text-align: center; font-size: 12px; color: #d9b99b; }
.actionbar { flex: 0 0 auto; height: 48px; display: flex; gap: 10px; justify-content: center; align-items: center; flex-wrap: wrap; }
.btn { border: none; border-radius: 24px; padding: 10px 22px; font-size: 14px; font-weight: 700; color: #33271a; background: linear-gradient(180deg, #fff7e5, #e6d6b2); box-shadow: 0 4px 0 #ac9770, 0 8px 14px rgba(0, 0, 0, .3); transition: .12s; }
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #ac9770; }
.btn.primary { background: linear-gradient(180deg, #ffe3a0, #ecaa3c); color: #3b2607; box-shadow: 0 4px 0 #a9711c, 0 8px 16px rgba(0, 0, 0, .35); }
.btn.ghost { background: rgba(255, 255, 255, .1); color: #f6e6d2; box-shadow: none; border: 1px solid var(--line); }
.btn.ghost:hover { background: rgba(255, 255, 255, .22); transform: none; }
.btn.small { padding: 8px 14px; font-size: 12px; }
.btn.on { outline: 2px solid var(--gold); }
.btn:disabled { opacity: .38; cursor: not-allowed; transform: none; }
.place-bar {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: 226px; z-index: 14;
  display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 30px;
  background: rgba(28, 12, 10, .92); border: 1px solid rgba(255, 210, 122, .5);
  box-shadow: var(--shadow); white-space: nowrap;
}
.place-bar .pick { font-size: 12px; color: #f0d6b4; margin-right: 4px; }
.place-bar .pick b { color: var(--gold); }
.place-bar .btn { padding: 7px 14px; font-size: 12px; }

/* 提示气泡 / 特效 */
.toast { position: absolute; left: 50%; top: 74px; transform: translate(-50%, -14px); background: rgba(30, 14, 10, .94); color: #fff; border: 1px solid rgba(255, 210, 122, .5); padding: 9px 20px; border-radius: 20px; font-size: 13px; font-weight: 600; opacity: 0; transition: .22s; pointer-events: none; z-index: 30; white-space: nowrap; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.fx { position: absolute; inset: 0; pointer-events: none; z-index: 20; overflow: hidden; }
.confetti { position: absolute; width: 9px; height: 15px; top: -20px; animation: fall linear both; }
@keyframes fall { to { transform: translateY(105vh) rotate(720deg); opacity: .2; } }
.spark { position: absolute; font-size: 24px; animation: spark 1s ease-out both; }
@keyframes spark { from { opacity: 1; transform: translate(0, 0) scale(.4); } to { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(1.5); } }

/* 弹窗 */
.modal { position: absolute; inset: 0; z-index: 40; display: grid; place-items: center; background: rgba(18, 7, 6, .78); backdrop-filter: blur(5px); padding: 18px; }
.modal-card { width: min(540px, 94vw); max-height: 88vh; overflow-y: auto; background: linear-gradient(165deg, #6a2f25, #2c1210); border: 1px solid rgba(255, 210, 122, .38); border-radius: 20px; box-shadow: 0 26px 70px rgba(0, 0, 0, .68); padding: 26px 28px; animation: modalIn .3s cubic-bezier(.2, .9, .3, 1) both; }
@keyframes modalIn { from { opacity: 0; transform: translateY(24px) scale(.94); } to { opacity: 1; transform: none; } }
.modal-card h2 { margin: 0 0 8px; color: var(--gold); font-size: 24px; letter-spacing: 2px; text-align: center; }
.modal-card .sub { text-align: center; color: #debda2; font-size: 12px; margin-bottom: 18px; }
.modal-card p { font-size: 13px; line-height: 1.85; color: #f3e2cd; }
.pick-row { display: flex; gap: 8px; justify-content: center; margin: 10px 0 16px; flex-wrap: wrap; }
.pick-row label { font-size: 11px; color: #debda2; align-self: center; margin-right: 4px; }
.pick-row button { padding: 9px 18px; border-radius: 12px; border: 1px solid var(--line); background: rgba(255, 255, 255, .07); color: #f3e2cd; font-size: 13px; }
.pick-row button b { display: block; font-size: 15px; }
.pick-row button.active { background: rgba(255, 210, 122, .18); border-color: var(--gold); color: var(--gold); }
.rule-table { width: 100%; border-collapse: collapse; font-size: 12px; margin-top: 8px; }
.rule-table td { padding: 7px 8px; border-bottom: 1px solid rgba(255, 255, 255, .09); color: #f0ddc4; }
.rule-table td:first-child { color: var(--gold); width: 100px; white-space: nowrap; }
.modal-btns { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 20px; }
.result-score { text-align: center; margin: 4px 0 16px; }
.result-score .big { font-size: 44px; font-weight: 900; letter-spacing: 2px; }
.result-score .big.plus { color: var(--gold); text-shadow: 0 0 26px rgba(255, 210, 122, .5); }
.result-score .big.minus { color: #ff9b8f; }
.result-rows { background: rgba(0, 0, 0, .24); border-radius: 12px; padding: 12px 16px; font-size: 13px; }
.result-row { display: flex; justify-content: space-between; padding: 5px 0; color: #e8cfb4; }
.result-row b { color: #fff; }
.result-row.total { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 10px; font-size: 15px; }
.result-row.total b { color: var(--gold); font-size: 19px; }
.badges { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; margin: 12px 0 2px; }
.badge { font-size: 11px; padding: 5px 10px; border-radius: 14px; background: rgba(255, 210, 122, .16); border: 1px solid rgba(255, 210, 122, .45); color: var(--gold); }
.stat-line { text-align: center; font-size: 11px; color: #c9a88e; margin-top: 14px; }

@media (max-width: 900px) {
  #app { padding: 0; }
  .table { border-radius: 0; border-width: 3px; }
  .topbar { height: 54px; padding: 0 8px; gap: 6px; }
  .brand { min-width: 0; }
  .brand-txt { display: none; }
  .chip { padding: 3px 8px; font-size: 10px; }
  .chip b { font-size: 12px; }
  .tools .tool span { display: none; }
  .tool { min-width: 30px; padding: 0 6px; height: 30px; font-size: 13px; }
  .board { height: calc(100% - 54px); padding: 6px 8px; gap: 5px; }
  .opponents { height: 66px; gap: 8px; }
  .opp { width: 100px; }
  .opp .avatar { width: 36px; height: 36px; font-size: 20px; }
  .opp-name { font-size: 10px; }
  .opp-backs { height: 16px; }
  .opp-backs .tile.back { width: 11px; height: 15px; }
  .chain-zone { min-height: 150px; }
  .chain-zone::before { font-size: 72px; letter-spacing: 12px; }
  .chain-zone::after { width: 220px; height: 220px; }
  .chain-scroll { right: 66px; top: 26px; }
  .tile { width: 68px; height: 44px; }
  .tile .half { width: 31px; }
  .pips { width: 24px; height: 24px; gap: 1px; }
  .pips i.on { width: 5px; height: 5px; }
  .tile-name { font-size: 7px; }
  .chain-scroll.compact .tile { width: 54px; height: 36px; }
  .chain-scroll.compact .half { width: 25px; }
  .chain-scroll.compact .pips { width: 20px; height: 20px; }
  .chain-scroll.compact .pips i.on { width: 4px; height: 4px; }
  .endcap { width: 46px; height: 60px; margin: 0 4px; }
  .endcap b { font-size: 18px; }
  .endcap small { font-size: 9px; }
  .pile { width: 60px; height: 88px; }
  .pile-stack { height: 60px; }
  .pile-stack .tile.back { width: 30px; height: 48px; margin-left: -15px; }
  .pile-num { font-size: 15px; top: 16px; }
  .my-bar { height: 104px; }
  .me-info { height: 20px; font-size: 11px; }
  .swipe-tip { display: inline; font-size: 10px; color: #c9a88e; }
  .hand-scroll { height: 82px; -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 10px, #000 calc(100% - 12px), transparent 100%); }
  .hand { gap: 5px; padding: 14px 6px 4px; }
  .status { height: 18px; font-size: 11px; }
  .actionbar { height: 44px; gap: 6px; }
  .btn { padding: 8px 13px; font-size: 12px; white-space: nowrap; }
  .btn.small { padding: 8px 10px; }
  .place-bar { bottom: 214px; padding: 6px 8px; gap: 5px; }
  .place-bar .pick { font-size: 10px; }
  .place-bar .btn { padding: 6px 9px; font-size: 11px; }
}
