/* ============================================================
   Base / Reset
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:         #0d0f14;
  --surface:    #181c26;
  --surface2:   #1f2535;
  --border:     #2a3048;
  --accent:     #e8a020;
  --accent-dim: #a06810;
  --text:       #d4dbe8;
  --text-muted: #6b7799;
  --good:       #3fb97a;
  --bad:        #d94f4f;
  --rank1:      #ffd700;
  --rank2:      #c0c0c0;
  --rank3:      #cd7f32;
  --font-mono:  'Courier New', Courier, monospace;

  --bar-odyssey:    #1a6ebd;
  --bar-horizons:   #7b3fa0;
}

html { font-size: 16px; }

body {
  background-color: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ============================================================
   Layout
   ============================================================ */
.page-wrapper {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 1.25rem;
}

/* ============================================================
   Header / Nav
   ============================================================ */
.site-header {
  border-bottom: 1px solid var(--border);
  padding: 1rem 0;
  margin-bottom: 2rem;
}

.site-header .inner {
  display: flex;
  align-items: center;
  gap: 2.5rem;
  flex-wrap: wrap;
}

.site-logo {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: .05em;
  color: var(--accent);
  white-space: nowrap;
}

.site-logo .logo-short {
  display: none;
}

.header-links {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  font-size: 0.95rem;
}

.header-links a {
  color: var(--text);
  transition: color 0.2s;
}

.header-links a:hover {
  color: var(--accent);
}

.header-links .sep {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.header-profile {
  display: flex;
  align-items: center;
  gap: .6rem;
  margin-left: auto;
  font-size: 0.9rem;
}

/* ============================================================
   Breadcrumb
   ============================================================ */
.breadcrumb {
  font-size: .85rem;
  color: var(--text-muted);
  margin-bottom: 1.25rem;
}
.breadcrumb a { color: var(--text-muted); }
.breadcrumb a:hover { color: var(--accent); }
.breadcrumb .sep { margin: 0 .4em; }

/* ============================================================
   Filter bar
   ============================================================ */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .75rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: .5rem;
  padding: 1rem 1.25rem;
  margin-bottom: 1.75rem;
}

.filter-group { display: flex; flex-direction: column; gap: .3rem; }

.filter-group label {
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
}

.filter-bar select,
.filter-bar input[type="text"] {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: .35rem;
  color: var(--text);
  font-size: .9rem;
  padding: .4rem .75rem;
  min-width: 180px;
  outline: none;
  appearance: none;
}

.filter-bar select:focus,
.filter-bar input[type="text"]:focus {
  border-color: var(--accent-dim);
}

.filter-toggle {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .9rem;
  cursor: pointer;
  padding-bottom: .1rem;
}

.filter-toggle input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  accent-color: var(--accent);
  cursor: pointer;
}

@media (min-width: 769px) {
  .filter-group {
    flex-direction: row;
    align-items: center;
    gap: 1.3rem;
  }
}

/* ============================================================
   Race grid (index page)
   ============================================================ */
#new-races-panel,
#notifications-panel {
  background: var(--surface);
  border: 1px solid var(--accent-dim);
  border-radius: .5rem;
  padding: .85rem 1.1rem;
  margin-bottom: 1.25rem;
}

.new-races-heading {
  font-size: .8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--accent);
  margin: 0 0 .6rem;
}

.new-races-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: .35rem .9rem;
}

.new-races-list li::before {
  content: '●';
  color: #f0c040;
  font-size: .6rem;
  margin-right: .35rem;
  vertical-align: middle;
}

.race-media-links .new-races-list li::before {
  content: none;
}

.new-races-list li a,
.new-races-list li .link-text {
  font-size: .85rem;
  color: var(--text);
  text-decoration: none;
}

.new-races-list li a i {
  font-size: .75rem;
  margin-right: .35rem;
}

.new-races-list li a .fa-youtube {
  color: #CD201F;
}

.new-races-list li a:hover {
  color: var(--accent);
  text-decoration: underline;
}

.races-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

.race-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: .5rem;
  padding: 1.1rem 1.25rem;
  transition: border-color .15s, background .15s;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  /* anchor reset */
  color: inherit;
  text-decoration: none;
}

.race-card:hover {
  border-color: var(--accent-dim);
  background: var(--surface2);
  text-decoration: none;
}

.race-card:hover .race-card-name {
  text-decoration: underline;
}

