:root {
  --grid-step: 32px;
  --tile-size: 60px;
  --board-size: 352px;
  --primary: #FFA94D;
  --primary-dark: #FF8C42;
  --primary-deep: #E67033;
  --bg-warm-1: #FFF4DC;
  --bg-warm-2: #FFD49B;
  --tile-bg: #FFFCF6;
  --tile-bg-2: #FFF1D6;
  --tile-shadow: rgba(180, 80, 0, 0.18);
  --tile-shadow-deep: rgba(180, 80, 0, 0.28);
  --text-dark: #5B3A1A;
  --text-mute: #A06433;
  --slot-bg: rgba(255, 255, 255, 0.45);
  --slot-border: #E5C28C;
  --danger: #E15D5D;
}

@media (max-width: 520px) {
  :root {
    --grid-step: 26px;
    --tile-size: 50px;
    --board-size: 286px;
  }
}

@media (max-width: 360px) {
  :root {
    --grid-step: 22px;
    --tile-size: 44px;
    --board-size: 242px;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  font-family: 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'Helvetica Neue', Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  background: linear-gradient(160deg, #FFF6E0 0%, #FFD49B 60%, #FFB870 100%);
  color: var(--text-dark);
  touch-action: manipulation;
  overscroll-behavior: none;
}

body {
  display: flex;
  align-items: stretch;
  justify-content: center;
  min-height: 100vh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    radial-gradient(circle at 10% 12%, rgba(255,255,255,0.5) 0 6px, transparent 7px),
    radial-gradient(circle at 80% 20%, rgba(255,255,255,0.4) 0 4px, transparent 5px),
    radial-gradient(circle at 30% 80%, rgba(255,255,255,0.35) 0 5px, transparent 6px),
    radial-gradient(circle at 70% 90%, rgba(255,255,255,0.4) 0 4px, transparent 5px);
  pointer-events: none;
  z-index: 0;
}

.screen {
  display: none;
  position: relative;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  z-index: 1;
  flex-direction: column;
}

.screen.active {
  display: flex;
}

/* ---------- 菜单 ---------- */
.menu-card {
  margin: auto;
  width: 100%;
  padding: 36px 24px;
}

.title {
  text-align: center;
  margin-bottom: 28px;
}

.title .emoji {
  font-size: 76px;
  display: block;
  margin-bottom: 6px;
  animation: bounce 1.8s ease-in-out infinite;
  filter: drop-shadow(0 6px 0 rgba(180, 80, 0, 0.2));
}

@keyframes bounce {
  0%, 100% { transform: translateY(0) rotate(-3deg); }
  50% { transform: translateY(-10px) rotate(3deg); }
}

.title h1 {
  font-size: 34px;
  margin: 0;
  letter-spacing: 6px;
  text-shadow: 0 3px 0 rgba(255, 255, 255, 0.7), 0 4px 0 var(--bg-warm-2);
}

.subtitle {
  margin: 6px 0 0;
  font-size: 13px;
  color: var(--text-mute);
}

.difficulty-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.diff-btn {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--tile-bg);
  border: none;
  border-radius: 18px;
  padding: 14px 16px;
  box-shadow: 0 5px 0 var(--tile-shadow);
  cursor: pointer;
  font-family: inherit;
  color: var(--text-dark);
  text-align: left;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
  width: 100%;
}

.diff-btn:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 var(--tile-shadow);
}

.diff-icon {
  font-size: 30px;
  width: 50px;
  height: 50px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-warm-1);
  flex-shrink: 0;
}

.diff-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.diff-name {
  font-size: 17px;
  font-weight: 700;
}

.diff-desc {
  font-size: 12px;
  color: var(--text-mute);
}

.diff-arrow {
  color: var(--primary-dark);
  font-size: 24px;
  font-weight: 700;
}

.menu-footer {
  margin-top: 22px;
  text-align: center;
  font-size: 12px;
  color: var(--text-mute);
  line-height: 1.7;
}

/* ---------- 游戏 ---------- */
.game-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 12px 8px;
}

.header-info {
  display: flex;
  gap: 6px;
  flex: 1;
  justify-content: center;
  flex-wrap: wrap;
}

.badge {
  background: rgba(255, 255, 255, 0.65);
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 12px;
  color: var(--text-dark);
  border: 1px solid rgba(180, 80, 0, 0.15);
  white-space: nowrap;
}

.badge b {
  color: var(--primary-deep);
  font-weight: 700;
  margin-left: 2px;
}

.btn-icon {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: var(--tile-bg);
  box-shadow: 0 3px 0 var(--tile-shadow);
  cursor: pointer;
  font-size: 18px;
  font-weight: 700;
  color: var(--text-dark);
  font-family: inherit;
  flex-shrink: 0;
}

.btn-icon:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--tile-shadow);
}

.board-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  flex: 1;
  min-height: 0;
}

.board {
  position: relative;
  width: var(--board-size);
  height: var(--board-size);
  background:
    radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.5) 0%, rgba(255, 255, 255, 0.1) 70%, transparent 100%);
  border-radius: 24px;
}

.tile {
  position: absolute;
  width: var(--tile-size);
  height: var(--tile-size);
  background: linear-gradient(160deg, var(--tile-bg) 0%, var(--tile-bg-2) 100%);
  border-radius: 14px;
  box-shadow:
    0 3px 0 var(--tile-shadow),
    inset 0 1px 0 rgba(255, 255, 255, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--tile-size) * 0.58);
  line-height: 1;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
  transition:
    transform 0.16s cubic-bezier(.4, 1.4, .6, 1),
    opacity 0.18s ease,
    box-shadow 0.16s ease;
  will-change: transform, opacity;
}

