.viz-root {
  --s-PHY: #2a78d6; --s-CHEM: #eb6834; --s-REV: #1baf7a; --s-BIO: #eda100; --s-MATH: #e87ba4; --s-ENG: #008300;
  --c-top: #2a78d6; --c-rest: #eb6834; --c-one: #2a78d6;
  --grid: #e9e8e4; --axis: #8a8985;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .viz-root {
    --s-PHY: #3987e5; --s-CHEM: #d95926; --s-REV: #199e70; --s-BIO: #c98500; --s-MATH: #d55181; --s-ENG: #008300;
    --c-top: #3987e5; --c-rest: #d95926; --c-one: #3987e5; --grid: #2e2e2b; --axis: #8f8e88;
  }
}
:root[data-theme="dark"] .viz-root {
  --s-PHY: #3987e5; --s-CHEM: #d95926; --s-REV: #199e70; --s-BIO: #c98500; --s-MATH: #d55181; --s-ENG: #008300;
  --c-top: #3987e5; --c-rest: #d95926; --c-one: #3987e5; --grid: #2e2e2b; --axis: #8f8e88;
}

.ihead { display: flex; gap: 16px; align-items: flex-end; justify-content: space-between; padding: 28px 0 8px; flex-wrap: wrap; }
.ihead h1 { margin: 10px 0 6px; font-size: clamp(26px, 4.5vw, 38px); line-height: 1.2; }
.ihead p { margin: 0; color: var(--muted); max-width: 640px; }
.ihead select, .sel { padding: 10px 12px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); font-weight: 600; }
.sel { width: 100%; margin-bottom: 12px; }

.segbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 18px 0 14px; position: sticky; top: 64px; z-index: 10; padding: 8px 0; background: var(--bg); }
.seg { display: inline-flex; padding: 4px; border-radius: 14px; background: var(--surface-2); border: 1px solid var(--border); }
.seg button { border: 0; background: none; padding: 8px 14px; border-radius: 10px; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; }
.seg button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.seg.small button { padding: 6px 10px; font-size: 13px; }
.segnote { color: var(--muted); font-size: 13px; }

