:root {
  color-scheme: dark;
  --bg: #0b0c0f;
  --panel: #111216;
  --panel-2: #15171c;
  --line: #272a31;
  --line-soft: #1d2025;
  --text: #f2f3f5;
  --muted: #8b909b;
  --muted-2: #626873;
  --red: #f04444;
  --red-soft: #6e2424;
  --orange: #ff951f;
  --blue: #168cff;
  --blue-soft: #123b66;
  --green: #24b47e;
  --yellow: #f7c84b;
  --radius: 6px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-width: 320px;
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    "DIN Alternate", "SF Pro Display", "PingFang SC", "Microsoft YaHei",
    sans-serif;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

.app-shell {
  width: min(100%, 980px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 0 12px 84px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 64px;
  padding: max(10px, env(safe-area-inset-top)) 2px 10px;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
}

.brand-mark {
  display: inline-grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border: 1px solid var(--orange);
  border-radius: var(--radius);
  color: var(--orange);
  font-size: 12px;
  font-weight: 700;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 16px;
  line-height: 1.1;
}

.brand small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.sync-state {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 11px;
}

.sync-state svg {
  width: 13px;
  height: 13px;
}

.game-tabs {
  display: flex;
  gap: 8px;
  margin: 0 -12px;
  padding: 12px;
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
  scrollbar-width: none;
}

.game-tabs::-webkit-scrollbar {
  display: none;
}

.game-tab {
  flex: 0 0 auto;
  min-width: 76px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--muted);
  cursor: pointer;
}

.game-tab strong,
.game-tab small {
  display: block;
  text-align: center;
}

.game-tab strong {
  color: var(--text);
  font-size: 13px;
}

.game-tab small {
  margin-top: 3px;
  font-size: 10px;
}

.game-tab.active {
  border-color: var(--orange);
  background: #1a1510;
}

.game-tab.active strong,
.game-tab.active small {
  color: var(--orange);
}

.result-hero,
.query-panel,
.query-result,
.chart-panel,
.table-panel,
.insight-item {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.result-hero {
  margin-top: 12px;
  padding: 14px;
}

.hero-kicker,
.status-row,
.panel-title,
.section-heading,
.query-result-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.hero-kicker {
  color: var(--orange);
  font-size: 12px;
  font-weight: 700;
}

.hero-kicker span:last-child {
  color: var(--text);
}

.hero-grid {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  gap: 14px;
  align-items: center;
  margin-top: 14px;
}

.gauge-wrap {
  position: relative;
  width: 112px;
  height: 112px;
}

.gauge-chart {
  width: 100%;
  height: 100%;
}

.gauge-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.gauge-center strong {
  font-size: 34px;
  line-height: 1;
}

.gauge-center span {
  margin-top: 7px;
  color: var(--muted);
  font-size: 11px;
}

.gauge-wrap.compact {
  width: 96px;
  height: 96px;
  flex: 0 0 auto;
}

.gauge-wrap.compact .gauge-center strong {
  font-size: 28px;
}

.status-row {
  justify-content: flex-start;
}

.status-pill,
.result-eyebrow {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border: 1px solid var(--red-soft);
  border-radius: 4px;
  background: #211214;
  color: var(--red);
  font-size: 11px;
}

.issue-meta {
  color: var(--muted);
  font-size: 11px;
}

.hero-content h1 {
  margin: 10px 0 9px;
  font-size: clamp(24px, 7vw, 42px);
  line-height: 1.08;
}

.next-draw {
  min-height: 18px;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 11px;
}

.ball-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
}

.ball {
  position: relative;
  display: inline-grid;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  place-items: center;
  border: 1px solid #ff6c6c;
  border-radius: 50%;
  background: #bd2026;
  color: #fff;
  font-size: 14px;
  font-weight: 700;
}

.ball.special {
  border-color: #55aaff;
  background: #086cc7;
}

.ball.small-ball {
  width: 29px;
  height: 29px;
  flex-basis: 29px;
  font-size: 12px;
}

.plus {
  color: var(--muted);
  font-size: 12px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 16px;
}

.metric {
  min-height: 64px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-2);
}

.metric span,
.metric strong {
  display: block;
}

.metric span {
  color: var(--muted);
  font-size: 11px;
}

.metric strong {
  margin-top: 7px;
  font-size: 18px;
}

.metric strong.positive {
  color: var(--green);
}

.metric strong.negative {
  color: var(--red);
}

.metric strong.accent {
  color: var(--orange);
}

.view-section {
  margin-top: 22px;
}

.section-heading {
  margin-bottom: 10px;
  padding: 0 1px;
}

