:root {
  color-scheme: light;
  --bg: #f7f8fb;
  --panel: #ffffff;
  --panel-2: #ffffff;
  --line: #dddddd;
  --table-line: #e6e8ef;
  --text: #222222;
  --heading: #333333;
  --muted: #667085;
  --gold: #d4af37;
  --gold-soft: rgba(212, 175, 55, 0.14);
  --blue: #2f80ed;
  --red: #dc4f4f;
  --orange: #f39b35;
  --green: #2e9d61;
  --purple: #8e5ad7;
  --header-bg: #ffffff;
  --badge-bg: #f1f3f7;
  --trend-down-bg: #eaf3ff;
  --trend-up-bg: #fff0f0;
  --pop-up-bg: #fff4e6;
  --pop-down-bg: #f4edff;
  --error-text: #a82020;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #08090b;
  --panel: #13161b;
  --panel-2: #191d24;
  --line: #303641;
  --table-line: #252b34;
  --text: #f5f1e8;
  --heading: #f5f1e8;
  --muted: #a7adba;
  --gold: #d7aa3e;
  --gold-soft: rgba(215, 170, 62, 0.16);
  --header-bg: linear-gradient(135deg, #15181d 0%, #0e1014 100%);
  --badge-bg: #252b34;
  --trend-down-bg: rgba(47, 128, 237, 0.15);
  --trend-up-bg: rgba(220, 79, 79, 0.14);
  --pop-up-bg: rgba(243, 155, 53, 0.18);
  --pop-down-bg: rgba(142, 90, 215, 0.18);
  --error-text: #ffd6d6;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Yu Gothic", Meiryo, sans-serif;
  letter-spacing: 0;
}

.app-shell {
  width: min(1180px, calc(100% - 28px));
  margin: 0 auto;
  padding: 24px 0 40px;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--header-bg);
  box-shadow: 0 8px 26px rgba(16, 24, 40, 0.06);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--gold);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(24px, 4vw, 42px);
  line-height: 1.2;
  color: var(--heading);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.theme-toggle {
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  font-weight: 700;
}

.race-meta {
  display: grid;
  gap: 4px;
  min-width: 96px;
  padding: 12px 14px;
  border: 1px solid rgba(215, 170, 62, 0.5);
  border-radius: 8px;
  background: var(--gold-soft);
  text-align: center;
}

.race-meta span {
  color: var(--muted);
  font-size: 12px;
}

.race-meta strong {
  color: var(--gold);
  font-size: 24px;
}

main {
  display: grid;
  gap: 20px;
  margin-top: 20px;
}

.view[hidden] {
  display: none;
}

.page-heading {
  padding: 0 2px 14px;
  border-bottom: 0;
}

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

.nav-card,
.race-card {
  color: var(--text);
  text-decoration: none;
}

.nav-card {
  display: grid;
  min-height: 130px;
  align-content: space-between;
  gap: 16px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 8px 22px rgba(16, 24, 40, 0.05);
}

.nav-card:hover,
.race-card:hover {
  border-color: rgba(212, 175, 55, 0.8);
}

.nav-card-title {
  color: var(--heading);
  font-size: 24px;
  font-weight: 800;
}

.nav-card-sub {
  color: var(--muted);
  font-size: 13px;
}

.race-list {
  display: grid;
  gap: 10px;
}

.race-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.race-card > div:first-child {
  display: flex;
  align-items: center;
  gap: 12px;
}

.race-no {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 42px;
  min-height: 30px;
  border-radius: 8px;
  background: var(--gold-soft);
  color: var(--gold);
  font-weight: 900;
}

.race-card-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  white-space: nowrap;
}

.rt-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 13px;
}

.rt-status strong {
  color: var(--text);
}

.error-area {
  padding: 14px 16px;
  border: 1px solid rgba(220, 79, 79, 0.7);
  border-radius: 8px;
  background: var(--trend-up-bg);
  color: var(--error-text);
  font-weight: 700;
}

