* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  background: #f5f6f8;
  color: #222;
}

.page {
  max-width: 980px;
  margin: 0 auto;
  padding: 20px 16px 32px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 18px;
}

h1 {
  margin: 0;
  font-size: 28px;
}

.subtitle {
  margin-top: 0;              /* remove top spacing now it's inline */
  font-size: 15px;            /* was 14px */
  color: #444;                /* darker than #666 */
  font-weight: 500;           /* subtle lift */
  
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;

  flex: 1;                    /* allows shrinking */
}

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

.topbar-logo {
  height: 80px;
  width: auto;
  object-fit: contain;
}

.ghost-btn {
  border: 1px solid rgba(0,0,0,0.14);
  background: #fff;
  color: #222;
  border-radius: 10px;
  padding: 9px 12px;
  cursor: pointer;
  font-size: 14px;
}

.ghost-btn:hover {
  background: #fafafa;
}

.content {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel {
  background: #fff;
  border-radius: 16px;
  border: 1px solid rgba(0,0,0,0.08);
  box-shadow: 0 2px 8px rgba(0,0,0,0.03);
  padding: 14px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.panel-header h2 {
  margin: 0;
  font-size: 18px;
}

.summary-text {
  font-size: 13px;
  color: #666;
}

.trials-scroll {
  padding-right: 4px;
}

.empty {
  text-align: center;
  color: #777;
  padding: 18px 8px;
  font-size: 14px;
}

.trial-card {
  border: 1px solid rgba(0,0,0,0.08);
  border-radius: 12px;
  margin-bottom: 8px;
  overflow: hidden;
  background: transparent;
}

.trial-card.post-run {
  background: #e8f5e9;
}

.trial-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(0,0,0,0.06);
}

.trial-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 10px 10px 10px 12px;
  cursor: pointer;
}

.trial-header:hover {
  background: rgba(0,0,0,0.02);
}

.horse-label {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chevron {
  flex: 0 0 auto;
  color: #666;
  font-size: 16px;
  line-height: 1;
}

.chevron {
  display: flex;
  align-items: center;
}

.trial-body {
  padding: 0 12px 10px 12px;
}

.trial-row {
  padding: 2px 2px 6px 2px;
}

.trial-link {
  text-decoration: none;
  color: #222;
  display: inline-block;
  line-height: 1.25;
  font-size: 12px;
  max-width: 100%;
}

.trial-link:hover {
  text-decoration: underline;
}

.trial-link.has-vision {
  cursor: pointer;
}

.trial-link.after-lr {
  color: #1b5e20;
}

.play-glyph {
  margin-left: 4px;
  color: #555;
  font-size: 12px;
  vertical-align: middle;
}

.raw-data {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 12px;
  line-height: 1.35;
  color: #333;
  background: #fafafa;
  border-radius: 10px;
  padding: 12px;
}

.horse-main {
  font-weight: 700;
  font-size: 20px;
  letter-spacing: 0.3px;
}

.horse-sub {
  font-weight: 400;
  font-size: 13px;
  color: #555;
  margin-left: 6px;
}

.trial-header-bold {
  font-weight: 700;
}

.trial-header-extra {
  font-weight: 400;
  color: #444;
}

.trial-detail {
  font-weight: 400;
}

.trial-win {
  color: #0b3d91;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.race-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 42px;
  align-items: center;
}

.race-tab {
  min-width: 38px;
  height: 38px;
  padding: 0 10px;
  border: 1px solid rgba(0,0,0,0.18);
  border-radius: 10px;
  background: #fff;
  color: #222;
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
}

.race-tab:hover {
  background: #f5f5f5;
}

.race-tab.active {
  background: #222;
  color: #fff;
  border-color: #222;
}

.race-tab.has-post-run {
  background: #e8f5e9;
  border-color: #b7d9ba;
}

.race-tab.has-post-run.active {
  background: #222;
  color: #fff;
  border-color: #222;
}

.race-tab.empty {
  cursor: default;
  color: #777;
  font-weight: 400;
}

.state-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.state-tab {
  min-width: 60px;
  height: 36px;
  border: 1px solid rgba(0,0,0,0.12);
  border-radius: 10px;
  background: #fafafa;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.state-tab:hover {
  background: #f5f5f5;
}

.state-tab.active {
  background: #222;
  color: #fff;
  border-color: #222;
}

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

.meeting-tab {
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid rgba(0,0,0,0.12);
  border-radius: 10px;
  background: #fafafa;
  color: #333;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.2;
  text-align: center;
  cursor: pointer;
  transition: all 0.15s ease;
}

.meeting-tab:hover {
  background: #f0f0f0;
}

.meeting-tab.active {
  background: #3a3a3a;
  color: #fff;
  border-color: #2e2e2e;
}

.info-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.14);
  background: #fafafa;
  color: #444;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

