/* 接龙牌 — 界面样式（参考牌九接龙：顶栏+对手区+链区+手牌；响应式） */
:root {
  --felt: #1f5f3f;
  --felt-dark: #174a31;
  --felt-light: #2c7a52;
  --tile-bg: #fdf9ee;
  --tile-edge: #d8cfa8;
  --pip: #2a2a2a;
  --gold: #e8c46a;
  --text: #f5f1e6;
  --text-dim: #c9c2ad;
  --accent: #f0b429;
  --tw: 56px; --th: 92px; --pipc: 12px; --pipd: 9px; --die: 44px; --seat-av: 40px;
}
@media (max-width: 640px) { :root { --tw: 46px; --th: 76px; --pipc: 10px; --pipd: 7px; --die: 38px; --seat-av: 32px; } }
@media (max-width: 380px) { :root { --tw: 42px; --th: 70px; --pipc: 9px; --pipd: 6px; } }
@media (max-width: 350px) { :root { --tw: 38px; --th: 64px; --pipc: 8px; --pipd: 5px; } }

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: radial-gradient(circle at 50% 30%, var(--felt-light), var(--felt) 60%, var(--felt-dark));
  color: var(--text);
  overflow: hidden;
  user-select: none;
  display: flex; flex-direction: column;
}

/* 顶栏 */
.topbar {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 8px;
  padding: 8px 14px;
  background: linear-gradient(180deg, rgba(0,0,0,.35), rgba(0,0,0,.15));
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.brand { display: flex; align-items: center; gap: 8px; }
.brand .logo { font-size: 26px; }
.brand-txt { display: flex; flex-direction: column; line-height: 1.1; }
.brand-txt b { font-size: 18px; color: var(--gold); letter-spacing: 1px; }
.brand-txt small { font-size: 10px; color: var(--text-dim); letter-spacing: 1px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  display: flex; align-items: center; gap: 4px;
  background: rgba(0,0,0,.28); border: 1px solid rgba(255,255,255,.12);
  border-radius: 8px; padding: 4px 9px; font-size: 12px; color: var(--text-dim);
}
.chip b { color: var(--text); font-size: 14px; }
.chip.coins b { color: var(--gold); }
.chip.streak b { color: #ff8f7a; }
.tools { display: flex; gap: 6px; }
.tool {
  width: 36px; height: 36px; border-radius: 8px; border: 1px solid rgba(255,255,255,.2);
  background: rgba(255,255,255,.08); color: var(--text); font-size: 16px; cursor: pointer;
  transition: .15s;
}
.tool:hover { background: rgba(255,255,255,.18); }
.tool.off { opacity: .45; }

/* 主区 */
.board { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* 对手区 */
.opponents {
  display: flex; justify-content: space-around; align-items: flex-start;
  padding: 8px 10px 2px; gap: 8px; flex: 0 0 auto;
}
.opp {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  background: rgba(0,0,0,.22); border: 1px solid rgba(255,255,255,.1);
  border-radius: 12px; padding: 7px 12px; min-width: 96px; position: relative;
}
.opp .avatar { font-size: calc(var(--seat-av) * 0.72); }
.opp .opp-name { font-size: 13px; }
.opp .opp-count { color: var(--text-dim); font-weight: 400; }
.opp .opp-backs { display: flex; margin-top: 2px; }
.opp .opp-backs .back {
  width: 16px; height: 26px; margin-left: -8px;
  background: linear-gradient(135deg, #c9a84c, #9c7b2a);
  border: 1px solid #7a5f1e; border-radius: 4px;
}
.opp .opp-backs .back:first-child { margin-left: 0; }
.opp.turn { border-color: var(--accent); box-shadow: 0 0 12px rgba(240,180,41,.45); }
.opp .bubble {
  position: absolute; top: -8px; left: 50%; transform: translateX(-50%) scale(.7);
  background: #fff; color: #2a2a2a; font-size: 12px; padding: 3px 9px; border-radius: 12px;
  white-space: nowrap; opacity: 0; pointer-events: none; transition: .18s;
  box-shadow: 0 3px 8px rgba(0,0,0,.3);
}
.opp .bubble::after { content: ''; position: absolute; bottom: -5px; left: 50%; transform: translateX(-50%); border: 5px solid transparent; border-top-color: #fff; border-bottom: none; }
.opp .bubble.show { opacity: 1; transform: translateX(-50%) scale(1); }

/* 骰子 */
#dice-box {
  position: absolute; top: 6px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 12px; align-items: center; z-index: 20;
  background: rgba(0,0,0,.32); padding: 8px 16px; border-radius: 12px;
  border: 1px solid rgba(255,255,255,.12);
}
.die {
  width: var(--die); height: var(--die); background: #fdf9ee; border-radius: 8px;
  border: 1px solid #c9b988; box-shadow: 0 3px 8px rgba(0,0,0,.3);
  display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr);
  place-items: center; gap: 2px; padding: 5px;
}
.die .pip { width: calc(var(--die) * 0.18); height: calc(var(--die) * 0.18); border-radius: 50%; }
.die .pip.on { background: var(--pip); }
.die .pip.off { background: transparent; }
.dice-label { font-size: 13px; color: var(--text-dim); }
.dice-note { font-size: 13px; color: var(--gold); font-weight: 600; }

/* 链区（弹性填充，中部） */
.chain-zone {
  flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center;
  justify-content: center; padding: 6px 8px; gap: 8px;
}
.chain-caption { font-size: 13px; color: var(--text-dim); }
.chain-scroll {
  display: flex; align-items: center; gap: 2px;
  max-width: 100%; overflow-x: auto; overflow-y: hidden;
  padding: 12px 12px; scrollbar-width: thin;
}
.chain-scroll::-webkit-scrollbar { height: 8px; }
.chain-scroll::-webkit-scrollbar-thumb { background: rgba(255,255,255,.25); border-radius: 4px; }
.endcap {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-width: 46px; padding: 6px 8px; margin: 0 2px; border-radius: 10px;
  background: rgba(0,0,0,.25); border: 1px dashed rgba(255,255,255,.2);
  font-size: 12px; color: var(--text-dim);
}
.endcap b { font-size: 20px; color: var(--accent); }
.endcap small { font-size: 10px; }
.chain { display: flex; align-items: center; }

/* 骨牌 */
.tile {
  width: var(--tw); height: var(--th); flex: 0 0 auto;
  background: var(--tile-bg);
  border: 1px solid var(--tile-edge);
  border-radius: 7px;
  box-shadow: 0 3px 8px rgba(0,0,0,.35);
  position: relative;
  display: flex; flex-direction: column;
}
.tile .half { flex: 1; display: grid; place-items: center; }
.tile .half:first-child { border-bottom: 1px solid var(--tile-edge); }
.pips { display: grid; grid-template-columns: repeat(3, var(--pipc)); grid-template-rows: repeat(3, var(--pipc)); gap: 2px; }
.pip { width: var(--pipd); height: var(--pipd); border-radius: 50%; }
.pip.on { background: var(--pip); }
.pip.off { background: transparent; }
.tile.newtile { animation: pop .28s ease; }
@keyframes pop { 0% { transform: scale(.4); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }

/* 我的手牌 */
.my-bar { flex: 0 0 auto; padding: 4px 8px 8px; }
.me-info { text-align: center; font-size: 13px; color: var(--text-dim); margin-bottom: 4px; }
.me-info .me-avatar { font-size: 16px; }
.me-info b { color: var(--text); }
.hand-scroll { overflow-x: auto; padding-bottom: 2px; }
.hand { display: flex; align-items: flex-end; justify-content: center; gap: 6px; min-height: calc(var(--th) + 4px); }
.hand .tile { cursor: pointer; transition: transform .12s, box-shadow .12s; }
.hand .tile:hover { transform: translateY(-8px); box-shadow: 0 10px 18px rgba(0,0,0,.4); }
.hand .tile.playable { outline: 3px solid var(--accent); box-shadow: 0 0 12px rgba(240,180,41,.5); }
.hand .tile.selected { transform: translateY(-12px); outline: 3px solid #fff; }
.hand .tile:not(.playable) { opacity: .5; cursor: not-allowed; }
.hand .tile:not(.playable):hover { transform: none; box-shadow: none; }

/* 信息条 & 操作按钮 */
.status {
  flex: 0 0 auto; text-align: center; font-size: 15px; color: var(--text);
  background: rgba(0,0,0,.28); padding: 8px 20px; border-radius: 20px;
  margin: 0 auto 6px; max-width: 92%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.status .end { color: var(--gold); font-weight: 700; }
.actionbar { flex: 0 0 auto; display: flex; justify-content: center; gap: 10px; padding: 2px 0 6px; }
.actionbar .btn {
  border: 1px solid rgba(255,255,255,.25); background: rgba(255,255,255,.1);
  color: var(--text); padding: 8px 16px; border-radius: 9px; cursor: pointer; font-size: 14px; transition: .15s;
}
.actionbar .btn:hover { background: rgba(255,255,255,.2); }
.actionbar .btn.primary { background: var(--accent); color: #3a2a00; font-weight: 700; border-color: var(--accent); }
.actionbar .btn.primary:hover { background: #ffc94d; }
.hidden { display: none !important; }

/* Toast */
.toast {
  position: fixed; top: 70px; left: 50%; transform: translateX(-50%) translateY(-10px);
  background: rgba(0,0,0,.75); color: var(--text); padding: 9px 20px; border-radius: 20px;
  font-size: 14px; opacity: 0; pointer-events: none; transition: .25s; z-index: 60;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* 弹窗 */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: grid; place-items: center; z-index: 80; }
.modal-card {
  background: linear-gradient(165deg, #2a7a55, #1c5538);
  border: 2px solid var(--gold); border-radius: 18px; padding: 24px 28px;
  box-shadow: 0 20px 60px rgba(0,0,0,.5); max-width: 92%; width: 420px; text-align: center;
}
.modal-card h2 { font-size: 24px; color: var(--gold); margin-bottom: 6px; }
.modal-card .sub { font-size: 12px; color: var(--text-dim); margin-bottom: 12px; }
.modal-card p { font-size: 13px; color: var(--text); margin: 6px 0; line-height: 1.5; }
.pick-row { display: flex; gap: 10px; justify-content: center; margin: 10px 0; flex-wrap: wrap; }
.pick-row label { flex: 0 0 100%; font-size: 13px; color: var(--text-dim); margin-bottom: -4px; }
.pick-row button {
  flex: 1; min-width: 110px; padding: 12px 10px; border-radius: 12px; cursor: pointer;
  background: rgba(255,255,255,.08); color: var(--text); border: 1px solid rgba(255,255,255,.18);
  font-size: 13px; line-height: 1.3; transition: .15s;
}
.pick-row button b { display: block; font-size: 17px; margin-bottom: 2px; }
.pick-row button.active { background: var(--accent); color: #3a2a00; border-color: var(--accent); font-weight: 700; }
.pick-row button:hover { background: rgba(255,255,255,.16); }
.modal-btns { display: flex; gap: 10px; justify-content: center; margin-top: 14px; }
.modal-btns .btn {
  border: 1px solid rgba(255,255,255,.25); background: rgba(255,255,255,.08); color: var(--text);
  padding: 10px 22px; border-radius: 10px; cursor: pointer; font-size: 15px; transition: .15s;
}
.modal-btns .btn.primary { background: var(--accent); color: #3a2a00; font-weight: 700; border-color: var(--accent); }
.modal-btns .btn.ghost { background: transparent; }
.modal-btns .btn:hover { background: rgba(255,255,255,.18); }
.modal-btns .btn.primary:hover { background: #ffc94d; }
.rule-table { width: 100%; border-collapse: collapse; margin: 10px 0; font-size: 12px; text-align: left; }
.rule-table td { border: 1px solid rgba(255,255,255,.14); padding: 6px 8px; }
.rule-table td:first-child { color: var(--gold); white-space: nowrap; font-weight: 600; }
.stats-line { font-size: 12px; color: #ffd9a0; margin-top: 8px; }

/* 特效 */
.fx { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 70; }
.confetti { position: absolute; top: -12px; width: 9px; height: 14px; border-radius: 2px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(105vh) rotate(720deg); opacity: .8; } }
.spark { position: absolute; animation: fly .9s ease-out forwards; font-size: 20px; }
@keyframes fly { to { transform: translate(var(--dx), var(--dy)) scale(.3); opacity: 0; } }

/* 极小屏：顶栏紧凑 */
@media (max-width: 480px) {
  .brand-txt b { font-size: 16px; }
  .brand .logo { font-size: 22px; }
  .chip { font-size: 11px; padding: 3px 7px; }
  .chip b { font-size: 13px; }
  .tool { width: 32px; height: 32px; font-size: 14px; }
}