.race-card-name {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

.race-card-meta {
  font-size: .8rem;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  gap: .3rem .75rem;
}

.badge {
  display: inline-block;
  font-size: .7rem;
  font-weight: 600;
  letter-spacing: .05em;
  padding: .15rem .55rem;
  border-radius: 1rem;
  text-transform: uppercase;
}

.badge-odyssey  { background: rgba(26,110,189,.25);  color: #5aabf0; border: 1px solid #1a6ebd; }
.badge-horizons { background: rgba(123,63,160,.25);  color: #c47eff; border: 1px solid #7b3fa0; }
/* Vehicle type badges */
.badge-ship     { background: rgba(32,180,232,.15);  color: #39c0f0; border: 1px solid #1a7aad; }
.badge-srv      { background: rgba(60,180,80,.15);   color: #5dd87a; border: 1px solid #2e8a42; }
.badge-fighter  { background: rgba(232,80,60,.15);   color: #f07060; border: 1px solid #a03828; }
.badge-onfoot   { background: rgba(232,160,32,.15);  color: var(--accent); border: 1px solid var(--accent-dim); }

.race-card-footer {
  margin-top: auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: .8rem;
  color: var(--text-muted);
  padding-top: .5rem;
  border-top: 1px solid var(--border);
}

.entry-count { font-weight: 600; color: var(--text); }
.activity-fresh { color: var(--good); }

.th-sortable { cursor: pointer; user-select: none; }
.th-sortable:hover { color: var(--accent); }
.th-sortable.th-active { color: var(--text); }

/* ============================================================
   Section heading
   ============================================================ */
.section-title {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 1.25rem;
}

/* ============================================================
   Race detail page
   ============================================================ */
.race-detail-header-wrapper {
  display: flex;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
  position: relative;
}

/* ── Daylight ambient overlay (::before) and horizon bar (::after) ───────── */
.race-detail-header-wrapper::before,
.race-detail-header-wrapper::after {
  content: '';
  position: absolute;
  pointer-events: none;
  opacity: 0;
  transition: opacity 1.2s ease;
}

/* Ambient glow: covers the whole header block */
.race-detail-header-wrapper::before {
  inset: 0;
  z-index: 0;
  border-radius: .25rem;
}

/* Horizon bar: 2px rule along the bottom edge */
.race-detail-header-wrapper::after {
  bottom: 0;
  left: 5%;
  right: 5%;
  height: 2px;
  border-radius: 1px;
  z-index: 0;
}

/* Ensure flex children sit above the pseudo-element overlay */
.race-detail-header-wrapper > * { position: relative; z-index: 1; }

/* Day: clear sky blue tint, blue→amber horizon */
.race-detail-header-wrapper[data-daylight="day"]::before {
  background: radial-gradient(ellipse 90% 60% at 50% -10%, rgba(26,110,189,.09) 0%, transparent 70%);
  opacity: 1;
}
.race-detail-header-wrapper[data-daylight="day"]::after {
  background: linear-gradient(to right, transparent 0%, rgba(26,110,189,.5) 20%, rgba(232,160,32,.7) 50%, rgba(26,110,189,.5) 80%, transparent 100%);
  opacity: 1;
}

/* Dawn: purple-magenta into orange */
.race-detail-header-wrapper[data-daylight="dawn"]::before {
  background: radial-gradient(ellipse 90% 60% at 50% -10%, rgba(140,45,110,.12) 0%, transparent 70%);
  opacity: 1;
}
.race-detail-header-wrapper[data-daylight="dawn"]::after {
  background: linear-gradient(to right, transparent 0%, rgba(130,40,110,.5) 20%, rgba(220,100,40,.7) 55%, rgba(232,160,32,.5) 80%, transparent 100%);
  opacity: 1;
}

/* Dusk: amber into purple */
.race-detail-header-wrapper[data-daylight="dusk"]::before {
  background: radial-gradient(ellipse 90% 60% at 50% -10%, rgba(200,75,30,.11) 0%, transparent 70%);
  opacity: 1;
}
.race-detail-header-wrapper[data-daylight="dusk"]::after {
  background: linear-gradient(to right, transparent 0%, rgba(232,160,32,.5) 20%, rgba(220,100,40,.7) 45%, rgba(130,40,110,.5) 80%, transparent 100%);
  opacity: 1;
}

/* Night: no override — the default dark theme is the correct night state */

.race-detail-header {
  flex: 1;
}

.race-detail-header h1 {
  font-size: 1.6rem;
  font-weight: 700;
  margin-bottom: .4rem;
}

.race-media-wrapper {
  flex-shrink: 0;
}

.race-map-container {
  /* No longer needs flex-shrink since wrapper handles it */
}

.race-map-container a {
  display: block;
  line-height: 0;
}

.race-map-container img {
  height: 190px;
  width: auto;
  border: 1px solid var(--border);
  border-radius: .5rem;
  transition: border-color .15s;
  cursor: pointer;
}

.race-map-container img:hover {
  border-color: var(--accent-dim);
}

.race-media-links {
  margin-top: .75rem;
  max-width: 450px;
}

/* .dev-tools {
  margin-top: 0.5rem;
  padding: 0.75rem;
  background: rgba(232, 160, 32, 0.1);
  border: 1px solid var(--accent-dim);
  border-radius: 4px;
} */

.add-media-link {
  color: var(--accent);
  font-size: 0.9rem;
  font-weight: 500;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.add-media-link:hover {
  color: #ffc14d;
  text-decoration: underline;
}

@media (max-width: 768px) {
  .race-detail-header-wrapper {
    flex-direction: column;
  }

  .race-detail-header .status-bar {
    margin-bottom: 0.5rem;
  }

  .race-media-wrapper {
    margin-top: 0;
  }

  /* Hide the thumbnail image on mobile, but keep the links list */
  .race-map-container {
    display: none !important;
  }

  .race-media-links {
    margin-top: 0;
  }

  /* Abbreviate Improvement column header on race page */
  #results-layout .results-table th:nth-child(5) {
    font-size: 0;
  }
  #results-layout .results-table th:nth-child(5)::before {
    content: "Impvmt";
    font-size: .82rem;
  }
}

/* Hide mobile-only map link on desktop (thumbnail is shown instead) */
@media (min-width: 769px) {
  .mobile-only-link {
    display: none !important;
  }
}

.race-detail-header .meta {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem .85rem;
  font-size: .85rem;
  color: var(--text-muted);
}

.copy-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: .3rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: .2rem .35rem;
  margin-left: .35rem;
  transition: all .15s ease;
  line-height: 1;
  vertical-align: middle;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.copy-btn:hover {
  border-color: var(--accent-dim);
  color: var(--accent);
  background: rgba(232,160,32,.05);
}

.copy-btn.copied {
  color: var(--good);
  border-color: var(--good);
  background: rgba(63,185,122,.1);
}

.copy-icon {
  width: 0.85rem;
  height: 0.85rem;
  display: block;
}

.constraints-list {
  list-style: disc;
  margin: 0.5rem 0 0 1.5rem;
  padding: 0;
  font-size: 0.85rem;
  line-height: 1.6;
  color: var(--text);
}

.constraints-list li {
  margin-bottom: 0.25rem;
}

.constraint-tag {
  font-size: .75rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: .3rem;
  padding: .15rem .55rem;
  color: var(--text-muted);
}

.constraints-label {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 0.25rem;
}

.race-info-row {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  margin-top: .6rem;
}

.info-badge {
  font-size: .75rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: .3rem;
  padding: .15rem .55rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.info-badge-accent {
  border-color: var(--accent);
  color: var(--accent);
}

.info-badge-horizons {
  border-color: var(--bar-horizons);
  color: #c47eff;
  background: rgba(123, 63, 160, .15);
}

.info-badge-filter {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(232, 160, 32, .15);
  font-weight: 600;
}

.info-badge-inactive {
  border-color: #888;
  color: #aaa;
  background: rgba(128, 128, 128, .15);
  font-weight: 600;
}

/* Daylight state badge variants */
a.info-badge { text-decoration: none; }
a.info-badge:hover { opacity: .8; }

.info-badge-daylight-day   { border-color: #3a8ec0; color: #7bc4ee; background: rgba(26,110,189,.12); }
.info-badge-daylight-dawn  { border-color: #c06030; color: #f09050; background: rgba(200,80,30,.12); }
.info-badge-daylight-dusk  { border-color: #8840a0; color: #c870ee; background: rgba(130,40,150,.12); }
.info-badge-daylight-night { border-color: #3a4a7a; color: #8898c8; background: rgba(30,40,100,.15); }

.race-notice {
  margin-top: .75rem;
  padding: .5rem .75rem;
  font-size: .875rem;
  color: #aaa;
  background: rgba(128, 128, 128, .1);
  border: 1px solid #555;
  border-radius: .4rem;
  line-height: 1.5;
}

.race-description {
  margin-top: .75rem;
  font-size: .875rem;
  color: var(--text-muted);
  line-height: 1.5;
}

/* ============================================================
   Results layout: chart above table
   ============================================================ */
.leaderboard-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
}

.filter-label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}

.ship-filter-select {
  flex: 1;
  max-width: 240px;
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  cursor: pointer;
  transition: border-color 0.2s;
}

.ship-filter-select:hover {
  border-color: var(--accent-dim);
}

.ship-filter-select:focus {
  outline: none;
  border-color: var(--accent);
}

.results-layout {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: .5rem;
  overflow: hidden;
}

.rivalry-panel {
  display: flex;
  flex-direction: column;
  margin-top: 1rem;
  padding: .75rem 1rem;
  background: var(--surface);
  border: 1px solid var(--accent-dim);
  border-radius: .5rem;
  font-size: .875rem;
  color: var(--text);
}

.rivalry-row {
  display: flex;
  align-items: baseline;
  gap: .6rem;
}

.rivalry-row + .rivalry-row {
  border-top: 1px solid var(--border);
  margin-top: .65rem;
  padding-top: .65rem;
}

.rivalry-icon {
  font-size: 1.1rem;
  flex-shrink: 0;
}

/* ============================================================
   ECharts container
   ============================================================ */
#race-chart {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: .75rem 1rem .5rem;
  width: 100%;
}

/* ============================================================
   Results table (right panel)
   ============================================================ */
.results-table-panel {
  overflow-x: auto;
}

.results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .9rem;
}

#races-table-container .results-table {
  table-layout: fixed;
}

#races-table-container {
  margin-right: -150px;
  overflow-x: auto;
}

.results-table thead tr {
  background: var(--surface2);
}

.results-table th {
  padding: .6rem 1rem;
  text-align: left;
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-muted);
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}

.results-table td {
  padding: .65rem 1rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

/* Column width constraints for races-table page */
#races-table-container .results-table th:nth-child(1),
#races-table-container .results-table td:nth-child(1) {
  width: 250px;
  max-width: 250px;
  white-space: normal;
  word-wrap: break-word;
}

#races-table-container .results-table th:nth-child(2),
#races-table-container .results-table td:nth-child(2) {
  width: 80px;
  max-width: 80px;
}

#races-table-container .results-table th:nth-child(3),
#races-table-container .results-table td:nth-child(3) {
  width: 250px;
  max-width: 250px;
  white-space: normal;
  word-wrap: break-word;
}

#races-table-container .results-table th:nth-child(4),
#races-table-container .results-table td:nth-child(4),
#races-table-container .results-table th:nth-child(5),
#races-table-container .results-table td:nth-child(5),
#races-table-container .results-table th:nth-child(6),
#races-table-container .results-table td:nth-child(6),
#races-table-container .results-table th:nth-child(7),
#races-table-container .results-table td:nth-child(7) {
  width: 120px;
  max-width: 120px;
}

