:root {
    --bg: #080c14;
    --surface: #0f1520;
    --surface2: #141c2e;
    --border: rgba(180, 150, 80, 0.15);
    --gold: #c9a84c;
    --gold-light: #e8c97a;
    --text: #e8dcc8;
    --text-muted: rgba(232, 220, 200, 0.5);
    --gryff: #ae0001;
    --slyth: #2a623d;
    --raven: #222f5b;
    --huffe: #f0c75e;
  }

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

  body {
    background: var(--bg);
    background-image:
      radial-gradient(ellipse at 15% 0%, rgba(174,0,1,0.08) 0%, transparent 45%),
      radial-gradient(ellipse at 85% 100%, rgba(34,47,91,0.12) 0%, transparent 45%);
    font-family: 'EB Garamond', serif;
    color: var(--text);
    min-height: 100vh;
  }

  /* ── HEADER ── */
  .header {
    background: linear-gradient(180deg, rgba(12,16,28,0.98) 0%, rgba(8,12,20,0.95) 100%);
    border-bottom: 1px solid var(--border);
    padding: 28px 40px 22px;
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    position: relative;
    overflow: hidden;
  }

  .header::before {
    content: '';
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(
      90deg,
      transparent,
      transparent 80px,
      rgba(201,168,76,0.02) 80px,
      rgba(201,168,76,0.02) 81px
    );
  }

  .header-left { position: relative; z-index: 1; }

  .header-eyebrow {
    font-family: 'Cinzel', serif;
    font-size: 0.65rem;
    letter-spacing: 0.35em;
    color: var(--gold);
    opacity: 0.7;
    text-transform: uppercase;
    margin-bottom: 6px;
  }

  .header h1 {
    font-family: 'Cinzel', serif;
    font-size: clamp(1.4rem, 3vw, 2.2rem);
    font-weight: 900;
    background: linear-gradient(135deg, var(--gold) 0%, var(--gold-light) 50%, var(--gold) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    line-height: 1.1;
    letter-spacing: 0.04em;
  }

  .header-sub {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 5px;
    letter-spacing: 0.05em;
  }

  .header-right {
    position: relative;
    z-index: 1;
    text-align: right;
  }

  .data-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    font-family: 'Cinzel', serif;
    font-size: 0.6rem;
    letter-spacing: 0.15em;
    color: var(--text-muted);
    margin-bottom: 6px;
  }

  .github-link {
    display: inline-block;
    margin-top: 8px;
    padding: 6px 14px;
    background: transparent;
    border: 1px solid var(--gold);
    color: var(--gold);
    border-radius: 4px;
    text-decoration: none;
    font-size: 0.8rem;
    letter-spacing: 0.05em;
    transition: all 0.2s ease;
  }

  .github-link:hover {
    background: var(--gold);
    color: #0d0d1a;
  }

  .author-tag {
    font-size: 0.72rem;
    color: var(--text-muted);
    letter-spacing: 0.1em;
  }

  /* ── FILTER BAR ── */
  .filter-bar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 12px 40px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
  }

  .filter-label {
    font-family: 'Cinzel', serif;
    font-size: 0.6rem;
    letter-spacing: 0.2em;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-right: 4px;
  }

  .pill {
    padding: 5px 14px;
    border: 1px solid rgba(201,168,76,0.2);
    background: transparent;
    color: var(--text-muted);
    font-family: 'Cinzel', serif;
    font-size: 0.62rem;
    letter-spacing: 0.1em;
    cursor: pointer;
    border-radius: 20px;
    transition: all 0.25s;
  }

  .pill:hover { border-color: var(--gold); color: var(--gold); }
  .pill.active { background: rgba(201,168,76,0.12); border-color: var(--gold); color: var(--gold); }
  .pill.g.active { background: rgba(174,0,1,0.2); border-color: var(--gryff); color: #ff6b6b; }
  .pill.s.active { background: rgba(42,98,61,0.2); border-color: var(--slyth); color: #6fcf97; }
  .pill.r.active { background: rgba(34,47,91,0.3); border-color: #4a6fa5; color: #90acda; }
  .pill.h.active { background: rgba(240,199,94,0.1); border-color: var(--huffe); color: var(--huffe); }

  /* ── MAIN LAYOUT ── */
  .canvas {
    padding: 28px 40px;
    display: flex;
    flex-direction: column;
    gap: 20px;
  }

  /* ── CARDS ── */
  .card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 20px 22px;
    position: relative;
    overflow: hidden;
    animation: fadeUp 0.5s ease forwards;
    opacity: 0;
  }

  .card::after {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent, rgba(201,168,76,0.3), transparent);
  }

  .card-title {
    font-family: 'Cinzel', serif;
    font-size: 0.68rem;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--gold);
    opacity: 0.8;
    margin-bottom: 16px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .card-tag {
    font-size: 0.58rem;
    padding: 2px 8px;
    background: rgba(201,168,76,0.08);
    border: 1px solid rgba(201,168,76,0.15);
    border-radius: 2px;
    letter-spacing: 0.15em;
    opacity: 0.7;
  }

  /* ── KPI ROW ── */
  .kpi-row {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 14px;
  }

  .kpi {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 16px 18px;
    position: relative;
    overflow: hidden;
    transition: transform 0.2s, border-color 0.2s;
    animation: fadeUp 0.5s ease forwards;
    opacity: 0;
  }

  .kpi:hover { transform: translateY(-2px); border-color: rgba(201,168,76,0.3); }

  .kpi::before {
    content: '';
    position: absolute;
    bottom: 0; left: 0; right: 0;
    height: 2px;
  }

  .kpi:nth-child(1)::before { background: var(--gryff); }
  .kpi:nth-child(2)::before { background: var(--slyth); }
  .kpi:nth-child(3)::before { background: #4a6fa5; }
  .kpi:nth-child(4)::before { background: var(--huffe); }
  .kpi:nth-child(5)::before { background: var(--gold); }

  .kpi:nth-child(1) { animation-delay: 0.05s; }
  .kpi:nth-child(2) { animation-delay: 0.1s; }
  .kpi:nth-child(3) { animation-delay: 0.15s; }
  .kpi:nth-child(4) { animation-delay: 0.2s; }
  .kpi:nth-child(5) { animation-delay: 0.25s; }

  .kpi-icon { font-size: 1.1rem; margin-bottom: 8px; opacity: 0.8; }

  .kpi-val {
    font-family: 'Cinzel', serif;
    font-size: 1.9rem;
    font-weight: 700;
    color: var(--gold-light);
    line-height: 1;
    margin-bottom: 4px;
  }

  .kpi-lbl {
    font-size: 0.72rem;
    color: var(--text-muted);
    line-height: 1.3;
  }

  /* ── ROW GRIDS ── */
  .row-2  { display: grid; grid-template-columns: 1.6fr 1fr; gap: 20px; }
  .row-3  { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
  .row-2b { display: grid; grid-template-columns: 1fr 1.4fr; gap: 20px; }

  /* ── HORIZONTAL BAR ── */
  .hbar-list { display: flex; flex-direction: column; gap: 9px; }
  .hbar-item { display: flex; align-items: center; gap: 10px; }

  .hbar-name {
    font-size: 0.78rem;
    width: 130px;
    flex-shrink: 0;
    opacity: 0.85;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .hbar-track {
    flex: 1;
    height: 20px;
    background: rgba(255,255,255,0.03);
    border-radius: 2px;
    overflow: hidden;
  }

  .hbar-fill {
    height: 100%;
    border-radius: 2px;
    width: 0%;
    transition: width 1.1s cubic-bezier(0.4,0,0.2,1);
    display: flex;
    align-items: center;
    padding-left: 8px;
    font-family: 'Cinzel', serif;
    font-size: 0.6rem;
    color: rgba(255,255,255,0.7);
  }

  .hbar-num {
    font-family: 'Cinzel', serif;
    font-size: 0.68rem;
    width: 36px;
    text-align: right;
    color: var(--gold);
    flex-shrink: 0;
  }

  /* bar colors — all HP palette */
  .c1 { background: linear-gradient(90deg, rgba(174,0,1,0.75),   rgba(174,0,1,0.4)); }
  .c2 { background: linear-gradient(90deg, rgba(42,98,61,0.75),  rgba(42,98,61,0.4)); }
  .c3 { background: linear-gradient(90deg, rgba(34,47,91,0.85),  rgba(74,111,165,0.5)); }
  .c4 { background: linear-gradient(90deg, rgba(201,168,76,0.6), rgba(232,201,122,0.3)); }
  .c5 { background: linear-gradient(90deg, rgba(174,0,1,0.5),    rgba(201,168,76,0.3)); }
  .cg { background: linear-gradient(90deg, rgba(201,168,76,0.6), rgba(232,201,122,0.3)); }

  /* ── MOVIE BARS — one HP color per film ── */
  .movie-grid { display: flex; flex-direction: column; gap: 11px; }
  .movie-row  { display: flex; align-items: center; gap: 10px; }

  .movie-num {
    font-family: 'Cinzel', serif;
    font-size: 0.6rem;
    width: 20px;
    color: var(--text-muted);
    flex-shrink: 0;
    text-align: center;
  }

  .movie-name {
    font-size: 0.75rem;
    width: 160px;
    flex-shrink: 0;
    opacity: 0.8;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .movie-track {
    flex: 1;
    height: 22px;
    background: rgba(255,255,255,0.03);
    border-radius: 2px;
    overflow: hidden;
  }

  .movie-fill {
    height: 100%;
    width: 0%;
    transition: width 1.2s cubic-bezier(0.4,0,0.2,1);
    border-radius: 2px;
    display: flex;
    align-items: center;
    padding-left: 10px;
    font-family: 'Cinzel', serif;
    font-size: 0.62rem;
    color: rgba(255,255,255,0.8);
  }

  /* Each movie gets a shade within the HP palette */
  .movie-fill.m1 { background: linear-gradient(90deg, #6b0001, #ae0001); } /* deep Gryffindor red */
  .movie-fill.m2 { background: linear-gradient(90deg, #ae0001, #c94040); } /* Gryffindor red bright */
  .movie-fill.m3 { background: linear-gradient(90deg, #1a3d26, #2a623d); } /* deep Slytherin */
  .movie-fill.m4 { background: linear-gradient(90deg, #2a623d, #3d8a57); } /* Slytherin green */
  .movie-fill.m5 { background: linear-gradient(90deg, #161f3a, #222f5b); } /* deep Ravenclaw */
  .movie-fill.m6 { background: linear-gradient(90deg, #222f5b, #4a6fa5); } /* Ravenclaw blue */
  .movie-fill.m7 { background: linear-gradient(90deg, #7a6010, #c9a84c); } /* deep gold */
  .movie-fill.m8 { background: linear-gradient(90deg, #c9a84c, #e8c97a); } /* bright gold */

  /* ── DONUT ── */
  .donut-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 18px;
  }

  .donut-svg-wrap { position: relative; width: 160px; height: 160px; }
  .donut-svg-wrap svg { transform: rotate(-90deg); }

  .donut-center {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
  }

  .donut-center-val {
    font-family: 'Cinzel', serif;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--gold-light);
    line-height: 1;
  }

  .donut-center-lbl {
    font-size: 0.58rem;
    color: var(--text-muted);
    letter-spacing: 0.1em;
    margin-top: 2px;
  }

  .donut-legend { width: 100%; display: flex; flex-direction: column; gap: 7px; }

  .dl-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.75rem;
  }

  .dl-dot   { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
  .dl-name  { flex: 1; opacity: 0.8; font-family: 'Cinzel', serif; font-size: 0.62rem; }
  .dl-val   { color: var(--gold); font-family: 'Cinzel', serif; font-size: 0.65rem; }

  /* ── SPELL TABLE ── */
  .spell-table { width: 100%; border-collapse: collapse; }

  .spell-table th {
    font-family: 'Cinzel', serif;
    font-size: 0.58rem;
    letter-spacing: 0.18em;
    color: var(--gold);
    opacity: 0.7;
    text-align: left;
    padding: 0 0 8px;
    border-bottom: 1px solid var(--border);
  }

  .spell-table td {
    padding: 7px 0;
    font-size: 0.78rem;
    border-bottom: 1px solid rgba(255,255,255,0.03);
    opacity: 0.85;
  }

  .spell-table td:last-child { text-align: right; }

  .spell-type {
    display: inline-block;
    padding: 1px 7px;
    border-radius: 2px;
    font-family: 'Cinzel', serif;
    font-size: 0.58rem;
    letter-spacing: 0.08em;
  }

  /* Spell type badges — full HP palette */
  .type-charm { background: rgba(201,168,76,0.12);  color: #e8c97a; border: 1px solid rgba(201,168,76,0.25); }
  .type-curse { background: rgba(174,0,1,0.15);     color: #ff6b6b; border: 1px solid rgba(174,0,1,0.25); }
  .type-jinx  { background: rgba(42,98,61,0.2);     color: #6fcf97; border: 1px solid rgba(42,98,61,0.3); }
  .type-hex   { background: rgba(34,47,91,0.3);     color: #90acda; border: 1px solid rgba(74,111,165,0.3); }
  .type-trans { background: rgba(240,199,94,0.08);  color: var(--text-muted); border: 1px solid var(--border); }
  .type-other { background: rgba(255,255,255,0.05); color: var(--text-muted); border: 1px solid var(--border); }

  /* ── LINE CHART ── */
  .line-wrap { position: relative; height: 160px; }
  .line-wrap svg { width: 100%; height: 100%; overflow: visible; }

  .animated-path {
    stroke-dasharray: 2000;
    stroke-dashoffset: 2000;
    animation: dash 2s ease forwards;
  }

  .ap2 { animation-delay: 0.3s; }
  .ap3 { animation-delay: 0.6s; }
  .ap4 { animation-delay: 0.9s; }

  @keyframes dash {
    to { stroke-dashoffset: 0; }
  }

  /* ── INSIGHT BOX ── */
  .insight {
    background: rgba(201,168,76,0.04);
    border: 1px solid rgba(201,168,76,0.12);
    border-left: 3px solid var(--gold);
    border-radius: 0 3px 3px 0;
    padding: 12px 14px;
    margin-top: 14px;
  }

  .insight-label {
    font-family: 'Cinzel', serif;
    font-size: 0.58rem;
    letter-spacing: 0.2em;
    color: var(--gold);
    margin-bottom: 5px;
    text-transform: uppercase;
  }

  .insight-text { font-size: 0.78rem; opacity: 0.75; line-height: 1.55; }

  /* ── FOOTER ── */
  .footer {
    margin: 10px 40px 30px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.65rem;
    color: var(--text-muted);
    font-family: 'Cinzel', serif;
    letter-spacing: 0.12em;
  }

  .footer-tools { display: flex; gap: 10px; }

  .tool-chip {
    padding: 3px 9px;
    border: 1px solid var(--border);
    border-radius: 2px;
    font-size: 0.58rem;
    letter-spacing: 0.12em;
  }

  @keyframes fadeUp {
    from { opacity: 0; transform: translateY(16px); }
    to   { opacity: 1; transform: translateY(0); }
  }

  .card:nth-child(1) { animation-delay: 0.3s; }
  .card:nth-child(2) { animation-delay: 0.4s; }
  .card:nth-child(3) { animation-delay: 0.5s; }
  .card:nth-child(4) { animation-delay: 0.6s; }

  @media (max-width: 1100px) {
    .kpi-row { grid-template-columns: repeat(3, 1fr); }
    .row-2, .row-2b { grid-template-columns: 1fr; }
    .row-3 { grid-template-columns: 1fr; }
    .canvas { padding: 20px; }
    .header, .filter-bar, .footer { padding-left: 20px; padding-right: 20px; }
  }

  @media (max-width: 700px) {
    .kpi-row { grid-template-columns: repeat(2, 1fr); }
  }
