/* ============================================
   OpenClaw Game — Felt Style CSS v3.4
   模組：抓娃娃遊戲頁面樣式
   
   依賴：
     - mujoo-tokens.css（Design Token 系統）
     - mujoo-responsive.css（響應式工具類）
   
   原則：
     - 所有數值引用 Token，不寫死
     - 響應式通過 Token 斷點自動適配
     - 結構化、模組化、可維護
   
   CHANGELOG:
     v3.0 - 全面毛毡主題改造
     v3.2 - 修復 crossOrigin CORS mismatch
     v3.3 - 添加三端響應式（硬編碼）
     v3.4 - Token 驅動重構，所有值引用變量
   ============================================ */

/* ===== 基礎重置 ===== */
* { box-sizing: border-box; margin: 0; padding: 0; }

/* ===== 毛毡海洋背景（全頁） ===== */
body {
  font-family: var(--mu-font-family);
  background: url('/mujoo/assets/openclaw/felt/felt_ocean_bg.webp') center center / cover no-repeat fixed;
  background-color: var(--mu-ocean-dark);
  min-height: 100vh;
  overflow-x: hidden;
  color: var(--mu-text);
}

/* ===== 返回按鈕（毛毡風格） ===== */
.back-btn {
  position: fixed;
  top: var(--mu-space-sm);
  left: var(--mu-space-sm);
  z-index: var(--mu-z-sticky);
  background: url('/mujoo/assets/openclaw/felt/felt_card_blue.webp') center / cover;
  border: none;
  color: var(--mu-white);
  font-size: var(--mu-font-size-sm);
  font-weight: var(--mu-font-weight-heavy);
  padding: var(--mu-space-sm) var(--mu-space-lg);
  border-radius: var(--mu-radius-pill);
  cursor: pointer;
  text-shadow: 0 1px 3px rgba(0,0,0,0.4);
  box-shadow: var(--mu-shadow-brand-md);
  transition: transform var(--mu-duration-fast) var(--mu-ease);
}
.back-btn:active { transform: scale(0.93); }

/* ===== Toast 提示（毛毡卡片） ===== */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: url('/mujoo/assets/openclaw/felt/felt_card_pink.webp') center / cover;
  color: #5a2d0c;
  font-weight: var(--mu-font-weight-heavy);
  padding: var(--mu-space-sm) var(--mu-space-xl);
  border-radius: var(--mu-radius-pill);
  font-size: var(--mu-font-size-sm);
  opacity: 0;
  pointer-events: none;
  transition: all var(--mu-duration-normal) var(--mu-ease);
  z-index: var(--mu-z-modal);
  box-shadow: var(--mu-shadow-brand-md);
  text-shadow: 0 1px 1px rgba(255,255,255,0.3);
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===== 結果彈窗（毛毡卡片） ===== */
.result-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(10, 30, 50, 0.65);
  z-index: var(--mu-z-modal);
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}
.result-overlay.show { display: flex; }

.result-card {
  --rc-width: 300px;
  --rc-min-height: 340px;
  width: var(--rc-width);
  min-height: var(--rc-min-height);
  padding: var(--mu-space-xl) var(--mu-space-lg);
  text-align: center;
  border-radius: var(--mu-radius-xl);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--mu-space-sm);
  animation: feltPopIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
@keyframes feltPopIn {
  from { transform: scale(0.5) rotate(-3deg); opacity: 0; }
  to { transform: scale(1) rotate(0); opacity: 1; }
}

.result-card.win {
  background: url('/mujoo/assets/openclaw/felt/felt_result_card.webp') center / cover;
  box-shadow: var(--mu-shadow-xl);
}
.result-card.lose {
  background: url('/mujoo/assets/openclaw/felt/felt_result_fail.webp') center / cover;
  box-shadow: var(--mu-shadow-xl);
}

.result-icon { font-size: 52px; margin-top: var(--mu-space-sm); }
.result-title {
  font-size: var(--mu-font-size-2xl);
  font-weight: var(--mu-font-weight-black);
  text-shadow: 0 1px 2px rgba(255,255,255,0.4);
}
.result-card.win .result-title { color: var(--mu-coral); }
.result-card.lose .result-title { color: var(--mu-text-light); }

.result-prize {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--mu-space-sm);
  font-size: var(--mu-font-size-md);
  color: #5d3a1a;
  font-weight: var(--mu-font-weight-bold);
}
.result-prize img {
  --prize-size: 100px;
  width: var(--prize-size);
  height: var(--prize-size);
  object-fit: contain;
  display: block;
  margin: var(--mu-space-xs) auto;
  filter: drop-shadow(0 4px 10px rgba(0,0,0,0.25));
  border-radius: var(--mu-radius-md);
}