#races-table-container .results-table th:nth-child(8),
#races-table-container .results-table td:nth-child(8) {
  width: 150px;
  max-width: 150px;
  white-space: normal;
  word-wrap: break-word;
}

#races-table-container .results-table th:nth-child(9),
#races-table-container .results-table td:nth-child(9) {
  width: 120px;
  max-width: 120px;
  white-space: normal;
  word-wrap: break-word;
}

.results-table tbody tr:last-child td { border-bottom: none; }

.results-table tbody tr:hover td { background: var(--surface2); }

/* Podium row backgrounds */
.results-table tbody tr.row-pos-1 td { background: rgba(255, 215,   0, .08); }
.results-table tbody tr.row-pos-2 td { background: rgba(192, 192, 192, .07); }
.results-table tbody tr.row-pos-3 td { background: rgba(205, 127,  50, .08); }
.results-table tbody tr.row-pos-1:hover td { background: rgba(255, 215,   0, .15); }
.results-table tbody tr.row-pos-2:hover td { background: rgba(192, 192, 192, .13); }
.results-table tbody tr.row-pos-3:hover td { background: rgba(205, 127,  50, .14); }

/* Recently-updated row (within 1 hour) */
@keyframes freshSweep {
  0%   { background-color: rgba(63, 185, 122, .22); }
  100% { background-color: rgba(63, 185, 122, .06); }
}
.results-table tbody tr.row-fresh td,
.stats-table tbody tr.row-fresh td {
  animation: freshSweep 2.5s ease-out forwards;
}
.updated-cell { color: var(--text-muted); }
.results-table tbody tr.row-fresh .updated-cell,
.stats-table tbody tr.row-fresh .activity-time {
  color: var(--good);
}

