:root {
  --felt: #0d2a1c;
  --felt-2: #123726;
  --panel: rgba(255, 255, 255, 0.06);
  --line: rgba(255, 255, 255, 0.12);
  --gold: #f0c05a;
  --gold-dim: #b98f33;
  --text: #eef3ee;
  --muted: #9db3a6;
  --danger: #e2573f;
  --ok: #4cc38a;
  --radius: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background:
    radial-gradient(120% 80% at 50% 0%, #16452e 0%, var(--felt) 55%, #081911 100%);
  color: var(--text);
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
  min-height: 100%;
  -webkit-tap-highlight-color: transparent;
}

button, select { font-family: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.38; }

.app {
  max-width: 1180px;
  margin: 0 auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* --------------------------------------------------------------- 顶栏 */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 14px;
}

.scoreboard { display: flex; align-items: center; gap: 10px; font-size: 15px; }
.seat-score { padding: 4px 10px; border-radius: 999px; background: rgba(0, 0, 0, 0.25); }
.seat-score b { color: var(--gold); font-size: 18px; }
.seat-score.you { color: #bfe6ff; }
.seat-score.ai { color: #ffd9bf; }
.score-sep { color: var(--muted); }

.topbar-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
#round-label { color: var(--muted); font-size: 13px; }

select, .ghost {
  background: rgba(0, 0, 0, 0.3);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 13px;
}
.ghost:hover { border-color: var(--gold-dim); }
.ghost.small { padding: 4px 8px; font-size: 12px; }

.banner {
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 13px;
  line-height: 1.5;
  border: 1px solid;
}
.banner.warn { background: rgba(226, 87, 63, 0.14); border-color: rgba(226, 87, 63, 0.5); }
.banner.info { background: rgba(240, 192, 90, 0.12); border-color: rgba(240, 192, 90, 0.4); }
.hidden { display: none !important; }

/* --------------------------------------------------------------- 牌桌 */
.table {
  display: flex;
  flex-direction: column;
  gap: 10px;
  background:
    radial-gradient(90% 70% at 50% 45%, rgba(255, 255, 255, 0.05), transparent 70%),
    var(--felt-2);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 16px;
  box-shadow: inset 0 0 60px rgba(0, 0, 0, 0.45);
}

.seat { display: flex; flex-direction: column; gap: 8px; }
.ai-seat { align-items: flex-start; }
.you-seat { align-items: flex-start; }
.seat-row { display: flex; align-items: center; gap: 12px; width: 100%; flex-wrap: wrap; }

.turn-badge {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 13px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  color: var(--gold);
  background: rgba(240, 192, 90, 0.16);
  border: 1px solid var(--gold-dim);
  animation: badgePulse 1.5s ease-in-out infinite;
}
.turn-badge.ai {
  color: #bfe9ff;
  background: rgba(127, 215, 255, 0.14);
  border-color: #7fd7ff;
}
.turn-badge[hidden] { display: none; }
@keyframes badgePulse {
  0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(240, 192, 90, 0.35); }
  50% { transform: scale(1.05); box-shadow: 0 0 0 6px rgba(240, 192, 90, 0); }
}
.seat-head { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.seat-head .name { font-weight: 600; letter-spacing: 1px; }
.seat-head .tag { font-size: 12px; color: var(--gold); }

.dice { display: flex; gap: 10px; flex-wrap: wrap; }

.die {
  width: 54px;
  height: 54px;
  border-radius: 12px;
  background: linear-gradient(160deg, #ffffff 0%, #e6e3d8 100%);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.35), inset 0 -2px 4px rgba(0, 0, 0, 0.12);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  padding: 7px;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.die span { display: block; }
.die span.pip {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #1a1a1e;
  align-self: center;
  justify-self: center;
}
.die.match {
  box-shadow: 0 0 0 3px var(--gold), 0 4px 0 rgba(0, 0, 0, 0.35);
  transform: translateY(-3px);
}
.die.wild { box-shadow: 0 0 0 3px #7fd7ff, 0 4px 0 rgba(0, 0, 0, 0.35); }

.die.back {
  background: linear-gradient(160deg, #2a4a38, #16301f);
  color: rgba(255, 255, 255, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.45), inset 0 0 12px rgba(0, 0, 0, 0.5);
}

.say {
  min-height: 20px;
  font-size: 14px;
  color: var(--gold);
  font-style: italic;
}

/* ----------------------------------------------------------- 中央信息 */
.center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px 0;
  border-top: 1px dashed var(--line);
  border-bottom: 1px dashed var(--line);
}
.current-bid {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--gold);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}
.bid-mode {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0;
  padding: 3px 12px;
  border-radius: 999px;
  border: 1px solid;
  vertical-align: middle;
}
.bid-mode.fei { color: #b6f0d3; background: rgba(76, 195, 138, 0.18); border-color: var(--ok); }
.bid-mode.zhai { color: #ffe6a8; background: rgba(240, 192, 90, 0.18); border-color: var(--gold-dim); }
.bid-mode[hidden] { display: none; }
.wild-state { font-size: 12px; color: var(--muted); }
.turn-hint { font-size: 13px; color: #cfe6d8; }

.thinking { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--gold); }
.thinking span {
  width: 6px; height: 6px; border-radius: 50%; background: var(--gold);
  animation: blink 1.2s infinite ease-in-out;
}
.thinking span:nth-child(2) { animation-delay: 0.2s; }
.thinking span:nth-child(3) { animation-delay: 0.4s; margin-right: 6px; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }

/* --------------------------------------------------------------- 操作 */
.controls {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.control-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.field { display: flex; align-items: center; gap: 10px; min-width: 0; }
.label { font-size: 13px; color: var(--muted); }
.spacer { flex: 1; }

.stepper { display: flex; align-items: center; gap: 8px; }
.stepper b { min-width: 34px; text-align: center; font-size: 20px; color: var(--gold); }
.round-btn {
  width: 34px; height: 34px; border-radius: 50%;
  background: rgba(0, 0, 0, 0.3); color: var(--text);
  border: 1px solid var(--line); font-size: 17px; line-height: 1;
}
.round-btn:hover { border-color: var(--gold); }

.faces { display: flex; gap: 6px; }
.face-btn {
  width: 36px; height: 36px; border-radius: 10px;
  background: rgba(0, 0, 0, 0.28); color: var(--text);
  border: 1px solid var(--line); font-size: 15px;
}
.face-btn.active { background: var(--gold); color: #241a00; border-color: var(--gold); font-weight: 700; }

.chip {
  padding: 7px 16px; border-radius: 999px;
  background: rgba(0, 0, 0, 0.28); color: var(--text);
  border: 1px solid var(--line); font-size: 14px;
}
.chip, .action {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.chip.active { background: rgba(127, 215, 255, 0.2); border-color: #7fd7ff; color: #bfe9ff; }
.chip.active.fei { background: rgba(76, 195, 138, 0.2); border-color: var(--ok); color: #b6f0d3; }
/* 高亮就是「这一手之后 1 是什么状态」：金色=斋（1 只算 1），绿色=飞（1 万能） */
#toggle-zhai.active { background: rgba(240, 192, 90, 0.18); border-color: var(--gold-dim); color: #ffe6a8; }
#toggle-fei.active { background: rgba(76, 195, 138, 0.18); border-color: var(--ok); color: #b6f0d3; }

.action {
  padding: 9px 18px; border-radius: 12px; font-size: 15px;
  border: 1px solid var(--line); background: rgba(0, 0, 0, 0.3); color: var(--text);
}
.action.primary { background: var(--gold); color: #241a00; border-color: var(--gold); font-weight: 700; }
.action.danger { border-color: rgba(226, 87, 63, 0.6); color: #ffb9ab; }
.action.danger:hover:not(:disabled) { background: rgba(226, 87, 63, 0.22); }
.action.primary:hover:not(:disabled) { filter: brightness(1.08); }

.hint { margin: 0; font-size: 12.5px; color: var(--muted); line-height: 1.5; }
.hint.bad { color: #ff9d8a; }
.hint.flash {
  color: #ffe6a8;
  background: rgba(240, 192, 90, 0.12);
  border: 1px solid rgba(240, 192, 90, 0.4);
  border-radius: 10px;
  padding: 8px 10px;
}

/* --------------------------------------------------------------- 侧栏 */
.side { display: flex; flex-direction: column; gap: 12px; min-height: 0; }
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.panel h3 { margin: 0 0 8px; font-size: 13px; color: var(--gold); letter-spacing: 1px; font-weight: 600; }
.memory { font-size: 13px; line-height: 1.7; color: #d7e6dc; }
.memory .row { display: flex; justify-content: space-between; gap: 8px; }
.memory .row span:last-child { color: var(--gold); }
.memory .empty { color: var(--muted); }
.log { font-size: 12.5px; line-height: 1.6; max-height: 300px; overflow-y: auto; color: #cbdcd1; }
.log div { padding: 2px 0; border-bottom: 1px dashed rgba(255, 255, 255, 0.06); }
.log .hl { color: var(--gold); }
.log .bad { color: #ff9d8a; }
.log .good { color: var(--ok); }

/* --------------------------------------------------------------- 浮层 */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(4, 12, 8, 0.72);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  padding: 18px;
}
.card {
  width: min(560px, 100%);
  max-height: 88vh; overflow-y: auto;
  background: linear-gradient(180deg, #17392a, #102519);
  border: 1px solid var(--gold-dim);
  border-radius: 20px;
  padding: 22px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}
.card h2 { margin: 0 0 12px; font-size: 21px; color: var(--gold); }
.card p { font-size: 14px; line-height: 1.8; margin: 8px 0; }
.card .dice { margin: 12px 0; }
.card .verdict { font-size: 16px; font-weight: 700; }
.card .verdict.win { color: var(--ok); }
.card .verdict.lose { color: var(--danger); }
.card .think { background: rgba(0, 0, 0, 0.28); border-left: 3px solid var(--gold); padding: 8px 12px; border-radius: 8px; font-size: 13px; color: #e9d9ac; }
.card .buttons { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.card ul { font-size: 13.5px; line-height: 1.8; padding-left: 18px; }

/* ------------------------------------------------- 结算卡：两排骰子 */
.settle-head h2 { margin-bottom: 4px; }
.settle-sub { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.settle-sub b { color: var(--gold); }

.settle-rows { display: flex; flex-direction: column; gap: 10px; margin: 14px 0 12px; }
.settle-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(0, 0, 0, 0.26);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  padding: 8px 10px;
}
.settle-row .dice { gap: 6px; flex-wrap: nowrap; }
.settle-row .die {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  padding: 5px;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.32);
}
.settle-row .die span.pip { width: 7px; height: 7px; }
.settle-row .die.match { box-shadow: 0 0 0 3px var(--gold), 0 3px 0 rgba(0, 0, 0, 0.32); transform: none; }
.settle-row .die.wild { box-shadow: 0 0 0 3px #7fd7ff, 0 3px 0 rgba(0, 0, 0, 0.32); transform: none; }
.settle-name { width: 40px; flex: none; font-size: 13px; color: var(--muted); }
.settle-count { margin-left: auto; flex: none; font-size: 13px; color: var(--gold); text-align: right; }
.settle-count b { font-size: 17px; }
.settle-count .leo { display: block; font-size: 11px; color: #7fd7ff; }

.settle-verdict { font-size: 15px; font-weight: 700; margin: 2px 0 6px; }
.settle-legend { font-size: 11.5px; color: var(--muted); margin: -4px 0 8px; display: flex; align-items: center; gap: 4px; }
.settle-legend .dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.settle-legend .dot.gold { background: var(--gold); }
.settle-legend .dot.blue { background: #7fd7ff; }
.settle-verdict b { font-size: 18px; }
.settle-verdict.win { color: var(--ok); }
.settle-verdict.lose { color: var(--danger); }
.settle-score { font-size: 13px; color: #d7e6dc; margin-bottom: 10px; }
.settle-score b { color: var(--gold); }

@media (max-width: 520px) {
  .settle-row .die { width: 34px; height: 34px; border-radius: 8px; padding: 4px; }
  .settle-row .die span.pip { width: 5.5px; height: 5.5px; }
  .settle-name { width: 32px; font-size: 12px; }
  .settle-count { font-size: 12px; }
  .settle-count b { font-size: 15px; }
}

/* --------------------------------------------------------------- 桌面 */
@media (min-width: 1000px) {
  .app {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 330px;
    grid-template-rows: auto auto 1fr auto;
    grid-template-areas:
      "top top"
      "banner banner"
      "table side"
      "controls side";
    align-items: start;
  }
  .topbar { grid-area: top; }
  #banner { grid-area: banner; }
  .table { grid-area: table; }
  .controls { grid-area: controls; }
  .side { grid-area: side; position: sticky; top: 14px; }
  .die { width: 58px; height: 58px; }
}

@media (max-width: 520px) {
  .die { width: 46px; height: 46px; border-radius: 10px; }
  .die span.pip { width: 7px; height: 7px; }
  .current-bid { font-size: 22px; }
  .face-btn { width: 32px; height: 32px; }
  .action { padding: 8px 13px; font-size: 14px; }
  /* 窄屏：数量和点数各占一行，标签和按钮永远在一起，不会错位 */
  .field { width: 100%; }
  .field .faces { flex: 1; justify-content: space-between; }
  /* 数量那行也铺满整行，跟点数行左右对齐 */
  .field .stepper { flex: 1; justify-content: space-between; }
  #btn-bid { width: 100%; }
}