.result-btn {
  background: url('/mujoo/assets/openclaw/felt/felt_btn_grab.webp') center / cover;
  border: none;
  color: var(--mu-white);
  font-size: var(--mu-font-size-md);
  font-weight: var(--mu-font-weight-heavy);
  padding: var(--mu-space-sm) var(--mu-space-2xl);
  border-radius: var(--mu-radius-pill);
  cursor: pointer;
  text-shadow: 0 1px 3px rgba(0,0,0,0.4);
  box-shadow: var(--mu-shadow-brand-md);
  transition: transform var(--mu-duration-fast) var(--mu-ease);
  margin-top: var(--mu-space-xs);
}
.result-btn:active { transform: scale(0.92); }

/* ===== 主容器 ===== */
.claw-machine-wrapper {
  --wrapper-max: 680px;
  max-width: var(--wrapper-max);
  margin: 0 auto;
  padding: calc(var(--mu-space-2xl) + var(--mu-space-sm)) var(--mu-space-md) var(--mu-space-xl);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--mu-space-md);
}

/* ===== 標題（毛線刺繡風） ===== */
.machine-title {
  text-align: center;
  font-size: var(--mu-font-size-3xl);
  font-weight: var(--mu-font-weight-black);
  color: var(--mu-white);
  text-shadow: 0 2px 8px rgba(0,0,0,0.5), 0 0 24px rgba(100,200,255,0.25);
  letter-spacing: 3px;
}

/* ===== 機台選擇網格 ===== */
.machine-select-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--mu-space-md);
  width: 100%;
  max-width: var(--wrapper-max);
}

.machine-card {
  border-radius: var(--mu-radius-lg);
  overflow: hidden;
  cursor: pointer;
  transition: transform var(--mu-duration-fast) var(--mu-ease), box-shadow var(--mu-duration-fast) var(--mu-ease);
  box-shadow: var(--mu-shadow-brand-md);
  position: relative;
  background: rgba(255,248,240,0.92);
}
.machine-card:active { transform: scale(0.96); }
.machine-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--mu-shadow-brand-lg);
}

/* 毛毡卡片背景 */
.machine-card-bg {
  --card-bg-height: 120px;
  height: var(--card-bg-height);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--mu-space-sm);
  padding: var(--mu-space-sm);
  position: relative;
}
.machine-card:nth-child(1) .machine-card-bg { background: url('/mujoo/assets/openclaw/felt/felt_card_blue.webp') center / cover; }
.machine-card:nth-child(2) .machine-card-bg { background: url('/mujoo/assets/openclaw/felt/felt_card_pink.webp') center / cover; }
.machine-card:nth-child(3) .machine-card-bg { background: url('/mujoo/assets/openclaw/felt/felt_card_purple.webp') center / cover; }
.machine-card:nth-child(4) .machine-card-bg { background: url('/mujoo/assets/openclaw/felt/felt_card_blue.webp') center / cover; }

.machine-card-bg img {
  --doll-preview: 70px;
  height: var(--doll-preview);
  width: var(--doll-preview);
  object-fit: contain;
  filter: drop-shadow(0 3px 6px rgba(0,0,0,0.25));
  transition: transform var(--mu-duration-normal) var(--mu-ease);
}
.machine-card:hover .machine-card-bg img { transform: scale(1.1) rotate(-5deg); }

.machine-card h3 {
  padding: var(--mu-space-sm) var(--mu-space-sm) var(--mu-space-xs);
  font-size: var(--mu-font-size-md);
  font-weight: var(--mu-font-weight-black);
  color: #5d3a1a;
}
.machine-card .prize-list {
  padding: 0 var(--mu-space-sm) var(--mu-space-xs);
  font-size: 11px;
  color: #8b6e5c;
}
.machine-card .cost-badge {
  display: block;
  padding: 7px var(--mu-space-sm);
  font-size: var(--mu-font-size-sm);
  font-weight: var(--mu-font-weight-heavy);
  color: #5d3a1a;
  border-top: 1px dashed rgba(180,150,100,0.3);
}

