:root {
  --bg-1: #0f172a;
  --bg-2: #1e293b;
  --table: #14532d;
  --felt: #166534;
  --gold: #f59e0b;
  --cream: #fef3c7;
  --danger: #ef4444;
  --text: #f8fafc;
  --muted: #cbd5e1;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", "Noto Sans SC", sans-serif;
  color: var(--text);
  background: radial-gradient(circle at 20% 20%, #1d4ed8 0%, transparent 35%),
              radial-gradient(circle at 80% 10%, #be123c 0%, transparent 30%),
              linear-gradient(160deg, var(--bg-1), var(--bg-2));
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.bg-shape {
  position: fixed;
  border-radius: 999px;
  filter: blur(40px);
  opacity: 0.25;
  z-index: 0;
}

.shape-a {
  width: 260px;
  height: 260px;
  background: #f59e0b;
  top: 10%;
  left: -80px;
}

.shape-b {
  width: 320px;
  height: 320px;
  background: #22c55e;
  right: -120px;
  bottom: 5%;
}

.table-wrap {
  position: relative;
  z-index: 1;
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px;
}

.title-area {
  text-align: center;
  margin-bottom: 16px;
  animation: fadeInDown 0.6s ease;
}

.title-area h1 {
  margin: 0;
  font-family: "STKaiti", "KaiTi", "PingFang SC", "Microsoft YaHei", serif;
  font-size: clamp(30px, 5vw, 48px);
  color: var(--cream);
  letter-spacing: 2px;
}

.title-area p {
  margin: 6px 0 0;
  color: var(--muted);
}

.arena {
  background: linear-gradient(145deg, var(--table), var(--felt));
  border: 3px solid rgba(245, 158, 11, 0.5);
  border-radius: 24px;
  padding: 18px;
  display: grid;
  grid-template-columns: 1fr 280px 1fr;
  gap: 14px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.35);
}

.player-side {
  background: rgba(15, 23, 42, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 16px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.side-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.status {
  font-size: 12px;
  color: var(--muted);
}

.dice-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 56px;
}

.die {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  background: #fff;
  display: grid;
  place-items: center;
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.25);
  transform: rotate(var(--r));
  animation: popIn 0.35s ease;
}

.die.hidden {
  background: linear-gradient(145deg, #e2e8f0, #94a3b8);
}

.pip-grid {
  width: 34px;
  height: 34px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  place-items: center;
}

.pip {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: transparent;
}

.pip.on {
  background: #111827;
}

.die.hidden .pip.on {
  background: #334155;
}

.center-panel {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 12px;
  text-align: center;
}

.current-bid {
  background: rgba(15, 23, 42, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 12px;
  padding: 10px 14px;
}

.current-bid strong {
  display: block;
  margin-top: 4px;
  color: var(--gold);
  font-size: 24px;
}

.turn-indicator {
  font-weight: 700;
  color: var(--cream);
}

.controls {
  margin-top: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
  justify-content: center;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.input-group input {
  width: 90px;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  background: rgba(15, 23, 42, 0.7);
  color: #fff;
  font-size: 16px;
}

.input-group label {
  font-size: 13px;
  color: var(--muted);
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font-weight: 700;
  cursor: pointer;
  background: #e2e8f0;
}

.btn.primary {
  background: var(--gold);
  color: #111827;
}

.btn.danger {
  background: var(--danger);
  color: #fff;
}

.btn.warn {
  background: #f97316;
  color: #fff;
}

.btn.zhai-btn {
  background: #475569;
  color: #e2e8f0;
  min-width: 64px;
  transition: background 0.2s, color 0.2s, box-shadow 0.2s;
}

.btn.zhai-btn.active {
  background: #f59e0b;
  color: #111827;
  box-shadow: 0 0 12px rgba(245, 158, 11, 0.5);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.log-panel {
  margin-top: 14px;
  background: rgba(15, 23, 42, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 14px;
  padding: 12px;
}

.score-panel {
  margin-top: 10px;
  display: flex;
  justify-content: center;
  gap: 20px;
  color: var(--cream);
  font-weight: 700;
}

.drunk-overlay {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.78);
  display: none;
  place-items: center;
  z-index: 20;
}

.drunk-overlay.show {
  display: grid;
}

.drunk-card {
  width: min(90vw, 420px);
  background: linear-gradient(145deg, #7f1d1d, #991b1b);
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-radius: 16px;
  padding: 20px;
  text-align: center;
  animation: drunkShake 0.6s ease infinite;
}

.drunk-face {
  font-size: 56px;
}

@keyframes drunkShake {
  0% { transform: rotate(0deg) translateX(0); }
  25% { transform: rotate(-2deg) translateX(-6px); }
  50% { transform: rotate(2deg) translateX(6px); }
  75% { transform: rotate(-1deg) translateX(-4px); }
  100% { transform: rotate(0deg) translateX(0); }
}

#log {
  max-height: 220px;
  overflow: auto;
  color: var(--muted);
  line-height: 1.6;
}

.avatar {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 28px;
}

.avatar.drink .cup {
  animation: drink 1s ease 2;
}

.avatar.drink .face {
  animation: tipsy 0.8s ease 2;
}

@keyframes drink {
  0% { transform: rotate(0deg) translateY(0); }
  40% { transform: rotate(-35deg) translateY(-6px); }
  100% { transform: rotate(0deg) translateY(0); }
}

@keyframes tipsy {
  0% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  50% { transform: translateX(4px); }
  100% { transform: translateX(0); }
}

@keyframes popIn {
  from { transform: scale(0.6) rotate(var(--r)); opacity: 0; }
  to { transform: scale(1) rotate(var(--r)); opacity: 1; }
}

@keyframes fadeInDown {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ─── 微信分享引导 ─── */
.share-tip {
  display: none;
  position: fixed;
  top: 12px;
  right: 16px;
  z-index: 30;
  background: rgba(0,0,0,0.85);
  color: #fff;
  padding: 10px 16px 10px 12px;
  border-radius: 12px;
  font-size: 14px;
  align-items: center;
  gap: 8px;
  animation: fadeInDown 0.4s ease;
  border: 1px solid rgba(245,158,11,0.4);
  max-width: 260px;
  backdrop-filter: blur(8px);
}

.share-tip.show {
  display: flex;
}

.share-tip-arrow {
  font-size: 22px;
  flex-shrink: 0;
}

.share-tip strong {
  color: #f59e0b;
}

.share-tip button {
  background: none;
  border: none;
  color: #94a3b8;
  font-size: 16px;
  cursor: pointer;
  padding: 0 4px;
  flex-shrink: 0;
}

@media (max-width: 900px) {
  .arena {
    grid-template-columns: 1fr;
  }

  .center-panel {
    order: -1;
  }
}

/* ─── 手机端优化 (≤600px) ─── */
@media (max-width: 600px) {
  .table-wrap {
    padding: 10px;
  }

  .title-area h1 {
    font-size: 26px;
  }

  /* 按钮区：两列网格 */
  .controls {
    flex-wrap: wrap;
    gap: 8px;
  }

  /* 输入组占一整行 */
  .controls .input-group {
    width: 100%;
    flex-direction: row;
    align-items: center;
    gap: 8px;
  }

  .controls .input-group label {
    min-width: 36px;
  }

  .input-group input {
    flex: 1;
    width: auto;
    font-size: 16px;
    padding: 12px 8px;
  }

  /* 按钮：两列 */
  .controls .btn {
    width: calc(50% - 4px);
    flex: none;
    padding: 12px 10px;
    font-size: 15px;
    border-radius: 12px;
    min-height: 48px;
  }

  /* 骰子缩小 */
  .die {
    width: 38px;
    height: 38px;
    border-radius: 8px;
  }

  .pip-grid {
    width: 26px;
    height: 26px;
  }

  .pip {
    width: 5px;
    height: 5px;
  }

  #log {
    max-height: 150px;
  }
}

/* ─── 极小屏 (≤380px) ─── */
@media (max-width: 380px) {
  .die {
    width: 32px;
    height: 32px;
    border-radius: 7px;
  }

  .pip-grid {
    width: 22px;
    height: 22px;
  }

  .pip {
    width: 4px;
    height: 4px;
  }

  .controls .btn {
    padding: 10px 8px;
    font-size: 14px;
    min-height: 44px;
  }
}