/* Selected commander highlight */
.results-table tbody tr.row-cmdr td { background: rgba(232, 160, 32, .12); }
.results-table tbody tr.row-cmdr:hover td { background: rgba(232, 160, 32, .2); }
.stats-table tbody tr.row-cmdr td { background: rgba(232, 160, 32, .12); }
.stats-table tbody tr.row-cmdr:hover td { background: rgba(232, 160, 32, .2); }
.results-table tbody tr.row-cmdr .cmdr-name {
  color: var(--accent);
}
.stats-table tbody tr.row-cmdr a {
  color: var(--accent);
}

.pos {
  font-weight: 700;
  width: 2rem;
  text-align: center;
  font-family: var(--font-mono);
}

.pos-1 { color: var(--rank1); }
.pos-2 { color: var(--rank2); }
.pos-3 { color: var(--rank3); }

.cmdr-name { font-weight: 600; }

.time-cell {
  font-family: var(--font-mono);
  font-size: .85rem;
}

.delta-cell {
  font-family: var(--font-mono);
  font-size: .8rem;
  color: var(--text-muted);
}

.improvement-cell {
  font-family: var(--font-mono);
  font-size: .8rem;
}

.improvement-better { color: var(--good); }
.improvement-worse  { color: var(--bad); }
.improvement-none   { color: var(--text-muted); }

/* ============================================================
   Status / loading / empty states
   ============================================================ */
.status-bar {
  display: flex;
  align-items: center;
  gap: .6rem;
  font-size: .8rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}
.dot.live     { background: var(--good); animation: pulse 2s infinite; }
.dot.offline  { background: var(--text-muted); }
.dot.error    { background: var(--bad); }
.dot.filtered { background: var(--accent); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .3; }
}

.loading-placeholder {
  padding: 3rem 1rem;
  text-align: center;
  color: var(--text-muted);
  font-size: .95rem;
}

.empty-state {
  padding: 3rem 1rem;
  text-align: center;
  color: var(--text-muted);
}

/* ============================================================
   Buttons
   ============================================================ */
.btn-primary {
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: .4rem;
  padding: .5rem 1.25rem;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s;
  text-decoration: none;
}
.btn-primary:hover { opacity: .85; text-decoration: none; }

.btn-secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: .4rem;
  padding: .5rem 1.25rem;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color .15s, color .15s;
  text-decoration: none;
}
.btn-secondary:hover {
  border-color: var(--text-muted);
  color: var(--text-muted);
  text-decoration: none;
}

.btn-chip {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: .2rem .65rem;
  font-size: .75rem;
  cursor: pointer;
  transition: border-color .15s, color .15s;
}
.btn-chip:hover { border-color: var(--accent-dim); color: var(--accent); }

/* ============================================================
   Filter bar — profile display
   ============================================================ */
.filter-group-label {
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  align-self: center;
  color: var(--text-muted);
}
.profile-display-row {
  display: flex;
  align-items: center;
  gap: .6rem;
  min-height: 2rem;
}
.profile-name { font-size: .9rem; color: var(--text); text-decoration: none; }
.profile-name[href]:hover { color: var(--accent); text-decoration: underline; }
.profile-name.no-profile { color: var(--text-muted); font-style: italic; }

/* ============================================================
   Profile modal
   ============================================================ */
.profile-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}
.profile-overlay.visible { opacity: 1; pointer-events: all; }

.profile-modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: .75rem;
  padding: 2rem;
  max-width: 500px;
  width: 90%;
  position: relative;
}
.modal-close-x {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 2rem;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  width: 2rem;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color .15s;
}
.modal-close-x:hover {
  color: var(--text);
}
.profile-modal-title {
  font-size: 1.2rem;
  color: var(--accent);
  margin-bottom: 1rem;
}
.profile-modal-intro {
  font-size: .9rem;
  color: var(--text-muted);
  line-height: 1.65;
  margin-bottom: 1.5rem;
}
.profile-modal-field {
  display: flex;
  flex-direction: column;
  gap: .4rem;
  margin-bottom: 1.25rem;
}
.profile-modal-field label {
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
}
.profile-modal-field select {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: .35rem;
  color: var(--text);
  font-size: .9rem;
  padding: .4rem .75rem;
  outline: none;
  appearance: none;
}
.profile-modal-field select:focus   { border-color: var(--accent-dim); }
.profile-modal-field select:disabled { opacity: .4; }
.profile-modal-actions   { display: flex; justify-content: flex-end; gap: .75rem; }

/* Commander name links (in race table + profile label) */
.cmdr-link          { color: var(--text); }
.cmdr-link:hover    { color: var(--accent); text-decoration: none; }
.cmdr-link-self     { color: var(--accent); font-weight: 600; }
.cmdr-link-self:hover { opacity: .8; }
.profile-name .cmdr-link { color: var(--accent); }

/* ============================================================
   Commander page
   ============================================================ */
.cmdr-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

.cmdr-header-content {
  flex: 1;
}

.cmdr-header h1 {
  margin-bottom: .75rem;
}

.cmdr-avatar-container {
  flex-shrink: 0;
}

.cmdr-avatar {
  max-height: 120px;
  width: auto;
  border-radius: .5rem;
  border: 2px solid var(--border);
  transition: border-color .2s;
}

.cmdr-avatar-container a:hover .cmdr-avatar {
  border-color: var(--accent-dim);
}

@media (max-width: 768px) {
  .cmdr-header {
    flex-direction: column-reverse;
    align-items: center;
  }
  .cmdr-header h1 {
    text-align: center;
  }
  .cmdr-avatar {
    max-height: 100px;
  }
}

.cmdr-overall-pct {
  font-size: 1.1rem;
  margin-bottom: .6rem;
}
.cmdr-overall-pct strong { color: var(--accent); }

.cmdr-type-stats {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem 1.25rem;
  font-size: .85rem;
  color: var(--text-muted);
}
.cmdr-type-stat strong { color: var(--text); }
.cmdr-type-stat .pct-highlight { color: var(--accent); }

.cmdr-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .75rem 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: .5rem;
  padding: .75rem 1.25rem;
  margin-bottom: 1.75rem;
}
.cmdr-sort-group {
  display: flex;
  align-items: center;
  gap: .6rem;
}

