/* redblack — 紅黑單雙 */

.app {
  max-width: 920px;
  padding-bottom: 32px;
}

/* ── HUD ───────────────────────────────────────────────── */
.hud {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin: 12px auto;
  max-width: 640px;
}
.hud-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 8px 10px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}
.hud-label { font-size: 11px; color: var(--text-muted); letter-spacing: 0.5px; }
.hud-value {
  font-size: 22px;
  font-weight: 800;
  color: var(--accent);
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}
.hud-value.hud-pulse { animation: hud-pulse 0.5s ease; }
@keyframes hud-pulse {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.18); color: gold; }
  100% { transform: scale(1); }
}

/* ── Table & seats ─────────────────────────────────────── */
.table {
  position: relative;
  background:
    radial-gradient(ellipse at center, rgba(255,255,255,0.08), transparent 70%),
    linear-gradient(180deg, #1e6b45, #14512f);
  border: 3px solid #8b5a2b;
  border-radius: var(--radius-lg);
  padding: 10px;
  box-shadow: inset 0 0 24px rgba(0,0,0,0.35), var(--shadow-sm);
  margin-bottom: 10px;
  color: #e8f5e9;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.table.shake { animation: table-shake 0.4s ease; }
@keyframes table-shake {
  0%, 100% { transform: translate(0, 0); }
  20% { transform: translate(-6px, 2px); }
  40% { transform: translate(6px, -2px); }
  60% { transform: translate(-4px, 1px); }
  80% { transform: translate(4px, 0); }
}

.table-mid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr) minmax(0, 1fr);
  gap: 8px;
  align-items: center;
}

