/* ============ 设计变量 ============ */
:root {
  --bg: #0e1116;
  --bg-elev: #161b22;
  --bg-elev2: #1c232c;
  --line: #262d38;
  --text: #e8edf4;
  --text-dim: #8b97a8;
  --text-dim2: #5f6b7c;

  --red: #e5484d;
  --red-soft: rgba(229, 72, 77, .14);
  --blue: #3b82f6;
  --blue-soft: rgba(59, 130, 246, .14);
  --gold: #e0a33e;
  --green: #3fb950;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --bar-h: 54px;
  --tab-h: 56px;

  --r: 14px;
  --r-sm: 10px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
        "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, sans-serif;
  overscroll-behavior-y: none;
}

body { -webkit-text-size-adjust: 100%; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }

/* ============ 顶栏 ============ */
#topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 50;
  height: calc(var(--bar-h) + var(--safe-top));
  padding: var(--safe-top) 16px 0;
  display: flex; align-items: center; justify-content: space-between;
  background: rgba(14, 17, 22, .82);
  backdrop-filter: saturate(180%) blur(18px);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  border-bottom: 1px solid var(--line);
}
.tb-left { display: flex; flex-direction: column; justify-content: center; min-width: 0; }
#tb-title { margin: 0; font-size: 17px; font-weight: 650; letter-spacing: .2px; }
.tb-sub { font-size: 11px; color: var(--text-dim2); line-height: 1.2; margin-top: 1px; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 50%;
  display: grid; place-items: center;
  color: var(--text-dim); transition: background .15s, color .15s;
}
.icon-btn:active { background: var(--bg-elev2); color: var(--text); }
.icon-btn.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ============ 主视图 ============ */
#view {
  padding: calc(var(--bar-h) + var(--safe-top) + 12px) 14px
           calc(var(--tab-h) + var(--safe-bottom) + 20px);
  max-width: 720px; margin: 0 auto;
}