.section-heading > div:first-child {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.section-heading h2 {
  margin: 0;
  font-size: 17px;
}

.section-index {
  color: var(--muted-2);
  font-size: 11px;
}

.section-note {
  color: var(--muted);
  font-size: 11px;
}

.insight-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.insight-item {
  min-height: 72px;
  padding: 10px;
}

.insight-item span,
.insight-item strong,
.insight-item small {
  display: block;
}

.insight-item span {
  color: var(--muted);
  font-size: 11px;
}

.insight-item strong {
  margin-top: 8px;
  color: var(--text);
  font-size: 20px;
}

.insight-item small {
  margin-top: 3px;
  color: var(--muted-2);
  font-size: 10px;
}

.chart-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-top: 10px;
}

.chart-panel,
.table-panel {
  min-width: 0;
  padding: 12px;
}

.chart-panel + .chart-panel,
.chart-panel + .table-panel,
.table-panel + .chart-panel {
  margin-top: 10px;
}

.panel-title {
  margin-bottom: 6px;
}

.panel-title h3 {
  margin: 0;
  font-size: 13px;
}

.panel-title span {
  color: var(--muted);
  font-size: 10px;
}

.chart {
  width: 100%;
  height: 230px;
}

.chart.tall {
  height: 300px;
}

.table-scroll {
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 620px;
  border-collapse: collapse;
}

th,
td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--line-soft);
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--muted-2);
  font-size: 10px;
  font-weight: 500;
}

td {
  color: #d9dce2;
  font-size: 11px;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.table-balls {
  display: flex;
  gap: 4px;
}

.table-balls .ball {
  width: 23px;
  height: 23px;
  flex-basis: 23px;
  font-size: 10px;
}

.segmented {
  display: flex;
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.segmented button {
  min-width: 43px;
  padding: 5px 7px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font-size: 10px;
  cursor: pointer;
}

.segmented button.active {
  background: #2b2117;
  color: var(--orange);
}

.query-panel {
  padding: 12px;
}

.number-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 7px;
}

.number-chip {
  aspect-ratio: 1;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--panel-2);
  color: #c9ccd2;
  font-size: 12px;
  cursor: pointer;
}

.number-chip[data-color="red"] {
  color: #ff7777;
}

.number-chip[data-color="blue"] {
  color: #63adff;
}

.number-chip.active {
  border-color: var(--orange);
  background: #392514;
  color: var(--orange);
  font-weight: 700;
}

.query-actions {
  display: grid;
  grid-template-columns: 1fr 1.5fr;
  gap: 8px;
  margin-top: 12px;
}

.button {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
}

.button svg {
  width: 16px;
  height: 16px;
}

.button.secondary {
  background: var(--panel-2);
  color: var(--muted);
}

.button.primary {
  border-color: #a85216;
  background: #a85216;
  color: #fff;
  font-weight: 700;
}

.query-result {
  margin-top: 12px;
  padding: 14px;
}

.query-result-head h3 {
  margin: 8px 0 0;
  font-size: 24px;
}

.hit-rate {
  color: var(--orange);
  font-size: 12px;
}

.query-result-body {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-top: 14px;
}

.query-detail {
  min-width: 0;
  flex: 1;
}

.query-metrics {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 10px;
}

.query-metrics .metric {
  min-height: 58px;
  padding: 8px;
}

.query-metrics .metric strong {
  font-size: 16px;
}

.empty-row {
  height: 82px;
  color: var(--muted-2);
  text-align: center;
}

.bottom-tabs {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  width: min(100%, 980px);
  min-height: 62px;
  margin: 0 auto;
  padding: 6px 10px max(6px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: #0d0e11;
}

.bottom-tabs button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border: 0;
  background: transparent;
  color: var(--muted-2);
  font-size: 10px;
  cursor: pointer;
}

.bottom-tabs button svg {
  width: 19px;
  height: 19px;
}

.bottom-tabs button.active {
  color: var(--orange);
}

@media (min-width: 720px) {
  .app-shell {
    padding-right: 18px;
    padding-left: 18px;
  }

  .game-tabs {
    margin-right: -18px;
    margin-left: -18px;
    padding-right: 18px;
    padding-left: 18px;
  }

  .result-hero {
    padding: 18px;
  }

  .hero-grid {
    grid-template-columns: 150px minmax(0, 1fr);
    gap: 22px;
  }

  .gauge-wrap {
    width: 150px;
    height: 150px;
  }

  .gauge-center strong {
    font-size: 46px;
  }

  .metric-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .insight-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .chart-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .chart-panel + .chart-panel {
    margin-top: 0;
  }

  .number-grid {
    grid-template-columns: repeat(10, minmax(0, 1fr));
  }
}

@media (max-width: 520px) {
  .hero-grid {
    grid-template-columns: 92px minmax(0, 1fr);
    gap: 12px;
  }

  .gauge-wrap {
    width: 92px;
    height: 92px;
  }

  .gauge-center strong {
    font-size: 30px;
  }

  .ball {
    width: 31px;
    height: 31px;
    flex-basis: 31px;
    font-size: 13px;
  }

  .insight-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .query-result-body {
    align-items: flex-start;
  }

  .query-detail {
    overflow: hidden;
  }
}
