:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --ink: #172033;
  --muted: #65738a;
  --line: #d9e1ec;
  --header: #18364f;
  --accent: #d9233f;
  --accent-soft: #fff0f3;
  --blue: #2d6cdf;
  --dot: #8da0b8;
  --shadow: 0 18px 40px rgba(23, 32, 51, 0.08);
  font-family: "Apple SD Gothic Neo", "Helvetica Neue", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

.page-shell {
  width: min(1440px, calc(100vw - 40px));
  margin: 0 auto;
  padding: 28px 0 40px;
}

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

.eyebrow {
  margin: 0 0 8px;
  color: var(--blue);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 30px;
  line-height: 1.2;
  letter-spacing: 0;
}

.subtitle {
  margin-top: 10px;
  max-width: 780px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.as-of {
  min-width: 190px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.as-of span,
.metric-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.as-of strong {
  display: block;
  margin-top: 6px;
  font-size: 16px;
}

.history-bar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(130px, auto) minmax(170px, auto) minmax(140px, auto);
  gap: 12px;
  align-items: end;
  padding: 14px 16px;
  margin-bottom: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.history-bar span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.history-bar strong {
  display: block;
  margin-top: 6px;
  font-size: 16px;
}

#snapshotSelect {
  min-width: 260px;
}

.metric-grid {
  display: grid;
  grid-template-columns: minmax(280px, 2fr) repeat(4, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.metric-card {
  min-height: 84px;
  padding: 14px 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric-card strong {
  display: block;
  margin-top: 8px;
  font-size: 20px;
  line-height: 1.25;
}

.target-card {
  background: var(--accent-soft);
  border-color: #f7bbc5;
}

.target-card strong {
  color: #a50f26;
  font-size: 18px;
}

.comparison-body {
  display: grid;
  grid-template-columns: minmax(360px, 1.35fr) minmax(520px, 2fr);
  gap: 14px;
  align-items: stretch;
  padding: 16px 20px 18px;
}

.report-sentence {
  display: flex;
  align-items: center;
  min-height: 100%;
  padding: 14px 16px;
  border: 1px solid #dce4ef;
  border-radius: 8px;
  background: #f8fafc;
  color: #243246;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.6;
}

.delta-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(128px, 1fr));
  gap: 10px;
  margin-top: 0;
}

.delta-card {
  min-height: 92px;
  padding: 12px 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, #ffffff 0%, #fbfdff 100%);
}

.delta-card span,
.delta-card small {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.delta-card strong {
  display: block;
  margin: 7px 0 5px;
  color: var(--ink);
  font-size: 18px;
  line-height: 1.2;
}

.compare-controls select {
  min-width: 220px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  margin-top: 14px;
}

.panel-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.panel-header h2 {
  font-size: 18px;
  line-height: 1.25;
}

.panel-header p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.chart-panel-header {
  display: block;
  padding: 16px 20px 14px;
}

.chart-title-block {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
}

.chart-title-block p {
  max-width: 520px;
  text-align: right;
}

.chart-toolbar {
  display: grid;
  grid-template-columns: minmax(520px, 1fr) auto;
  gap: 14px;
  align-items: start;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid #edf2f7;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: flex-end;
}

.range-controls {
  justify-content: flex-start;
}

.genre-fieldset {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.genre-accordion {
  position: relative;
}

.genre-accordion summary {
  display: inline-flex;
  align-items: center;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  list-style: none;
}

.genre-accordion summary::-webkit-details-marker {
  display: none;
}

.genre-accordion summary::after {
  content: "▾";
  margin-left: 8px;
  color: #7b8797;
}

.genre-accordion:not([open]) summary::after {
  content: "▸";
}

.genre-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
  margin-top: 6px;
}

.genre-check {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 32px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
  font-size: 12px;
  cursor: pointer;
}

.genre-check:has(input:checked) {
  border-color: #8ab4f8;
  background: #eff6ff;
  color: #174ea6;
  box-shadow: 0 0 0 2px rgba(45, 108, 223, 0.1);
}

.genre-check em {
  min-width: 24px;
  padding: 2px 6px;
  border-radius: 999px;
  background: #edf2f7;
  color: #4b5b70;
  font-style: normal;
  font-size: 11px;
  text-align: center;
}

.genre-check input {
  min-width: 0;
  width: 14px;
  height: 14px;
  margin: 0;
}

.empty-filter {
  display: inline-flex;
  align-items: center;
  height: 36px;
  color: var(--muted);
  font-size: 12px;
}

label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

select,
input {
  display: block;
  min-width: 124px;
  height: 34px;
  margin-top: 5px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
}

.search-box input {
  width: min(320px, 36vw);
}

.chart-wrap {
  position: relative;
  height: 500px;
  padding: 12px 20px 4px;
}

.trend-chart-wrap {
  height: 280px;
  padding: 14px 20px 18px;
}

#dotChart,
#targetTrendChart {
  width: 100%;
  height: 100%;
  display: block;
}

.axis path,
.axis line {
  stroke: #cad3df;
  shape-rendering: crispEdges;
}

.axis text,
.axis-label {
  fill: #526178;
  font-size: 11px;
  font-weight: 700;
}

.grid-line {
  stroke: #e7edf5;
  stroke-width: 1;
}

.axis-title {
  fill: #344154;
  font-size: 11px;
  font-weight: 700;
}

.dot {
  fill: var(--dot);
  opacity: 0.72;
  stroke: #ffffff;
  stroke-width: 1;
  cursor: pointer;
}

.dot:hover {
  opacity: 1;
  stroke: #1f2937;
  stroke-width: 1.5;
}

.genre-glow {
  fill: #2d6cdf;
  opacity: 0.92;
  stroke: #ffffff;
  stroke-width: 1.4;
  filter: drop-shadow(0 0 7px rgba(45, 108, 223, 0.62));
}

.target-halo {
  fill: rgba(217, 35, 63, 0.14);
  stroke: var(--accent);
  stroke-width: 1.5;
}

.target-ghost {
  fill: rgba(217, 35, 63, 0.05);
  stroke: rgba(217, 35, 63, 0.45);
  stroke-width: 1.5;
  stroke-dasharray: 4 3;
}

.target-move-arrow {
  stroke: rgba(217, 35, 63, 0.75);
  stroke-width: 1.6;
  stroke-dasharray: 5 4;
}

.target-star {
  fill: var(--accent);
  font-size: 24px;
  font-weight: 900;
  pointer-events: none;
}

.chart-label {
  fill: #a50f26;
  font-size: 12px;
  font-weight: 800;
  paint-order: stroke;
  stroke: #ffffff;
  stroke-width: 4px;
  stroke-linejoin: round;
}

.trend-line {
  fill: none;
  stroke-width: 2;
}

.views-line,
.views-point {
  stroke: #2563eb;
  fill: #ffffff;
  stroke-width: 2;
}

.rank-line,
.rank-point {
  stroke: #d9233f;
  fill: #ffffff;
  stroke-width: 2;
}

.views-legend {
  fill: #2563eb;
  stroke: #2563eb;
}

.rank-legend {
  fill: #d9233f;
  stroke: #d9233f;
}

.trend-legend {
  font-size: 12px;
  font-weight: 700;
  fill: #344154;
}

.tooltip {
  position: absolute;
  z-index: 10;
  width: 280px;
  padding: 12px 13px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  box-shadow: 0 20px 48px rgba(23, 32, 51, 0.18);
  pointer-events: none;
}

.tooltip strong {
  display: block;
  margin-bottom: 8px;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.3;
}

.tooltip dl {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 5px 8px;
  margin: 0;
  font-size: 12px;
}

.tooltip dt {
  color: var(--muted);
  font-weight: 700;
}

.tooltip dd {
  margin: 0;
  text-align: right;
}

.chart-footnote {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  padding: 10px 20px 16px;
  color: var(--muted);
  font-size: 12px;
  border-top: 1px solid #edf2f7;
}

.table-wrap {
  max-height: 620px;
  overflow: auto;
}

.compact-table {
  max-height: 260px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--header);
  color: #ffffff;
  font-weight: 800;
  white-space: nowrap;
  cursor: pointer;
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid #e4ebf4;
  text-align: right;
  vertical-align: middle;
}

th:first-child,
td:first-child {
  text-align: left;
  min-width: 300px;
}

tbody tr:hover {
  background: #f7faff;
}

tbody tr.target-row {
  background: #fff7d8;
  font-weight: 800;
}

.sort-indicator {
  margin-left: 4px;
  color: #b9d4ff;
}

@media (max-width: 980px) {
  .page-shell {
    width: min(100vw - 24px, 900px);
    padding-top: 18px;
  }

  .report-header,
  .panel-header {
    display: block;
  }

  .as-of {
    margin-top: 14px;
  }

  .metric-grid {
    grid-template-columns: 1fr 1fr;
  }

  .delta-grid {
    grid-template-columns: 1fr 1fr;
  }

  .comparison-body {
    grid-template-columns: 1fr;
  }

  .history-bar {
    grid-template-columns: 1fr;
  }

  .target-card {
    grid-column: 1 / -1;
  }

  .controls {
    margin-top: 14px;
    align-items: flex-start;
  }

  .chart-title-block {
    display: block;
  }

  .chart-title-block p {
    max-width: none;
    text-align: left;
  }

  .chart-toolbar {
    grid-template-columns: 1fr;
  }

  .range-controls {
    margin-top: 0;
  }

  .genre-filters {
    justify-content: flex-start;
  }

  .chart-wrap {
    height: 460px;
    padding-left: 10px;
    padding-right: 10px;
  }

  .trend-chart-wrap {
    height: 260px;
  }
}

@media (max-width: 640px) {
  h1 {
    font-size: 24px;
  }

  .metric-grid {
    grid-template-columns: 1fr;
  }

  .delta-grid {
    grid-template-columns: 1fr;
  }

  .controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .chart-toolbar .controls {
    margin-top: 0;
  }

  .genre-filters {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .genre-check {
    justify-content: space-between;
  }

  select,
  input,
  .search-box input {
    width: 100%;
    min-width: 0;
  }

  .chart-footnote {
    display: block;
  }
}
