/* ---------- Colours ---------- */

:root {
  --nav: #0e0e0e;
  --bg: #141414;
  --panel: #1c1c1b;
  --panel2: #242423;
  --hover: #2c2c2a;
  --rule: rgba(255, 255, 255, .08);
  --ink: #ffffff;
  --text: #e3e1db;
  --muted: #a3a29b;
  --dim: #6f6e68;
  --accent: #e0443e;
  --accent-soft: rgba(224, 68, 62, .14);
  --error: #ff7b72;
  /* one colour per person, in this order (validated categorical palette, dark steps) */
  --person-0: #3987e5;
  --person-1: #d95926;
  --person-2: #199e70;
  --person-3: #c98500;
  --person-4: #d55181;
  --person-5: #9085e9;
  --scrollbar: #4a4946 transparent;
  color-scheme: dark;
}

/* ---------- Base ---------- */

*, *::before, *::after { box-sizing: border-box; }

html {
  background: var(--nav);
  scroll-padding-top: 16px;
}
@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: radial-gradient(1100px 480px at 75% -140px, rgba(224, 68, 62, .16), transparent 70%), var(--bg);
  font: 15px/1.5 "Albert Sans", system-ui, Arial, sans-serif;
  font-variant-numeric: tabular-nums;
}

a { color: var(--ink); text-decoration-color: var(--dim); text-underline-offset: 2px; }
a:hover { text-decoration-color: var(--accent); }

h1, h2 { color: var(--ink); line-height: 1.2; }
h1 { font-size: clamp(1.6rem, 5vw, 2.4rem); margin: 0 0 .4em; }
h2 { font-size: clamp(1.15rem, 3.4vw, 1.45rem); margin: 0 0 .7em; }

:focus-visible { outline: 1.5px solid var(--accent); outline-offset: 2px; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 0 16px 48px; }

.note { color: var(--muted); font-size: .9rem; max-width: 70ch; }
.error { color: var(--error); }

/* ---------- Nav and footer ---------- */

.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px max(16px, calc((100% - 1180px) / 2 + 16px));
  background: var(--nav);
  border-bottom: 1px solid #000;
}
.logo { display: flex; align-items: center; gap: 10px; color: var(--ink); font-weight: 700; text-decoration: none; }
.logo-mark { width: 22px; height: 22px; border-radius: 50%; background: conic-gradient(var(--person-0) 0 33%, var(--accent) 0 66%, var(--person-2) 0); }
.home { color: var(--muted); font-size: .9rem; text-decoration: none; }
.home:hover { color: var(--ink); }

.footer { max-width: 1180px; margin: 0 auto; padding: 24px 16px 40px; color: var(--dim); font-size: .85rem; border-top: 1px solid var(--rule); }
.footer a, .link-btn { color: var(--muted); }
.link-btn { background: none; border: 0; padding: 0; font: inherit; text-decoration: underline; text-decoration-color: var(--dim); cursor: pointer; }

/* ---------- Buttons and inputs ---------- */

.btn, select, input[type="text"], input[type="search"] {
  font: inherit;
  color: var(--text);
  background: var(--panel2);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 8px 12px;
}
.btn { cursor: pointer; font-weight: 600; }
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.small { padding: 4px 10px; font-size: .85rem; }
select { padding-right: 28px; }

/* ---------- Intro and people ---------- */

.intro { padding: 36px 0 12px; }
.lead { font-size: 1.05rem; max-width: 62ch; margin: 0 0 18px; }
.add-form { display: flex; gap: 8px; max-width: 460px; }
.add-form input { flex: 1; min-width: 0; }

.people {
  list-style: none;
  padding: 0;
  margin: 18px 0 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 270px), 1fr));
  gap: 10px;
}
.person {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 4px 12px;
  align-items: center;
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--rule);
  border-left: 4px solid var(--color);
  border-radius: 10px;
}
.avatar {
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--color); color: #fff; font-weight: 700;
  object-fit: cover;
}
.person-name { font-weight: 700; color: var(--ink); overflow-wrap: anywhere; }
.person-status { color: var(--muted); font-size: .85rem; }
.person-status.error { color: var(--error); }
.person-actions { display: flex; gap: 4px; }
.icon-btn {
  width: 30px; height: 30px; border-radius: 6px;
  display: grid; place-items: center;
  background: none; border: 1px solid transparent; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--hover); color: var(--ink); }
.icon-btn svg { width: 16px; height: 16px; }
.progress { grid-column: 1 / -1; height: 4px; border-radius: 2px; background: var(--panel2); overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--color); transition: width .3s; }

