/* ---------- theme tokens ---------- */
:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f0f2f7;
  --text: #161a22;
  --muted: #5d6879;
  --line: #e1e5ed;
  --accent: #4263eb;
  --accent-soft: #edf2ff;
  --accent-text: #ffffff;
  --ok: #2b8a3e;
  --ok-soft: #e8f7ec;
  --bad: #c92a2a;
  --bad-soft: #fdecec;
  --warn: #c76a00;
  --warn-soft: #fff3e3;
  --shadow: 0 1px 2px rgb(16 24 40 / .05), 0 1px 3px rgb(16 24 40 / .06);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1f232c;
    --text: #e7eaf0;
    --muted: #98a2b3;
    --line: #2a2f3a;
    --accent: #7b93ff;
    --accent-soft: #1d2440;
    --accent-text: #0b0d12;
    --ok: #63d07b;
    --ok-soft: #132a1b;
    --bad: #ff8a8a;
    --bad-soft: #2f1719;
    --warn: #ffb057;
    --warn-soft: #2e2112;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1f232c;
  --text: #e7eaf0;
  --muted: #98a2b3;
  --line: #2a2f3a;
  --accent: #7b93ff;
  --accent-soft: #1d2440;
  --accent-text: #0b0d12;
  --ok: #63d07b;
  --ok-soft: #132a1b;
  --bad: #ff8a8a;
  --bad-soft: #2f1719;
  --warn: #ffb057;
  --warn-soft: #2e2112;
  --shadow: none;
  color-scheme: dark;
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; line-height: 1.25; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 1.12rem; margin: 0 0 .5rem; }
h3 { font-size: 1rem; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: .86rem; }
.tiny { font-size: .78rem; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: .9rem;
  padding: .65rem 1.25rem;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 750; color: var(--text); margin-right: auto; }
.brand:hover { text-decoration: none; }
.brand-mark {
  display: grid; place-items: center; width: 1.9rem; height: 1.9rem; border-radius: 8px;
  background: var(--accent); color: var(--accent-text); font-size: .8rem; font-weight: 800;
}
.brand-text span { color: var(--accent); }
.crumb { color: var(--muted); font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  display: inline-grid; place-items: center; width: 2.25rem; height: 2.25rem; padding: 0;
  color: var(--text); background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; cursor: pointer;
}
.icon-btn:hover { border-color: var(--accent); }
.icon-btn svg { width: 1.1rem; height: 1.1rem; }
.theme-toggle [data-icon] { display: none; }
.theme-toggle[data-mode="system"] [data-icon="system"],
.theme-toggle[data-mode="light"] [data-icon="light"],
.theme-toggle[data-mode="dark"] [data-icon="dark"] { display: block; }

.progress-line { position: absolute; left: 0; bottom: -1px; height: 3px; background: var(--accent); transition: width .2s; }