.btn-toggle-group { display: flex; gap: .35rem; }
.btn-toggle {
  background: var(--surface2);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: .35rem;
  padding: .3rem .85rem;
  font-size: .82rem;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.btn-toggle:hover        { border-color: var(--accent-dim); color: var(--text); }
.btn-toggle.active       { background: rgba(232,160,32,.15); color: var(--accent); border-color: var(--accent-dim); }

.cmdr-type-section { margin-bottom: 2.5rem; }

/* Limit race name width on cmdr page tables */
.cmdr-type-section .results-table th:nth-child(1),
.cmdr-type-section .results-table td:nth-child(1) {
  max-width: 250px;
  white-space: normal;
  word-wrap: break-word;
}

/* Limit ship column width on cmdr page tables */
.cmdr-type-section .results-table th:nth-child(5),
.cmdr-type-section .results-table td:nth-child(5) {
  max-width: 250px;
  white-space: normal;
  word-wrap: break-word;
}

/* Limit stolen by and race columns on cmdr page thieves table */
.thievses-section .results-table th:nth-child(2),
.thievses-section .results-table td:nth-child(2),
.thievses-section .results-table th:nth-child(3),
.thievses-section .results-table td:nth-child(3) {
  max-width: 250px;
  white-space: normal;
  word-wrap: break-word;
}

.cmdr-section-heading {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: .75rem;
  display: flex;
  align-items: baseline;
  gap: .75rem;
}
.cmdr-type-heading {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: .75rem;
  display: flex;
  align-items: baseline;
  gap: .75rem;
}
.cmdr-type-avg {
  font-size: .78rem;
  font-weight: 400;
  color: var(--text-muted);
}

/* Percentile colour coding */
.pct-elite { color: var(--rank1);  font-weight: 600; }
.pct-good  { color: var(--good);   }
.pct-mid   { color: var(--text);   }
.pct-low   { color: var(--text-muted); }

/* Position delta (7-day trend) */
.delta-up   { color: var(--good); font-weight: 600; }
.delta-down { color: var(--bad); font-weight: 600; }

/* Opportunity highlight row */
.row-opportunity td {
  background: rgba(217, 79, 79, .07);
}

/* Legend */
.cmdr-legend {
  display: flex;
  align-items: center;
  gap: .6rem;
  font-size: .82rem;
  color: var(--text-muted);
  margin-top: .5rem;
  margin-bottom: 2rem;
}
.legend-swatch {
  display: inline-block;
  width: 1rem;
  height: 1rem;
  border-radius: .2rem;
  flex-shrink: 0;
}
.legend-swatch.highlight-opportunity { background: rgba(217, 79, 79, .3); border: 1px solid var(--bad); }

/* Trophy case */
.trophy-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 2.5rem;
}
.trophy-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: .6rem;
  padding: 1.25rem 2rem;
  min-width: 110px;
  text-align: center;
}
.trophy-icon  { width: 150px; height: 150px; object-fit: contain; }
.trophy-count { font-size: 1.8rem; font-weight: 700; line-height: 1.1; }
.trophy-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .07em; color: var(--text-muted); }

.trophy-gold   { border-color: var(--rank1); background: rgba(255,215,0,.07); }
.trophy-gold   .trophy-count { color: var(--rank1); }
.trophy-silver { border-color: var(--rank2); background: rgba(192,192,192,.07); }
.trophy-silver .trophy-count { color: var(--rank2); }
.trophy-bronze { border-color: var(--rank3); background: rgba(205,127,50,.07); }
.trophy-bronze .trophy-count { color: var(--rank3); }

/* ── Thievses ──────────────────────────────────────────────────────────── */
.thievses-section {
  margin-top: 2.5rem;
  margin-bottom: 2.5rem;
}
.thievses-section .cmdr-section-heading { color: var(--bad); }
.thievses-gollum {
  font-style: italic;
  color: var(--text-muted);
  font-size: .9rem;
  line-height: 1.6;
  max-width: 120ch;
  margin: 0 0 1rem;
}
.theft-pos-1 { color: var(--rank1); font-weight: 700; }
.theft-pos-2 { color: var(--rank2); font-weight: 700; }
.theft-pos-3 { color: var(--rank3); font-weight: 700; }

.reclaimed-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  background: linear-gradient(135deg, #2a5d2a 0%, #3a7d3a 100%);
  color: #ffd700;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 4px;
  white-space: nowrap;
}

.redeemed-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  background: linear-gradient(135deg, #3a5a7d 0%, #4a6a9d 100%);
  color: #ffd700;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 4px;
  white-space: nowrap;
}

.thief-lost-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  background: linear-gradient(135deg, #6a5a3a 0%, #7a6a4a 100%);
  color: #e0d0b0;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 4px;
  white-space: nowrap;
}

.reclaimed-theft {
  opacity: 0.6;
}

.reclaimed-theft:hover {
  opacity: 1;
  transition: opacity 0.2s ease;
}

.redeemed-theft {
  opacity: 0.7;
}

.redeemed-theft:hover {
  opacity: 1;
  transition: opacity 0.2s ease;
}

.thief-lost-theft {
  opacity: 0.9;
}

.thief-lost-theft:hover {
  opacity: 1;
  transition: opacity 0.2s ease;
}

/* Status badges for thefts table */
.status-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 4px;
  white-space: nowrap;
}

