:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-2: #edf3f5;
  --surface-3: #f8fafc;
  --line: #d8dee6;
  --line-strong: #b8c3cc;
  --text: #17202a;
  --muted: #667085;
  --accent: #0f766e;
  --accent-2: #b42318;
  --accent-soft: #e3f4f1;
  --ok: #067647;
  --ok-bg: #dcfae6;
  --warn-bg: #fff4df;
  --shadow: 0 16px 32px rgba(16, 24, 40, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Hiragino Kaku Gothic ProN", "Meiryo", system-ui, sans-serif;
  line-height: 1.6;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  padding: 0.9rem clamp(1rem, 3vw, 2rem);
  background: #111827;
  border-bottom: 1px solid #243042;
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  color: #ffffff;
  font-size: 1.18rem;
  font-weight: 800;
  letter-spacing: 0;
}

.brand span { color: #5eead4; }
.tagline { color: #cbd5e1; font-size: 0.86rem; }

.container {
  max-width: 1180px;
  margin: 0 auto;
  padding: clamp(1rem, 3vw, 2rem);
}

.eyebrow {
  margin: 0 0 0.25rem;
  color: var(--accent);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.filter-panel {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  position: sticky;
  top: 3.45rem;
  z-index: 9;
  margin-bottom: 1.2rem;
  padding: 0.75rem;
  background: rgba(245, 247, 250, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  backdrop-filter: blur(10px);
}

.filters {
  display: flex;
  gap: 0.8rem;
  align-items: end;
  flex-wrap: wrap;
}

.filters label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.filters select {
  min-width: 170px;
  min-height: 40px;
  padding: 0.45rem 2rem 0.45rem 0.65rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  font: inherit;
}

.meta {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
  white-space: nowrap;
}

.date-section {
  margin: 1.5rem 0 2rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.date-section-head {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: end;
  gap: 0.7rem;
  padding: 0.85rem 1rem;
  background: var(--surface-3);
  cursor: pointer;
  list-style: none;
}

.date-section-head::-webkit-details-marker,
.venue-head::-webkit-details-marker {
  display: none;
}

.date-section h2 {
  margin: 0;
  font-size: 1.25rem;
  letter-spacing: 0;
}

.tree-caret {
  align-self: center;
  width: 1.35rem;
  height: 1.35rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  font-weight: 900;
}

.tree-caret::before {
  content: "›";
  transition: transform 160ms ease;
}

.date-section[open] > .date-section-head .tree-caret::before,
.venue-group[open] > .venue-head .tree-caret::before {
  transform: rotate(90deg);
}

.section-count {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
  white-space: nowrap;
}

.venue-tree {
  display: grid;
  gap: 0;
  padding: 0.7rem;
  background: var(--surface);
}

.venue-group {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.venue-group + .venue-group {
  margin-top: 0.65rem;
}

.venue-head {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 0.55rem;
  padding: 0.7rem 0.8rem;
  background: #eef6f4;
  cursor: pointer;
  list-style: none;
}

.venue-name {
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.venue-count {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
  white-space: nowrap;
}

.race-tree {
  display: grid;
  padding-left: 2.45rem;
  background: var(--surface);
  border-top: 1px solid var(--line);
}

.race-node {
  display: grid;
  grid-template-columns: 4.3rem minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 0.7rem;
  width: 100%;
  min-height: 70px;
  padding: 0.7rem 0.8rem 0.7rem 0;
  color: var(--text);
  text-align: left;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}

.race-node:last-child {
  border-bottom: 0;
}

.race-node:hover,
.race-node:focus-visible {
  background: var(--surface-3);
  outline: 0;
}

.race-node-no {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.1rem;
  color: var(--accent-2);
  background: #fff5f4;
  border: 1px solid #fecdca;
  border-radius: 8px;
  font-weight: 900;
}

.race-node-main {
  display: grid;
  gap: 0.25rem;
  min-width: 0;
}

.race-node-title,
.race-node-pick {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-width: 0;
}

.race-node-title {
  font-weight: 800;
}

.race-node-pick {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
}

.race-node-title,
.race-node-pick {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-action {
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 800;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0.05rem 0.45rem;
  color: #ffffff;
  background: #475467;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 800;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  margin-left: auto;
  padding: 0.05rem 0.5rem;
  color: #7a4b00;
  background: var(--warn-bg);
  border: 1px solid #f5d38a;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 800;
}

.status-pill.done {
  color: var(--ok);
  background: var(--ok-bg);
  border-color: #a6e9b8;
}

.empty {
  color: var(--muted);
  text-align: center;
  padding: 1.5rem;
}

.back {
  display: inline-flex;
  margin-bottom: 0.9rem;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.race-meta {
  padding: 1rem 0 1.1rem;
  border-bottom: 1px solid var(--line);
  margin-bottom: 1rem;
}

.meta-head {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
  font-size: 1.3rem;
  font-weight: 800;
}

.meta-head .date {
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 700;
}

.meta-tags {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.meta-sub {
  color: var(--muted);
  font-size: 0.96rem;
  margin-top: 0.35rem;
}

.section-head {
  margin: 1.25rem 0 0.65rem;
  color: var(--text);
  font-size: 1.05rem;
  letter-spacing: 0;
}

.top-picks { margin-bottom: 1rem; }

.pick-cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.8rem;
}

.pick-card {
  padding: 0.9rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
}

.pick-card.rank-1 { border-left-color: var(--accent-2); }
.pick-card.hit { background: #f0fdf4; }

.pick-rank {
  display: inline-block;
  margin-bottom: 0.45rem;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
}

.pick-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin: 0.7rem 0 0;
}

.pick-stats div {
  padding: 0.45rem 0.55rem;
  background: var(--surface-3);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.pick-stats dt {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
}

.pick-stats dd {
  margin: 0.1rem 0 0;
  font-weight: 800;
}

.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 0.92rem;
}

.table th,
.table td {
  padding: 0.68rem 0.75rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

.table th {
  color: var(--muted);
  background: var(--surface-3);
  font-size: 0.78rem;
  font-weight: 800;
}

.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-3); }
.table tbody tr.hit { background: #f0fdf4; }
.table .r { text-align: right; }
.table.compact { font-size: 0.88rem; }
.table.compact th,
.table.compact td { padding: 0.55rem 0.6rem; }

.rank { font-weight: 800; }
.player-name { font-weight: 700; }
.score { font-variant-numeric: tabular-nums; }

/* 競輪の車番色（1〜9） */
.car {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  min-width: 1.65rem;
  min-height: 1.65rem;
  padding: 0 0.28rem;
  border-radius: 6px;
  font-weight: 900;
  line-height: 1;
}

.car1 { background:#f4f4f5; color:#111; border:1px solid #c7c7cc; }
.car2 { background:#111; color:#fff; }
.car3 { background:#e2403a; color:#fff; }
.car4 { background:#2b6be4; color:#fff; }
.car5 { background:#f2c200; color:#111; }
.car6 { background:#2faa4a; color:#fff; }
.car7 { background:#222; color:#fff; border:1px solid #e2403a; }
.car8 { background:#e9529b; color:#fff; }
.car9 { background:#7a4bd0; color:#fff; }

.bets { margin-top: 1.2rem; }

.bet-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.85rem;
}

.bet-card {
  min-width: 0;
}

.bets-head {
  margin: 0 0 0.45rem;
  color: var(--accent);
  font-size: 0.95rem;
}

.combo {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  white-space: nowrap;
}

.arrow { color: var(--muted); font-weight: 800; }
.ev-plus { color: var(--ok); font-weight: 900; }

.note {
  color: var(--muted);
  font-size: 0.82rem;
  margin: 0.7rem 0 0;
}

.status {
  color: var(--muted);
  padding: 0.5rem 0;
}

.footer {
  color: var(--muted);
  font-size: 0.8rem;
  text-align: center;
  padding: 2rem 1rem;
  border-top: 1px solid var(--line);
  margin-top: 2rem;
}

@media (max-width: 900px) {
  .filter-panel {
    align-items: stretch;
    flex-direction: column;
    position: static;
  }

  .filters select {
    min-width: min(220px, 100%);
  }

  .race-node {
    grid-template-columns: 3.7rem minmax(0, 1fr) auto;
  }

  .race-node .card-action {
    display: none;
  }

  .pick-cards,
  .bet-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 0.2rem;
  }

  .container {
    padding: 1rem;
  }

  .filters,
  .filters label,
  .filters select {
    width: 100%;
  }

  .date-section-head {
    align-items: center;
    grid-template-columns: auto minmax(0, 1fr);
  }

  .section-count {
    grid-column: 2;
  }

  .venue-tree {
    padding: 0.5rem;
  }

  .venue-head {
    grid-template-columns: auto minmax(0, 1fr) auto;
  }

  .venue-head .badge {
    display: none;
  }

  .race-tree {
    padding-left: 0.65rem;
  }

  .race-node {
    grid-template-columns: 3.2rem minmax(0, 1fr);
    gap: 0.55rem;
  }

  .race-node .status-pill {
    grid-column: 2;
    justify-self: start;
    margin-left: 0;
  }

  .race-node-title,
  .race-node-pick {
    white-space: normal;
  }

  .table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }
}
