/* ============================================================
   幸运抽奖 · 样式表
   Apple 原生风格（参考 HIG）：
   - 系统字体栈（SF Pro / PingFang SC 优先，自动回退）
   - 毛玻璃材质（backdrop-filter + 半透明表面）
   - 系统色（蓝 #007aff / 绿 #34c759 / 红 #ff3b30）与发丝分隔线
   - 深色模式：默认跟随系统（prefers-color-scheme），
     并可通过 html[data-theme] 手动覆盖（见 app.js 主题切换）
   ============================================================ */

* { margin: 0; padding: 0; box-sizing: border-box; }

/* ---------- 主题变量 ---------- */
:root {
  color-scheme: light dark;

  /* 浅色模式（默认） */
  --bg: #f5f5f7;                              /* 页面背景 */
  --bg-glow: rgba(0, 122, 255, .08);          /* 顶部微光晕 */
  --surface: rgba(255, 255, 255, .72);        /* 毛玻璃面板 */
  --surface-solid: #ffffff;                   /* 实色卡片 */
  --fill-2: rgba(120, 120, 128, .12);         /* 次级填充（按钮/输入框） */
  --fill-3: rgba(120, 120, 128, .22);
  --separator: rgba(60, 60, 67, .14);         /* 发丝分隔线 */
  --text: #1d1d1f;                            /* 主文字 */
  --text-2: #6e6e73;                          /* 次要文字 */
  --text-3: #aeaeb2;                          /* 占位文字 */
  --accent: #007aff;                          /* 系统蓝 */
  --accent-2: #5e5ce6;                        /* 渐变辅助（紫） */
  --accent-tint: rgba(0, 122, 255, .12);      /* 蓝色浅底 */
  --green: #34c759;                           /* 系统绿（开关） */
  --red: #ff3b30;                             /* 系统红（危险） */
  --red-tint: rgba(255, 59, 48, .1);
  --hud: rgba(28, 28, 30, .82);               /* Toast：恒为深色 HUD */
  --hud-text: #f5f5f7;
  --backdrop: rgba(0, 0, 0, .32);             /* 弹窗遮罩 */
  --shadow-card: 0 1px 2px rgba(0, 0, 0, .04), 0 10px 30px rgba(0, 0, 0, .06);
  --shadow-pop: 0 24px 64px rgba(0, 0, 0, .18);
}

/* 深色模式变量（手动切换为深色时） */
[data-theme="dark"] {
  --bg: #0a0a0b;
  --bg-glow: rgba(10, 132, 255, .12);
  --surface: rgba(28, 28, 30, .68);
  --surface-solid: #1c1c1e;
  --fill-2: rgba(120, 120, 128, .22);
  --fill-3: rgba(120, 120, 128, .32);
  --separator: rgba(84, 84, 88, .5);
  --text: #f5f5f7;
  --text-2: #98989d;
  --text-3: #636366;
  --accent: #0a84ff;
  --accent-2: #bf5af2;
  --accent-tint: rgba(10, 132, 255, .16);
  --green: #30d158;
  --red: #ff453a;
  --red-tint: rgba(255, 69, 58, .14);
  --backdrop: rgba(0, 0, 0, .5);
  --shadow-card: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px rgba(0, 0, 0, .35);
  --shadow-pop: 0 24px 64px rgba(0, 0, 0, .55);
}

/* 深色模式变量（跟随系统，且未被手动切为浅色时） */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a0a0b;
    --bg-glow: rgba(10, 132, 255, .12);
    --surface: rgba(28, 28, 30, .68);
    --surface-solid: #1c1c1e;
    --fill-2: rgba(120, 120, 128, .22);
    --fill-3: rgba(120, 120, 128, .32);
    --separator: rgba(84, 84, 88, .5);
    --text: #f5f5f7;
    --text-2: #98989d;
    --text-3: #636366;
    --accent: #0a84ff;
    --accent-2: #bf5af2;
    --accent-tint: rgba(10, 132, 255, .16);
    --green: #30d158;
    --red: #ff453a;
    --red-tint: rgba(255, 69, 58, .14);
    --backdrop: rgba(0, 0, 0, .5);
    --shadow-card: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px rgba(0, 0, 0, .35);
    --shadow-pop: 0 24px 64px rgba(0, 0, 0, .55);
  }
}

html { scrollbar-width: thin; scrollbar-color: var(--fill-3) transparent; }

/* ---------- 基础 ---------- */
body {
  height: 100vh;
  overflow: hidden;            /* 大屏场景整页不滚动，各区内部滚动 */
  display: flex;
  flex-direction: column;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC",
               "Helvetica Neue", "Segoe UI", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  background:
    radial-gradient(1100px 520px at 50% -8%, var(--bg-glow), transparent 70%),
    var(--bg);
  transition: background .3s, color .3s;
}