.status-reclaimed {
  background: linear-gradient(135deg, #2a5d2a 0%, #3a7d3a 100%);
  color: #ffd700;
}

.status-redeemed {
  background: linear-gradient(135deg, #3a5a7d 0%, #4a6a9d 100%);
  color: #ffd700;
}

.status-dropped {
  background: linear-gradient(135deg, #6a5a3a 0%, #7a6a4a 100%);
  color: #e0d0b0;
}

.status-active {
  background: linear-gradient(135deg, #7d3a2a 0%, #9d4a3a 100%);
  color: #ffaa80;
}

.active-theft {
  /* Active thefts are fully visible */
  opacity: 1;
}

/* ============================================================
   Opportunities (NENDY + NEIDY)
   ============================================================ */
.nearby-section {
  margin-bottom: 2.5rem;
}
.nearby-section-heading {
  margin-bottom: .5rem;
}
.section-intro {
  font-size: .88rem;
  color: var(--text-muted);
  line-height: 1.6;
  margin: 0 0 1.25rem;
  max-width: 150ch;
  border: 1px solid var(--border);
  border-radius: .375rem;
  padding: 1rem 1.25rem;
  position: relative;
}
.section-intro strong { color: var(--text); }
.section-intro-close {
  position: absolute;
  top: .5rem;
  right: .5rem;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  padding: .25rem .5rem;
  border-radius: .25rem;
  transition: all 0.2s;
}
.section-intro-close:hover {
  color: var(--text);
  background: var(--surface2);
}
.rankings-heading {
  margin-top: 0;
  margin-bottom: .75rem;
}
.neidy-filters {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: .5rem;
  padding: .75rem 1.25rem;
  margin-bottom: 1rem;
}
.nendy-controls {
  display: flex;
  flex-direction: column;
  gap: .3rem;
  margin-bottom: 1rem;
}
.nendy-input-row {
  display: flex;
  gap: .5rem;
  align-items: center;
}
.nendy-input {
  padding: .35rem .65rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: .35rem;
  color: var(--text);
  font-size: .875rem;
  width: 220px;
}
.nendy-input:focus {
  outline: none;
  border-color: var(--accent);
}
.nendy-autocomplete {
  position: relative;
}
.nendy-suggestions {
  position: absolute;
  top: calc(100% + 2px);
  left: 0;
  min-width: 100%;
  max-height: 220px;
  overflow-y: auto;
  list-style: none;
  margin: 0;
  padding: .25rem 0;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: .35rem;
  z-index: 50;
  box-shadow: 0 4px 16px rgba(0,0,0,.4);
}
.nendy-suggestions li {
  padding: .35rem .65rem;
  font-size: .875rem;
  cursor: pointer;
  white-space: nowrap;
}
.nendy-suggestions li:hover,
.nendy-suggestions li.active {
  background: var(--surface);
  color: var(--accent);
}
.nendy-origin {
  font-size: .8rem;
  color: var(--text-muted);
  margin: 0 0 .75rem;
}
.nendy-more {
  font-size: .8rem;
  color: var(--text-muted);
  margin: .6rem 0 0;
}

/* ── Nearby tabs ─────────────────────────────────────────────── */
.nearby-tabs {
  display: flex;
  gap: .5rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: .5rem;
}
.nearby-tab {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: .35rem .35rem 0 0;
  color: var(--text-muted);
  padding: .3rem .9rem;
  font-size: .82rem;
  cursor: pointer;
  transition: color .15s, border-color .15s, background .15s;
}
.nearby-tab:hover { color: var(--text); border-color: var(--accent-dim); }
.nearby-tab.active {
  background: var(--surface2);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}
.tab-badge {
  display: inline-block;
  background: var(--accent);
  color: var(--bg);
  border-radius: 10px;
  font-size: .7rem;
  font-weight: 700;
  padding: .1rem .45rem;
  margin-left: .4rem;
  min-width: 1.4em;
  text-align: center;
  line-height: 1.5;
  vertical-align: middle;
}
.nearby-tab.active .tab-badge {
  background: var(--bg);
  color: var(--accent);
}
.nendy-teaser {
  display: flex;
  align-items: center;
  gap: .75rem;
  flex-wrap: wrap;
  margin-top: 1.25rem;
  padding: .65rem 1rem;
  background: var(--surface2);
  border: 1px solid var(--accent-dim);
  border-radius: .4rem;
  font-size: .85rem;
  color: var(--text-muted);
}
.nendy-teaser strong { color: var(--text); }

/* ── NEIDY catchability bar ──────────────────────────────────── */
.neidy-bar-cell { width: 90px; padding-right: .5rem; }
.neidy-bar {
  height: 6px;
  background: var(--surface2);
  border-radius: 3px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.neidy-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width .3s ease;
}
.neidy-legend {
  font-size: .78rem;
  color: var(--text-muted);
  margin: 0 0 .75rem;
  display: flex;
  flex-wrap: wrap;
  gap: .5rem 1.5rem;
}
.neidy-legend-item strong { color: var(--text); }

/* ── Participation Progress Bars ──────────────────────────────── */
.participation-section {
  margin-bottom: 2.5rem;
}
.participation-intro {
  font-size: .88rem;
  color: var(--text-muted);
  line-height: 1.6;
  margin: 0 0 1.25rem;
  max-width: 150ch;
}
.participation-intro strong { color: var(--text); }
.participation-bars {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem 1.5rem;
  max-width: 900px;
}
@media (max-width: 768px) {
  .participation-bars {
    grid-template-columns: 1fr;
  }
}
.participation-bar-row {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.participation-bar-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: .88rem;
}
.participation-bar-type {
  font-weight: 600;
  color: var(--text);
}
.participation-bar-count {
  color: var(--text-muted);
  font-size: .82rem;
}
.participation-bar-wrapper {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.participation-bar-wrapper .neidy-bar {
  flex: 1;
  height: 8px;
}
.participation-bar-pct {
  font-size: .82rem;
  color: var(--text-muted);
  min-width: 2.5rem;
  text-align: right;
}

/* ============================================================
   Site footer
   ============================================================ */
.site-footer {
  border-top: 1px solid var(--border);
  margin-top: 4rem;
  padding: 1.25rem 0;
  font-size: .82rem;
  color: var(--text-muted);
}
.site-footer .page-wrapper {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .4rem .75rem;
}
.site-footer a { color: var(--text-muted); }
.site-footer a:hover { color: var(--accent); }
.site-footer .sep { opacity: .4; }
.site-footer .build-ver { opacity: .45; font-size: .75rem; }

/* ============================================================
   About page
   ============================================================ */
.about-page { max-width: 72ch; }
.guide-page { /* Uses default page-wrapper width */ }

.about-title {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 2rem;
}
.about-section {
  margin-bottom: 2.5rem;
}
.about-section p {
  color: var(--text-muted);
  line-height: 1.7;
  margin: 0 0 .9rem;
}
.about-section p:last-child { margin-bottom: 0; }
.about-section a { color: var(--accent); }
.about-section a:hover { text-decoration: underline; }
.about-section ul,
.about-section ol {
  margin-bottom: 1rem;
  padding-left: 1.5rem;
  line-height: 1.7;
  color: var(--text-muted);
}
.about-section li {
  margin-bottom: 0.5rem;
}
.about-issue-link {
  display: inline-block;
  margin-top: .5rem;
  text-decoration: none;
}
.site-logo-link {
  color: inherit;
  text-decoration: none;
}
.site-logo-link:hover { color: var(--accent); }

/* ============================================================
   Racing Guide page
   ============================================================ */
.guide-content h1 {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 1.5rem;
  color: var(--accent);
}
.guide-content h2 {
  font-size: 1.5rem;
  font-weight: 600;
  margin-top: 2rem;
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--accent);
  color: var(--text);
}
.guide-content h3 {
  font-size: 1.25rem;
  font-weight: 600;
  margin-top: 1.5rem;
  margin-bottom: 0.5rem;
  color: var(--text);
}
.guide-content h4 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-top: 1rem;
  margin-bottom: 0.4rem;
  color: var(--accent);
}
.guide-content ul,
.guide-content ol {
  margin-bottom: 1rem;
  padding-left: 1.5rem;
  line-height: 1.7;
  color: var(--text-muted);
}
.guide-content li {
  margin-bottom: 0.5rem;
}
.guide-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
  font-size: 0.9rem;
}
.guide-content table th {
  background-color: rgba(0, 188, 212, 0.1);
  padding: 0.75rem;
  text-align: left;
  border: 1px solid rgba(255, 255, 255, 0.1);
  font-weight: 600;
  color: var(--text);
}
.guide-content table td {
  padding: 0.75rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-muted);
}
.guide-content table tr:nth-child(even) {
  background-color: rgba(255, 255, 255, 0.02);
}
.guide-content img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 1.5rem auto;
  border-radius: 4px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}