/* ---------- Controls ---------- */

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 24px;
  align-items: end;
  margin: 24px 0 8px;
  padding: 14px 16px;
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: 12px;
}
.control { display: grid; gap: 4px; }
.control-label { color: var(--muted); font-size: .8rem; }
.segmented { display: flex; flex-wrap: wrap; background: var(--panel2); border: 1px solid var(--rule); border-radius: 8px; padding: 2px; }
.segmented button { display: inline-flex; align-items: center; justify-content: center; white-space: nowrap; font: inherit; color: var(--muted); background: none; border: 0; border-radius: 6px; padding: 6px 12px; cursor: pointer; }
.segmented button[aria-pressed="true"] { background: var(--accent); color: #fff; font-weight: 600; }

/* ---------- Sections and panels ---------- */

.section { margin-top: 40px; }
.section-head { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: baseline; justify-content: space-between; margin-bottom: .7em; }
.section-head h2 { margin: 0; }
.section-tools { display: flex; gap: 8px; }
.section-tools input { width: 200px; max-width: 100%; }

.panel { background: var(--panel); border: 1px solid var(--rule); border-radius: 12px; padding: 16px; min-width: 0; }
.panel h3 { margin: 0 0 10px; font-size: 1rem; color: var(--ink); }

.hscroll { overflow-x: auto; scrollbar-width: thin; scrollbar-color: var(--scrollbar); }

.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: var(--color); margin-right: 6px; vertical-align: baseline; flex: none; }

/* ---------- Head-to-head stats ---------- */

.stats-table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--rule); border-radius: 12px; overflow: hidden; }
.stats-table th, .stats-table td { padding: 9px 14px; text-align: right; border-bottom: 1px solid var(--rule); }
.stats-table tr:last-child > * { border-bottom: 0; }
.stats-table thead th { color: var(--ink); font-weight: 700; white-space: nowrap; background: var(--panel2); }
.stats-table th[scope="row"] { text-align: left; color: var(--muted); font-weight: 500; white-space: nowrap; }
.stats-table tbody tr:nth-child(even) { background: rgba(255, 255, 255, .02); }
.stats-table td.lead-value { color: var(--ink); font-weight: 700; }
.stats-table td.lead-value::before { content: "▲ "; color: var(--accent); font-size: .7em; vertical-align: 2px; }
.stats-table td.text { min-width: 9em; }
.stats-table .sub { display: block; color: var(--muted); font-size: .8rem; font-weight: 400; }

/* ---------- Overlap ---------- */

.overlap-grid { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 16px; }
@media (max-width: 760px) { .overlap-grid { grid-template-columns: minmax(0, 1fr); } }
.venn { width: 100%; max-width: 420px; display: block; margin: 0 auto; }
.venn text { fill: var(--ink); font-size: 15px; font-weight: 700; text-anchor: middle; dominant-baseline: middle; }
.venn text.venn-name { font-size: 13px; font-weight: 600; fill: var(--muted); }

.big-number { font-size: clamp(2.4rem, 8vw, 3.6rem); font-weight: 700; color: var(--ink); line-height: 1; margin: 6px 0 8px; }
.matrix { border-collapse: separate; border-spacing: 2px; margin-top: 4px; }
.matrix th { font-size: .8rem; color: var(--muted); font-weight: 600; padding: 4px 6px; white-space: nowrap; }
.matrix thead th { text-align: center; }
.matrix th[scope="row"] { text-align: right; }
.matrix td { width: 4.2em; height: 2.4em; text-align: center; border-radius: 4px; font-weight: 600; font-size: .85rem; }
.matrix td.self { background: var(--panel2); color: var(--dim); }

/* label / bar / value rows */
.bar-rows { display: grid; gap: 6px; }
.bar-row { display: grid; grid-template-columns: 9em minmax(0, 1fr) 4.5em; gap: 10px; align-items: center; font-size: .9rem; }
.bar-row .bar { height: 12px; background: var(--panel2); border-radius: 0 4px 4px 0; }
.bar-row .bar span { display: block; height: 100%; background: var(--muted); border-radius: 0 4px 4px 0; min-width: 2px; }
.bar-row .value { text-align: right; color: var(--ink); }

/* ---------- Shared table ---------- */

