:root {
  color-scheme: dark;
  --bg: #0f1115;
  --bg-elevated: #171a21;
  --bg-week-a: #14171d;
  --bg-week-b: #191c23;
  --border: #2a2e38;
  --text: #e8eaed;
  --text-dim: #9aa3b2;
  --text-faint: #5b6270;
  --accent: #f5c518;
  --line: #4c5566;
  --line-evicted: #3a3f4a;
  --shadow: 0 8px 24px rgba(0,0,0,0.4);
  --row-h: 48px;
  --col-w: 108px;
  --header-h: 96px;
  --name-col-w: 200px;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f6f8;
  --bg-elevated: #ffffff;
  --bg-week-a: #ffffff;
  --bg-week-b: #eef0f4;
  --border: #d7dbe3;
  --text: #1a1d24;
  --text-dim: #565f70;
  --text-faint: #98a0ad;
  --accent: #b8860b;
  --line: #7c8494;
  --line-evicted: #c3c9d3;
  --shadow: 0 8px 24px rgba(20,20,30,0.08);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #f5f6f8;
    --bg-elevated: #ffffff;
    --bg-week-a: #ffffff;
    --bg-week-b: #eef0f4;
    --border: #d7dbe3;
    --text: #1a1d24;
    --text-dim: #565f70;
    --text-faint: #98a0ad;
    --accent: #b8860b;
    --line: #7c8494;
    --line-evicted: #c3c9d3;
    --shadow: 0 8px 24px rgba(20,20,30,0.08);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  height: 100%;
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  z-index: 20;
}

@media (max-width: 680px) {
  .topbar {
    flex-wrap: wrap;
  }
  .topbar h1 {
    flex: 1 1 auto;
  }
  .zoom-presets {
    order: 4;
    flex-basis: 100%;
    width: 100%;
  }
  .season-select {
    order: 2;
  }
  #showAllToggle {
    order: 3;
  }
}

.season-select {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  flex: none;
  max-width: 160px;
}

.topbar h1 {
  font-size: 16px;
  font-weight: 700;
  margin: 0 8px 0 0;
  white-space: nowrap;
  letter-spacing: 0.02em;
}

.topbar h1 span {
  color: var(--accent);
}

.zoom-presets {
  display: flex;
  gap: 6px;
  flex-wrap: nowrap;
  flex: 1;
  overflow-x: auto;
  scrollbar-width: thin;
  min-width: 0;
}

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-dim);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.btn:hover { color: var(--text); border-color: var(--accent); }
.btn.active { background: var(--accent); color: #1a1408; border-color: var(--accent); }

.icon-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  flex: none;
}
.icon-btn:hover { border-color: var(--accent); }

/* ---------- Legend ---------- */
.legend {
  display: flex;
  gap: 14px;
  padding: 6px 16px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  font-size: 11.5px;
  color: var(--text-dim);
  flex-wrap: wrap;
  overflow-x: auto;
}
.legend-item { display: flex; align-items: center; gap: 5px; white-space: nowrap; }
.legend-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.legend-bar { width: 16px; height: 6px; border-radius: 3px; flex: none; opacity: 0.55; }

/* ---------- Chart area ---------- */
.chart-wrap {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

.name-col {
  flex: none;
  width: var(--name-col-w);
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  position: relative;
  overflow: hidden;
  z-index: 10;
  box-shadow: var(--shadow);
}

.name-col-header {
  height: var(--header-h);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 14px;
  font-size: 11px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.name-rows {
  position: relative;
}

.name-row {
  position: absolute;
  left: 0;
  right: 0;
  height: var(--row-h);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  transition: top 0.45s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.3s, background 0.15s;
  border-bottom: 1px solid transparent;
  cursor: pointer;
}
.name-row:hover { background: var(--bg-week-b); }
.name-row.is-highlighted { background: var(--bg-week-b); border-bottom-color: var(--border); }

.name-row .avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--line);
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  overflow: hidden;
}
.name-row .avatar img { width: 100%; height: 100%; object-fit: cover; }

.name-row .meta { min-width: 0; }
.name-row .nm {
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.name-row.evicted .nm { color: var(--text-faint); text-decoration: line-through; text-decoration-color: var(--text-faint); }
.name-row .chips { display: flex; gap: 3px; margin-top: 2px; }
.name-row .chip { width: 6px; height: 6px; border-radius: 50%; }
.name-row .tag {
  font-size: 9px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.scroll-region {
  flex: 1;
  overflow: auto;
  position: relative;
  cursor: grab;
}
.scroll-region.dragging {
  cursor: grabbing;
  user-select: none;
}

.scroll-inner {
  position: relative;
}

.week-band {
  position: absolute;
  top: 0;
  bottom: 0;
}

.week-header {
  position: sticky;
  top: 0;
  height: var(--header-h);
  z-index: 5;
}

svg text { font-family: inherit; }

.event-col-label {
  fill: var(--text-dim);
  font-size: 10.5px;
}

.week-label-text {
  fill: var(--text);
  font-size: 13px;
  font-weight: 700;
}

.week-divider {
  stroke: var(--border);
  stroke-width: 1;
}

.contestant-line {
  fill: none;
  stroke-width: 2.5;
  stroke-linecap: round;
}

.contestant-line.dimmed { opacity: 0.15; }
.contestant-line.evicted-seg { stroke-dasharray: 3 4; }

.status-span {
  opacity: 0.4;
  pointer-events: none;
  transition: opacity 0.2s;
}
.status-span.dimmed { opacity: 0.06; }

.event-dot {
  cursor: pointer;
}
.event-dot circle.ring {
  fill: var(--bg);
}

.tooltip {
  position: fixed;
  pointer-events: none;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 12px;
  max-width: 240px;
  box-shadow: var(--shadow);
  z-index: 100;
  opacity: 0;
  transition: opacity 0.1s;
}
.tooltip.show { opacity: 1; }
.tooltip b { color: var(--accent); }
.tooltip .role-line { display: flex; align-items: center; gap: 6px; margin-top: 3px; }
.tooltip .role-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }

.loading, .error-banner {
  padding: 40px;
  text-align: center;
  color: var(--text-dim);
}
.error-banner { color: #e5484d; }

.admin-link {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-faint);
  text-decoration: none;
  border: 1px solid var(--border);
  padding: 5px 10px;
  border-radius: 999px;
}
.admin-link:hover { color: var(--text); border-color: var(--accent); }
