:root {
  color-scheme: light;
  --bg: #f4f1e8;
  --panel: #fffdf7;
  --ink: #17332f;
  --muted: #6d7975;
  --line: #d8ddd4;
  --brand: #0b6b61;
  --brand-soft: #dceee9;
  --red: #b64235;
  --red-soft: #f7e6e1;
  --blue: #2565a8;
  --blue-soft: #e4edf8;
  --shadow: 0 18px 50px rgba(31, 58, 51, 0.09);
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 12% 2%, rgba(11, 107, 97, 0.12), transparent 32rem),
    linear-gradient(180deg, #f7f4ec 0%, var(--bg) 100%);
  color: var(--ink);
  font-family: "Noto Sans SC", "Microsoft YaHei", system-ui, sans-serif;
}
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; }

.app-shell {
  width: min(1120px, calc(100% - 28px));
  min-height: 100vh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: max(14px, env(safe-area-inset-top)) 0 14px;
  background: rgba(244, 241, 232, 0.9);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid rgba(216, 221, 212, 0.7);
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 15px;
  background: var(--brand);
  color: #fff;
  font-weight: 800;
  letter-spacing: -0.06em;
}
.brand strong, .brand small { display: block; }
.brand strong { font-size: 1rem; }
.brand small { margin-top: 2px; color: var(--muted); font-size: 0.72rem; }
.game-switch {
  display: flex;
  gap: 5px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255,255,255,0.72);
}
.game-switch a {
  padding: 8px 15px;
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 650;
}
.game-switch a.active { background: var(--brand); color: white; }

.app-main { flex: 1; padding: 34px 0 42px; }
.footer {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  padding: 20px 0 max(24px, env(safe-area-inset-bottom));
  color: var(--muted);
  font-size: 0.75rem;
  border-top: 1px solid var(--line);
}

.hero { padding: clamp(24px, 5vw, 58px); border-radius: 32px; background: var(--panel); box-shadow: var(--shadow); }
.eyebrow { margin: 0 0 10px; color: var(--brand); font-size: 0.78rem; font-weight: 750; letter-spacing: 0.13em; }
.hero h1 { margin: 0; font-size: clamp(2.1rem, 6vw, 4.5rem); letter-spacing: -0.06em; line-height: 1; }
.hero p { max-width: 720px; color: var(--muted); line-height: 1.8; }
.game-cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-top: 28px; }
.game-card {
  padding: 24px;
  min-height: 180px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: #fff;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: transform .18s ease, box-shadow .18s ease;
}
.game-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.game-card strong { font-size: 1.45rem; }
.game-card small { color: var(--muted); line-height: 1.7; }
.game-card .arrow { color: var(--brand); font-size: 1.5rem; align-self: flex-end; }

.page-head { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.page-head h1 { margin: 0; font-size: clamp(1.8rem, 5vw, 3.2rem); letter-spacing: -0.05em; }
.page-head p { margin: 8px 0 0; color: var(--muted); }
.period-badge {
  padding: 11px 15px;
  border-radius: 15px;
  background: var(--brand-soft);
  color: var(--brand);
  font-weight: 750;
}

.view-tabs {
  display: flex;
  gap: 4px;
  padding: 5px;
  margin-bottom: 24px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: rgba(255,255,255,.68);
}
.view-tabs a {
  flex: 1;
  min-width: max-content;
  padding: 10px 14px;
  border-radius: 12px;
  color: var(--muted);
  text-align: center;
  font-size: .84rem;
  font-weight: 650;
}
.view-tabs a.active { background: var(--brand); color: white; }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 12px; }
.stat-card, .panel {
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--panel);
  box-shadow: 0 8px 28px rgba(31,58,51,0.045);
}
.stat-card { padding: 18px; }
.stat-card span { display: block; color: var(--muted); font-size: 0.76rem; }
.stat-card strong { display: block; margin-top: 8px; font-size: 1.35rem; }
.panel { margin-top: 16px; padding: 22px; }
.panel h2 { margin: 0 0 14px; font-size: 1.02rem; }
.panel p { color: var(--muted); line-height: 1.7; }

