/* main.css —— 全局样式：经典绿桌面背景、卡片、布局与动画过渡 */

:root {
  --card-w: 90px;
  --card-h: 130px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", sans-serif;
  /* 经典绿色牌桌：径向渐变营造桌面质感 */
  background: radial-gradient(ellipse at center, #2f8f46 0%, #1f6b34 55%, #124a23 100%);
  min-height: 100vh;
  color: #fff;
  user-select: none;
  -webkit-user-select: none;
  overflow-x: hidden;
}

/* 首屏加载界面 */
#loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 3000;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 42%, rgba(46, 139, 70, 0.38), transparent 34%),
    linear-gradient(145deg, #071b12 0%, #0c3522 52%, #06130c 100%);
  opacity: 1;
  transition: opacity 0.6s ease, visibility 0.6s ease;
}

#loading-overlay.is-ready {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

#loading-overlay::before {
  position: absolute;
  inset: 0;
  background-image: radial-gradient(rgba(255, 255, 255, 0.12) 0.7px, transparent 0.7px);
  background-size: 5px 5px;
  content: "";
  opacity: 0.08;
  pointer-events: none;
}

.loading-orb {
  position: absolute;
  width: 38vw;
  max-width: 520px;
  aspect-ratio: 1;
  border: 1px solid rgba(218, 177, 91, 0.15);
  border-radius: 50%;
  box-shadow: 0 0 90px rgba(32, 153, 79, 0.12);
  pointer-events: none;
}

.loading-orb::before,
.loading-orb::after {
  position: absolute;
  inset: 11%;
  border: inherit;
  border-radius: inherit;
  content: "";
}

.loading-orb::after {
  inset: 24%;
  border-color: rgba(255, 255, 255, 0.08);
}

.loading-orb--left {
  top: -20%;
  left: -16%;
  transform: rotate(28deg);
}

.loading-orb--right {
  right: -18%;
  bottom: -28%;
  transform: rotate(-22deg);
}

.loading-panel {
  position: relative;
  width: min(430px, calc(100% - 40px));
  padding: 30px 34px 34px;
  border: 1px solid rgba(255, 239, 190, 0.2);
  border-radius: 22px;
  background: linear-gradient(155deg, rgba(22, 71, 43, 0.86), rgba(7, 29, 18, 0.9));
  box-shadow: 0 26px 80px rgba(0, 0, 0, 0.38), inset 0 1px rgba(255, 255, 255, 0.09);
  text-align: center;
  animation: loadingPanelIn 0.8s ease both;
}

.loading-cards {
  position: relative;
  width: 190px;
  height: 104px;
  margin: 0 auto 16px;
}

.loading-card {
  position: absolute;
  top: 5px;
  left: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 62px;
  height: 88px;
  border: 2px solid rgba(255, 249, 224, 0.85);
  border-radius: 7px;
  background: #fffdf6;
  color: #22382b;
  font: 700 30px Georgia, serif;
  box-shadow: 0 7px 13px rgba(0, 0, 0, 0.28);
  transform-origin: 50% 110%;
}

.loading-card--back {
  background:
    linear-gradient(135deg, transparent 45%, rgba(255, 236, 165, 0.5) 46%, transparent 48%),
    linear-gradient(45deg, transparent 45%, rgba(255, 236, 165, 0.5) 46%, transparent 48%),
    #226a3e;
  border-color: rgba(255, 240, 183, 0.9);
  transform: translateX(-50%) rotate(0deg);
  animation: loadingCardCenter 2.8s ease-in-out infinite;
}

.loading-card--left {
  color: #bd433d;
  transform: translateX(-50%) rotate(-19deg) translate(-30px, 7px);
  animation: loadingCardLeft 2.8s ease-in-out infinite;
}

.loading-card--center {
  color: #bd433d;
  transform: translateX(-50%) rotate(-2deg) translateY(-3px);
  animation: loadingCardCenter 2.8s ease-in-out infinite reverse;
}

.loading-card--right {
  color: #22382b;
  transform: translateX(-50%) rotate(19deg) translate(30px, 7px);
  animation: loadingCardRight 2.8s ease-in-out infinite;
}

.loading-kicker {
  color: #d9b766;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.24em;
}

.loading-panel h1 {
  margin-top: 8px;
  color: #fff5d7;
  font-family: Georgia, "Microsoft YaHei", serif;
  font-size: clamp(30px, 8vw, 42px);
  letter-spacing: 0.12em;
}

.loading-subtitle {
  margin-top: 5px;
  color: rgba(255, 247, 221, 0.68);
  font-size: 12px;
  letter-spacing: 0.22em;
}

.loading-subtitle span {
  margin: 0 5px;
  color: #d9b766;
}

.loading-progress {
  margin-top: 32px;
  text-align: left;
}

.loading-status-row,
.loading-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.loading-status-row {
  color: rgba(255, 248, 225, 0.88);
  font-size: 13px;
}

.loading-status-row strong {
  color: #f1ce7c;
  font-size: 14px;
}

.loading-track {
  height: 7px;
  margin-top: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.28);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.3);
}

#loading-progress-bar {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #bb8c3e, #f4d47f 50%, #fff0b5);
  box-shadow: 0 0 13px rgba(244, 212, 127, 0.55);
  transition: width 0.2s ease;
}

.loading-meta {
  margin-top: 9px;
  color: rgba(255, 248, 225, 0.45);
  font-size: 11px;
}

