/* ============================================================
   前台主样式
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; scroll-behavior: smooth;
       -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  background: var(--bg, #0a0a1a);
  color: var(--text, #e0f4ff);
  font-family: 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  min-height: 100vh;
  min-height: 100dvh;             /* 移动端动态视口高度 */
  overflow-x: hidden;
  position: relative;
  touch-action: manipulation;      /* 消除移动端300ms点击延迟与双击缩放 */
  -webkit-tap-highlight-color: transparent;  /* 去除 iOS 点击高亮 */
  padding-bottom: env(safe-area-inset-bottom); /* 刘海屏底部安全区 */
}

/* ── 粒子画布 ── */
#particles-canvas {
  position: fixed; inset: 0; z-index: 0;
  pointer-events: none; opacity: .4;
}

/* ── 扫描线 ── */
.scan-line {
  position: fixed; left: 0; right: 0; height: 2px; z-index: 1;
  background: linear-gradient(90deg, transparent, var(--primary), transparent);
  animation: scan 4s linear infinite; opacity: .25;
}
@keyframes scan { 0%{top:0} 100%{top:100%} }

/* ── Header ── */
.site-header {
  position: sticky; top: 0; z-index: 100;
  background: var(--header-bg, rgba(0,10,30,.95));
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
}
.header-inner {
  max-width: 900px; margin: 0 auto;
  padding: 12px 16px;
  display: flex; align-items: center; gap: 12px;
}
.header-left { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.site-logo { height: 40px; width: 40px; object-fit: contain; border-radius: 6px; }
.site-logo-text {
  width: 40px; height: 40px; display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem; background: var(--bg-cell); border-radius: 8px;
  border: 1px solid var(--border);
}
.site-name {
  font-size: clamp(.9rem,3vw,1.2rem);
  font-weight: 700; color: var(--primary);
  text-shadow: 0 0 12px var(--primary-glow);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.header-right { display: flex; align-items: center; gap: 8px; shrink: 0; }
.icon-btn {
  background: var(--bg-card); border: 1px solid var(--border);
  color: var(--text); cursor: pointer; border-radius: 8px;
  padding: 7px 10px; font-size: 1.1rem; transition: border-color .25s;
  min-width: 44px; min-height: 40px;   /* 触摸目标 ≥44px */
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { border-color: var(--primary); }
.icon-btn:active { transform: scale(.92); }

/* ── 导航 ── */
.site-nav {
  display: flex; gap: 4px; padding: 0 16px 8px;
  max-width: 900px; margin: 0 auto;
}
.nav-link {
  padding: 6px 14px; border-radius: 20px;
  text-decoration: none; color: var(--text-muted);
  font-size: .88rem; transition: all .25s;
  border: 1px solid transparent;
}
.nav-link:hover, .nav-link.active {
  color: var(--primary); border-color: var(--border);
  background: var(--bg-card);
  text-shadow: 0 0 8px var(--primary-glow);
}

/* ── Main ── */
.lottery-wrap, .page-main {
  max-width: 900px; margin: 0 auto;
  padding: 20px 16px 40px;
  position: relative; z-index: 2;
}

/* ── Code Input（已移至转盘下方，使用 margin-top）── */
.code-section { margin-top: 20px; margin-bottom: 0; }
.code-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px; padding: 20px;
  backdrop-filter: blur(6px);
}
.code-label { font-size: .85rem; color: var(--text-muted); margin-bottom: 10px; }
.code-input-row { display: flex; gap: 10px; }
.code-input {
  flex: 1; min-width: 0;
  background: var(--input-bg, rgba(0,0,0,.3)); border: 1px solid var(--border);
  border-radius: 8px; padding: 12px 16px;
  color: var(--text); font-size: 1rem; outline: none;
  letter-spacing: 2px; text-transform: uppercase;
  transition: border-color .3s;
}
.code-input:focus { border-color: var(--primary); box-shadow: 0 0 10px var(--primary-glow); }
.code-input::placeholder { color: var(--text-muted); text-transform: none; letter-spacing: 0; }

/* ── Spin Button ── */
.spin-btn {
  position: relative; overflow: hidden;
  padding: 12px 24px; border: none; border-radius: 8px;
  background: var(--btn-bg); color: var(--btn-text);
  font-size: 1rem; font-weight: 700; cursor: pointer;
  white-space: nowrap; letter-spacing: 1px;
  transition: transform .2s, opacity .2s;
  min-width: 100px;
}
.spin-btn:hover { transform: translateY(-1px); opacity: .92; }
.spin-btn:active { transform: translateY(0); }
.spin-btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn-glow {
  position: absolute; inset: 0;
  background: radial-gradient(circle at 50% 50%, rgba(255,255,255,.25), transparent 70%);
  opacity: 0; transition: opacity .3s;
}
.spin-btn:hover .btn-glow { opacity: 1; }

/* ── Lottery Grid (九宫格) ── */
.lottery-board-wrap { margin-bottom: 0; }
.board-frame {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px; padding: 20px;
  backdrop-filter: blur(6px);
}
.board-title {
  text-align: center; color: var(--text-muted);
  font-size: .85rem; letter-spacing: 4px; margin-bottom: 16px;
}

/* ── 驾校元素：红绿灯 ── */
.traffic-light {
  display: flex; justify-content: center; gap: 10px;
  margin-bottom: 14px;
}
.tl {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.35);
  box-shadow: inset 0 1px 3px rgba(0,0,0,.35);
  opacity: .35;
}
.tl-red    { background: #e74c3c; }
.tl-yellow { background: #f1c40f; }
.tl-green  { background: #27ae60; }
/* 红绿灯循环点亮动画 */
@keyframes tlCycle {
  0%, 33%   { opacity: 1; } 34%, 100% { opacity: .3; }
}
@keyframes tlCycle2 {
  0%, 33%   { opacity: .3; } 34%, 66% { opacity: 1; } 67%, 100% { opacity: .3; }
}
@keyframes tlCycle3 {
  0%, 66%   { opacity: .3; } 67%, 100% { opacity: 1; }
}
.tl-red    { animation: tlCycle  3s infinite; }
.tl-yellow { animation: tlCycle2 3s infinite; }
.tl-green  { animation: tlCycle3 3s infinite; }

/* ── 驾校元素：斑马线 ── */
.zebra-crossing {
  display: flex; justify-content: center; gap: 4px;
  margin-top: 16px;
}
.zebra-crossing span {
  width: 22px; height: 6px; border-radius: 2px;
  background: var(--text-muted); opacity: .4;
}

/* ── 驾校元素：标语 ── */
.header-title-wrap { display: flex; flex-direction: column; }
.site-slogan {
  font-size: .7rem; color: var(--text-muted);
  letter-spacing: 2px; margin-top: 2px;
}

/* ── 驾校元素：方向盘背景装饰 ── */
.board-frame::before {
  content: '';
  position: absolute; top: 50%; left: 50%;
  width: 300px; height: 300px;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle, transparent 58%, var(--border) 58%, var(--border) 60%, transparent 60%);
  opacity: .12; pointer-events: none; z-index: 0;
}
.board-frame { position: relative; }
#gridStage { position: relative; z-index: 1; }

/* 九宫格容器：3列等宽 */
.grid-stage {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  width: min(420px, 92vw);
  margin: 0 auto;
}

/* 单个格子 */
.grid-cell {
  aspect-ratio: 1;
  border-radius: 10px;
  background: var(--bg-cell);
  border: 2px solid var(--border);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 6px 4px;
  text-align: center;
  cursor: default;
  transition: background .1s, border-color .1s, box-shadow .1s, transform .1s;
  position: relative; overflow: hidden;
}

/* 跑马灯高亮态 */
.grid-cell.active {
  background: var(--bg-cell-active);
  border-color: var(--border-active);
  box-shadow: var(--cell-shadow);
  transform: scale(1.05);
  z-index: 2;
}

/* 格子内图片 */
.grid-cell-img {
  width: 52%; aspect-ratio: 1;
  object-fit: cover; border-radius: 6px;
  margin-bottom: 4px; display: block;
}

/* 无图片时 emoji 占位 */
.grid-cell-icon {
  font-size: clamp(1.4rem, 5vw, 2rem);
  line-height: 1; margin-bottom: 4px;
}

/* 奖品名称 */
.grid-cell-name {
  font-size: clamp(.62rem, 2.2vw, .76rem);
  font-weight: 600; color: var(--text);
  word-break: break-all; line-height: 1.25;
  max-height: 2.5em; overflow: hidden;
}

/* 中心"开始抽奖"格子 */
.grid-center {
  background: var(--btn-bg) !important;
  border: 3px solid rgba(255,255,255,.55) !important;
  cursor: pointer;
  box-shadow: 0 0 24px var(--primary-glow), inset 0 0 12px rgba(255,255,255,.15);
}
.grid-center:hover  { transform: scale(1.07); }
.grid-center:active { transform: scale(.96);  }
.grid-center:disabled { opacity: .6; cursor: not-allowed; transform: none; }
.grid-center-text {
  font-size: clamp(.85rem, 3.5vw, 1.1rem);
  font-weight: 800; color: var(--btn-text);
  line-height: 1.3; text-shadow: 0 1px 3px rgba(0,0,0,.4);
  pointer-events: none;
}

/* ── Tips ── */
.tips-bar {
  text-align: center; color: var(--text-muted);
  font-size: .82rem; padding: 8px; letter-spacing: .5px;
}

/* ── 中奖历史滚动展示 ── */
.history-section {
  width: min(520px, 92vw);
  margin: 16px auto 0;
}
.history-title {
  text-align: center; color: var(--primary);
  font-size: .85rem; font-weight: 700;
  letter-spacing: 2px; margin-bottom: 8px;
  text-shadow: 0 0 8px var(--primary-glow);
}
.history-marquee {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  overflow: hidden;
  white-space: nowrap;
  position: relative;
  backdrop-filter: blur(6px);
}
/* 左右渐隐遮罩 */
.history-marquee::before,
.history-marquee::after {
  content: ''; position: absolute; top: 0; bottom: 0; width: 24px; z-index: 2;
  pointer-events: none;
}
.history-marquee::before { left: 0;  background: linear-gradient(90deg, var(--bg-card), transparent); }
.history-marquee::after  { right: 0; background: linear-gradient(270deg, var(--bg-card), transparent); }
.history-track {
  display: inline-block;
  white-space: nowrap;
  will-change: transform;
}
.history-item {
  display: inline-block;
  margin-right: 40px;
  font-size: .82rem;
  color: var(--text);
}
.history-item b { color: var(--primary); font-weight: 700; }
.history-item i {
  font-style: normal; color: var(--text-muted);
  font-size: .72rem; margin-left: 6px;
}
.history-item em {
  font-style: normal; color: var(--text-muted);
  font-size: .72rem;
}
.history-empty {
  font-size: .8rem; color: var(--text-muted);
}
/* 无缝滚动动画 */
@keyframes historyScroll {
  from { transform: translateX(0); }
  to   { transform: translateX(-50%); }
}
.history-track.history-anim {
  animation: historyScroll 20s linear infinite;
}
.history-marquee:hover .history-anim {
  animation-play-state: paused;   /* 鼠标悬停暂停 */
}

/* ── Query & Activity pages ── */
.query-card, .activity-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px; padding: 24px;
  backdrop-filter: blur(6px);
}
.query-title { text-align: center; color: var(--primary); font-size: 1.3rem; margin-bottom: 20px; }
.query-form { display: flex; gap: 10px; margin-bottom: 20px; flex-wrap: wrap; }
.query-result { margin-top: 16px; }
/* ── 表格横向滚动容器（小屏防溢出） ── */
.table-scroll {
  width: 100%; overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 8px;
}
.result-table {
  width: 100%; border-collapse: collapse; font-size: .9rem;
  min-width: 420px;   /* 低于此宽度在容器内横向滚动 */
}
.result-table th, .result-table td {
  padding: 10px 12px; text-align: left;
  border-bottom: 1px solid var(--border);
}
.result-table th { color: var(--text-muted); font-weight: 600; font-size: .82rem; }
.prize-cell-name { color: var(--primary); }
.empty-tip { text-align: center; color: var(--text-muted); padding: 30px; }

.activity-header { margin-bottom: 16px; }
.activity-header h2 { color: var(--primary); font-size: 1.2rem; }
.activity-body { color: var(--text); line-height: 1.8; }
.activity-body h3 { color: var(--primary); margin: 16px 0 8px; }
.activity-body p { margin-bottom: 10px; color: var(--text-muted); }

/* ── Badges ── */
.badge {
  display: inline-flex; align-items: center;
  padding: 3px 10px; border-radius: 20px;
  font-size: .78rem; font-weight: 600;
}
.badge-success { background: rgba(0,200,100,.15); color: #00c864; border: 1px solid rgba(0,200,100,.3); }
.badge-warn    { background: rgba(255,160,0,.15);  color: #ffa000; border: 1px solid rgba(255,160,0,.3); }
.badge-info    { background: rgba(0,180,255,.15);  color: #00b4ff; border: 1px solid rgba(0,180,255,.3); }
.badge-default { background: rgba(150,150,150,.1); color: #888; border: 1px solid rgba(150,150,150,.2); }

/* ── Modals ── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: var(--overlay-bg); display: none;
}
.modal-overlay.show { display: block; }
.win-modal, .lose-modal, .success-modal {
  position: fixed; z-index: 201;
  top: 50%; left: 50%; transform: translate(-50%,-50%) scale(.8);
  width: min(420px, calc(100% - 32px));
  max-height: 86vh; max-height: 86dvh;   /* 移动端浏览器工具栏下仍可见 */
  overflow-y: auto;                        /* 内容超高时可滚动 */
  -webkit-overflow-scrolling: touch;
  background: var(--bg);
  border: 1px solid var(--border-active);
  border-radius: 20px; padding: 28px;
  text-align: center;
  box-shadow: 0 0 50px var(--primary-glow);
  transition: transform .3s, opacity .3s;
  opacity: 0; pointer-events: none;
}
.win-modal.show, .lose-modal.show, .success-modal.show {
  transform: translate(-50%,-50%) scale(1);
  opacity: 1; pointer-events: auto;
}
.win-fireworks { font-size: 2rem; margin-bottom: 4px; }
.win-title { color: var(--primary); font-size: 1.4rem; margin-bottom: 16px;
             text-shadow: 0 0 12px var(--primary-glow); }
.win-prize-info { margin-bottom: 20px; }
.win-prize-img { width: 80px; height: 80px; object-fit: contain; border-radius: 10px; }
.win-prize-emoji { font-size: 3rem; }
.win-prize-name { font-size: 1.1rem; font-weight: 700; color: var(--primary); margin-top: 8px; }
.claim-form { display: flex; flex-direction: column; gap: 12px; }
.claim-form input {
  background: var(--input-bg, rgba(0,0,0,.4)); border: 1px solid var(--border);
  border-radius: 8px; padding: 12px 16px; color: var(--text);
  font-size: 1rem; outline: none; transition: border-color .3s;
}
.claim-form input:focus { border-color: var(--primary); }
.claim-btn {
  padding: 13px; border: none; border-radius: 8px;
  background: var(--btn-bg); color: var(--btn-text);
  font-size: 1rem; font-weight: 700; cursor: pointer;
  transition: opacity .3s;
}
.claim-btn:hover { opacity: .88; }
.lose-icon, .success-icon { font-size: 3.5rem; margin-bottom: 10px; }
.lose-title, .success-title { font-size: 1.3rem; font-weight: 700; margin-bottom: 8px; color: var(--primary); }
.lose-sub, .success-sub { color: var(--text-muted); margin-bottom: 20px; }
.close-btn {
  padding: 10px 28px; border: 1px solid var(--border);
  border-radius: 8px; background: transparent; color: var(--text);
  font-size: .95rem; cursor: pointer; transition: border-color .25s;
}
.close-btn:hover { border-color: var(--primary); color: var(--primary); }

/* ── Theme Panel ── */
.theme-overlay {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(0,0,0,.6); display: none;
}
.theme-overlay.show { display: block; }
.theme-panel {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 301;
  background: var(--bg); border-top: 1px solid var(--border);
  border-radius: 20px 20px 0 0; padding: 20px;
  transform: translateY(100%); transition: transform .3s;
}
.theme-panel.show { transform: translateY(0); }
.theme-panel-inner { max-width: 400px; margin: 0 auto; }
.theme-panel-title { text-align: center; font-size: 1rem; color: var(--text-muted); margin-bottom: 16px; }
.theme-options { display: grid; grid-template-columns: repeat(5,1fr); gap: 12px; margin-bottom: 16px; }
.theme-opt { text-align: center; cursor: pointer; }
.theme-opt span { font-size: .8rem; color: var(--text-muted); display: block; margin-top: 6px; }
.theme-preview { height: 50px; border-radius: 10px; border: 2px solid transparent; transition: border-color .25s; }
.theme-opt:hover .theme-preview, .theme-opt.selected .theme-preview { border-color: var(--primary); }
.theme-preview-red    { background: linear-gradient(135deg, #fff8f0, #e0342b); }
.theme-preview-blue   { background: linear-gradient(135deg, #0a0a1a, #00d4ff); }
.theme-preview-purple { background: linear-gradient(135deg, #0d0a1a, #c084fc); }
.theme-preview-cyber  { background: linear-gradient(135deg, #0a0008, #f0ff00); }
.theme-preview-green  { background: linear-gradient(135deg, #030f0a, #00ff88); }
.theme-close {
  width: 100%; padding: 10px; background: var(--bg-card);
  border: 1px solid var(--border); border-radius: 8px;
  color: var(--text-muted); cursor: pointer; font-size: .9rem;
}

/* ── 喜庆红金主题专属优化 ── */
[data-theme="festival"] .scan-line { display: none; }           /* 扫描线不适合亮色主题 */
[data-theme="festival"] #particles-canvas { opacity: .1; }     /* 粒子减淡，避免遮挡 */
[data-theme="festival"] .site-header {
  background: rgba(255,251,247,.97);
  border-bottom: 2px solid rgba(224,52,43,.18);
  box-shadow: 0 2px 14px rgba(224,52,43,.1);
}
[data-theme="festival"] .board-frame {
  border: 2px solid rgba(224,52,43,.2);
  box-shadow: 0 4px 20px rgba(224,52,43,.08);
}
[data-theme="festival"] .code-box {
  border: 1.5px solid rgba(224,52,43,.2);
  box-shadow: 0 2px 12px rgba(224,52,43,.06);
}
[data-theme="festival"] .nav-link:hover,
[data-theme="festival"] .nav-link.active {
  text-shadow: none;   /* 亮色主题无需发光效果 */
}
[data-theme="festival"] .tips-bar { color: #a4756a; }

/* ── Responsive（移动端自适应）── */
/* ═══════════ 移动端适配：平板 ≥ 手机 ═══════════ */

/* ── 平板 / 大屏手机横屏 ── */
@media (max-width: 768px) {
  .lottery-wrap, .page-main { padding: 18px 16px 36px; }
  .code-box { padding: 18px; }
  .board-frame { padding: 16px; }
  .site-name { font-size: 1.1rem; }
}

/* ── 手机竖屏 ── */
@media (max-width: 480px) {
  /* 布局压缩 */
  .code-input-row { flex-direction: column; }
  .spin-btn { width: 100%; min-height: 48px; }       /* 全宽大按钮易点击 */
  .header-inner { padding: 10px 12px; }
  .lottery-wrap, .page-main { padding: 14px 12px 32px; }
  .code-box { padding: 14px; }
  .board-frame { padding: 12px; border-radius: 12px; }

  /* header：小屏压缩标题与标语 */
  .site-name { font-size: 1rem; max-width: 46vw; }
  .site-slogan { font-size: .62rem; letter-spacing: 1px; }
  .site-logo { height: 32px; width: 32px; }
  .site-logo-text { font-size: 1.3rem; }
  .icon-btn { min-width: 40px; min-height: 40px; padding: 6px 8px; font-size: 1rem; }
  .site-logo-text, .header-left { gap: 8px; }

  /* 导航横向滑动 */
  .site-nav { padding: 0 8px 6px; overflow-x: auto; -webkit-overflow-scrolling: touch;
              scrollbar-width: none; }
  .site-nav::-webkit-scrollbar { display: none; }
  .nav-link { padding: 8px 12px; font-size: .82rem; white-space: nowrap;
              min-height: 36px; display: inline-flex; align-items: center; }

  /* 九宫格：小屏紧凑 */
  .grid-stage { gap: 6px; width: min(360px, 100%); }
  .grid-cell-name { font-size: .60rem; }
  .grid-center-text { font-size: .82rem; }
  .grid-cell-img { width: 48%; margin-bottom: 3px; }
  .grid-cell-icon { font-size: 1.35rem; margin-bottom: 3px; }

  /* 驾校装饰元素缩小 */
  .traffic-light { gap: 8px; margin-bottom: 10px; }
  .tl { width: 14px; height: 14px; }
  .zebra-crossing { margin-top: 12px; gap: 3px; }
  .zebra-crossing span { width: 16px; height: 5px; }
  .board-title { font-size: .78rem; letter-spacing: 2px; margin-bottom: 12px; }

  /* 输入区 */
  .code-input { padding: 13px 14px; font-size: 16px; }  /* 16px防iOS聚焦缩放 */
  .tips-bar { font-size: .78rem; }

  /* 弹窗小屏化 */
  .win-modal, .lose-modal, .success-modal {
    padding: 20px 16px; border-radius: 16px;
    width: calc(100% - 24px);
    max-height: 82dvh;
  }
  .win-title { font-size: 1.2rem; }
  .win-prize-img { width: 64px; height: 64px; }
  .win-prize-emoji { font-size: 2.4rem; }
  .lose-icon, .success-icon { font-size: 2.8rem; }
  .claim-form input { padding: 12px 14px; font-size: 16px; }

  /* 记录页 / 活动页 */
  .query-card, .activity-card { padding: 16px 14px; }
  .query-form { flex-direction: column; }
  .query-form .code-input { width: 100%; }
  .result-table { font-size: .8rem; }
  .result-table th, .result-table td { padding: 8px 6px; }
  .theme-options { grid-template-columns: repeat(3,1fr); }
  .theme-preview { height: 40px; }
}

/* ── 超小屏（iPhone SE / 折叠机外屏） ── */
@media (max-width: 360px) {
  .site-name { font-size: .9rem; max-width: 40vw; }
  .site-slogan { display: none; }           /* 超小屏隐藏标语避免换行 */
  .grid-stage { gap: 5px; }
  .grid-cell-name { font-size: .56rem; }
  .grid-center-text { font-size: .76rem; }
  .header-inner { padding: 8px 10px; }
  .nav-link { padding: 7px 9px; font-size: .78rem; }
  .spin-btn { padding: 12px 16px; }
  .win-modal, .lose-modal, .success-modal { width: calc(100% - 16px); padding: 18px 12px; }
}

/* ── 横屏矮屏（手机横置） ── */
@media (max-width: 900px) and (max-height: 500px) and (orientation: landscape) {
  .grid-stage { width: min(300px, 60vh); }   /* 横屏限制高度，避免超屏 */
  .traffic-light, .zebra-crossing { display: none; }
  .lottery-wrap, .page-main { padding: 10px 12px 20px; }
}