.table-panel { padding: 0; overflow: hidden; }
.table { min-width: min-content; }
.table-row {
  display: grid;
  grid-template-columns: var(--columns);
  gap: 0 12px;
  align-items: center;
  padding: 7px 16px;
}
.table-head {
  background: var(--panel2);
  border-bottom: 1px solid var(--rule);
  overflow-y: hidden;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  font-size: .85rem;
  font-weight: 600;
  color: var(--ink);
}
.table-head button {
  font: inherit; color: inherit; background: none; border: 0; padding: 2px 0; cursor: pointer;
  text-align: inherit; border-bottom: 2px solid transparent;
}
.table-head button[aria-sort] { border-bottom-color: var(--accent); }
.table-body { overflow-y: auto; scrollbar-gutter: stable; scrollbar-width: thin; scrollbar-color: var(--scrollbar); }
.table-body .table-row:nth-child(even) { background: rgba(255, 255, 255, .025); }
.table-body .table-row:hover { background: var(--hover); }
.table .num { text-align: right; }
.table .num.zero { color: var(--dim); }
.table .num.under { color: var(--muted); }
.item-name { color: var(--ink); font-weight: 600; overflow-wrap: anywhere; }
.item-sub { display: block; color: var(--muted); font-size: .8rem; font-weight: 400; }
.first-cell { font-size: .85rem; white-space: nowrap; }
.first-cell .item-sub { font-size: .78rem; }
.first-inline { display: none; }
.empty { padding: 20px 16px; color: var(--muted); }

/* ---------- Only one of you ---------- */

.unique-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); gap: 12px; align-items: start; }
.unique-grid .panel { padding: 0; overflow: hidden; border-top: 3px solid var(--color); }
.unique-grid h3 { padding: 12px 14px 8px; margin: 0; display: flex; justify-content: space-between; gap: 8px; }
.unique-grid h3 small { color: var(--muted); font-weight: 400; }
.unique-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--scrollbar); }
.unique-list li { display: grid; grid-template-columns: minmax(0, 1fr) 4.5em; gap: 8px; padding: 6px 14px; align-items: center; }
.unique-list li:nth-child(even) { background: rgba(255, 255, 255, .025); }
.unique-list li:hover { background: var(--hover); }
.unique-list .item-name { overflow-wrap: anywhere; }
.unique-list .num { text-align: right; color: var(--ink); }

/* ---------- Timeline chart ---------- */