.tile:active:not(.covered):not(.removed):not(.in-slot) {
  transform: scale(0.92);
}

.tile.covered {
  filter: brightness(0.55) saturate(0.55);
  pointer-events: none;
  cursor: not-allowed;
  box-shadow: 0 2px 0 var(--tile-shadow);
}

.tile.removed {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.4) rotate(20deg);
}

.tile.in-slot {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.6);
}

.tile.flying {
  z-index: 9999 !important;
  transition: transform 0.32s cubic-bezier(.4, 0, .2, 1), opacity 0.32s ease;
}

/* ---------- 槽位 ---------- */
.slot-area {
  padding: 10px 14px 10px;
}

.slot-row {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 5px;
  max-width: 360px;
  margin: 0 auto;
  background: var(--slot-bg);
  padding: 8px;
  border-radius: 14px;
  border: 2px dashed var(--slot-border);
}

.slot-cell {
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  line-height: 1;
}

.slot-cell.filled {
  background: linear-gradient(160deg, var(--tile-bg) 0%, var(--tile-bg-2) 100%);
  box-shadow: inset 0 0 0 2px rgba(180, 80, 0, 0.12), 0 2px 0 var(--tile-shadow);
  animation: pop 0.18s ease;
}

@keyframes pop {
  0% { transform: scale(0.7); }
  100% { transform: scale(1); }
}

.slot-row.danger {
  border-color: var(--danger);
  animation: shake 0.4s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

/* ---------- 道具 ---------- */
.tool-bar {
  display: flex;
  gap: 10px;
  padding: 6px 14px 18px;
  justify-content: center;
}

.tool-btn {
  position: relative;
  border: none;
  background: var(--tile-bg);
  border-radius: 14px;
  padding: 9px 14px;
  box-shadow: 0 4px 0 var(--tile-shadow);
  cursor: pointer;
  font-size: 12px;
  color: var(--text-dark);
  font-family: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 64px;
  transition: transform 0.08s ease;
}

.tool-btn:active:not(:disabled) {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--tile-shadow);
}

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

.tool-icon {
  font-size: 20px;
  line-height: 1;
}

.tool-count {
  position: absolute;
  top: -6px;
  right: -6px;
  background: var(--primary-deep);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  min-width: 20px;
  height: 20px;
  border-radius: 999px;
  padding: 0 6px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---------- 结算 ---------- */
.result-card {
  margin: auto;
  width: calc(100% - 32px);
  max-width: 380px;
  background: var(--tile-bg);
  border-radius: 24px;
  padding: 30px 24px;
  text-align: center;
  box-shadow: 0 12px 32px rgba(180, 80, 0, 0.22);
}

.result-emoji {
  font-size: 64px;
  margin-bottom: 8px;
  animation: bounce 1.6s ease-in-out infinite;
}

.result-card h2 {
  font-size: 24px;
  margin: 0 0 4px;
  letter-spacing: 1px;
}

.result-tip {
  margin: 0 0 22px;
  color: var(--text-mute);
  font-size: 13px;
}

.result-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 24px;
}

.stat-item {
  background: var(--bg-warm-1);
  border-radius: 14px;
  padding: 12px 6px;
}

.stat-label {
  display: block;
  font-size: 11px;
  color: var(--text-mute);
}

.stat-value {
  display: block;
  font-size: 17px;
  font-weight: 700;
  color: var(--primary-deep);
  margin-top: 4px;
}

.result-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn-primary {
  background: linear-gradient(180deg, var(--primary) 0%, var(--primary-deep) 100%);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 14px 24px;
  font-size: 15px;
  font-weight: 700;
  box-shadow: 0 4px 0 #B85E1F, 0 8px 16px rgba(184, 94, 31, 0.4);
  cursor: pointer;
  font-family: inherit;
}

.btn-primary:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #B85E1F;
}

.btn-secondary {
  background: var(--tile-bg);
  color: var(--text-dark);
  border: none;
  border-radius: 999px;
  padding: 12px 24px;
  font-size: 14px;
  box-shadow: 0 3px 0 var(--tile-shadow);
  cursor: pointer;
  font-family: inherit;
}

.btn-secondary:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--tile-shadow);
}

.btn-text {
  background: transparent;
  border: none;
  color: var(--text-mute);
  font-size: 13px;
  cursor: pointer;
  padding: 8px;
  font-family: inherit;
}

/* ---------- 分享 ---------- */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal.active {
  display: flex;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-mask {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}

.share-card-wrap {
  position: relative;
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  z-index: 1;
}

.share-image-frame {
  width: 100%;
  position: relative;
  border-radius: 22px;
  overflow: hidden;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.25);
  background: rgba(255, 255, 255, 0.2);
  min-height: 200px;
}

.share-image {
  display: block;
  width: 100%;
  height: auto;
  /* 关键：移动端长按弹出"存储图像 / 保存到相册"菜单 */
  -webkit-touch-callout: default;
  touch-callout: default;
  user-select: auto;
  -webkit-user-select: auto;
  pointer-events: auto;
}

.share-image:not([src]) {
  visibility: hidden;
}

.share-image-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  color: var(--text-mute);
  background: linear-gradient(160deg, #FFF4DC 0%, #FFC580 100%);
}

.share-image-frame.ready .share-image-loading {
  display: none;
}

.share-tip {
  background: rgba(255, 255, 255, 0.95);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 12px;
  color: var(--text-dark);
  margin: 0;
}

.share-actions {
  display: flex;
  gap: 10px;
}

/* ---------- toast ---------- */
.toast {
  position: fixed;
  top: 20%;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 999;
  animation: toastIn 0.2s ease;
  pointer-events: none;
}

@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, -10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}