.machine-card .start-btn {
  display: block;
  width: calc(100% - 16px);
  min-height: 44px;
  margin: 0 8px 12px;
  padding: 10px 16px;
  border: 2px dashed #175e5a;
  border-radius: 12px;
  background: #a5e0d6;
  color: #214742;
  font: inherit;
  font-weight: var(--mu-font-weight-heavy);
  line-height: 1.4;
  cursor: pointer;
}
.machine-card .start-btn:hover { background: #c2ede3; }
.machine-card .start-btn:focus-visible { outline: 3px solid #9a3654; outline-offset: 2px; }
.machine-card .start-btn:active { background: #81d8d0; }

/* ===== 遊戲區域 ===== */
.game-area {
  width: 100%;
  max-width: var(--wrapper-max);
  display: none;
  flex-direction: column;
  align-items: center;
  gap: var(--mu-space-sm);
}
.game-area.active { display: flex; }

/* ===== 毛毡機器外殼 ===== */
.machine-shell {
  width: 100%;
  position: relative;
  background: url('/mujoo/assets/openclaw/felt/felt_machine_frame.webp') center top / 100% auto no-repeat;
  border-radius: var(--mu-radius-xl);
  padding: var(--mu-space-md) var(--mu-space-sm) 0;
  min-height: 460px;
}
.machine-shell::before {
  content: 'MUJOO OpenClaw';
  position: absolute;
  top: -14px;
  left: 50%;
  transform: translateX(-50%);
  background: url('/mujoo/assets/openclaw/felt/felt_btn_grab.webp') center / cover;
  color: white;
  font-weight: var(--mu-font-weight-black);
  font-size: var(--mu-font-size-xs);
  padding: 5px 22px;
  border-radius: var(--mu-radius-pill);
  letter-spacing: 2px;
  white-space: nowrap;
  box-shadow: var(--mu-shadow-brand-md);
  text-shadow: 0 1px 3px rgba(0,0,0,0.4);
}

/* Canvas 容器 */
#claw-canvas-container {
  width: 100%;
  border-radius: var(--mu-radius-md);
  overflow: hidden;
  position: relative;
  box-shadow: inset 0 2px 12px rgba(0,0,0,0.15);
}
#claw-canvas-container canvas,
#claw-root canvas {
  display: block;
  width: 100% !important;
  height: auto !important;
  border-radius: var(--mu-radius-md);
}

/* 底部信息欄 */
.machine-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--mu-space-sm) var(--mu-space-md);
  margin-top: var(--mu-space-xs);
}
.coin-display {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: var(--mu-font-size-md);
  font-weight: var(--mu-font-weight-heavy);
  color: var(--mu-gold);
  text-shadow: 0 1px 2px rgba(0,0,0,0.15);
}
.coin-icon {
  display: inline-block;
  width: 24px;
  height: 24px;
  background: url('/mujoo/assets/openclaw/felt/felt_coin.webp') center / contain no-repeat;
  font-size: 0;
  overflow: hidden;
  color: transparent;
}
.machine-name-display {
  font-size: var(--mu-font-size-sm);
  font-weight: var(--mu-font-weight-bold);
  color: #5a4030;
}

/* ===== 毛毡控制器 ===== */
.controller {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--mu-space-sm);
}
.dpad {
  --dpad-size: 60px;
  display: grid;
  grid-template-columns: repeat(3, var(--dpad-size));
  grid-template-rows: repeat(3, var(--dpad-size));
  gap: 5px;
}
.dpad-btn {
  width: var(--dpad-size);
  height: var(--dpad-size);
  border: none;
  border-radius: var(--mu-radius-full);
  font-size: 20px;
  font-weight: var(--mu-font-weight-heavy);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s;
  color: var(--mu-white);
  text-shadow: 0 1px 3px rgba(0,0,0,0.4);
  background: url('/mujoo/assets/openclaw/felt/felt_btn_arrow.webp') center / cover;
  box-shadow: var(--mu-shadow-brand-sm);
  user-select: none;
  -webkit-user-select: none;
}
.dpad-btn:active { transform: scale(0.88); }
.dpad-btn.empty {
  background: none !important;
  box-shadow: none;
  cursor: default;
}
.dpad-btn.center {
  background: url('/mujoo/assets/openclaw/felt/felt_btn_grab.webp') center / cover;
  font-size: var(--mu-font-size-md);
  box-shadow: 0 4px 14px rgba(200,80,50,0.35);
}
.dpad-btn.center:active { transform: scale(0.85); }

.control-hint {
  font-size: var(--mu-font-size-xs);
  color: rgba(255,255,255,0.65);
  text-shadow: 0 1px 3px rgba(0,0,0,0.4);
  text-align: center;
}

