:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #182033;
  --muted: #6f7b91;
  --line: #e6ebf2;
  --primary: #246bff;
  --success: #11a36a;
  --danger: #db4d4d;
  --warning: #d28a17;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}
button, input, textarea, select { font: inherit; }
.app-page {
  max-width: 760px;
  margin: 0 auto;
  padding: 12px 12px 92px;
}
.screen { display: none; gap: 12px; }
.screen.active { display: grid; }
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 2px;
}
.app-header.compact { padding-top: 8px; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 26px; }
h2 { font-size: 19px; }
p, .subtle { color: var(--muted); font-size: 14px; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: 0 8px 24px rgba(16,24,40,.05);
  padding: 14px;
}
.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.primary, .ghost, .danger-btn {
  border: 0;
  border-radius: 14px;
  padding: 12px 16px;
  cursor: pointer;
  font-weight: 700;
}
.primary { background: var(--primary); color: #fff; }
.primary.xl { width: 100%; min-height: 54px; font-size: 18px; }
.ghost { background: #f2f5fb; border: 1px solid var(--line); color: var(--text); }
.danger-btn { background: #fff1f1; color: var(--danger); }
.action-card { display: grid; gap: 10px; }
.scan-panel { display: grid; grid-template-columns: 1fr; gap: 10px; }
.scanner-video, .preview {
  width: 100%; min-height: 220px; border-radius: 16px; border: 1px dashed var(--line);
  background: #eef3f9; object-fit: cover;
}
.preview {
  display: flex; align-items: center; justify-content: center; color: var(--muted); overflow: hidden;
}
.preview img { width: 100%; height: 100%; object-fit: contain; }
.draw-cards, .history-draws { display: grid; gap: 10px; }
.draw-card, .history-draw-item, .result-item, .mobile-record {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  background: #fafcff;
}
.draw-title { font-weight: 700; margin-bottom: 10px; }
.ball-row, .number-line {
  display: flex; flex-wrap: wrap; gap: 8px;
}
.ball, .number-chip {
  min-width: 34px; height: 34px; border-radius: 999px; display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-size: 14px; font-weight: 700; padding: 0 9px;
}
.ball.red, .number-chip.red, .number-chip.hit-red { background: #e84d5b; }
.ball.blue, .number-chip.blue, .number-chip.hit-blue { background: #387dff; }
.ball.orange, .number-chip.orange, .number-chip.hit-orange { background: #ff9800; }
.number-chip.dim { background: #eef2f8; color: var(--text); }
.result-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.result-item .label { color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.result-item .value { font-weight: 700; word-break: break-word; }
.result-status.win { color: var(--success); }
.result-status.lose { color: var(--danger); }
.result-status.wait { color: var(--warning); }
.bet-block { display: grid; gap: 8px; }
.bet-row { display: flex; gap: 10px; align-items: flex-start; flex-wrap: wrap; }
.bet-label { min-width: 18px; font-weight: 800; color: var(--muted); padding-top: 6px; }
.history-panel summary { cursor: pointer; color: var(--muted); }
.table-tools { display: flex; gap: 10px; flex-wrap: wrap; }
.table-tools.stacked { display: grid; grid-template-columns: 1fr auto; }
input {
  width: 100%; border: 1px solid var(--line); border-radius: 12px; padding: 11px 12px; background: #fff; color: var(--text);
}
.mobile-list { display: grid; gap: 10px; margin-top: 12px; }
.mobile-record-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.mobile-record-meta { display: grid; gap: 6px; margin-top: 10px; color: var(--muted); font-size: 13px; }
.mobile-record-actions { display: flex; gap: 10px; margin-top: 12px; }
.table-wrap { overflow: auto; margin-top: 14px; }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { text-align: left; padding: 12px 10px; border-bottom: 1px solid var(--line); font-size: 14px; }
th { color: var(--muted); background: #fafcff; }
.table-link { background: transparent; color: var(--primary); border: 0; padding: 0; font-weight: 700; }
.status-pill {
  display: inline-flex; align-items: center; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 700;
}
.status-pill.win { background: #e9f8f1; color: var(--success); }
.status-pill.lose { background: #fff0f0; color: var(--danger); }
.status-pill.wait { background: #fff8e8; color: var(--warning); }
.empty-cell { text-align: center; color: var(--muted); padding: 18px; }
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: rgba(244,246,251,.96); backdrop-filter: blur(12px);
  border-top: 1px solid rgba(230,235,242,.9);
}
.tabbar-btn {
  border: 0; border-radius: 14px; padding: 12px; background: #fff; color: var(--muted); font-weight: 800;
  box-shadow: 0 4px 14px rgba(16,24,40,.04);
}
.tabbar-btn.active { background: var(--primary); color: #fff; }
.detail-dialog {
  width: min(720px, calc(100vw - 24px)); border: 1px solid var(--line); border-radius: 18px; padding: 18px; box-shadow: 0 16px 48px rgba(16,24,40,.18);
}
.detail-dialog::backdrop { background: rgba(8,15,33,.45); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.desktop-only { display: none; }
@media (min-width: 900px) {
  .app-page { max-width: 1080px; }
  .screen[data-tab='home'] { grid-template-columns: 1fr 1fr; align-items: start; }
  .screen[data-tab='home'] .app-header, .screen[data-tab='home'] #latestResultCard { grid-column: 1 / -1; }
  .desktop-only { display: block; }
}
@media (max-width: 768px) {
  h1 { font-size: 24px; }
  .app-header { align-items: flex-start; flex-direction: column; }
  .table-tools.stacked { grid-template-columns: 1fr; }
  .result-grid { grid-template-columns: 1fr 1fr; }
}
