/* ── Reset ─────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

[hidden] { display: none !important; }

/* ── Base ──────────────────────────────────────────────────── */
body {
  font-family: 'Noto Sans TC', 'PingFang TC', sans-serif;
  background: #1a1a2e;
  color: #333;
  height: 100dvh;          /* dvh 計入瀏覽器工具列，避免被壓縮 */
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* ── 橫向提示 ──────────────────────────────────────────────── */
#rotate-notice {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: #1a1a2e;
  color: white;
  align-items: center;
  justify-content: center;
  text-align: center;
}

@media screen and (orientation: landscape) {
  body { overflow: hidden; }
  #app { display: none; }
  #rotate-notice { display: flex; }
}

.rotate-inner { padding: 24px; }
.rotate-icon {
  font-size: 64px;
  margin-bottom: 16px;
  animation: rotateAnim 2s ease-in-out infinite;
}
@keyframes rotateAnim {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(-90deg); }
}
.rotate-inner p { font-size: 16px; color: #ccc; }

/* ── App 容器 ────────────────────────────────────────────── */
#app {
  max-width: 480px;
  margin: 0 auto;
  height: 100dvh;
  overflow: hidden;
  background: #f0f0f5;
  display: flex;
  flex-direction: column;
}

/* ── 載入 / 錯誤 / 無刮刮紙 ──────────────────────────────── */
#loading, #error, #no-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100dvh;
  gap: 16px;
  padding: 32px 24px;
  text-align: center;
  background: #f0f0f5;
}

#loading p, #no-card p { font-size: 15px; color: #555; }
.sub-text { font-size: 13px; color: #999; }
.state-icon { font-size: 64px; }

.spinner {
  width: 44px;
  height: 44px;
  border: 4px solid #ddd;
  border-top-color: #6c3fb5;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#error p { font-size: 15px; color: #c0392b; }
#error button {
  background: #6c3fb5;
  color: white;
  border: none;
  border-radius: 10px;
  padding: 12px 32px;
  font-size: 15px;
  cursor: pointer;
  margin-top: 8px;
}

/* ── 主遊戲（flex column，佔滿整個 dvh） ─────────────────── */
#game {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

/* ── 頂部：中獎配率資訊 ──────────────────────────────────── */
#stats-bar {
  background: white;
  padding: 8px 12px 6px;
  border-bottom: 1px solid #e8e8ee;
  flex-shrink: 0;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

#prize-list {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 6px;
  min-height: 24px;
}

.prize-chip {
  background: #6c3fb5;
  color: white;
  border-radius: 12px;
  padding: 3px 9px;
  font-size: 11px;
  white-space: nowrap;
}
.prize-chip.won {
  background: #ccc;
  color: #888;
  text-decoration: line-through;
}

#stats-row {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: #777;
  border-top: 1px solid #f0f0f0;
  padding-top: 5px;
}

/* ── 刮刮紙格子區（彈性填滿） ───────────────────────────── */
#card-area {
  flex: 1;
  overflow: hidden;
  padding: 10px 14px 0;
  min-height: 0;  /* flex 子元素需要此設定才能正確縮小 */
}

#pages-wrapper {
  display: flex;
  height: 100%;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  align-items: flex-start;
}

.card-page {
  /* width set by JS */
  height: 100%;
  flex-shrink: 0;
  flex-grow: 0;
  background: white;
  border-radius: 14px;
  padding: 10px 10px 6px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  margin-right: 8px;
  display: flex;
  flex-direction: column;
}

/* 格子 Grid */
.slot-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  flex: 1;
  align-content: start;
}

/* 頁碼 */
.page-num {
  text-align: center;
  font-size: 12px;
  color: #999;
  min-height: 16px;
  line-height: 16px;
  flex-shrink: 0;
  padding-top: 4px;
}

/* ── 格子 ────────────────────────────────────────────────── */
.slot {
  aspect-ratio: 1;
  border-radius: 6px;
  overflow: hidden;
  position: relative;
  cursor: pointer;
  background: #e8e0f5;
}

.slot-empty {
  aspect-ratio: 1;
}

/* 底層內容（中獎 / 未中獎） */
.slot-content {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  padding: 3px;
  text-align: center;
}

.slot-prize { background: linear-gradient(135deg, #ffe066, #ffb300); }
.slot-no-prize { background: #ebebeb; }

.prize-star { font-size: 13px; line-height: 1; }
.prize-letter {
  font-weight: bold;
  font-size: 13px;
  color: #5a3000;
  line-height: 1;
}
.prize-name-small {
  font-size: 9px;
  color: #6a4000;
  line-height: 1.2;
  word-break: break-all;
  max-width: 100%;
}
.no-prize-mark { font-size: 20px; color: #bbb; }

/* Canvas 遮罩（未刮開） */
.scratch-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
  border-radius: 6px;
}

/* 已刮開未中獎：底層略暗 */
.slot.scratched.no-prize .slot-content {
  opacity: 0.55;
}

/* ── 遊戲結束橫幅 ─────────────────────────────────────────── */
#finish-banner {
  margin: 6px 14px 0;
  padding: 10px;
  background: linear-gradient(135deg, #4caf50, #2e7d32);
  color: white;
  text-align: center;
  font-size: 14px;
  font-weight: bold;
  border-radius: 10px;
  flex-shrink: 0;
  animation: pop-in 0.3s ease;
}

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

/* ── 同步狀態 ─────────────────────────────────────────────── */
#sync-status {
  text-align: center;
  font-size: 11px;
  color: #888;
  padding: 2px 0;
  flex-shrink: 0;
}

/* ── 導航列 ──────────────────────────────────────────────── */
#nav-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  gap: 8px;
  flex-shrink: 0;
  background: #f0f0f5;
}

.nav-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 2px solid #6c3fb5;
  background: white;
  color: #6c3fb5;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, opacity 0.15s;
}
.nav-btn:active { background: #f0eaff; }
.nav-btn:disabled {
  border-color: #ccc;
  color: #ccc;
  cursor: default;
}

#ad-space {
  flex: 1;
  height: 50px;
  /* 上線後在此嵌入 AdSense 廣告單元（320×50） */
}

/* ── 中獎彈窗 ─────────────────────────────────────────────── */
#modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

#modal {
  background: white;
  border-radius: 20px;
  padding: 28px 24px 20px;
  max-width: 320px;
  width: 100%;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0,0,0,0.25);
  animation: modalIn 0.25s ease;
}
@keyframes modalIn {
  from { transform: scale(0.85); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

#modal-title {
  font-size: 24px;
  font-weight: bold;
  margin-bottom: 14px;
}

#modal-prize-name {
  font-size: 20px;
  color: #6c3fb5;
  font-weight: bold;
  margin-bottom: 10px;
}

#modal-message {
  font-size: 16px;
  color: #e65100;
  font-weight: bold;
  margin-bottom: 8px;
  word-break: break-all;
}

#modal-footer {
  font-size: 13px;
  color: #888;
  margin-bottom: 18px;
  line-height: 1.5;
}

#modal-btn {
  background: #6c3fb5;
  color: white;
  border: none;
  border-radius: 10px;
  padding: 13px;
  font-size: 16px;
  cursor: pointer;
  width: 100%;
  font-weight: bold;
}
#modal-btn:active { background: #5a2fa0; }