.kpis { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 12px 14px; }
.kpi .k { font-size: 12px; color: var(--muted); font-weight: 600; }
.kpi .v { font-size: 24px; font-weight: 700; font-family: "Inter", "Hind Siliguri", sans-serif; }
.kpi .v small { font-size: 13px; color: var(--muted); font-weight: 500; }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 16px; min-width: 0; }
.panel h2 { margin: 0 0 4px; font-size: 18px; }
.ph { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.ph p { margin: 0; color: var(--muted); font-size: 13px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.two .panel { margin-bottom: 16px; }

.insights { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; margin-top: 10px; }
.ins { display: flex; gap: 10px; padding: 12px 14px; border-radius: 14px; background: var(--surface-2); }
.ins .ic { flex: none; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; color: #fff; font-size: 14px; }
.ins.good .ic { background: var(--good); } .ins.bad .ic { background: var(--bad); } .ins.warn .ic { background: var(--warn); } .ins.info .ic { background: var(--c-one); }
.ins b { display: block; margin-bottom: 2px; }
.ins span { font-size: 14px; color: var(--muted); }

.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-bottom: 10px; font-size: 13px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i, .dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; background: var(--c); flex: none; }
.key.top { background: var(--c-top); border-radius: 50%; } .key.rest { background: var(--c-rest); border-radius: 50%; }

/* Exam bars */
.bars { display: grid; gap: 2px; }
.bar { display: grid; grid-template-columns: minmax(180px, 34%) 1fr; gap: 12px; align-items: center; padding: 5px 4px; border-radius: 8px; cursor: default; }
.bar:hover, .bar:focus { background: var(--surface-2); outline: none; }
.bl { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 14px; }
.bl .no { color: var(--muted); font-size: 12px; white-space: nowrap; font-family: "Inter", sans-serif; }
.bl .t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bt { position: relative; height: 18px; margin-right: 52px; }
.bt i { position: absolute; left: 0; top: 2px; bottom: 2px; border-radius: 0 4px 4px 0; background: var(--c); min-width: 2px; }
.bt em { position: absolute; top: -1px; font-style: normal; font-size: 13px; font-weight: 600; font-family: "Inter", sans-serif; color: var(--text); white-space: nowrap; }
.pm { position: absolute; top: -3px; bottom: -3px; width: 0; border-left: 1px solid var(--axis); }
.subj-sep { margin: 10px 0 2px; font-size: 12px; font-weight: 700; color: var(--muted); letter-spacing: .02em; }
.subj-sep:first-child { margin-top: 0; }

/* Subjects */
.subjects { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 10px; }
.sj { padding: 14px; border-radius: 14px; background: var(--surface-2); border-top: 4px solid var(--c); }
.sj .top { display: flex; justify-content: space-between; align-items: baseline; }
.sj b { font-size: 16px; }
.sj .avg { font-size: 22px; font-weight: 700; font-family: "Inter", sans-serif; }
.sj .d { font-size: 13px; color: var(--muted); }
.sj .meter { height: 6px; border-radius: 99px; background: var(--border); margin-top: 8px; overflow: hidden; }
.sj .meter i { display: block; height: 100%; border-radius: 99px; background: var(--c); }

/* Dumbbells */
.dumbbells { display: grid; gap: 2px; }
.db { display: grid; grid-template-columns: minmax(180px, 34%) 1fr; gap: 12px; align-items: center; padding: 6px 4px; border-radius: 8px; }
.db:hover, .db:focus { background: var(--surface-2); outline: none; }
.dt { position: relative; height: 22px; margin: 0 8px; }
.dt::before { content: ""; position: absolute; left: 0; right: 0; top: 50%; border-top: 1px solid var(--grid); }
.dt .min { position: absolute; top: 2px; bottom: 2px; border-left: 2px dashed var(--axis); opacity: .5; }
.dt .ln { position: absolute; top: 50%; height: 2px; margin-top: -1px; background: var(--axis); opacity: .6; }
.dt .d { position: absolute; top: 50%; width: 12px; height: 12px; margin: -6px 0 0 -6px; border-radius: 50%; box-shadow: 0 0 0 2px var(--surface); }
.dt .d.top { background: var(--c-top); } .dt .d.rest { background: var(--c-rest); }
.axis100 { display: grid; grid-template-columns: minmax(180px, 34%) 1fr; gap: 12px; font-size: 11px; color: var(--muted); font-family: "Inter", sans-serif; }
.axis100 div { display: flex; justify-content: space-between; margin: 0 8px; }

/* SVG charts */
.chart { position: relative; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .g line { stroke: var(--grid); stroke-width: 1; }
.chart text { fill: var(--muted); font: 11px "Inter", "Hind Siliguri", sans-serif; }
.chart .ref { stroke: var(--axis); stroke-width: 1; }
.chart .reflab { fill: var(--muted); font-weight: 600; paint-order: stroke; stroke: var(--surface); stroke-width: 5px; }
.chart .bar1 { fill: var(--c-one); }
.chart .bar1.on { opacity: .75; }
.chart .ln1 { fill: none; stroke: var(--c-one); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area1 { fill: var(--c-one); opacity: .1; }
.chart .pt { fill: var(--c-one); stroke: var(--surface); stroke-width: 2; }
.chart .pt.on { r: 6; }
.chart .xh { stroke: var(--axis); stroke-width: 1; opacity: 0; }
.chart .xh.on { opacity: .6; }
.hstats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.hstats div { background: var(--surface-2); border-radius: 10px; padding: 8px 10px; }
.hstats span { display: block; font-size: 12px; color: var(--muted); }
.hstats b { font-family: "Inter", sans-serif; }

/* Table */
.tablewrap { overflow-x: auto; margin: 0 -20px; padding: 0 20px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
th, td { padding: 8px 8px; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
th:nth-child(-n+3), td:nth-child(-n+3) { text-align: left; }
td:nth-child(3) { white-space: normal; min-width: 180px; }
th { color: var(--muted); font-weight: 600; cursor: pointer; user-select: none; position: sticky; top: 0; background: var(--surface); }
th[aria-sort="ascending"]::after { content: " ↑"; } th[aria-sort="descending"]::after { content: " ↓"; }

.tip { position: fixed; z-index: 50; pointer-events: none; max-width: 280px; background: var(--ink); color: #fff; padding: 10px 12px; border-radius: 10px; font-size: 13px; line-height: 1.5; opacity: 0; transition: opacity .1s; }
:root[data-theme="dark"] .tip { background: #2b2b38; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .tip { background: #2b2b38; } }
.tip.on { opacity: 1; }
.tip b { display: block; margin-bottom: 2px; }
.tip small { color: rgba(255, 255, 255, .7); }

@media (max-width: 900px) {
  .kpis { grid-template-columns: repeat(3, 1fr); }
  .two { grid-template-columns: 1fr; gap: 0; }
}
@media (max-width: 720px) {
  .panel { padding: 14px; }
  .tablewrap { margin: 0 -14px; padding: 0 14px; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .subjects { grid-template-columns: 1fr 1fr; }
  .segbar { top: 56px; }
  .seg button { padding: 7px 10px; font-size: 14px; }
  /* bar/dumbbell: label upore, bar niche */
  .bar, .db, .axis100 { grid-template-columns: 1fr; gap: 4px; }
  .axis100 > span { display: none; }
  .hstats { grid-template-columns: 1fr 1fr; }
}
.sj .top { gap: 6px; flex-wrap: wrap; }
@media (max-width: 720px) { .sj { padding: 12px; } .sj .avg { font-size: 18px; } .sj b { font-size: 15px; } }
.bt em { z-index: 1; background: var(--surface); padding: 0 3px; border-radius: 4px; }
.bar:hover .bt em { background: var(--surface-2); }

.key.m { background: var(--c-rest); } .key.t { background: var(--c-top); } .key.a { background: var(--s-REV); }
.sbar { position: relative; height: 18px; margin-right: 52px; display: flex; gap: 2px; }
.sbar i { display: block; height: 100%; min-width: 2px; }
.sbar i:last-of-type { border-radius: 0 4px 4px 0; }
.sbar em { position: absolute; top: -1px; font-style: normal; font-size: 13px; font-weight: 600; font-family: "Inter", sans-serif; white-space: nowrap; }
.funnel { display: grid; gap: 14px; }
.fstep .fl { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 4px; }
.fstep .fl b { font-family: "Inter", sans-serif; }
.fstep .ft { height: 26px; border-radius: 6px; background: var(--surface-2); overflow: hidden; }
.fstep .ft i { display: block; height: 100%; background: var(--c-one); border-radius: 6px; }
.fstep.top .ft i { background: var(--good); }
.fstep .fs { font-size: 12px; color: var(--muted); margin-top: 3px; }
.chart .bub { fill: var(--c-one); fill-opacity: .45; stroke: var(--c-one); stroke-width: 1.5; }
.chart .bub.on { fill-opacity: .85; }
.chart .quad { fill: var(--muted); font-weight: 600; }
