:root {
  --green: #00513f;
  --green-2: #0a7a44;
  --dark: #34454b;
  --line: #b6bcc2;
  --paper: #ffffff;
  --bg: #f2f3f1;
  --blue: #1976bf;
  --red: #c81926;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: #333;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", sans-serif;
}
a { color: inherit; text-decoration: none; }
.site-header {
  background: var(--green);
  color: white;
  padding: 18px 22px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-top: 5px solid #0b7a26;
}
.brand { font-size: 30px; font-weight: 800; letter-spacing: .02em; }
.subtitle { font-size: 15px; font-weight: 700; opacity: .9; }
.site-nav {
  margin-left: auto;
  display: flex;
  gap: 12px;
  transform: translateY(-1px);
}
.site-nav a {
  border: 1px solid rgba(255,255,255,.45);
  border-radius: 4px;
  padding: 5px 10px;
  font-size: 14px;
  font-weight: 700;
}
main { padding: 20px; }
.date-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.home-actions {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}
.date-tab {
  background: white;
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 12px 24px;
  font-weight: 700;
  box-shadow: 0 2px 5px rgba(0,0,0,.12);
}
.date-tab.active { background: #444; color: white; }
.program-refresh-button {
  background: var(--green);
  border: 1px solid var(--green);
  border-radius: 4px;
  box-shadow: 0 2px 5px rgba(0,0,0,.12);
  color: white;
  cursor: pointer;
  flex: 0 0 auto;
  font: inherit;
  font-weight: 700;
  padding: 12px 16px;
}
.home-note {
  color: #666;
  font-size: 12px;
  margin: 0 0 16px;
}
.program-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(330px, 1fr));
  gap: 20px;
}
.racecourse-panel h2 {
  margin: 0;
  background: var(--green);
  color: white;
  text-align: center;
}
.accordion-toggle {
  width: 100%;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 28px;
  font-weight: 700;
  padding: 12px;
  cursor: pointer;
}
.program-table, .analysis-table {
  width: 100%;
  border-collapse: collapse;
  background: white;
}
.program-table th {
  background: var(--dark);
  color: white;
  font-size: 20px;
  font-weight: 700;
  padding: 12px 8px;
  border: 2px solid var(--line);
}
.program-table td {
  border: 2px solid var(--line);
  vertical-align: middle;
}
.race-num-cell {
  width: 82px;
  background: #2180c7;
  color: white;
  text-align: center;
  font-weight: 700;
}
.race-num-cell a { display: block; padding: 10px 6px; }
.race-number { font-size: 32px; line-height: 1; display: block; }
.race-number small { display: block; font-size: 16px; margin-top: 5px; }
.race-name-cell a { display: block; padding: 12px 10px; font-size: 21px; line-height: 1.55; }
.program-table strong { font-weight: 600; }
.race-time-cell { width: 112px; text-align: center; font-size: 20px; font-weight: 700; }
tr.disabled { opacity: .45; }
.analysis { max-width: 1480px; margin: 0 auto; }
.analysis-head, .featured, .table-wrap, .race-nav {
  background: white;
  border: 1px solid #ddd;
  padding: 18px;
  margin-bottom: 18px;
}
.analysis-head h1 { margin: 8px 0; font-size: 28px; }
.cache-note {
  color: #666;
  font-size: 13px;
  margin-top: -4px;
}
.refresh-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.refresh-row span {
  color: #777;
  font-size: 12px;
}
.back-link, .refresh-link, .nav-actions a, .fetch-button {
  display: inline-block;
  background: white;
  border: 1px solid #ccc;
  border-radius: 4px;
  padding: 8px 12px;
  color: #075c40;
  font-weight: 700;
  box-shadow: 0 2px 5px rgba(0,0,0,.12);
}
.refresh-link, .fetch-button {
  cursor: pointer;
  font: inherit;
}
.fetch-panel {
  background: white;
  border: 1px solid #ddd;
  margin-bottom: 18px;
  padding: 22px;
}
.fetch-panel h2 {
  color: var(--green);
  font-size: 22px;
  margin: 0 0 8px;
}
.fetch-panel p {
  color: #555;
  line-height: 1.7;
  margin: 0 0 16px;
}
.fetch-button {
  background: var(--green);
  border-color: var(--green);
  color: white;
  font-size: 18px;
  padding: 10px 18px;
}
.progress-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  background: rgba(0,0,0,.38);
  padding: 20px;
}
.progress-modal[hidden] { display: none; }
.progress-dialog {
  width: min(420px, 100%);
  background: white;
  border: 1px solid #d0d0d0;
  border-radius: 6px;
  box-shadow: 0 18px 42px rgba(0,0,0,.28);
  padding: 22px;
}
.progress-dialog h2 {
  color: var(--green);
  font-size: 22px;
  margin: 0 0 10px;
}
.progress-message {
  color: #444;
  min-height: 1.6em;
  margin: 0 0 14px;
}
.progress-bar {
  width: 100%;
  height: 14px;
  overflow: hidden;
  background: #e6e8e3;
  border: 1px solid #c8ccc7;
  border-radius: 999px;
}
.progress-bar span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--green-2);
  transition: width .25s ease;
}
.progress-percent {
  color: #555;
  font-size: 13px;
  font-weight: 700;
  margin-top: 6px;
  text-align: right;
}
.progress-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}
.progress-actions button {
  border: 1px solid #bbb;
  border-radius: 4px;
  background: white;
  color: #333;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  padding: 8px 12px;
}
.progress-cancel { color: #6a2222; }
.featured-group + .featured-group { margin-top: 16px; }
.featured h3 {
  margin: 0 0 8px;
  font-size: 18px;
  font-weight: 700;
}
.featured ol {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 10px;
  padding-left: 20px;
  margin: 0;
}
.featured li { padding: 8px; }
.featured span { display: block; font-size: 14px; color: #555; margin-top: 4px; }
.analysis-table th {
  background: var(--dark);
  color: white;
  font-weight: 700;
  padding: 10px 8px;
  white-space: nowrap;
}
.sort-button {
  appearance: none;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  padding: 0;
}
.sort-button::after {
  content: "↕";
  font-size: 11px;
  margin-left: 4px;
  opacity: .7;
}
.sort-button.active::after {
  content: "↑";
  opacity: 1;
}
.analysis-table td {
  border: 1px solid var(--line);
  padding: 9px 8px;
  white-space: nowrap;
}
.distance-time strong,
.distance-time small {
  display: block;
}
.distance-time small {
  color: #555;
  font-size: 12px;
  font-weight: 700;
  margin-top: 3px;
}
.distance-time strong span {
  font-size: 12px;
  font-weight: 700;
}
.calc-note {
  color: #666;
  font-size: 80%;
  line-height: 1.7;
  margin-top: 14px;
}
.calc-note h3 {
  color: #555;
  font-size: 1em;
  font-weight: 700;
  margin: 0 0 4px;
}
.calc-note p { margin: 0; }
.muted { color: #999; }
.missing-time {
  display: block;
  font-size: 80%;
}
.horse-name { font-weight: 800; }
.horse-name a { color: #075c40; text-decoration: none; }
.horse-jockey {
  display: block;
  color: #555;
  font-size: 80%;
  font-weight: 700;
  margin-top: 2px;
}
.age-cell { text-align: center; font-weight: 800; }
.age-cell span,
.age-cell small {
  display: block;
}
.age-cell small {
  color: #555;
  font-size: 80%;
  font-weight: 700;
  margin-top: 2px;
}
.watch-cell { background: #fbfbf3; }
.strong,
.gold {
  background: #f4e476;
  font-weight: 900;
}
.good,
.silver {
  background: #e0e3eb;
  font-weight: 900;
}
.bronze {
  background: #e9bf86;
  font-weight: 900;
}
.table-wrap { overflow-x: auto; }
.race-nav {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: start;
}
.meeting-nav {
  background: #f0f1ec;
  display: grid;
  gap: 8px;
  padding: 8px;
}
.meeting-row {
  display: grid;
  grid-template-columns: 170px 1fr;
  gap: 8px;
  align-items: stretch;
}
.meeting-date {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #e5e6dc;
  color: #444;
  font-size: 20px;
  font-weight: 700;
  padding: 8px;
}
.meeting-buttons {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 8px;
}
.meeting-link {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  background: linear-gradient(#fff, #f5f5f5);
  border: 1px solid #d5d5d5;
  border-radius: 5px;
  color: #0070b6;
  font-size: 20px;
  font-weight: 700;
  box-shadow: 0 2px 5px rgba(0,0,0,.14);
}
.meeting-link::before {
  content: "›";
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 21px;
  height: 21px;
  margin-right: 7px;
  border-radius: 50%;
  background: #16874a;
  color: white;
  font-size: 22px;
  line-height: 1;
}
.meeting-link.active {
  background: #444;
  border-color: #444;
  color: white;
}
.meeting-link.active::before { background: white; color: #444; }
.nav-actions {
  display: grid;
  gap: 10px;
  min-width: 170px;
}
.race-jumps {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 8px;
}
.race-jump {
  background: linear-gradient(#fff, #eee);
  border: 1px solid #ccc;
  border-radius: 4px;
  text-align: center;
  padding: 8px;
  font-size: 24px;
  font-weight: 700;
}
.race-jump.active { background: #444; color: white; }
.race-jump.disabled { opacity: .45; }
.notice { background: white; padding: 20px; border: 1px solid #ddd; }
.about {
  max-width: 980px;
  margin: 0 auto;
  background: white;
  border: 1px solid #ddd;
  padding: 24px;
  line-height: 1.8;
}
.about h1 {
  color: var(--green);
  font-size: 32px;
  margin: 0 0 8px;
}
.about h2 {
  border-bottom: 2px solid var(--line);
  color: #26383e;
  font-size: 20px;
  font-weight: 700;
  margin: 28px 0 10px;
  padding-bottom: 5px;
}
.about p { margin: 0 0 10px; }
.about .lead {
  color: #333;
  font-size: 17px;
  font-weight: 400;
}
.about .inline-list {
  background: #f5f6f4;
  border: 1px solid #ddd;
  padding: 10px 12px;
}
.about table {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0 18px;
}
.about th,
.about td {
  border: 1px solid var(--line);
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
}
.about th {
  background: var(--dark);
  color: white;
  font-weight: 700;
  white-space: nowrap;
}
.about code {
  background: #f2f3f1;
  border: 1px solid #e0e0dc;
  border-radius: 3px;
  padding: 2px 5px;
}

@media (max-width: 760px) {
  main { padding: 12px; }
  .site-header {
    align-items: center;
    flex-wrap: nowrap;
    gap: 8px;
    padding: 12px 14px;
  }
  .brand {
    flex: 0 0 auto;
    font-size: 24px;
  }
  .subtitle {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .site-nav {
    margin-left: 0;
    flex: 0 0 auto;
    transform: translateY(-1px);
  }
  .site-nav a {
    padding: 4px 8px;
    font-size: 13px;
    white-space: nowrap;
  }
  .home-actions {
    display: block;
  }
  .date-tabs {
    margin-bottom: 8px;
  }
  .program-refresh-button {
    width: 100%;
  }
  .program-grid { display: block; }
  .racecourse-panel { margin-bottom: 10px; }
  .racecourse-body { display: none; }
  .racecourse-panel.open .racecourse-body { display: block; }
  .accordion-toggle { font-size: 24px; }
  .program-table th { font-size: 16px; }
  .race-name-cell a { font-size: 18px; }
  .race-time-cell { font-size: 17px; width: 92px; }
  .race-nav { display: block; }
  .meeting-nav { margin-bottom: 12px; }
  .meeting-row {
    display: block;
    margin-bottom: 12px;
  }
  .meeting-date {
    background: transparent;
    font-size: 26px;
    padding: 4px;
  }
  .meeting-buttons {
    grid-template-columns: repeat(auto-fit, minmax(112px, 1fr));
  }
  .meeting-link {
    min-height: 62px;
    font-size: 22px;
    color: #111;
    white-space: nowrap;
  }
  .meeting-link::before { display: none; }
  .nav-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin: 10px 0;
  }
  .race-jumps { grid-template-columns: repeat(3, 1fr); }
  .analysis-head h1 { font-size: 22px; }
  .about { padding: 18px 14px; }
  .about h1 { font-size: 28px; }
  .about h2 { font-size: 18px; }
  .about table { font-size: 14px; }
}