/* ---------- layout ---------- */
main { max-width: 1080px; margin: 0 auto; padding: 1.5rem 1.25rem 3rem; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1.15rem 1.25rem; margin-bottom: 1rem;
}
.card.narrow { max-width: 640px; margin-inline: auto; }
.section-title { display: flex; justify-content: space-between; align-items: baseline; margin: 1.6rem 0 .7rem; }
.row { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; }
.mt { margin-top: 1rem; }
.stack { display: grid; gap: 1.25rem; }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .55rem 1.05rem; font: inherit; font-weight: 600; line-height: 1.2;
  color: var(--text); background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; cursor: pointer;
}
.btn:hover { border-color: var(--accent); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.small { padding: .35rem .75rem; font-size: .86rem; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .45; cursor: default; }
.btn:disabled:hover { border-color: var(--line); }

input[type=text], input:not([type]), input[type=number] {
  width: 100%; min-width: 0; padding: .6rem .8rem; font: inherit; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px;
}
input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field { display: grid; gap: .35rem; font-weight: 600; font-size: .92rem; }
.field .hint { font-weight: 400; }

/* ---------- small pieces ---------- */
.pill { display: inline-flex; align-items: center; gap: .3rem; font-size: .76rem; font-weight: 600;
  padding: .12rem .55rem; border-radius: 99px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.accent { background: var(--accent-soft); color: var(--accent); }
.alert { background: var(--warn-soft); color: var(--warn); padding: .6rem .85rem; border-radius: 10px; font-weight: 600; }

.bar { display: flex; height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar > .ok { background: var(--ok); }
.bar > .bad { background: var(--bad); }

/* ---------- dashboard ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: .8rem; margin-bottom: 1.25rem; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: .9rem 1rem; }
.stat b { display: block; font-size: 1.55rem; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: .84rem; }

.course-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 1rem; }
.course-card { display: flex; flex-direction: column; gap: .8rem; margin: 0; }
.course-card h3 a { color: var(--text); }
.course-card .meta { display: flex; gap: .4rem; flex-wrap: wrap; }
.course-card .figures { display: flex; gap: 1.2rem; font-size: .88rem; color: var(--muted); flex-wrap: wrap; }
.course-card .figures b { color: var(--text); font-variant-numeric: tabular-nums; }
.course-card .actions { display: flex; gap: .5rem; margin-top: auto; flex-wrap: wrap; }


.empty { text-align: center; padding: 2.5rem 1rem; }


/* ---------- course page ---------- */
.mode-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: .8rem; }
.mode-card {
  display: grid; gap: .25rem; align-content: start; padding: .95rem 1rem; color: var(--text);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.mode-card:hover { border-color: var(--accent); text-decoration: none; }
.mode-card .mode-top { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.mode-card p { margin: 0; color: var(--muted); font-size: .84rem; }

.week-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: .8rem; }
.week-tile { display: grid; gap: .55rem; padding: .9rem 1rem; margin: 0; }
.week-tile .top { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.week-tile .nums { display: flex; justify-content: space-between; font-size: .82rem; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- quiz setup ---------- */
.choice-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.choice-card { position: relative; display: grid; gap: .15rem; padding: .8rem .95rem .8rem 2.6rem;
  border: 1px solid var(--line); border-radius: 12px; cursor: pointer; background: var(--surface); }
.choice-card:hover { border-color: var(--accent); }
.choice-card input { position: absolute; left: .95rem; top: 1rem; accent-color: var(--accent); }
.choice-card:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.choice-card span { font-size: .82rem; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: .45rem; }
.chip { display: inline-flex; align-items: center; padding: .38rem .8rem; border: 1px solid var(--line);
  border-radius: 99px; cursor: pointer; font-size: .9rem; user-select: none; background: var(--surface); }
.chip:hover { border-color: var(--accent); }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.chip:has(input:checked) { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.legend-row { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: .55rem; }
.legend-row b { font-size: .95rem; }
.link-btn { background: none; border: 0; padding: 0 .2rem; color: var(--accent); font: inherit; font-size: .84rem; cursor: pointer; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
[hidden] { display: none !important; }

/* ---------- question ---------- */
.quiz { display: grid; grid-template-columns: minmax(0, 1fr) 240px; gap: 1.1rem; align-items: start; }
.palette { position: sticky; top: 5rem; }
.q-meta { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .8rem; }
.stem { font-size: 1.08rem; line-height: 1.6; overflow-wrap: anywhere; }
.stem p, .context p { margin: .4rem 0; }
.stem img, .context img, .opt-text img, .explanation img {
  max-width: 100%; height: auto; display: block; margin: .6rem 0; background: #fff; border-radius: 8px; border: 1px solid var(--line); }
.context { background: var(--surface-2); border-left: 3px solid var(--accent); padding: .7rem .95rem; border-radius: 8px; margin-bottom: .8rem; }
.instructions { margin: 0 0 .8rem; }
.instructions summary { cursor: pointer; }
.instructions div { padding: .5rem .2rem 0; }

.options { list-style: none; padding: 0; margin: 1.1rem 0 0; display: grid; gap: .55rem; }
.option {
  display: flex; gap: .75rem; align-items: flex-start; padding: .75rem .9rem;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
}
.option.selectable { cursor: pointer; transition: border-color .12s, background .12s; }
.option.selectable:hover { border-color: var(--accent); }
.option.selectable:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.option input { margin-top: .32rem; accent-color: var(--accent); }
.opt-letter {
  display: inline-grid; place-items: center; flex: none; width: 1.6rem; height: 1.6rem; border-radius: 7px;
  background: var(--surface-2); color: var(--muted); font-weight: 700; font-size: .82rem;
}
.option.selectable:has(input:checked) .opt-letter { background: var(--accent); color: var(--accent-text); }
.opt-text { padding-top: .1rem; }
.option .tag { margin-left: auto; font-size: .78rem; font-weight: 700; white-space: nowrap; padding-top: .15rem; }
.option.right { border-color: var(--ok); background: var(--ok-soft); }
.option.right .tag, .option.right .opt-letter { color: var(--ok); }
.option.wrong { border-color: var(--bad); background: var(--bad-soft); }
.option.wrong .tag, .option.wrong .opt-letter { color: var(--bad); }
.verdict { display: flex; align-items: center; gap: .5rem; font-weight: 700; margin: 1.1rem 0 0; }
.verdict.ok { color: var(--ok); }
.verdict.bad { color: var(--bad); }
.explanation { background: var(--surface-2); padding: .75rem .95rem; border-radius: 10px; margin-top: .8rem; }
.numeric { display: grid; gap: .45rem; margin-top: 1.1rem; font-weight: 600; max-width: 340px; }
.numeric input { font-size: 1.15rem; }
.q-actions { display: flex; justify-content: space-between; align-items: center; gap: .6rem; flex-wrap: wrap; margin-top: 1.1rem; }
.kbd-hint { color: var(--muted); font-size: .78rem; margin: .9rem 0 0; }
kbd { font: .74rem ui-monospace, monospace; padding: .05rem .35rem; border: 1px solid var(--line); border-bottom-width: 2px;
  border-radius: 5px; background: var(--surface-2); }

.dots { display: grid; grid-template-columns: repeat(5, 1fr); gap: .4rem; }
.dot {
  display: inline-grid; place-items: center; height: 2.1rem; font: inherit; font-size: .84rem; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; cursor: pointer; text-decoration: none;
}
.dot:hover { border-color: var(--accent); text-decoration: none; }
.legend .dot { display: inline-block; width: .85rem; height: .85rem; vertical-align: -1px; margin: 0 .25rem 0 .6rem; }
.legend .dot:first-child { margin-left: 0; }
.dot.current { outline: 2px solid var(--accent); outline-offset: 1px; }
.dot.answered, .dot.ok { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }
.dot.bad { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }
.dot.marked { border-color: var(--warn); box-shadow: inset 0 -3px 0 var(--warn); }
.palette-foot { margin-top: 1rem; display: grid; gap: .6rem; }

.timer { font-variant-numeric: tabular-nums; font-weight: 700; padding: .3rem .7rem; border-radius: 8px; background: var(--surface-2); }
.timer.low { color: var(--bad); background: var(--bad-soft); }

/* ---------- results ---------- */
.result-hero { display: grid; grid-template-columns: auto 1fr; gap: 1.5rem; align-items: center; }
.ring { --p: 0; width: 120px; height: 120px; border-radius: 50%; display: grid; place-items: center;
  background: conic-gradient(var(--ring-color, var(--accent)) calc(var(--p) * 1%), var(--surface-2) 0); }
.ring div { width: 92px; height: 92px; border-radius: 50%; background: var(--surface); display: grid; place-items: center; }
.ring b { font-size: 1.6rem; font-variant-numeric: tabular-nums; }
table.plain { width: 100%; border-collapse: collapse; font-size: .92rem; }
.plain th { text-align: left; font-weight: 600; color: var(--muted); font-size: .82rem; }
.plain th, .plain td { padding: .5rem .3rem; border-bottom: 1px solid var(--line); }
.plain tr:last-child td { border-bottom: 0; }
.review { border-left: 4px solid var(--line); }
.review.ok { border-left-color: var(--ok); }
.review.bad { border-left-color: var(--bad); }
.filter-on .review.ok { display: none; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { font: inherit; font-size: .86rem; padding: .35rem .8rem; border: 0; background: var(--surface); color: var(--text); cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); }

/* ---------- static site ---------- */
.bar-extra { display: flex; align-items: center; gap: .6rem; min-width: 0; }
.bar-extra:empty { display: none; }
.sub { margin: .3rem 0 0; }
.title { margin-top: .3rem; }
.setup-title { margin: .4rem 0 1.1rem; }
.flush { margin: 0; }
.score { margin: .2rem 0 .5rem; }
.row.tight { gap: .4rem; }
.mark { gap: .4rem; cursor: pointer; }
.dots { margin-top: .7rem; }
.legend { margin: .8rem 0 0; }
.foot { text-align: center; margin-top: 1.5rem; }
.banner { display: flex; justify-content: space-between; align-items: center; gap: 1rem; border-color: var(--accent); }
.banner .small { margin-top: .15rem; }

/* Question HTML from NPTEL: keep wide tables and code inside the card. */
.opt-text { min-width: 0; overflow-wrap: anywhere; }
.stem table, .context table, .opt-text table, .explanation table, .instructions table {
  display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; margin: .5rem 0; }
.stem td, .stem th, .context td, .context th, .opt-text td, .opt-text th,
.explanation td, .explanation th, .instructions td, .instructions th { border: 1px solid var(--line); padding: .3rem .55rem; }
.stem pre, .context pre, .opt-text pre, .explanation pre { max-width: 100%; overflow-x: auto; }

/* Touch screens: no keyboard hints, roomier buttons. */
@media (hover: none) {
  .kbd-hint { display: none; }
  .btn { min-height: 2.6rem; }
  .btn.small { min-height: 2.25rem; }
}

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .mode-grid { grid-template-columns: repeat(2, 1fr); }
  .quiz { grid-template-columns: 1fr; }
  .palette { position: static; }
  .dots { grid-template-columns: repeat(auto-fill, minmax(2.6rem, 1fr)); }
}
@media (max-width: 560px) {
  main { padding: 1rem 16px 2.5rem; }
  .topbar { padding: .55rem 16px; gap: .6rem; }
  h1 { font-size: 1.35rem; }
  .choice-grid, .fields { grid-template-columns: 1fr; }
  .course-grid { grid-template-columns: 1fr; }
  .result-hero { grid-template-columns: 1fr; justify-items: center; text-align: center; }
  .result-hero .row { justify-content: center; }
  .crumb { display: none; }
  .topbar:has(.bar-extra .pill) .brand-text { display: none; }
  .week-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .stat b { font-size: 1.3rem; }
  .banner { flex-wrap: wrap; }
  .q-actions .row { flex: 1; justify-content: flex-end; }
}