.ad-slot {
  display: grid;
  min-height: 76px;
  place-items: center;
  border: 1px dashed rgba(215, 170, 62, 0.52);
  border-radius: 8px;
  background: rgba(215, 170, 62, 0.08);
  color: var(--muted);
}

.ad-slot-bottom {
  min-height: 120px;
}

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

.panel,
.table-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.panel {
  padding: 16px;
}

.panel-header,
.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel h2,
.section-heading h2 {
  font-size: 18px;
}

.badge,
.judge-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--badge-bg);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.badge-main {
  background: rgba(215, 170, 62, 0.2);
  color: var(--gold);
}

.badge-sub {
  background: rgba(47, 128, 237, 0.2);
  color: var(--blue);
}

.candidate-list,
.axis-box {
  margin-top: 14px;
  color: var(--text);
  line-height: 1.7;
}

.candidate-list.empty {
  color: var(--muted);
}

.candidate-list ul {
  display: grid;
  gap: 6px;
  margin: 0;
  padding-left: 18px;
}

.analysis-panel {
  padding: 16px;
}

.analysis-summary {
  margin-top: 14px;
  color: var(--text);
  line-height: 1.7;
}

.analysis-reason {
  margin: 0 0 8px;
  color: var(--muted);
}

.analysis-summary ul {
  display: grid;
  gap: 6px;
  margin: 0;
  padding-left: 18px;
}

.analysis-mark {
  display: inline-flex;
  min-width: 1.8em;
  font-weight: 900;
}

.mark-main {
  color: var(--red);
}

.mark-sub {
  color: var(--blue);
}

.mark-third {
  color: var(--orange);
}

.mark-star {
  color: var(--green);
}

.table-section {
  overflow: hidden;
}

.section-heading {
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.section-heading p {
  color: var(--muted);
  font-size: 13px;
}

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

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

th,
td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--table-line);
  text-align: right;
  font-size: 14px;
  white-space: nowrap;
}

th {
  background: var(--panel-2);
  color: var(--gold);
  font-size: 12px;
  font-weight: 800;
}

td:first-child,
th:first-child,
.name,
.pair {
  text-align: left;
}

.num {
  color: var(--gold);
  font-weight: 800;
}

.name {
  min-width: 160px;
  font-weight: 700;
}

.odds {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
}

.judge {
  display: flex;
  justify-content: flex-end;
  gap: 5px;
}

.empty-cell {
  padding: 22px;
  color: var(--muted);
  text-align: center;
}

tr.trend-down {
  background: var(--trend-down-bg);
}

tr.trend-up {
  background: var(--trend-up-bg);
}

.judge-pop-up {
  border: 1px solid rgba(243, 155, 53, 0.5);
  background: var(--pop-up-bg);
  color: var(--orange);
}

.judge-pop-down {
  border: 1px solid rgba(142, 90, 215, 0.5);
  background: var(--pop-down-bg);
  color: var(--purple);
}

.judge-odds-down {
  background: var(--trend-down-bg);
  color: var(--blue);
}

.judge-odds-up {
  background: var(--trend-up-bg);
  color: var(--red);
}

@media (max-width: 760px) {
  .app-shell {
    width: min(100% - 18px, 1180px);
    padding-top: 12px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
    padding: 16px;
  }

  .race-meta {
    width: 100%;
  }

  .topbar-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .summary-grid {
    grid-template-columns: 1fr;
  }

  .card-grid {
    grid-template-columns: 1fr;
  }

  .race-card,
  .race-card > div:first-child,
  .race-card-meta {
    align-items: flex-start;
    flex-direction: column;
  }

  .rt-status {
    align-items: flex-start;
    flex-direction: column;
  }

  .panel-header,
  .section-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  th,
  td {
    padding: 10px 8px;
    font-size: 13px;
  }
}