.loading-tip {
  margin-top: 25px;
  color: rgba(255, 248, 225, 0.62);
  font-size: 12px;
}

@keyframes loadingPanelIn {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes loadingCardLeft {
  0%, 100% { transform: translateX(-50%) rotate(-19deg) translate(-30px, 7px); }
  50% { transform: translateX(-50%) rotate(-25deg) translate(-35px, 2px); }
}

@keyframes loadingCardCenter {
  0%, 100% { transform: translateX(-50%) rotate(0deg) translateY(-1px); }
  50% { transform: translateX(-50%) rotate(4deg) translateY(-7px); }
}

@keyframes loadingCardRight {
  0%, 100% { transform: translateX(-50%) rotate(19deg) translate(30px, 7px); }
  50% { transform: translateX(-50%) rotate(25deg) translate(35px, 2px); }
}

@media (max-width: 480px) {
  .loading-panel {
    padding: 25px 22px 28px;
  }

  .loading-progress {
    margin-top: 27px;
  }
}

#app {
  max-width: 800px;
  margin: 0 auto;
  padding: 14px 16px;
}

/* ---- 顶部工具栏 ---- */
#toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  flex-wrap: wrap;
  gap: 8px;
}

.toolbar-left {
  display: flex;
  gap: 8px;
}

.toolbar-right {
  display: flex;
  gap: 18px;
  font-size: 16px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

.stat b {
  color: #ffe27a;
  font-size: 17px;
}

button {
  background: #ece5d8;
  border: none;
  border-radius: 6px;
  padding: 8px 16px;
  cursor: pointer;
  font-size: 14px;
  color: #223;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
  transition: filter 0.15s, transform 0.05s;
}

button:hover {
  filter: brightness(1.06);
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* 音效开关：静音态弱化 */
#sound-btn.is-off {
  background: #c8c2b8;
  color: #666;
}

/* ---- 牌桌 ---- */
#board {
  position: relative;
  height: 720px;
}

/* 空槽占位 */
.pile-empty {
  position: absolute;
  width: var(--card-w);
  height: var(--card-h);
  border: 2px dashed rgba(255, 255, 255, 0.3);
  border-radius: 8px;
  pointer-events: none;
}

/* ---- 牌 ---- */
.card {
  position: absolute;
  width: var(--card-w);
  height: var(--card-h);
  background-size: cover;
  background-position: center;
  border-radius: 8px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.35);
  transition: transform 0.18s ease;
  will-change: transform;
  cursor: grab;
  transform: var(--card-transform, translate(0, 0));
  transform-style: preserve-3d;
  backface-visibility: hidden;
}

.card--dragging {
  z-index: 1000 !important;
  cursor: grabbing;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.55);
  transition: none;
}

/* 生成/发牌出现动画：从 stock 位置飞入 */
.card--deal {
  animation: deal 0.5s ease both;
  animation-delay: var(--deal-delay, 0ms);
}

@keyframes deal {
  from {
    transform: var(--card-start-transform, translate(0, 0)) scale(0.7);
    opacity: 0.2;
  }
  to {
    transform: var(--card-transform);
    opacity: 1;
  }
}

.card--spawn {
  animation: spawn 0.25s ease both;
}

@keyframes spawn {
  from {
    transform: var(--card-transform) scale(0.6);
    opacity: 0.2;
  }
  to {
    transform: var(--card-transform) scale(1);
    opacity: 1;
  }
}

/* 翻牌过渡：仅旋转特殊元素，避免覆盖位置 */
.card--flip {
  animation: flip 0.3s ease;
  transform-style: preserve-3d;
}

@keyframes flip {
  from {
    transform: var(--card-transform) rotateY(90deg);
  }
  to {
    transform: var(--card-transform) rotateY(0deg);
  }
}

/* 选中的牌（点击移动） */
.card--selected {
  outline: 3px solid #4fc3f7;
  outline-offset: 2px;
  border-radius: 8px;
}

/* 提示高亮 */
.card--hint {
  outline: 3px solid #ffd54f;
  outline-offset: 2px;
  border-radius: 8px;
}

/* ---- 底部说明 ---- */
#footer {
  margin-top: 12px;
  text-align: center;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.75);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

/* 新游戏洗牌效果 */
#board.board--shuffle {
  animation: shuffleWobble 0.6s ease;
}

@keyframes shuffleWobble {
  0%, 100% {
    transform: rotate(0deg);
  }
  25% {
    transform: rotate(-0.8deg);
  }
  75% {
    transform: rotate(0.8deg);
  }
}

/* 胜利时牌桌光晕 */
#board.board--won {
  animation: wonGlow 1.2s ease infinite;
}

@keyframes wonGlow {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(255, 215, 0, 0);
  }
  50% {
    box-shadow: 0 0 60px 20px rgba(255, 215, 0, 0.45);
  }
}

/* ---- 胜利弹窗 ---- */
#win-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

#win-overlay.hidden {
  display: none;
}

.win-box {
  background: #fff;
  color: #223;
  border-radius: 14px;
  padding: 30px 44px;
  text-align: center;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5);
  animation: pop 0.3s ease;
}

.win-box h1 {
  margin-bottom: 14px;
  font-size: 26px;
}

.win-box p {
  margin: 6px 0;
  font-size: 16px;
}

.win-box button {
  margin-top: 16px;
  background: #2f8f46;
  color: #fff;
  font-size: 15px;
}

@keyframes pop {
  from {
    transform: scale(0.8);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}