button { font-family: inherit; }

::selection { background: var(--accent-tint); }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--fill-3);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: content-box;
}

/* ---------- 顶部栏（毛玻璃 + 发丝底线） ---------- */
.topbar {
  position: relative;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 22px;
  background: var(--surface);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 0.5px solid var(--separator);
}

.logo {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: .2px;
  color: var(--text);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 9px;
  flex-wrap: wrap;
}

.stat-chip {
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--accent-tint);
  color: var(--accent);
  font-size: .9rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.stat-chip b { font-weight: 700; }

/* ---------- 按钮（Apple tinted / filled 风格） ---------- */
.btn {
  padding: 7px 15px;
  border-radius: 9px;
  border: none;
  background: var(--fill-2);
  color: var(--text);
  font-size: .9rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, transform .1s, filter .15s;
}
.btn:hover { background: var(--fill-3); }
.btn:active { transform: scale(.96); }

/* 无底色按钮：主色文字，悬停出现浅色底 */
.btn-ghost { background: transparent; color: var(--accent); }
.btn-ghost:hover { background: var(--accent-tint); }

/* 主按钮：系统蓝填充 */
.btn-primary {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }

/* 危险按钮：红色浅底红字 */
.btn-danger { background: var(--red-tint); color: var(--red); font-weight: 500; }
.btn-danger:hover { background: var(--red-tint); filter: brightness(.97) saturate(1.4); }

.btn-small { padding: 4px 11px; font-size: .8rem; border-radius: 7px; background: var(--accent-tint); color: var(--accent); font-weight: 500; }
.btn-small:hover { background: var(--accent-tint); filter: brightness(.97); }

/* ---------- 主体三栏布局 ---------- */
.layout {
  flex: 1;
  min-height: 0;               /* 允许子面板内部滚动 */
  display: grid;
  grid-template-columns: 1fr minmax(420px, 1.5fr) 1fr;
  gap: 16px;
  padding: 16px;
}

/* ---------- 左右侧面板（毛玻璃卡片） ---------- */
.panel {
  min-height: 0;
  overflow-y: auto;
  background: var(--surface);
  -webkit-backdrop-filter: blur(28px) saturate(180%);
  backdrop-filter: blur(28px) saturate(180%);
  border: 0.5px solid var(--separator);
  border-radius: 18px;
  box-shadow: var(--shadow-card);
  padding: 16px;
}

.panel-title {
  font-size: .95rem;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  position: sticky;
  top: -16px;
  padding: 6px 0;
  background: linear-gradient(to bottom, var(--surface-solid) 65%, transparent);
  z-index: 1;
}

.badge {
  min-width: 26px;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--fill-2);
  color: var(--text-2);
  font-size: .8rem;
  font-weight: 600;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.badge-gold { background: var(--accent-tint); color: var(--accent); }

.panel-empty {
  color: var(--text-2);
  text-align: center;
  padding: 30px 0;
  font-size: .9rem;
}

/* ---------- 号码网格 ---------- */
.number-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(52px, 1fr));
  gap: 7px;
}

.num-cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-solid);
  border: 0.5px solid var(--separator);
  border-radius: 9px;
  font-size: .9rem;
  font-weight: 500;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  transition: transform .12s;
}
.num-cell:hover { transform: scale(1.06); }

/* 已抽区号码：蓝色浅底主色字，与待抽区明确区分 */
.num-won {
  background: var(--accent-tint);
  border-color: transparent;
  color: var(--accent);
  font-weight: 600;
}

/* ---------- 中央舞台（内容即界面，无卡片装饰） ---------- */
.stage {
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  position: relative;
}

.stage-hint {
  color: var(--text-2);
  font-size: 1rem;
  margin-bottom: 30px;
  text-align: center;
}

.result-wrap {
  position: relative;
  min-height: 180px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3rem;
  flex-wrap: wrap;
}

.result-placeholder {
  font-size: 6rem;
  font-weight: 700;
  color: var(--text-3);
  user-select: none;
}

/* 抽取结果：大号 tabular 数字 + 系统色渐变 */
.result-num {
  font-size: clamp(4.5rem, 13vw, 10.5rem);
  font-weight: 800;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
  background: linear-gradient(135deg, var(--accent) 20%, var(--accent-2) 90%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 8px 28px var(--accent-tint));
}

/* 滚动中：轻微模糊抖动，营造抽取动感 */
.result-wrap.rolling .result-num {
  filter: blur(2px);
  opacity: .8;
  transform: scale(.96);
}

/* 定格弹出动画（Apple 弹性缓动） */
@keyframes pop {
  0%   { transform: scale(.4); opacity: 0; }
  55%  { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(1); }
}
.result-num.landed {
  animation: pop .45s cubic-bezier(.24, 1.3, .35, 1) both;
}