.dw3-thanks-content img {
  float: right;
  margin: 0 0 1.5rem 4.5rem;
  width: 35%;
}
.guide-content code {
  background-color: rgba(255, 255, 255, 0.05);
  padding: 0.2rem 0.4rem;
  border-radius: 3px;
  font-family: 'Courier New', Monaco, monospace;
  font-size: 0.9em;
  color: var(--accent);
}
.guide-content pre {
  background-color: rgba(255, 255, 255, 0.05);
  padding: 1rem;
  border-radius: 4px;
  overflow-x: auto;
  margin: 1rem 0;
}
.guide-content pre code {
  background: none;
  padding: 0;
  color: var(--text-muted);
}
.guide-content blockquote {
  border-left: 4px solid var(--accent);
  padding-left: 1rem;
  margin: 1rem 0;
  font-style: italic;
  color: var(--text-muted);
  opacity: 0.9;
}

/* ============================================================
   About Me page
   ============================================================ */
.about-me-content {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(240px, 360px);
  column-gap: 2rem;
  row-gap: 1rem;
  align-items: start;
}

.about-me-content > h1,
.about-me-content > h2,
.about-me-content > p:not(h2 + ul + p),
.about-me-content > ul + p + p {
  grid-column: 1 / -1;
}

.about-me-content > ul,
.about-me-content > ol {
  grid-column: 1;
  margin-bottom: 0;
}

.about-me-content > h2 + ul + p {
  grid-column: 2;
  margin: 0;
  align-self: start;
}

.about-me-content > h2 + ul + p img {
  width: 100%;
  margin: 0;
}

@media (max-width: 900px) {
  .about-me-content {
    display: block;
  }

  .about-me-content > h2 + ul + p {
    margin: 1.5rem 0;
  }

  .about-me-content > h2 + ul + p img {
    margin: 1.5rem auto;
  }
}

/* ============================================================
   Responsive
   ============================================================ */
/* ── Portrait-mode banner ─────────────────────────────────────────── */
.portrait-banner {
  display: none;
  background: var(--accent);
  color: #fff;
  text-align: center;
  font-size: .85rem;
  padding: .45rem 1rem;
  letter-spacing: .02em;
}
@media (max-width: 600px) and (orientation: portrait) {
  .portrait-banner { display: block; }
  .site-logo { font-size: .9rem; white-space: normal; }
  .site-logo .logo-full { display: none; }
  .site-logo .logo-short { display: inline; }

  /* Trophy case: shrink items so all 3 fit on one row */
  .trophy-item {
    padding: .75rem .6rem;
    min-width: 0;
    flex: 1 1 0;
  }
  .trophy-icon { width: 64px; height: 64px; }
  .trophy-count { font-size: 1.3rem; }
}