.info-btn:hover {
  background: #f0f0f0;
  border-color: rgba(0, 0, 0, 0.22);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 1000;
}

.modal-card {
  width: min(680px, 100%);
  max-height: 85vh;
  overflow-y: auto;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.18);
  border: 1px solid rgba(0, 0, 0, 0.08);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px 10px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

.modal-header h2 {
  margin: 0;
  font-size: 22px;
}

.modal-close {
  width: 34px;
  height: 34px;
  border: none;
  background: transparent;
  color: #555;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  border-radius: 50%;
}

.modal-close:hover {
  background: #f3f3f3;
}

.modal-body {
  padding: 18px 20px 22px;
  font-size: 14px;
  line-height: 1.55;
  color: #333;
}

.modal-body p {
  margin-top: 0;
  margin-bottom: 14px;
}

.hidden {
  display: none !important;
}

@media (max-width: 700px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .topbar-actions {
    justify-content: flex-end;
  }

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

  .topbar-logo {
    height: 60px;
  }

  .meeting-tabs {
    grid-template-columns: 1fr;
  }
}

.trial-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
  margin-left: auto;
}

.trial-filter-btn {
  min-height: 34px;
  padding: 6px 12px;
  border: 1px solid rgba(0,0,0,0.12);
  border-radius: 999px;
  background: #fafafa;
  color: #333;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.trial-filter-btn:hover {
  background: #f0f0f0;
}

.trial-filter-btn.active {
  background: #222;
  color: #fff;
  border-color: #222;
}

.panel-header {
  align-items: center;
}

.panel-header {
  display: flex;
  align-items: center;
  gap: 10px;                  /* slightly tighter */
}

.race-subtitle {
  font-size: 14px;
  color: #555;
  
  /* THIS is the magic */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;

  /* allow it to shrink */
  flex: 1;
}

.trial-card.first-starter {
  background: #e8f4ff;
  border-color: #b9dcff;
}

.race-tab.has-first-starter {
  background: #e8f4ff;
  border-color: #b9dcff;
  color: #1f3b57;
}

.race-tab.has-first-starter.active {
  background: #222;
  border-color: #222;
  color: #fff;
}

.horse-right-meta {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-left: 12px;
}

.trial-rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 38px;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid #dcdcdc;
  background: #f5f5f5;
  color: #666;
  font-size: 12px;
  font-weight: 700;
}

.trial-rank-badge.top1 {
  background: #e8f5e9;
  border-color: #4caf50;
  color: #2e7d32;
}

.trial-rank-badge.top2 {
  background: #e3f2fd;
  border-color: #2196f3;
  color: #1565c0;
}

.trial-rank-badge.top3 {
  background: #fff3e0;
  border-color: #fb8c00;
  color: #e65100;
}

.trial-rank-badge:not(.top1):not(.top2):not(.top3) {
  opacity: 0.6;
}

.trial-rank-medal {
  font-size: 16px;
  line-height: 1;
}

.trial-rank-ordinal {
  font-size: 11px;
  color: #888;
  font-weight: 600;
}

.trial-rank-circle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid #d0d0d0;
  background: #f5f5f5;
  color: #555;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}

.trial-rank-circle.top1 {
  background: linear-gradient(145deg, #ffd700, #f5c400);
  border-color: #d4af37;
  color: #000;
}

.trial-rank-circle.top2 {
  background: linear-gradient(145deg, #e0e0e0, #cfcfcf);
  border-color: #b0b0b0;
  color: #000;
}

.trial-rank-circle.top3 {
  background: linear-gradient(145deg, #cd7f32, #b87333);
  border-color: #8c5a2b;
  color: #fff;
}