/* =========================================================
   摇骰子开盖小游戏 - 样式表
   ========================================================= */

/* 全局重置 */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI",
               "PingFang SC", "Microsoft YaHei", sans-serif;
  /* 柔和渐变背景 */
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

/* 主容器（卡片）*/
.container {
  background: rgba(255, 255, 255, 0.96);
  border-radius: 20px;
  padding: 30px 40px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  text-align: center;
  max-width: 600px;
  width: 100%;
}

h1 {
  color: #333;
  font-size: 2rem;
  margin-bottom: 8px;
}

.subtitle {
  color: #888;
  font-size: 0.95rem;
  margin-bottom: 25px;
}

/* =========================================================
   骰盅区域（仿真实圆筒骰盅：椭圆盖 + 圆柱杯身 + 椭圆底座）
   ========================================================= */
.dice-cup-wrapper {
  perspective: 1200px;                  /* 3D 透视 */
  margin: 20px auto;
  width: 260px;
  height: 290px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.dice-cup {
  position: relative;
  width: 200px;
  height: 250px;
  transform-style: preserve-3d;
}

/* 摇晃动画：左右摇摆，单次 0.2s，循环 5 次约 1 秒 */
@keyframes shake {
  0%, 100% { transform: rotate(0deg) translateX(0); }
  10% { transform: rotate(-8deg) translateX(-10px); }
  20% { transform: rotate(8deg)  translateX(10px); }
  30% { transform: rotate(-8deg) translateX(-10px); }
  40% { transform: rotate(8deg)  translateX(10px); }
  50% { transform: rotate(-6deg) translateX(-8px); }
  60% { transform: rotate(6deg)  translateX(8px); }
  70% { transform: rotate(-4deg) translateX(-5px); }
  80% { transform: rotate(4deg)  translateX(5px); }
  90% { transform: rotate(-2deg) translateX(-2px); }
}

.dice-cup.shaking {
  animation: shake 0.2s ease-in-out 5;
}

/* ---- 盖子（椭圆盘 + 把手）---- */
.lid {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 34px;
  transform-origin: 50% 100%;          /* 绕底部翻转 */
  transform: rotateX(0deg);
  transition: transform 0.7s cubic-bezier(0.68, -0.4, 0.27, 1.4);
  z-index: 12;
}

/* 揭盖：盖子向后上方翻转 */
.lid.open {
  transform: rotateX(-150deg) translateY(-6px);
}

/* 盖面：椭圆形（模拟圆盘盖）*/
.lid-top {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 22px;
  background: linear-gradient(145deg, #6b3e1f 0%, #b0723a 50%, #6b3e1f 100%);
  border-radius: 50%;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.4),
              inset 0 -3px 6px rgba(0, 0, 0, 0.35);
}

/* 盖顶把手 */
.lid-knob {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 26px;
  height: 14px;
  background: linear-gradient(145deg, #d4a373, #6b3e1f);
  border-radius: 8px 8px 4px 4px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

/* ---- 杯身（圆柱侧面：左右暗中间亮模拟曲面）---- */
.cup-body {
  position: absolute;
  top: 22px;
  left: 0;
  width: 100%;
  height: 206px;
  background: linear-gradient(90deg,
              #2a1808 0%,
              #5a3010 10%,
              #9a5a2a 32%,
              #c07a3a 50%,
              #9a5a2a 68%,
              #5a3010 90%,
              #2a1808 100%);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.5);
}

/* 杯口椭圆边（盖子下方一圈深色边沿）*/
.cup-rim {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 16px;
  background: linear-gradient(145deg, #1a0e04, #4a2810);
  border-radius: 50%;
  z-index: 2;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.6);
}

/* 骰盅底座（椭圆，略宽于杯身）*/
.cup-base {
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 106%;
  height: 22px;
  background: linear-gradient(145deg, #1a0e04, #3a2010);
  border-radius: 50%;
  z-index: 3;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.45);
}

/* ---- 骰子区域（杯内深色空间，衬托白色骰子）---- */
.dice-area {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 8px;
  padding: 14px;
  width: 100%;
  margin-top: 14px;                    /* 给杯口椭圆让位 */
  background: rgba(20, 10, 4, 0.55);
  border-radius: 8px;
  box-shadow: inset 0 4px 10px rgba(0, 0, 0, 0.5);
}

/* =========================================================
   骰子（CSS 绘制点数，3x3 网格）
   ========================================================= */
.die {
  width: 50px;
  height: 50px;
  background: linear-gradient(145deg, #ffffff, #e8e8e8);
  border-radius: 10px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  padding: 6px;
  gap: 2px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3),
              inset 0 -2px 4px rgba(0, 0, 0, 0.1);
  cursor: pointer;
  border: 2px solid transparent;
  /* 默认隐藏（盖子内不可见），揭盖后直接显示 */
  opacity: 0;
  transition: opacity 0.12s ease,
              box-shadow 0.2s, border-color 0.2s, background 0.2s;
}

.die.visible {
  opacity: 1;
}

/* 选中状态：高亮边框 */
.die.selected {
  border-color: #ff6b6b;
  background: linear-gradient(145deg, #fff5f5, #ffe0e0);
  box-shadow: 0 0 15px #ff6b6b, 0 4px 8px rgba(0, 0, 0, 0.3);
}

/* 圆点 */
.dot {
  width: 8px;
  height: 8px;
  background: #333;
  border-radius: 50%;
  align-self: center;
  justify-self: center;
  opacity: 0;            /* 默认不显示，由下方规则控制 */
}

/* 点数显示规则（3x3 位置编号）
   1 2 3
   4 5 6
   7 8 9                                            */
.die[data-value="1"] .dot:nth-child(5) { opacity: 1; }

.die[data-value="2"] .dot:nth-child(1),
.die[data-value="2"] .dot:nth-child(9) { opacity: 1; }

.die[data-value="3"] .dot:nth-child(1),
.die[data-value="3"] .dot:nth-child(5),
.die[data-value="3"] .dot:nth-child(9) { opacity: 1; }

.die[data-value="4"] .dot:nth-child(1),
.die[data-value="4"] .dot:nth-child(3),
.die[data-value="4"] .dot:nth-child(7),
.die[data-value="4"] .dot:nth-child(9) { opacity: 1; }

.die[data-value="5"] .dot:nth-child(1),
.die[data-value="5"] .dot:nth-child(3),
.die[data-value="5"] .dot:nth-child(5),
.die[data-value="5"] .dot:nth-child(7),
.die[data-value="5"] .dot:nth-child(9) { opacity: 1; }

.die[data-value="6"] .dot:nth-child(1),
.die[data-value="6"] .dot:nth-child(3),
.die[data-value="6"] .dot:nth-child(4),
.die[data-value="6"] .dot:nth-child(6),
.die[data-value="6"] .dot:nth-child(7),
.die[data-value="6"] .dot:nth-child(9) { opacity: 1; }

/* =========================================================
   控制按钮
   ========================================================= */
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  margin: 25px 0 15px;
}

.btn {
  padding: 12px 24px;
  border: none;
  border-radius: 25px;
  font-size: 1rem;
  font-weight: 600;
  color: #fff;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, opacity 0.15s;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.btn:active:not(:disabled) {
  transform: translateY(0);
}

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

.btn-primary { background: linear-gradient(145deg, #667eea, #764ba2); }
.btn-success { background: linear-gradient(145deg, #11998e, #38ef7d); }
.btn-warning { background: linear-gradient(145deg, #f12711, #f5af19); }

/* 数量 +/- 控件 */
.count-control {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 15px 0;
}

.btn-count {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(145deg, #667eea, #764ba2);
  color: #fff;
  font-size: 1.3rem;
  font-weight: bold;
  cursor: pointer;
  transition: transform 0.15s;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.15);
}

.btn-count:hover:not(:disabled) { transform: scale(1.1); }
.btn-count:disabled { opacity: 0.4; cursor: not-allowed; }

.count-label {
  font-size: 1rem;
  color: #555;
  min-width: 130px;
}

.count-label strong {
  color: #764ba2;
  font-size: 1.2rem;
}

/* 状态提示 */
.status-text {
  margin-top: 15px;
  color: #666;
  font-size: 0.9rem;
  min-height: 20px;
}

/* =========================================================
   响应式（手机适配）
   ========================================================= */
@media (max-width: 480px) {
  .container { padding: 20px; }
  h1 { font-size: 1.5rem; }
  .dice-cup-wrapper { width: 240px; height: 270px; }
  .dice-cup { width: 170px; height: 215px; }
  .cup-body { top: 20px; height: 175px; }
  .die { width: 40px; height: 40px; padding: 5px; }
  .dot { width: 6px; height: 6px; }
  .btn { padding: 10px 18px; font-size: 0.9rem; }
}