/* ===== 退出按鈕（毛毡風格） ===== */
.exit-game-btn {
  display: block;
  margin: var(--mu-space-sm) auto 0;
  background: url('/mujoo/assets/openclaw/felt/felt_card_pink.webp') center / cover;
  border: none;
  color: #5a2d0c;
  font-size: var(--mu-font-size-sm);
  font-weight: var(--mu-font-weight-heavy);
  padding: var(--mu-space-sm) var(--mu-space-lg);
  border-radius: var(--mu-radius-pill);
  cursor: pointer;
  box-shadow: var(--mu-shadow-brand-sm);
  transition: transform var(--mu-duration-fast) var(--mu-ease);
  text-shadow: 0 1px 1px rgba(255,255,255,0.3);
}
.exit-game-btn:active { transform: scale(0.93); }

/* ===== 響應式 — 手機端 (<768px) ===== */
@media (max-width: 767px) {
  .machine-select-grid { grid-template-columns: 1fr; }
  .dpad { --dpad-size: 52px; }
  .claw-machine-wrapper { padding-top: 50px; padding-left: var(--mu-space-sm); padding-right: var(--mu-space-sm); }
  .result-card { --rc-width: 280px; --rc-min-height: 300px; }
}

/* ===== 響應式 — 平板端 (768px - 991px) ===== */
@media (min-width: 768px) and (max-width: 991px) {
  .claw-machine-wrapper {
    --wrapper-max: 720px;
    padding-top: 60px;
    padding-left: var(--mu-space-lg);
    padding-right: var(--mu-space-lg);
  }
  .machine-select-grid { gap: var(--mu-space-lg); }
  .machine-card-bg { --card-bg-height: 140px; }
  .machine-card-bg img { --doll-preview: 80px; }
  .dpad { --dpad-size: 64px; }
  .result-card { --rc-width: 340px; }
}

/* ===== 響應式 — PC 端 (≥992px) ===== */
@media (min-width: 992px) {
  .claw-machine-wrapper {
    --wrapper-max: 960px;
    padding-top: 60px;
    padding-left: var(--mu-space-xl);
    padding-right: var(--mu-space-xl);
  }
  .machine-select-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: var(--mu-space-lg);
  }
  .machine-card-bg { --card-bg-height: 150px; }
  .machine-card-bg img { --doll-preview: 90px; }
  .machine-card h3 { font-size: var(--mu-font-size-md); padding: var(--mu-space-sm) var(--mu-space-md) var(--mu-space-xs); }
  .machine-shell { max-width: 700px; min-height: 520px; }
  .dpad { --dpad-size: 68px; }
  .result-card { --rc-width: 380px; --rc-min-height: 380px; }
  .result-prize img { --prize-size: 120px; }
}

/* ===== 響應式 — 大屏 (≥1200px) ===== */
@media (min-width: 1200px) {
  .claw-machine-wrapper { --wrapper-max: 1100px; }
}

/* Practice recovery shares the existing warm felt palette; history stays secondary. */
.game-records { margin-block: 16px 28px; padding: clamp(16px, 3vw, 24px); background: #142f34; color: #f8edd9; border-radius: 12px; line-height: 1.65; overflow-wrap: anywhere; }
.game-records h2 { font-size: 1.25rem; margin: 0 0 8px; }
.game-records h3 { font-size: 1.05rem; margin: 24px 0 8px; }
.game-records p { margin: 8px 0; max-width: 72ch; }
.game-records [data-record-warning]:empty { display: none; }
.game-records [data-record-warning] { color: #ffdda8; }
.game-records details { margin-block-start: 16px; }
.game-records summary { cursor: pointer; padding-block: 10px; }
.game-record-row { padding-block: 12px; border-block-start: 1px solid #567278; font-variant-numeric: tabular-nums; }
.game-record-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.game-records button, .game-records a { min-height: 44px; padding: 10px 14px; border: 1px solid #b8cfc9; border-radius: 8px; background: #173c41; color: #fff0d5; font: inherit; cursor: pointer; text-underline-offset: .2em; }
.game-records button:hover, .game-records a:hover { background: #255057; }
.game-records button:disabled { cursor: default; color: #bfd1ce; background: #273d40; border-color: #6f8587; }
.game-records :is(button,a,summary):focus-visible { outline: 3px solid #ffd393; outline-offset: 3px; }
.game-records ::selection { color: #142f34; background: #ffd393; }
.game-records [hidden] { display: none; }
