:root {
  --blue: #1a3a8f;
  --blue-light: #2a5bbf;
  --gray: #b0b0b0;
  --gray-dark: #8a8a8a;
  --yellow: #e6b800;
  --yellow-dark: #c9a000;
  --bg: #fafafa;
  --text: #1a1a1a;
  --accent: #0d47a1;
  --border: #ddd;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
  --regen-red: #d32f2f;
  --ctrl-h: 34px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
  padding: 1.5rem;
}

.app {
  max-width: 1180px;
  margin: 0 auto;
  background: var(--bg);
}

header {
  text-align: center;
  margin-bottom: 0.5rem;
}

h1 {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.subtitle {
  color: #555;
  margin-top: 0.15rem;
  font-size: 0.95rem;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  align-items: center;
  margin-top: 1rem;
}

/* Uniform control height & text colour for buttons and checkbox labels */
button,
.btn-like {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: var(--ctrl-h);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0 0.85rem;
  font-size: 0.85rem;
  font-family: inherit;
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  box-shadow: var(--shadow);
  line-height: 1;
  white-space: nowrap;
}

button:hover,
.btn-like:hover {
  background: #f0f4ff;
  border-color: var(--blue-light);
}

button.active {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
}

.toggle-option {
  gap: 0.4rem;
}

.toggle-option input {
  accent-color: var(--blue);
  cursor: pointer;
  width: 14px;
  height: 14px;
  margin: 0;
  flex-shrink: 0;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 1.25rem;
  margin-top: 0.85rem;
  font-size: 0.8rem;
  color: #444;
}

.leg-item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.swatch {
  display: inline-block;
  width: 14px;
  height: 18px;
  border-radius: 3px 3px 1px 1px;
}

.swatch.found {
  background: linear-gradient(180deg, var(--blue-light), var(--blue));
}
.swatch.missing {
  background: linear-gradient(180deg, #c8c8c8, var(--gray));
}
.swatch.recreated {
  background: linear-gradient(180deg, #f0d060, var(--yellow-dark));
}

/* ===== Season rows ===== */
.season {
  display: grid;
  grid-template-columns: 108px 1fr 88px;
  gap: 0.6rem 0.75rem;
  align-items: center;
  border-bottom: 1px solid #eee;
}

.season-meta {
  font-size: 0.8rem;
  line-height: 1.35;
}

.season-meta .label {
  font-weight: 700;
  font-size: 0.9rem;
}

.season-meta .years {
  color: #555;
}

.season-meta .doctor {
  color: #666;
  font-size: 0.75rem;
}

.bars-area {
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: thin;
}

.serials-row {
  display: flex;
  flex-wrap: nowrap;
  gap: 0;
  align-items: flex-end;
  min-height: 52px;
}

.serial-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 5px 2px;
  margin-right: 1px;
  position: relative;
  min-width: fit-content;
}

.serial-group.edit-hover {
  outline: 2px dashed var(--blue-light);
  outline-offset: 1px;
  border-radius: 4px;
}

.serial-group.doctor-change::after {
  content: "";
  position: absolute;
  right: -1px;
  top: 0;
  bottom: 18px;
  width: 3px;
  background: var(--regen-red);
  border-radius: 1px;
  z-index: 2;
}

.episodes {
  display: flex;
  gap: 2px;
}

.ep-bar {
  width: 13px;
  height: 30px;
  border-radius: 4px 4px 2px 2px;
  cursor: pointer;
  transition: transform 0.12s, filter 0.12s;
  border: none;
  padding: 0;
  flex-shrink: 0;
  position: relative;
  font-size: 0;
  color: transparent;
  line-height: 1;
}

.ep-bar:hover {
  transform: scaleY(1.12);
  filter: brightness(1.12);
}

.ep-bar.found {
  background: linear-gradient(180deg, var(--blue-light), var(--blue));
}

.ep-bar.missing {
  background: linear-gradient(180deg, #c8c8c8, var(--gray));
}

.ep-bar.recreated {
  background: linear-gradient(180deg, #f0d060, var(--yellow-dark));
}

.ep-bar.show-num {
  font-size: 0.55rem;
  font-weight: 700;
  color: rgba(255,255,255,0.95);
  text-shadow: 0 0 2px rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
}

.ep-bar.show-num.missing {
  color: rgba(40,40,40,0.85);
  text-shadow: none;
}

.serial-label {
  font-size: 0.6rem;
  color: #444;
  text-align: center;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 3px;
  line-height: 1.15;
  padding: 0 1px;
}

.serial-label.note-star::before {
  content: "* ";
  color: #c62828;
}

.season-pie {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
}

.season-pie canvas {
  width: 52px;
  height: 52px;
}

.season-pie .pct {
  font-size: 0.72rem;
  font-weight: 600;
  color: #333;
  text-align: center;
  line-height: 1.2;
}

/* ===== Footer / summary ===== */
.summary {
  margin-top: 1.75rem;
}

.doctors {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-end;
  gap: 2.25rem;
  margin-bottom: 1.25rem;
}

.doctor-card {
  text-align: center;
}

.doctor-photo {
  width: 128px;
  height: 128px;
  object-fit: cover;
  object-position: center top;
  margin: 0 auto 0.4rem;
  border-radius: 4px;
  box-shadow: var(--shadow);
  display: block;
  background: #d0c0a8;
}

.doctor-name {
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}
.doctor-name span {
  font-weight: 400;
  font-size: 0.78rem;
  color: #555;
}

.pie-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
}

.pie-label {
  font-size: 0.8rem;
  font-weight: 600;
}

.overall {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
}

.overall-text {
  text-align: center;
  font-size: 0.95rem;
}
.overall-text strong {
  display: block;
  font-size: 1.05rem;
}

.note {
  font-size: 0.8rem;
  color: #666;
  text-align: center;
  max-width: 760px;
  margin: 0 auto 0.75rem;
  line-height: 1.5;
}

.sources {
  font-size: 0.72rem;
  color: #777;
  text-align: center;
  max-width: 820px;
  margin: 0 auto;
  line-height: 1.45;
}
.sources a {
  color: var(--accent);
  text-decoration: none;
}
.sources a:hover {
  text-decoration: underline;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal.hidden { display: none; }

.modal-content {
  background: #fff;
  padding: 1.5rem;
  border-radius: 10px;
  width: 90%;
  max-width: 340px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.2);
}
.modal-content h3 { margin-bottom: 1rem; }
.modal-content label {
  display: block;
  margin-bottom: 0.75rem;
  font-size: 0.9rem;
}
.modal-content input {
  display: block;
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.95rem;
}
.modal-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
}
.modal-actions button { flex: 1; }

@media (max-width: 800px) {
  .season {
    grid-template-columns: 1fr;
    gap: 0.35rem;
  }
  .season-pie {
    flex-direction: row;
    justify-content: flex-start;
    gap: 0.6rem;
  }
  h1 { font-size: 1.45rem; }
  .ep-bar { width: 11px; height: 26px; }
  .ep-bar.show-num { font-size: 0.5rem; }
  .serial-group { padding: 0 3px 2px; }
}
