/* dice701 — 701 擲骰派對 */

.app {
  max-width: 900px;
  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;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.hud-value.small { font-size: 16px; line-height: 26px; }
.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 ─────────────────────────────────────────────── */
.table {
  position: relative;
  background: linear-gradient(180deg, #3b2a5c, #261a3f);
  border: 3px solid #6a4c9c;
  border-radius: var(--radius-lg);
  padding: 12px;
  box-shadow: inset 0 0 24px rgba(0,0,0,0.35), var(--shadow-sm);
  margin-bottom: 10px;
  color: #f3eaff;
}
.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); }
}

.felt {
  position: relative;
  display: grid;
  grid-template-columns: minmax(118px, 1fr) minmax(0, 1.5fr) minmax(118px, 1fr);
  grid-template-rows: auto minmax(230px, auto) auto;
  grid-template-areas:
    ".    top    ."
    "left center right"
    ".    bottom .";
  gap: 8px;
  align-items: center;
  justify-items: center;
}
.felt::before {
  content: "";
  position: absolute;
  left: 50%; top: 50%;
  height: calc(100% + 8px);
  max-width: 96%;
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background:
    radial-gradient(circle at center, rgba(255,255,255,0.10), transparent 70%),
    radial-gradient(circle at center, #1f7a57 0%, #145c41 70%);
  border: 6px solid #8b5a2b;
  box-shadow: inset 0 0 30px rgba(0,0,0,0.45), 0 4px 14px rgba(0,0,0,0.4);
  pointer-events: none;
}
.seat.s2 { grid-area: top; }
.seat.s1 { grid-area: left; }
.seat.s3 { grid-area: right; }
.seat.s0 { grid-area: bottom; }

/* ── Seats ─────────────────────────────────────────────── */
.seat {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(0,0,0,0.35);
  border: 2px solid transparent;
  border-radius: var(--radius-md);
  padding: 6px 10px;
  min-width: 0;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.seat.me { background: rgba(60, 20, 90, 0.7); }
.seat.active { border-color: #ffd54f; box-shadow: 0 0 14px rgba(255,213,79,0.5); }
.seat.winner { border-color: #66bb6a; box-shadow: 0 0 16px rgba(102,187,106,0.6); }
.avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: rgba(255,255,255,0.92);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
  flex: none;
}
.seat-meta { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.seat-name { font-size: 13px; font-weight: 800; white-space: nowrap; }
.seat-pen { font-size: 12px; opacity: 0.9; white-space: nowrap; }
.seat-pen b { font-size: 20px; color: #ffcc80; font-variant-numeric: tabular-nums; }
.rank-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 800;
  border-radius: 999px;
  padding: 0 6px;
  background: rgba(255,255,255,0.18);
  vertical-align: 1px;
}
.rank-badge.r1 { background: #66bb6a; color: #0b2e10; }
.seat-dir {
  font-size: 20px;
  font-weight: 900;
  color: #ffd54f;
  min-width: 18px;
  text-align: center;
}
.reroll-tag {
  position: absolute;
  top: -11px; right: -6px;
  font-size: 11px;
  font-weight: 900;
  color: #fff;
  background: #e53935;
  border-radius: 999px;
  padding: 1px 8px;
  animation: warn-pulse 0.7s ease-in-out infinite alternate;
}
@keyframes warn-pulse { from { opacity: 0.7; } to { opacity: 1; transform: scale(1.08); } }
.pen-float {
  position: absolute;
  left: 50%; top: 0;
  transform: translate(-50%, 0);
  font-size: 22px;
  font-weight: 900;
  color: #ff8a65;
  text-shadow: 0 2px 4px rgba(0,0,0,0.6);
  pointer-events: none;
  animation: pen-rise 1.2s ease-out forwards;
}
@keyframes pen-rise {
  0%   { opacity: 0; transform: translate(-50%, 10px) scale(0.6); }
  20%  { opacity: 1; transform: translate(-50%, -8px) scale(1.2); }
  100% { opacity: 0; transform: translate(-50%, -40px) scale(1); }
}

/* ── Center: pool + dice ───────────────────────────────── */
.center {
  grid-area: center;
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 0;
  width: 100%;
}
.dir-ring {
  font-size: 12px;
  font-weight: 800;
  padding: 2px 10px;
  border-radius: 999px;
  background: rgba(0,0,0,0.3);
  color: #ffd54f;
}
.dir-ring.bump { animation: hud-pulse 0.5s ease; }
.pool { text-align: center; line-height: 1.05; }
.pool-label { font-size: 12px; font-weight: 800; opacity: 0.85; letter-spacing: 1px; }
.pool-value {
  font-size: 46px;
  font-weight: 900;
  color: #fff3c4;
  text-shadow: 0 2px 8px rgba(0,0,0,0.5);
  font-variant-numeric: tabular-nums;
}
.pool.hot .pool-value { color: #ff8a65; text-shadow: 0 0 14px rgba(255,112,67,0.8); }
.pool.bump { animation: hud-pulse 0.5s ease; }
.event-line {
  font-size: 14px;
  font-weight: 800;
  text-align: center;
  min-height: 40px;
  max-width: 100%;
  padding: 0 6px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.6);
}
.event-line.pop { animation: banner-pop 0.3s cubic-bezier(.2,1.4,.5,1); }
.event-line.hit { color: #ffab91; }

/* ── 3D dice (adapted from sicbo) ──────────────────────── */
.dice-stage {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 26px;
  padding: 12px 0 8px;
  perspective: 600px;
  min-height: 84px;
}
.die {
  width: 56px;
  height: 56px;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.7s cubic-bezier(.18,.7,.25,1);
  /* no `filter` here — it flattens preserve-3d */
}
.die-faces { transform-style: preserve-3d; position: absolute; inset: 0; }
.dice-stage.pre-roll-shake { animation: dice-stage-shake 0.2s ease-in-out; }
@keyframes dice-stage-shake {
  0%   { transform: translate(0, 0); }
  25%  { transform: translate(-4px, -2px); }
  50%  { transform: translate(4px, -2px); }
  75%  { transform: translate(-3px, 3px); }
  100% { transform: translate(0, 0); }
}
.die.landed .face { animation: die-land-flash 0.32s cubic-bezier(.2,1.4,.5,1); }
@keyframes die-land-flash {
  0%   { box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15); }
  40%  { box-shadow: 0 0 12px gold, 0 1px 2px rgba(0, 0, 0, 0.15); }
  100% { box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15); }
}
.die .face {
  position: absolute;
  inset: 0;
  background: #fefefe;
  border: 2px solid #d8d8d8;
  border-radius: 9px;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr 1fr;
  padding: 6px;
  box-sizing: border-box;
  backface-visibility: hidden;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}
.die .face .pip {
  width: 9px;
  height: 9px;
  background: #222;
  border-radius: 50%;
  align-self: center;
  justify-self: center;
  display: block;
}
/* 1 and 4 pips are red */
.die .face.f1 .pip,
.die .face.f4 .pip { background: #c0392b; }

.die .face.f1 .pip:nth-child(1) { grid-area: 2 / 2; width: 13px; height: 13px; }
.die .face.f2 .pip:nth-child(1) { grid-area: 1 / 1; }
.die .face.f2 .pip:nth-child(2) { grid-area: 3 / 3; }
.die .face.f3 .pip:nth-child(1) { grid-area: 1 / 1; }
.die .face.f3 .pip:nth-child(2) { grid-area: 2 / 2; }
.die .face.f3 .pip:nth-child(3) { grid-area: 3 / 3; }
.die .face.f4 .pip:nth-child(1) { grid-area: 1 / 1; }
.die .face.f4 .pip:nth-child(2) { grid-area: 1 / 3; }
.die .face.f4 .pip:nth-child(3) { grid-area: 3 / 1; }
.die .face.f4 .pip:nth-child(4) { grid-area: 3 / 3; }
.die .face.f5 .pip:nth-child(1) { grid-area: 1 / 1; }
.die .face.f5 .pip:nth-child(2) { grid-area: 1 / 3; }
.die .face.f5 .pip:nth-child(3) { grid-area: 2 / 2; }
.die .face.f5 .pip:nth-child(4) { grid-area: 3 / 1; }
.die .face.f5 .pip:nth-child(5) { grid-area: 3 / 3; }
.die .face.f6 .pip:nth-child(1) { grid-area: 1 / 1; }
.die .face.f6 .pip:nth-child(2) { grid-area: 1 / 3; }
.die .face.f6 .pip:nth-child(3) { grid-area: 2 / 1; }
.die .face.f6 .pip:nth-child(4) { grid-area: 2 / 3; }
.die .face.f6 .pip:nth-child(5) { grid-area: 3 / 1; }
.die .face.f6 .pip:nth-child(6) { grid-area: 3 / 3; }
/* cube transforms — after pip rules */
.die .face.f1 { transform: translateZ(28px); }
.die .face.f2 { transform: rotateY(180deg) translateZ(28px); }
.die .face.f3 { transform: rotateY(90deg)  translateZ(28px); }
.die .face.f4 { transform: rotateY(-90deg) translateZ(28px); }
.die .face.f5 { transform: rotateX(90deg)  translateZ(28px); }
.die .face.f6 { transform: rotateX(-90deg) translateZ(28px); }

/* ── Result banner ─────────────────────────────────────── */
.result-banner {
  margin: 10px auto 0;
  max-width: 420px;
  text-align: center;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  background: rgba(0,0,0,0.5);
  color: #fff;
  animation: banner-pop 0.35s cubic-bezier(.2,1.4,.5,1);
}
.result-banner[hidden] { display: none; }
.result-banner.win { box-shadow: 0 0 18px rgba(255,215,0,0.6); }
.banner-head { font-size: 20px; font-weight: 900; }
.banner-sub  { font-size: 12px; opacity: 0.9; margin-top: 4px; }
.standings { list-style: none; margin: 6px 0 0; padding: 0; }
.standings li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 8px;
  border-radius: 8px;
  font-weight: 700;
}
.standings li.me { background: rgba(255,213,79,0.18); }
.standings li b { margin-left: auto; color: #ffcc80; font-variant-numeric: tabular-nums; }
.standings .rk { width: 26px; text-align: left; opacity: 0.85; }
@keyframes banner-pop {
  from { transform: scale(0.7); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

/* ── Status & controls ─────────────────────────────────── */
.status-line {
  font-size: 14px;
  font-weight: 700;
  text-align: center;
  min-height: 20px;
  color: var(--text);
}
.status-line.mine { color: var(--accent); }
.dots i { font-style: normal; animation: dot-blink 1.2s infinite; opacity: 0.2; }
.dots i:nth-child(2) { animation-delay: 0.2s; }
.dots i:nth-child(3) { animation-delay: 0.4s; }
@keyframes dot-blink { 30% { opacity: 1; } }

.controls {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  margin: 10px 0 14px;
}
.controls[hidden] { display: none; }
.controls .btn { min-width: 92px; }
.controls .btn.primary {
  background: linear-gradient(180deg, #8e44ad, #5b2c6f);
  color: #fff;
  border: none;
  font-weight: 800;
  min-width: 160px;
  animation: d701-glow 1.6s ease-in-out infinite alternate;
}
@keyframes d701-glow {
  0%   { box-shadow: 0 0 0 0 rgba(255, 215, 0, 0); }
  100% { box-shadow: 0 0 18px 4px rgba(255, 215, 0, 0.55); }
}
.controls .btn.primary:disabled {
  background: var(--btn-disabled);
  color: rgba(255,255,255,0.6);
  cursor: not-allowed;
  animation: none;
}
.add-btn { font-size: 18px; font-weight: 900; }
.add-btn[data-add="3"] { background: linear-gradient(180deg, #ff7043, #d84315); color: #fff; border: none; }
.target-btn { font-weight: 700; }
.target-btn.leader { border-color: #66bb6a; box-shadow: 0 0 0 2px rgba(102,187,106,0.5); }
.target-btn.self { opacity: 0.85; }

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

/* ── Responsive ────────────────────────────────────────── */
@media (max-width: 640px) {
  .table { padding: 8px 4px; }
  .felt { grid-template-columns: 84px minmax(0, 1fr) 84px; grid-template-rows: auto minmax(200px, auto) auto; gap: 4px; }
  .seat.s1, .seat.s3 { flex-direction: column; gap: 2px; padding: 5px 4px; text-align: center; }
  .seat.s1 .seat-meta, .seat.s3 .seat-meta { align-items: center; }
  .avatar { width: 32px; height: 32px; font-size: 18px; }
  .seat-name { font-size: 12px; }
  .seat-pen b { font-size: 17px; }
  .pool-value { font-size: 36px; }
  .event-line { font-size: 12px; }
  .die { width: 46px; height: 46px; }
  .die .face { padding: 5px; border-radius: 8px; }
  .die .face .pip { width: 7px; height: 7px; }
  .die .face.f1 .pip:nth-child(1) { width: 11px; height: 11px; }
  .die .face.f1 { transform: translateZ(23px); }
  .die .face.f2 { transform: rotateY(180deg) translateZ(23px); }
  .die .face.f3 { transform: rotateY(90deg)  translateZ(23px); }
  .die .face.f4 { transform: rotateY(-90deg) translateZ(23px); }
  .die .face.f5 { transform: rotateX(90deg)  translateZ(23px); }
  .die .face.f6 { transform: rotateX(-90deg) translateZ(23px); }
  .dice-stage { gap: 18px; perspective: 480px; min-height: 70px; }
  .controls .btn { min-width: 70px; }
}
@media (max-width: 380px) {
  .felt { grid-template-columns: 74px minmax(0, 1fr) 74px; }
  .seat-name .rank-badge { display: none; }
}

/* 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); }