/* ── Mobile styles ─────────────────────────────────────────────────── */
@media (max-width: 768px) {
  /* Header: use shorter logo and reduce gap */
  .site-header .inner { gap: 1.25rem; }
  .site-logo .logo-full { display: none; }
  .site-logo .logo-short { display: inline; }

  /* Race page: hide chart on narrow portrait, show only table */
  #race-chart { display: none; }
  .results-layout { display: block; }

  /* Race page: clamp Commander name column */
  .results-table-panel .results-table td:nth-child(2),
  .results-table-panel .results-table th:nth-child(2) {
    max-width: 110px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* Cmdr page: clamp Race name column (1st col) */
  .cmdr-type-section .results-table td:nth-child(1),
  .cmdr-type-section .results-table th:nth-child(1) {
    max-width: 130px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* Hide Ship column on cmdr page mobile */
  .cmdr-type-section .results-table th:nth-child(5),
  .cmdr-type-section .results-table td:nth-child(5) {
    display: none;
  }

  /* Creators page: limit creator name column */
  #creators-table-container .results-table th:nth-child(1),
  #creators-table-container .results-table td:nth-child(1) {
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

/* ============================================================
   Stats Page
   ============================================================ */
.stats-section {
  margin-bottom: 3rem;
}

.stats-section-description {
  font-size: .9rem;
  color: var(--text-dim);
  margin: .5rem 0 1rem 0;
  line-height: 1.5;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.activity-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
}

.activity-column {
  min-width: 0; /* Prevent grid overflow */
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: .5rem;
  padding: 1.25rem 1rem;
  text-align: center;
  transition: border-color .2s;
}

.stat-card:hover {
  border-color: var(--accent-dim);
}

.stat-card-label {
  font-size: .85rem;
  color: var(--text-muted);
  margin-bottom: .5rem;
  text-transform: uppercase;
  letter-spacing: .05em;
}

.stat-card-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.2;
}

.stat-card-subtitle {
  font-size: .8rem;
  color: var(--text-muted);
  margin-top: .5rem;
}

.stats-subsection-heading {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
  margin-top: 1.5rem;
  margin-bottom: .75rem;
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: .5rem;
  overflow: hidden;
  margin-bottom: 1.5rem;
}

.label-mobile { display: none; }

.stats-table thead {
  background: var(--surface2);
}

.stats-table th {
  padding: .75rem 1rem;
  text-align: left;
  font-size: .85rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  border-bottom: 1px solid var(--border);
}

.stats-table td {
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--border);
}

.stats-table tbody tr:last-child td {
  border-bottom: none;
}

.stats-table tbody tr:hover {
  background: var(--surface2);
}

.stats-table .stats-rank {
  text-align: center;
  font-size: 1.2rem;
  white-space: nowrap;
}

.stats-table .stats-count,
.stats-table .stats-time {
  text-align: right;
  white-space: nowrap;
}

.page-title {
  font-size: 2rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 1.5rem;
}

@media (max-width: 1470px) {
  #races-table-container {
    margin-left: 0;
    margin-right: 0;
  }

  #races-table-container .results-table th:nth-child(9),
  #races-table-container .results-table td:nth-child(9) {
    display: none;
  }
}

@media (max-width: 1250px) {
  #races-table-container .results-table th:nth-child(7),
  #races-table-container .results-table td:nth-child(7),
  #races-table-container .results-table th:nth-child(8),
  #races-table-container .results-table td:nth-child(8) {
    display: none;
  }
}

/* Shrink ship column on race page below 1000px */
@media (max-width: 1000px) {
  #results-layout .results-table th:nth-child(6), #results-layout .results-table td:nth-child(6) {
    max-width: 230px;
    overflow: hidden;
  }
}

@media (max-width: 968px) {
  #races-table-container .results-table th:nth-child(5),
  #races-table-container .results-table td:nth-child(5) {
    display: none;
  }
}

/* Shrink ship column on race page below 900px */
@media (max-width: 900px) {
  #results-layout .results-table th:nth-child(6),
  #results-layout .results-table td:nth-child(6) {
    max-width: 130px;
    overflow: hidden;
  }
}

@media (max-width: 720px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .activity-grid {
    grid-template-columns: 1fr;
  }

  .stat-card-value {
    font-size: 1.5rem;
  }

  .stats-table {
    font-size: .85rem;
  }

  .stats-table th,
  .stats-table td {
    padding: .5rem .75rem;
  }

  .stats-table .stats-rank {
    font-size: 0.95rem;
  }

  .label-desktop { display: none; }
  .label-mobile  { display: inline; }

  /* Make filter inputs full width on mobile when stacked */
  .filter-group {
    width: 100%;
  }

  .filter-bar input[type="text"] {
    width: 100%;
    min-width: unset;
  }
}

/* Hide Restrictions column on narrower screens */
@media (max-width: 1000px) {
  .col-restrictions {
    display: none;
  }
}

/* Use shorter column labels on narrow screens */
@media (max-width: 850px) {
  th[data-short] .th-label {
    display: none;
  }

  th[data-short]::after {
    content: attr(data-short);
  }
}

/* Hide ship column on race page below 650px */
@media (max-width: 650px) {
  #results-layout .results-table th:nth-child(6),
  #results-layout .results-table td:nth-child(6) {
    display: none;
  }
}

/* ============================================================
   Add Media Form
   ============================================================ */
.add-media-page .page-title {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 2rem;
}

.media-form {
  max-width: 800px;
}

.form-section {
  margin-bottom: 2rem;
  padding: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
}

.form-section-heading {
  margin-top: 0;
  margin-bottom: 1rem;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--accent);
}

.form-help {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin: 0.5rem 0;
  line-height: 1.5;
}

.link-input-group {
  margin-bottom: 1.5rem;
  padding: 1rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 0.4rem;
}

.link-input-group:last-child {
  margin-bottom: 0;
}

.link-input-group label {
  display: block;
  margin-top: 0.5rem;
  margin-bottom: 0.35rem;
  font-weight: 500;
  font-size: 0.9rem;
  color: var(--text);
}

.link-input-group label:first-child {
  margin-top: 0;
}

.form-input,
.form-select,
.file-input {
  width: 100%;
  padding: 0.6rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 0.4rem;
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
  transition: border-color 0.15s;
}

.form-input:focus,
.form-select:focus,
.file-input:focus {
  outline: none;
  border-color: var(--accent);
}

.form-input::placeholder {
  color: var(--text-muted);
  opacity: 0.6;
}

.file-input {
  padding: 0.5rem;
  cursor: pointer;
}

.file-input::file-selector-button {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 0.3rem;
  padding: 0.4rem 0.8rem;
  margin-right: 0.75rem;
  cursor: pointer;
  font-size: 0.85rem;
  transition: background 0.15s;
}

.file-input::file-selector-button:hover {
  background: var(--surface);
}

.form-actions {
  display: flex;
  gap: 1rem;
  margin-top: 2rem;
}

.success-banner {
  padding: 1rem 1.25rem;
  margin-bottom: 1.5rem;
  background: rgba(232, 160, 32, 0.1);
  border: 1px solid var(--accent);
  border-radius: 0.5rem;
  color: var(--accent);
  font-weight: 500;
}