/* 中奖庆祝：扩散光环 */
@keyframes ring {
  from { transform: scale(.85); opacity: .8; }
  to   { transform: scale(1.18); opacity: 0; }
}
.result-wrap.celebrate::after {
  content: '';
  position: absolute;
  inset: -16px;
  border-radius: 24px;
  border: 2px solid var(--accent);
  animation: ring 1.3s ease-out 2;
  pointer-events: none;
}

/* 开始抽取主按钮 */
.draw-btn {
  margin-top: 34px;
  padding: 16px 64px;
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: 1px;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 14px;
  cursor: pointer;
  box-shadow: 0 10px 28px rgba(0, 122, 255, .3);
  transition: transform .12s, filter .15s, box-shadow .15s, opacity .15s;
}
.draw-btn:hover { filter: brightness(1.06); transform: translateY(-1px); }
.draw-btn:active { transform: scale(.97); }
.draw-btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

/* ---------- 对话框（毛玻璃 sheet） ---------- */
.dlg {
  position: fixed;
  inset: 0;          /* 配合 margin:auto 恢复原生居中（全局 * {margin:0} 会覆盖它） */
  margin: auto;
  background: var(--surface);
  -webkit-backdrop-filter: blur(32px) saturate(180%);
  backdrop-filter: blur(32px) saturate(180%);
  color: var(--text);
  border: 0.5px solid var(--separator);
  border-radius: 16px;
  padding: 22px 24px;
  width: min(440px, 92vw);
  max-height: 82vh;
  box-shadow: var(--shadow-pop);
}
.dlg::backdrop { background: var(--backdrop); }

.dlg-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 16px;
  color: var(--text);
  /* 标题栏即拖拽热区：按住可移动对话框 */
  cursor: move;
  touch-action: none;      /* 触摸拖动时阻止浏览器滚动/手势 */
  user-select: none;
  padding: 4px 0;
}
.dlg-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.dlg-head .dlg-title { margin-bottom: 0; flex: 1; }
.dlg-tip { color: var(--text-2); font-size: .82rem; margin: 14px 0 4px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

.field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 13px;
  font-size: .95rem;
}
.field > span { color: var(--text-2); }

.field input[type="number"] {
  width: 130px;
  padding: 8px 12px;
  border-radius: 10px;
  border: none;
  background: var(--fill-2);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  font-variant-numeric: tabular-nums;
  transition: background .15s, box-shadow .15s;
}
.field input[type="number"]:focus {
  outline: none;
  background: var(--surface-solid);
  box-shadow: 0 0 0 1px var(--accent), 0 0 0 4px var(--accent-tint);
}

/* iOS 风格开关 */
.switch-field { justify-content: flex-start; gap: 10px; }
.switch-field input {
  appearance: none;
  -webkit-appearance: none;
  flex-shrink: 0;
  width: 44px;
  height: 27px;
  border-radius: 999px;
  background: var(--fill-3);
  position: relative;
  cursor: pointer;
  outline: none;
  transition: background .2s;
}
.switch-field input:checked { background: var(--green); }
.switch-field input::before {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 23px;
  height: 23px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, .25), 0 0 1px rgba(0, 0, 0, .15);
  transition: transform .2s cubic-bezier(.3, .9, .4, 1);
}
.switch-field input:checked::before { transform: translateX(17px); }
.switch-field span { font-size: .9rem; color: var(--text); }

/* ---------- 历史记录列表 ---------- */
.hist-list {
  max-height: 62vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 120px;
}

.hist-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: 12px;
  background: var(--surface-solid);
  border: 0.5px solid var(--separator);
}

.hist-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 3px; }
.hist-head b { color: var(--text); font-weight: 700; }
.hist-time { color: var(--text-2); font-size: .78rem; font-variant-numeric: tabular-nums; }
.hist-numbers {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: .5px;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.hist-empty {
  color: var(--text-2);
  text-align: center;
  padding: 40px 0;
  font-size: .9rem;
}

/* ---------- 轻提示（HUD 风格，恒为深色） ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 40px;
  transform: translateX(-50%) translateY(16px);
  background: var(--hud);
  -webkit-backdrop-filter: blur(16px) saturate(180%);
  backdrop-filter: blur(16px) saturate(180%);
  color: var(--hud-text);
  padding: 11px 22px;
  border-radius: 999px;
  font-size: .92rem;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s, transform .25s;
  z-index: 999;
  max-width: 86vw;
  box-shadow: 0 8px 32px rgba(0, 0, 0, .25);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- 窄屏 / 投影以外场景：单列堆叠，舞台置顶 ---------- */
@media (max-width: 1100px) {
  body { height: auto; overflow: auto; }
  .layout { grid-template-columns: 1fr; }
  .stage { order: -1; min-height: 55vh; }
  .panel { max-height: none; }
}