.draw-numbers { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.ball {
  width: 43px;
  height: 43px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-variant-numeric: tabular-nums;
  font-weight: 750;
}
.ball.primary { background: var(--red-soft); color: var(--red); }
.ball.secondary { background: var(--blue-soft); color: var(--blue); }
.draw-meta { display: flex; gap: 16px; margin-top: 14px; color: var(--muted); font-size: .8rem; }

.metric-grid, .range-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}
.metric-grid > div, .range-card {
  padding: 15px;
  border-radius: 15px;
  background: #f8f7f2;
}
.metric-grid span, .range-card small { display: block; color: var(--muted); font-size: .74rem; }
.metric-grid strong { display: block; margin-top: 7px; font-size: 1.13rem; }
.range-card strong { display: block; margin-bottom: 7px; }
.range-card div { margin: 6px 0; font-variant-numeric: tabular-nums; }

.condition-selector {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(260px, 1.2fr);
  gap: 14px 20px;
  align-items: center;
}
.condition-selector label { align-self: end; color: var(--muted); font-size: .78rem; }
.condition-selector select {
  width: 100%;
  min-height: 44px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
}
.condition-current {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px;
  border-radius: 15px;
  background: var(--brand-soft);
}
.condition-current strong { font-size: 1.55rem; color: var(--brand); }
.condition-current span { color: #345c55; line-height: 1.65; }

.distribution {
  height: 160px;
  display: flex;
  gap: 7px;
  align-items: end;
  padding-top: 10px;
}
.distribution-item {
  flex: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: end;
  gap: 5px;
}
.distribution-item span, .distribution-item small { font-size: .68rem; color: var(--muted); }
.distribution-item i {
  width: min(34px, 70%);
  min-height: 5px;
  border-radius: 7px 7px 3px 3px;
  background: #b8d4ce;
}
.distribution-item.current i { background: var(--brand); }
.distribution-item.current span { color: var(--brand); font-weight: 750; }

.table-scroll { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .79rem; }
th, td { padding: 10px 9px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
thead th { color: var(--muted); font-size: .72rem; font-weight: 650; }
.indicator-family-row th {
  padding-top: 18px;
  color: var(--brand);
  text-align: left;
  background: linear-gradient(90deg, var(--brand-soft), transparent);
}
.indicator-chip {
  display: inline-block;
  min-width: 46px;
  padding: 4px 8px;
  border-radius: 999px;
  background: #f1f0ea;
  text-align: center;
}
.heat { font-weight: 750; }
.heat-热 { color: #b64235; }
.heat-温 { color: #9a711c; }
.heat-冷 { color: #2565a8; }

.grid-panel { display: grid; gap: 14px; }
.number-grid {
  display: grid;
  grid-template-columns: repeat(var(--grid-columns), minmax(0, 1fr));
  gap: 6px;
  max-width: 640px;
}
.grid-cell {
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--muted);
  font-size: clamp(.7rem, 2.6vw, .9rem);
  font-variant-numeric: tabular-nums;
}
.grid-cell.missing-row, .grid-cell.missing-column {
  background: repeating-linear-gradient(135deg, #ebeae4, #ebeae4 5px, #f7f6f1 5px, #f7f6f1 10px);
  color: #9ca39f;
}
.grid-cell.missing-column { outline: 1px dashed #aeb5b0; outline-offset: 2px; }
.grid-cell.drawn {
  border-color: var(--red);
  background: var(--red);
  color: white;
  font-weight: 750;
  box-shadow: 0 6px 14px rgba(182,66,53,.2);
}
.simple-table td:first-child { font-variant-numeric: tabular-nums; }

.feature-highlight strong {
  display: block;
  margin: 3px 0 8px;
  color: var(--blue);
  font-size: 2rem;
}
.secondary-metrics { margin-top: 18px; }
.candidate-ranking { display: grid; gap: 8px; margin-top: 16px; }
.candidate-ranking article {
  display: grid;
  grid-template-columns: 26px 44px repeat(3, minmax(80px, 1fr));
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border-radius: 14px;
  background: #f8f7f2;
}
.candidate-ranking article > span { color: var(--muted); font-size: .72rem; }
.candidate-ranking article > div { display: flex; gap: 6px; align-items: baseline; }
.candidate-ranking small { color: var(--muted); font-size: .68rem; }

.selection-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 18px 28px;
}
.selection-controls > div { display: grid; gap: 7px; }
.selection-controls span { color: var(--muted); font-size: .72rem; }
.segmented {
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: 12px;
  background: #efeee8;
}
.segmented a {
  padding: 7px 12px;
  border-radius: 9px;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 650;
}
.segmented a.active { background: white; color: var(--brand); box-shadow: 0 3px 10px rgba(31,58,51,.08); }
.selection-cost { margin-left: auto; }
.selection-cost strong { font-size: 1.35rem; color: var(--brand); }
.research-warning {
  margin-top: 16px;
  padding: 17px 19px;
  border: 1px solid #e7cfa2;
  border-radius: 18px;
  background: #fff7e9;
  color: #72531d;
}
.research-warning p { margin: 7px 0 0; line-height: 1.65; font-size: .83rem; }
.ticket-list { display: grid; gap: 12px; margin-top: 16px; }
.ticket-card {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--panel);
  box-shadow: 0 8px 28px rgba(31,58,51,.045);
}
.ticket-card header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: .78rem;
}
.ticket-card header strong { color: var(--brand); }
.ticket-metrics { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 14px; }
.ticket-metrics span {
  padding: 5px 8px;
  border-radius: 9px;
  background: #f2f1eb;
  color: var(--muted);
  font-size: .7rem;
}
.candidate-ranking.compact article { grid-template-columns: 24px 40px repeat(3, minmax(62px, 1fr)); }
.primary-button {
  min-height: 42px;
  padding: 9px 16px;
  border: 0;
  border-radius: 12px;
  background: var(--brand);
  color: white;
  font-weight: 700;
  cursor: pointer;
}
.primary-button:disabled { opacity: .55; cursor: wait; }
.backtest-output { margin-top: 16px; }
.backtest-status { color: var(--muted); }
.backtest-stats { margin-bottom: 14px; }

.quality-list { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.quality-list li { display: flex; align-items: center; gap: 10px; padding: 11px 13px; border-radius: 13px; background: #f8f7f2; }
.status-dot { width: 9px; height: 9px; flex: none; border-radius: 50%; background: #2e8b57; }
.status-dot.warn { background: #d68a18; }
.status-dot.fail { background: #b64235; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .78rem; overflow-wrap: anywhere; }
.empty-state { padding: 48px 24px; text-align: center; color: var(--muted); }
.loading { padding: 80px 20px; text-align: center; color: var(--muted); }
.error-box { padding: 18px; border-radius: 16px; background: #fff0ed; color: #8f2c22; }

@media (max-width: 760px) {
  .app-shell { width: min(100% - 20px, 1120px); }
  .brand small { display: none; }
  .game-switch a { padding: 8px 11px; }
  .app-main { padding-top: 22px; }
  .hero { border-radius: 24px; }
  .game-cards, .stats-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .metric-grid, .range-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .page-head { align-items: start; flex-direction: column; }
  .footer { flex-direction: column; }
  .condition-selector { grid-template-columns: 1fr; }
  .condition-current { grid-column: 1; }
  .candidate-ranking article { grid-template-columns: 22px 40px repeat(3, 1fr); }
  .selection-cost { margin-left: 0; }
}

@media (max-width: 480px) {
  .game-cards { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .brand-mark { width: 40px; height: 40px; border-radius: 13px; }
  .game-switch a { font-size: .8rem; }
}