.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-bottom: 10px; font-size: .9rem; }
.legend span { display: inline-flex; align-items: center; }
.chart-scroll { overflow-x: auto; scrollbar-width: thin; scrollbar-color: var(--scrollbar); }
.chart { position: relative; min-width: 600px; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .grid line { stroke: var(--rule); }
.chart .axis text { fill: var(--muted); font-size: 11px; }
.chart .series { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .crosshair { stroke: var(--muted); stroke-dasharray: 3 3; }
.tooltip {
  position: absolute; top: 0; pointer-events: none; z-index: 2;
  background: var(--panel2); border: 1px solid var(--rule); border-radius: 8px;
  padding: 8px 10px; font-size: .85rem; white-space: nowrap; box-shadow: 0 6px 20px rgba(0, 0, 0, .4);
}
.tooltip b { color: var(--ink); display: block; margin-bottom: 4px; }
.tooltip div { display: flex; justify-content: space-between; gap: 16px; }
.tooltip .total { border-top: 1px solid var(--rule); margin-top: 4px; padding-top: 4px; color: var(--ink); }

/* ---------- Phones ---------- */

@media (max-width: 560px) {
  .controls { gap: 12px; }
  .control { flex: 1 1 140px; }
  .control select { width: 100%; }
  .segmented { width: 100%; }
  .segmented button { flex: 1; padding: 6px 4px; }
  .section-tools { width: 100%; }
  .section-tools input { flex: 1; width: auto; min-width: 0; }
  .table-row { padding: 7px 12px; grid-template-columns: var(--columns-narrow); }
  .table .first-cell { display: none; }
  .first-inline { display: block; }
  .stats-table th, .stats-table td { padding: 8px 10px; }
  .stats-table th[scope="row"] { white-space: normal; min-width: 7.5em; }
  .stats-table td.text { min-width: 7em; }
  .bar-row { grid-template-columns: 7em minmax(0, 1fr) 4em; }
}

/* ---------- View tabs ---------- */

.view-tabs { display: flex; gap: 4px; margin-top: 28px; border-bottom: 1px solid var(--rule); }
.view-tabs button {
  font: inherit; font-weight: 600; color: var(--muted); background: none; border: 0;
  padding: 10px 18px; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.view-tabs button:hover { color: var(--ink); }
.view-tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
#compareNeedsTwo { margin-top: 20px; }

/* ---------- Shared bits for reports ---------- */

.muted { color: var(--muted); font-weight: 400; }
.badge { display: inline-block; font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--accent); border: 1px solid currentColor; border-radius: 4px; padding: 0 4px; vertical-align: 1px; }
.segmented .swatch { margin-right: 6px; }
.segmented button[aria-pressed="true"] .swatch { outline: 1px solid #fff; }
.period-nav { display: flex; gap: 4px; align-items: center; }
.period-nav select { min-width: 0; max-width: 220px; }
.btn.icon { padding: 6px 12px; font-size: 1.1rem; line-height: 1; }
.btn:disabled { opacity: .35; cursor: default; }
.btn:disabled:hover { background: var(--panel2); }

.three-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; align-items: start; }
.two-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.genre-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: 12px; align-items: start; }
@media (max-width: 900px) {
  .three-grid { grid-template-columns: minmax(0, 1fr); }
  .genre-grid, .two-grid { grid-template-columns: minmax(0, 1fr); }
}
.panel h3 { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.panel h3 small { color: var(--muted); font-weight: 400; font-size: .85rem; }

/* summary tiles: one row on desktop */
.tiles { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px; }
@media (max-width: 900px) { .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 560px) { .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.tile { background: var(--panel); border: 1px solid var(--rule); border-radius: 12px; padding: 12px 14px; min-width: 0; }
.tile-label { color: var(--muted); font-size: .8rem; }
.tile-value { color: var(--ink); font-size: clamp(1.4rem, 3vw, 1.9rem); font-weight: 700; line-height: 1.2; }
.tile-value small { color: var(--muted); font-size: .55em; font-weight: 500; }
.tile-sub { font-size: .8rem; color: var(--muted); }
.delta { color: var(--text); font-weight: 600; }

.facts { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px; margin-top: 10px; }
@media (max-width: 900px) { .facts { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 560px) { .facts { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.fact { padding: 10px 14px; border: 1px solid var(--rule); border-radius: 12px; font-size: .9rem; min-width: 0; }
.fact-label { color: var(--muted); font-size: .8rem; }
.fact-value { color: var(--ink); font-weight: 600; overflow-wrap: anywhere; }
.fact-value .muted { display: block; font-size: .8rem; }
#reportTitle .muted { font-size: .7em; }

/* top lists */
.list-panel { padding: 0; overflow: hidden; }
.list-panel h3 { padding: 12px 14px 8px; margin: 0; }
.ranked { counter-reset: rank; }
.ranked li { grid-template-columns: 1.8em minmax(0, 1fr) 4.5em; }
.ranked li::before { counter-increment: rank; content: counter(rank); color: var(--dim); font-size: .85rem; }
.new-stat { padding: 0 14px 10px; font-size: .9rem; }
.new-stat b { color: var(--ink); font-size: 1.1rem; }

/* column charts */
.chart.compact { min-width: 0; }
.chart .previous { stroke: var(--text); stroke-width: 2; stroke-linecap: round; opacity: .55; }
.chart .band-highlight { fill: rgba(255, 255, 255, .05); }
.previous-key { display: inline-block; width: 14px; height: 0; border-top: 2px solid var(--text); opacity: .55; margin-right: 6px; }
.tooltip .muted { color: var(--muted); }

/* genres */
.genre-rows .bar-row { grid-template-columns: 9em minmax(0, 1fr) 3.5em; }
.genre-rows .bar-row > span:first-child { overflow-wrap: anywhere; }
.genre-compare { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 330px), 1fr)); gap: 14px 28px; }
.genre-name { color: var(--ink); font-weight: 600; margin-bottom: 4px; }
.person-bar { grid-template-columns: 8em minmax(0, 1fr) 3.5em; font-size: .85rem; }
.person-bar > span:first-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.person-bar .bar { height: 10px; }

/* month by month */
.month-row { cursor: pointer; }
.month-row.current, .month-row.current:hover { background: var(--accent-soft) !important; box-shadow: inset 3px 0 var(--accent); }
.inline-bar { display: grid; grid-template-columns: minmax(0, 1fr) 4.5em; align-items: center; gap: 8px; }
.inline-bar span { height: 10px; background: var(--muted); border-radius: 0 4px 4px 0; min-width: 2px; }
.inline-bar b { text-align: right; color: var(--ink); font-weight: 600; }

/* fingerprint */
.metric + .metric { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--rule); }
.metric-head { display: flex; flex-wrap: wrap; gap: 2px 10px; align-items: baseline; margin-bottom: 8px; }
.metric-head b { color: var(--ink); }
.metric-head .muted { font-size: .85rem; }

@media (max-width: 560px) {
  .period-nav { width: 100%; }
  .period-nav select { flex: 1; max-width: none; }
  .view-tabs button { flex: 1; }
  .person-bar { grid-template-columns: 6.5em minmax(0, 1fr) 3.2em; }
}

/* ---------- Dialog ---------- */

.dialog { max-width: min(420px, calc(100vw - 32px)); color: var(--text); background: var(--panel); border: 1px solid var(--rule); border-radius: 12px; padding: 20px; }
.dialog::backdrop { background: rgba(0, 0, 0, .6); }
.dialog h3 { margin: 0 0 8px; color: var(--ink); }
.dialog-buttons { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