.seat {
  --ds: 30px;  /* die size */
  background: rgba(0,0,0,0.22);
  border: 2px solid transparent;
  border-radius: var(--radius-md);
  padding: 6px 8px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 0;
  transition: border-color 0.2s, box-shadow 0.2s, opacity 0.3s;
}
.seat.top { align-self: center; margin: 0 auto; min-width: 240px; }
.me-seat { --ds: 46px; margin: 0 auto; min-width: 300px; }
.seat.is-caller {
  border-color: gold;
  box-shadow: 0 0 14px rgba(255, 215, 0, 0.45);
}
.seat.is-out { opacity: 0.45; }
.seat.lost { animation: seat-lost 0.9s ease; }
@keyframes seat-lost {
  0%, 100% { box-shadow: none; }
  30% { box-shadow: 0 0 0 4px #ef5350, 0 0 22px #ef5350; }
}

.seat-head { display: flex; align-items: center; gap: 6px; font-weight: 800; font-size: 14px; }
.avatar { font-size: 20px; line-height: 1; }
.caller-badge {
  background: linear-gradient(180deg, #ffd54f, #f9a825);
  color: #3e2723;
  font-size: 11px;
  font-weight: 900;
  border-radius: 999px;
  padding: 1px 8px;
}
.seat-meta { display: flex; gap: 8px; align-items: center; font-size: 12px; opacity: 0.92; white-space: nowrap; }
.lives { letter-spacing: 1px; font-size: 13px; }

.cup-area {
  min-height: calc(var(--ds) * 1.7 + 6px);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
}
.out-tag, .empty-tag {
  font-weight: 900;
  font-size: 14px;
  color: #ffcdd2;
  background: rgba(0,0,0,0.3);
  border-radius: 999px;
  padding: 2px 12px;
}
.empty-tag { color: #ffab91; }

/* ── Dice cup (骰盅) ───────────────────────────────────── */
.cup {
  position: relative;
  width: calc(var(--ds) * 2.2);
  height: calc(var(--ds) * 1.6);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
}
.cup-body {
  width: 82%;
  flex: 1;
  border-radius: 46% 46% 10% 10% / 60% 60% 10% 10%;
  background:
    radial-gradient(ellipse at 32% 24%, rgba(255,255,255,0.45), transparent 38%),
    linear-gradient(180deg, #b71c1c, #6d0f0f);
  border: 2px solid #ffd54f;
  box-shadow: inset 0 -6px 10px rgba(0,0,0,0.35);
  display: flex;
  align-items: center;
  justify-content: center;
}
.cup-count {
  color: #ffe082;
  font-weight: 900;
  font-size: calc(var(--ds) * 0.5);
  text-shadow: 0 1px 2px rgba(0,0,0,0.6);
}
.cup-base {
  width: 100%;
  height: 22%;
  border-radius: 50%;
  background: linear-gradient(180deg, #ffca28, #b8860b);
  margin-top: -4px;
  box-shadow: 0 3px 5px rgba(0,0,0,0.35);
}
.cup.shake { animation: cup-shake 0.18s ease-in-out infinite; }
@keyframes cup-shake {
  0%   { transform: translate(0, 0) rotate(0); }
  25%  { transform: translate(-3px, -2px) rotate(-6deg); }
  50%  { transform: translate(3px, -3px) rotate(5deg); }
  75%  { transform: translate(-2px, 1px) rotate(-3deg); }
  100% { transform: translate(0, 0) rotate(0); }
}
.cup.peek .cup-body { animation: cup-peek 0.9s ease-in-out infinite alternate; transform-origin: 85% 100%; }
@keyframes cup-peek {
  from { transform: rotate(0); }
  to   { transform: rotate(-14deg) translateY(-4px); }
}
.blind-tag {
  position: absolute;
  top: -6px;
  right: -14px;
  background: #311b92;
  color: #fff;
  font-size: 11px;
  font-weight: 900;
  border-radius: 999px;
  padding: 1px 7px;
  border: 1px solid #b39ddb;
}

/* ── 3D dice (copied from sicbo; size via --ds) ────────── */
.dice-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: calc(var(--ds) * 0.32);
  perspective: 600px;
  padding: calc(var(--ds) * 0.2) 2px;
}
.die-slot {
  width: var(--ds);
  height: var(--ds);
  animation: die-pop 0.28s cubic-bezier(.2,1.4,.5,1) both;
}
@keyframes die-pop {
  from { transform: scale(0.4); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}
/* Removed dice: red glow, then pulled away */
.die-slot.removed {
  animation: die-pop 0.28s cubic-bezier(.2,1.4,.5,1) both, die-pull 0.9s ease-in 0.45s forwards;
}
.die-slot.removed .face { border-color: #ef5350; box-shadow: 0 0 8px #ef5350; }
@keyframes die-pull {
  0%   { transform: scale(1) translateY(0); opacity: 1; }
  30%  { transform: scale(1.15) translateY(-4px); opacity: 1; }
  100% { transform: scale(0.2) translateY(-26px); opacity: 0; }
}
.die {
  width: var(--ds);
  height: var(--ds);
  position: relative;
  transform-style: preserve-3d;
  /* DO NOT add `filter` here — it flattens preserve-3d descendants. */
}
.die-faces { transform-style: preserve-3d; position: absolute; inset: 0; }
.die .face, .mface {
  background: #fefefe;
  border: 2px solid #d8d8d8;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr 1fr;
  box-sizing: border-box;
}
.die .face {
  position: absolute;
  inset: 0;
  border-radius: calc(var(--ds) * 0.16);
  padding: calc(var(--ds) * 0.11);
  backface-visibility: hidden;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}
.die .face .pip {
  width: calc(var(--ds) * 0.16);
  height: calc(var(--ds) * 0.16);
  background: #222;
  border-radius: 50%;
  align-self: center;
  justify-self: center;
  display: block;
}
.die .face.f1 .pip { width: calc(var(--ds) * 0.24); height: calc(var(--ds) * 0.24); }
/* Chinese convention: the 1 and 4 faces have red pips — that's what 紅 means here */
.f1 .pip, .f4 .pip { background: #c0392b !important; }

/* Pip placements (3×3 grid) — shared by cube faces and flat mini faces */
.f1 .pip:nth-child(1) { grid-area: 2 / 2; }
.f2 .pip:nth-child(1) { grid-area: 1 / 1; }
.f2 .pip:nth-child(2) { grid-area: 3 / 3; }
.f3 .pip:nth-child(1) { grid-area: 1 / 1; }
.f3 .pip:nth-child(2) { grid-area: 2 / 2; }
.f3 .pip:nth-child(3) { grid-area: 3 / 3; }
.f4 .pip:nth-child(1) { grid-area: 1 / 1; }
.f4 .pip:nth-child(2) { grid-area: 1 / 3; }
.f4 .pip:nth-child(3) { grid-area: 3 / 1; }
.f4 .pip:nth-child(4) { grid-area: 3 / 3; }
.f5 .pip:nth-child(1) { grid-area: 1 / 1; }
.f5 .pip:nth-child(2) { grid-area: 1 / 3; }
.f5 .pip:nth-child(3) { grid-area: 2 / 2; }
.f5 .pip:nth-child(4) { grid-area: 3 / 1; }
.f5 .pip:nth-child(5) { grid-area: 3 / 3; }
.f6 .pip:nth-child(1) { grid-area: 1 / 1; }
.f6 .pip:nth-child(2) { grid-area: 1 / 3; }
.f6 .pip:nth-child(3) { grid-area: 2 / 1; }
.f6 .pip:nth-child(4) { grid-area: 2 / 3; }
.f6 .pip:nth-child(5) { grid-area: 3 / 1; }
.f6 .pip:nth-child(6) { grid-area: 3 / 3; }

/* Cube face transforms — after the pip rules */
.die .face.f1 { transform: translateZ(calc(var(--ds) / 2)); }
.die .face.f2 { transform: rotateY(180deg) translateZ(calc(var(--ds) / 2)); }
.die .face.f3 { transform: rotateY(90deg)  translateZ(calc(var(--ds) / 2)); }
.die .face.f4 { transform: rotateY(-90deg) translateZ(calc(var(--ds) / 2)); }
.die .face.f5 { transform: rotateX(90deg)  translateZ(calc(var(--ds) / 2)); }
.die .face.f6 { transform: rotateX(-90deg) translateZ(calc(var(--ds) / 2)); }

/* Flat mini faces (buttons, center label) */
.mface-row { display: inline-flex; gap: 3px; }
.mface {
  --ms: 18px;
  width: var(--ms);
  height: var(--ms);
  border-width: 1px;
  border-radius: 4px;
  padding: 2px;
}
.mface .pip {
  width: 3.5px;
  height: 3.5px;
  background: #222;
  border-radius: 50%;
  align-self: center;
  justify-self: center;
}
.mface.f1 .pip { width: 5px; height: 5px; }

/* ── Center ────────────────────────────────────────────── */
.center {
  background: rgba(0,0,0,0.25);
  border-radius: var(--radius-md);
  padding: 8px 10px;
  text-align: center;
  min-height: 170px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 0;
}
.round-line { font-size: 11px; opacity: 0.75; }
.caller-line { font-size: 14px; font-weight: 800; min-height: 20px; }
.call-label {
  font-size: 46px;
  font-weight: 900;
  line-height: 1.05;
  letter-spacing: 2px;
  color: #fff;
  text-shadow: 0 2px 6px rgba(0,0,0,0.5);
}
.call-label.waiting { opacity: 0.5; animation: wait-pulse 1s ease-in-out infinite alternate; }
@keyframes wait-pulse { from { opacity: 0.35; } to { opacity: 0.7; } }
.call-label.pop { animation: label-pop 0.45s cubic-bezier(.2,1.5,.5,1); }
@keyframes label-pop { from { transform: scale(0.3); } to { transform: scale(1); } }
.call-label.cat-red, .cat-red.call-label { color: #ff6b6b; }
.call-label.cat-black { color: #e0e0e0; }
.call-label.cat-big   { color: #ffd54f; }
.call-label.cat-small { color: #81d4fa; }
.call-label.cat-odd   { color: #c5e1a5; }
.call-label.cat-even  { color: #ce93d8; }
.call-faces { min-height: 20px; }
.call-log {
  list-style: none;
  margin: 4px 0 0;
  padding: 0;
  font-size: 11.5px;
  line-height: 1.5;
  width: 100%;
  text-align: left;
  opacity: 0.92;
}
.call-log li { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.call-log li.loss { color: #ffab91; }
.call-log .log-n { opacity: 0.6; font-variant-numeric: tabular-nums; }
.call-log b.cat-red { color: #ff8a80; }

/* ── Round banner & match over ─────────────────────────── */
.round-banner {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 5;
  background: rgba(20, 20, 20, 0.88);
  border: 2px solid #ffb74d;
  border-radius: var(--radius-md);
  padding: 12px 20px;
  text-align: center;
  min-width: 260px;
  max-width: 92%;
  box-shadow: 0 8px 26px rgba(0,0,0,0.5);
  animation: banner-in 0.35s cubic-bezier(.2,1.4,.5,1);
}
.round-banner.me { border-color: #ef5350; }
.round-banner.draw { border-color: #90caf9; }
@keyframes banner-in { from { transform: translate(-50%, -50%) scale(0.6); opacity: 0; } to { transform: translate(-50%, -50%) scale(1); opacity: 1; } }
.banner-head { font-size: 19px; font-weight: 900; }
.banner-sub { font-size: 13px; opacity: 0.9; margin-top: 4px; }

.over-panel {
  position: absolute;
  inset: 0;
  z-index: 6;
  background: rgba(10, 30, 20, 0.86);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px;
  animation: fade-in 0.4s ease;
}
.over-panel[hidden] { display: none; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.over-title { font-size: 26px; font-weight: 900; text-align: center; }
.over-panel.win .over-title { color: #ffd54f; }
.over-panel.lose .over-title { color: #ff8a80; }
.ranking { list-style: none; margin: 0; padding: 0; width: min(320px, 100%); }
.ranking li {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  align-items: center;
  gap: 8px;
  background: rgba(255,255,255,0.08);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  margin-bottom: 6px;
  font-size: 15px;
}
.ranking li.me { outline: 2px solid gold; }
.ranking .rk { font-weight: 900; font-size: 18px; color: #ffd54f; text-align: center; }
.ranking .nm { font-weight: 700; }

/* ── Category buttons ──────────────────────────────────── */
.hint-line {
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  min-height: 20px;
  margin: 2px 0 6px;
}
.hint-line.on { color: var(--text-strong); font-weight: 700; }
.cat-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  max-width: 760px;
  margin: 0 auto;
}
.cat-btn {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 4px 10px;
  border-radius: var(--radius-md);
  border: 2px solid rgba(255,255,255,0.18);
  background: linear-gradient(180deg, #37474f, #263238);
  color: #fff;
  cursor: pointer;
  font: inherit;
  transition: transform 0.12s, box-shadow 0.12s, opacity 0.2s;
}
.cat-btn.cat-red { background: linear-gradient(180deg, #c62828, #8e1b1b); }
.cat-btn.cat-black { background: linear-gradient(180deg, #424242, #1c1c1c); }
.cat-btn:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 6px 12px rgba(0,0,0,0.3); }
.cat-btn:disabled { opacity: 0.42; cursor: not-allowed; filter: grayscale(0.4); }
.cat-grid.active .cat-btn { animation: btn-glow 1.4s ease-in-out infinite alternate; }
@keyframes btn-glow {
  from { box-shadow: 0 0 0 0 rgba(255, 215, 0, 0); }
  to   { box-shadow: 0 0 12px 2px rgba(255, 215, 0, 0.55); }
}
.cat-name { font-size: 22px; font-weight: 900; line-height: 1; }
.cat-key {
  position: absolute;
  top: 3px;
  left: 6px;
  font-size: 10px;
  opacity: 0.6;
}
.cat-prob { position: absolute; top: 3px; right: 6px; font-size: 10px; opacity: 0.7; }
.cat-btn .mface { --ms: 16px; }
.cat-btn .mface-row { flex-wrap: wrap; justify-content: center; }
.cat-hit {
  font-size: 11px;
  font-weight: 800;
  background: rgba(0,0,0,0.35);
  border-radius: 999px;
  padding: 0 7px;
  color: #ffab91;
}
.cat-hit.zero { color: #a5d6a7; }

/* ── Bottom actions ────────────────────────────────────── */
.action-row { display: flex; justify-content: center; gap: 10px; margin: 14px 0 6px; }
.action-row .btn { min-width: 120px; }
.action-row .btn.warn { background: #c62828; color: #fff; }
.over-panel .btn.primary {
  background: linear-gradient(180deg, #e74c3c, #c0392b);
  color: #fff;
  border: none;
  font-weight: 800;
  min-width: 140px;
}

.legend {
  margin-top: 12px;
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.5;
}

/* ── Phone ─────────────────────────────────────────────── */
@media (max-width: 600px) {
  .table { padding: 6px; gap: 6px; }
  .table-mid { grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr) minmax(0, 1fr); gap: 4px; }
  .seat { --ds: 17px; padding: 4px 3px 6px; }
  .seat.top { min-width: 0; width: 60%; }
  .me-seat { --ds: 38px; min-width: 0; width: 100%; }
  .seat-head { font-size: 12px; gap: 3px; }
  .avatar { font-size: 16px; }
  .seat-meta { flex-direction: column; gap: 0; font-size: 11px; }
  .lives { font-size: 11px; letter-spacing: 0; }
  .ai-seat .dice-row { gap: 4px; }
  .center { min-height: 150px; padding: 6px 4px; }
  .call-label { font-size: 34px; }
  .call-log { font-size: 10px; }
  .cat-grid { grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .cat-name { font-size: 19px; }
}

/* Light mode: accent-gold HUD numbers on white were ~1.7:1 contrast. Darken the active accent
   (works with every profile accent colour); :where() keeps specificity at .hud-value so
   win/lose-coloured values still override it. Dark mode keeps the bright accent. */
:where(body:not(.dark)) .hud-value { color: color-mix(in srgb, var(--accent) 55%, #000); }