/* ============ 底部标签栏 ============ */
#tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
  height: calc(var(--tab-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: flex;
  background: rgba(14, 17, 22, .92);
  backdrop-filter: saturate(180%) blur(18px);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  border-top: 1px solid var(--line);
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; color: var(--text-dim2); font-size: 10.5px; transition: color .15s;
}
.tab.active { color: var(--red); }
.tab:active { opacity: .6; }

/* ============ 通用卡片 / 段落 ============ */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 14px;
  margin-bottom: 12px;
}
.card.tight { padding: 10px 12px; }
.sec-title {
  font-size: 12px; font-weight: 600; color: var(--text-dim2);
  text-transform: uppercase; letter-spacing: .8px;
  margin: 20px 2px 8px;
}
.sec-title:first-child { margin-top: 4px; }
.muted { color: var(--text-dim); }
.dim2 { color: var(--text-dim2); }
.small { font-size: 12px; }
.tiny { font-size: 11px; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.row { display: flex; align-items: center; gap: 8px; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.mt8 { margin-top: 8px; } .mt12 { margin-top: 12px; } .mt16 { margin-top: 16px; }

/* ============ 玩法切换 ============ */
.game-switch {
  display: flex; gap: 4px; padding: 4px;
  background: var(--bg-elev); border: 1px solid var(--line);
  border-radius: 12px; margin-bottom: 12px;
}
.game-switch button {
  flex: 1; padding: 8px 6px; border-radius: 9px;
  font-size: 13.5px; font-weight: 600; color: var(--text-dim);
  transition: background .15s, color .15s;
}
.game-switch button.active { background: var(--bg-elev2); color: var(--text); }
.game-switch button.active[data-game="ssq"] { color: #ff6b6f; box-shadow: inset 0 0 0 1px var(--red-soft); }
.game-switch button.active[data-game="dlt"] { color: #58a6ff; box-shadow: inset 0 0 0 1px var(--blue-soft); }

/* ============ 号码球 ============ */
.balls { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.ball {
  width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 14.5px; font-weight: 650;
  font-variant-numeric: tabular-nums;
  flex: none;
}
.ball.sm { width: 27px; height: 27px; font-size: 12px; }
.ball.xs { width: 22px; height: 22px; font-size: 10.5px; }
.ball.red  { background: linear-gradient(160deg, #f0575c, #c8323a); color: #fff; box-shadow: 0 1px 5px rgba(229,72,77,.35); }
.ball.blue { background: linear-gradient(160deg, #5595f7, #2563d4); color: #fff; box-shadow: 0 1px 5px rgba(59,130,246,.35); }
.ball.hit  { outline: 2px solid var(--gold); outline-offset: 2px; }
.ball.ghost { background: var(--bg-elev2); color: var(--text-dim2); box-shadow: none; }
.ball-sep { width: 1px; height: 22px; background: var(--line); margin: 0 3px; flex: none; }

/* ============ 开奖卡片 ============ */
.draw-latest { position: relative; overflow: hidden; }
.draw-latest::after {
  content: ''; position: absolute; top: -60px; right: -60px;
  width: 160px; height: 160px; border-radius: 50%;
  background: radial-gradient(circle, rgba(229,72,77,.12), transparent 70%);
  pointer-events: none;
}
.draw-issue { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.draw-date { font-size: 12px; color: var(--text-dim2); }
.badge {
  display: inline-block; padding: 2px 7px; border-radius: 6px;
  font-size: 10.5px; font-weight: 600; letter-spacing: .3px;
}
.badge.red { background: var(--red-soft); color: #ff7b7f; }
.badge.blue { background: var(--blue-soft); color: #7cb0ff; }
.badge.gold { background: rgba(224,163,62,.15); color: var(--gold); }
.badge.green { background: rgba(63,185,80,.15); color: var(--green); }
.badge.gray { background: var(--bg-elev2); color: var(--text-dim); }

.kv-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 8px; }
.kv { min-width: 0; }
.kv .k { font-size: 10.5px; color: var(--text-dim2); }
.kv .v { font-size: 13.5px; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ============ 历史列表 ============ */
.hist-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 4px; border-bottom: 1px solid var(--line);
}
.hist-item:last-child { border-bottom: none; }
.hist-meta { flex: none; width: 62px; }
.hist-issue { font-size: 12.5px; font-weight: 650; font-variant-numeric: tabular-nums; }
.hist-date { font-size: 10.5px; color: var(--text-dim2); }
.hist-balls { display: flex; flex-wrap: wrap; gap: 4px; }

/* ============ 按钮 ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 11px 16px; border-radius: var(--r-sm);
  background: var(--bg-elev2); color: var(--text);
  font-size: 14.5px; font-weight: 600;
  transition: transform .1s, opacity .15s;
}
.btn:active { transform: scale(.975); }
.btn.primary { background: linear-gradient(160deg, #f0575c, #cf3340); color: #fff; }
.btn.accent { background: linear-gradient(160deg, #4a90f7, #2563d4); color: #fff; }
.btn.green { background: linear-gradient(160deg, #3fb950, #2a8f3a); color: #fff; }
.btn.ghost { background: transparent; box-shadow: inset 0 0 0 1px var(--line); color: var(--text-dim); }
.btn.danger { background: transparent; box-shadow: inset 0 0 0 1px rgba(229,72,77,.5); color: #ff7b7f; }
.btn.block { width: 100%; }
.btn.sm { padding: 7px 12px; font-size: 13px; border-radius: 9px; }
.btn[disabled] { opacity: .4; pointer-events: none; }
.btn-row { display: flex; gap: 8px; }

/* ============ 输入 ============ */
.field { margin-bottom: 12px; }
.field > label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 5px; }
input[type=text], input[type=password], input[type=number], input[type=date], select, textarea {
  width: 100%; padding: 10px 12px;
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-sm);
  color: var(--text); font-size: 15px; outline: none;
  transition: border-color .15s;
  -webkit-appearance: none; appearance: none;
}
input:focus, select:focus, textarea:focus { border-color: #3d4b5c; }
textarea { resize: vertical; min-height: 90px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; line-height: 1.45; }
select { background-image: none; padding-right: 32px; }
.hint { font-size: 11.5px; color: var(--text-dim2); margin-top: 5px; line-height: 1.45; }

.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 0; }
.switch .sw-label { font-size: 14px; }
.switch .sw-desc { font-size: 11.5px; color: var(--text-dim2); margin-top: 2px; }
.toggle {
  position: relative; width: 46px; height: 28px; flex: none;
  background: var(--bg-elev2); border-radius: 14px; transition: background .2s;
}
.toggle::after {
  content: ''; position: absolute; top: 3px; left: 3px;
  width: 22px; height: 22px; border-radius: 50%; background: #6b7787;
  transition: transform .2s, background .2s;
}
.toggle.on { background: rgba(229,72,77,.35); }
.toggle.on::after { transform: translateX(18px); background: #fff; }

/* ============ 号码选择盘 ============ */
.picker-head {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-bottom: 7px; font-size: 12.5px;
}
.picker-head .cnt { font-variant-numeric: tabular-nums; color: var(--text-dim); }
.picker-head .cnt.ok { color: var(--green); }
.numgrid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.numgrid button {
  aspect-ratio: 1; border-radius: 50%;
  background: var(--bg-elev2); color: var(--text-dim);
  font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums;
  display: grid; place-items: center; transition: transform .1s, background .12s, color .12s;
}
.numgrid button:active { transform: scale(.9); }
.numgrid.red button.on { background: linear-gradient(160deg, #f0575c, #c8323a); color: #fff; }
.numgrid.blue button.on { background: linear-gradient(160deg, #5595f7, #2563d4); color: #fff; }
.numgrid button.omit { color: var(--gold); }
.numgrid button .o {
  position: absolute; font-size: 8px; margin-top: 21px; color: var(--text-dim2);
}
.numgrid button { position: relative; }

/* ============ 中奖结果 ============ */
.result-line {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 0; border-bottom: 1px dashed var(--line);
}
.result-line:last-child { border-bottom: none; }
.result-line .idx { font-size: 11px; color: var(--text-dim2); width: 32px; flex: none; font-variant-numeric: tabular-nums; }
.result-line .amt { margin-left: auto; font-weight: 700; font-variant-numeric: tabular-nums; flex: none; }
.amt.win { color: var(--gold); }
.amt.lose { color: var(--text-dim2); font-weight: 500; }
.win-banner {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; border-radius: var(--r-sm);
  background: linear-gradient(135deg, rgba(224,163,62,.18), rgba(224,163,62,.06));
  border: 1px solid rgba(224,163,62,.32);
}
.win-banner .big { font-size: 20px; font-weight: 750; color: var(--gold); font-variant-numeric: tabular-nums; }

/* ============ 统计条 ============ */
.bar-row { display: flex; align-items: center; gap: 8px; margin-bottom: 5px; }
.bar-row .lbl { width: 30px; flex: none; font-size: 11.5px; font-variant-numeric: tabular-nums; color: var(--text-dim); }
.bar-row .track { flex: 1; height: 9px; background: var(--bg-elev2); border-radius: 5px; overflow: hidden; }
.bar-row .fill { height: 100%; border-radius: 5px; background: linear-gradient(90deg, #c8323a, #f0575c); }
.bar-row.blue .fill { background: linear-gradient(90deg, #2563d4, #5595f7); }
.bar-row .num { width: 42px; flex: none; text-align: right; font-size: 11.5px; font-variant-numeric: tabular-nums; color: var(--text-dim); }

/* ============ 空态 / 加载 ============ */
.empty { padding: 44px 20px; text-align: center; color: var(--text-dim2); }
.empty .em-icon { font-size: 34px; opacity: .5; margin-bottom: 10px; }
.empty .em-title { font-size: 14.5px; color: var(--text-dim); margin-bottom: 5px; }
.skeleton {
  height: 14px; border-radius: 7px; margin-bottom: 9px;
  background: linear-gradient(90deg, var(--bg-elev) 25%, var(--bg-elev2) 50%, var(--bg-elev) 75%);
  background-size: 200% 100%; animation: sk 1.3s linear infinite;
}
@keyframes sk { to { background-position: -200% 0; } }

/* ============ 底部弹层 ============ */
#sheet { position: fixed; inset: 0; z-index: 100; }
#sheet[hidden] { display: none; }
.sheet-mask { position: absolute; inset: 0; background: rgba(0,0,0,.6); animation: fade .2s; }
@keyframes fade { from { opacity: 0; } }
.sheet-body {
  position: absolute; left: 0; right: 0; bottom: 0;
  max-height: 92vh; overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: var(--bg-elev);
  border-radius: 18px 18px 0 0;
  padding: 8px 16px calc(20px + var(--safe-bottom));
  animation: slideup .26s cubic-bezier(.32,.72,0,1);
  border-top: 1px solid var(--line);
}
@keyframes slideup { from { transform: translateY(100%); } }
.sheet-grip { width: 36px; height: 4px; border-radius: 2px; background: var(--line); margin: 6px auto 14px; }
.sheet-title { font-size: 17px; font-weight: 700; margin: 0 0 14px; }

/* ============ Toast ============ */
#toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tab-h) + var(--safe-bottom) + 22px);
  z-index: 200; max-width: 86vw;
  padding: 10px 18px; border-radius: 22px;
  background: rgba(38,45,56,.97); color: var(--text);
  font-size: 13.5px; text-align: center;
  opacity: 0; pointer-events: none; transition: opacity .22s, transform .22s;
  box-shadow: 0 6px 24px rgba(0,0,0,.45);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }

/* ============ 免责 / 提示条 ============ */
.notice {
  display: flex; gap: 8px; align-items: flex-start;
  padding: 10px 12px; border-radius: var(--r-sm);
  background: rgba(224,163,62,.08); border: 1px solid rgba(224,163,62,.22);
  font-size: 11.5px; line-height: 1.5; color: #d9b46a;
}
.notice.info { background: rgba(59,130,246,.08); border-color: rgba(59,130,246,.22); color: #8cb6f5; }
.notice.err { background: rgba(229,72,77,.08); border-color: rgba(229,72,77,.24); color: #f08b8e; }
.notice .ni { flex: none; }

/* 图片预览 */
.thumb { width: 100%; max-height: 220px; object-fit: contain; border-radius: var(--r-sm); background: #000; display: block; }

.kbd {
  display: inline-block; padding: 1px 5px; border-radius: 4px;
  background: var(--bg-elev2); font-family: ui-monospace, monospace;
  font-size: 11px; color: var(--text-dim);
}

/* 打印/宽屏微调 */
@media (min-width: 560px) {
  .numgrid { grid-template-columns: repeat(10, 1fr); }
  .hist-meta { width: 76px; }
}
