:root {
  --bg: #f6f7fb; --panel: #ffffff; --panel2: #eef1f8; --ink: #161a2b; --muted: #636b85; --line: #dde2ee;
  --brand: #3b5bdb; --brand-ink: #ffffff; --ok: #1f9d55; --ok-bg: #e3f6ea; --bad: #d63a3a; --bad-bg: #fde8e8;
  --warn: #c77700; --warn-bg: #fff3dc; --star: #f0a500; --shadow: 0 1px 2px rgba(20,30,60,.06), 0 4px 16px rgba(20,30,60,.06);
  --img-filter: none;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1220; --panel: #171b2e; --panel2: #1f2440; --ink: #e8eaf4; --muted: #9aa2bf; --line: #2b3152;
    --brand: #7b93ff; --brand-ink: #0f1220; --ok: #4fd18b; --ok-bg: #133325; --bad: #ff7a7a; --bad-bg: #3a1a1f;
    --warn: #ffb547; --warn-bg: #3a2c12; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
    --img-filter: invert(.88) hue-rotate(180deg) contrast(.92);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1220; --panel: #171b2e; --panel2: #1f2440; --ink: #e8eaf4; --muted: #9aa2bf; --line: #2b3152;
  --brand: #7b93ff; --brand-ink: #0f1220; --ok: #4fd18b; --ok-bg: #133325; --bad: #ff7a7a; --bad-bg: #3a1a1f;
  --warn: #ffb547; --warn-bg: #3a2c12; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
  --img-filter: invert(.88) hue-rotate(180deg) contrast(.92);
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 16px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; }
a { color: var(--brand); text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; }
h1, h2, h3 { margin: 0 0 .5em; line-height: 1.25; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; }
.muted { color: var(--muted); }

/* header */
.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 18px; padding: 10px 20px;
  background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); white-space: nowrap; }
.brand small { color: var(--muted); }
.logo { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; font-weight: 800;
  background: linear-gradient(135deg, var(--brand), #9b5de5); color: #fff; }
.tabs { display: flex; gap: 4px; }
.tabs a { padding: 7px 12px; border-radius: 8px; color: var(--muted); font-weight: 600; }
.tabs a.on, .tabs a:hover { background: var(--panel2); color: var(--ink); }
.search { position: relative; margin-left: auto; width: min(340px, 40vw); }
.search input { width: 100%; padding: 8px 12px; border-radius: 9px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); }
.search-results { position: absolute; right: 0; top: 42px; width: min(560px, 92vw); max-height: 70vh; overflow: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 6px; }
.search-results a { display: block; padding: 8px 10px; border-radius: 8px; color: var(--ink); }
.search-results a:hover, .search-results a.sel { background: var(--panel2); }
.search-results small { color: var(--muted); display: block; }
.icon-btn { border: 1px solid var(--line); background: var(--panel); border-radius: 9px; width: 36px; height: 36px; }

main { max-width: 1380px; margin: 0 auto; padding: 22px 20px 80px; }

/* cards & grids */
.hero { display: grid; grid-template-columns: 1.4fr 1fr; gap: 18px; margin-bottom: 22px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 18px; box-shadow: var(--shadow); }
.hero .card h1 { margin-bottom: 6px; }
.quick { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin: 18px 0 26px; }
.quick a { display: block; padding: 14px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); color: var(--ink); box-shadow: var(--shadow); }
.quick a:hover { border-color: var(--brand); }
.quick b { display: block; margin-bottom: 2px; }
.quick small { color: var(--muted); }
.quick .ico { font-size: 1.3rem; display: block; margin-bottom: 6px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }
.tile { display: block; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px; color: var(--ink); box-shadow: var(--shadow); transition: transform .12s, border-color .12s; }
.tile:hover { transform: translateY(-2px); border-color: var(--brand); }
.tile .row { display: flex; align-items: center; gap: 12px; }
.tile h3 { margin: 0; }
.tile .sub { color: var(--muted); font-size: .88rem; }
.bar { height: 7px; background: var(--panel2); border-radius: 9px; overflow: hidden; display: flex; margin-top: 10px; }
.bar i { display: block; height: 100%; }
.bar .ok { background: var(--ok); } .bar .bad { background: var(--bad); }
.ring { --p: 0; width: 46px; height: 46px; border-radius: 50%; flex: none; display: grid; place-items: center; font-size: .75rem; font-weight: 700;
  background: conic-gradient(var(--brand) calc(var(--p) * 1%), var(--panel2) 0); }
.ring span { width: 36px; height: 36px; border-radius: 50%; background: var(--panel); display: grid; place-items: center; }
.crumbs { color: var(--muted); margin-bottom: 12px; font-size: .92rem; }
.crumbs a { color: var(--muted); } .crumbs a:hover { color: var(--brand); }
.list { display: grid; gap: 8px; }
.list a.item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; color: var(--ink); }
.list a.item:hover { border-color: var(--brand); }
.list .grow { flex: 1; min-width: 0; }
.list .cnt { color: var(--muted); font-size: .88rem; white-space: nowrap; }
.mini-bar { width: 120px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 4px 0 16px; }
.chip-btn { border: 1px solid var(--line); background: var(--panel); padding: 6px 12px; border-radius: 999px; font-size: .88rem; }
.chip-btn.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn { border: 1px solid var(--line); background: var(--panel); padding: 9px 16px; border-radius: 10px; font-weight: 600; }
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn:disabled { opacity: .45; cursor: default; }
.years { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.year h3 { font-size: 1.4rem; margin-bottom: 8px; }
.year .papers { display: grid; gap: 6px; }
.year .papers a { display: flex; justify-content: space-between; padding: 8px 10px; border-radius: 9px; background: var(--panel2); color: var(--ink); font-size: .92rem; }
.year .papers a:hover { outline: 1px solid var(--brand); }

/* practice */
.practice { display: grid; grid-template-columns: minmax(0, 1fr) 240px; gap: 18px; align-items: start; }
.qcard { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); overflow: hidden; }
.qhead { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); background: var(--panel2); }
.qhead .qno { font-weight: 800; font-size: 1.1rem; margin-right: 4px; }
.tag { font-size: .78rem; padding: 3px 9px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.tag.flag-out { background: var(--bad-bg); color: var(--bad); border-color: transparent; font-weight: 700; }
.tag.flag-borderline { background: var(--warn-bg); color: var(--warn); border-color: transparent; font-weight: 700; }
.qhead .sp { flex: 1; }
.star { border: none; background: none; font-size: 1.35rem; line-height: 1; color: var(--muted); padding: 0 4px; }
.star.on { color: var(--star); }
.qbody { padding: 18px; overflow-x: auto; }
.qimg { display: block; max-width: none; width: calc(100% * var(--qz, 1)); height: auto; filter: var(--img-filter); cursor: zoom-in; border-radius: 6px; }
.flagnote { margin-top: 10px; font-size: .88rem; padding: 8px 12px; border-radius: 9px; }
.flagnote.out { background: var(--bad-bg); color: var(--bad); } .flagnote.borderline { background: var(--warn-bg); color: var(--warn); }
.answer { padding: 16px 18px; border-top: 1px dashed var(--line); }
.answer .label { font-size: .85rem; color: var(--muted); margin-bottom: 8px; }
.opts { display: flex; flex-wrap: wrap; gap: 10px; }
.opt { width: 76px; height: 60px; border-radius: 12px; border: 2px solid var(--line); background: var(--panel); font-weight: 800; font-size: 1.4rem; }
.opt small { display: block; font-size: .65rem; font-weight: 500; color: var(--muted); }
.opt:hover:not(:disabled) { border-color: var(--brand); }
.opt.picked { border-color: var(--brand); background: var(--panel2); }
.opt.right { border-color: var(--ok); background: var(--ok-bg); color: var(--ok); }
.opt.wrong { border-color: var(--bad); background: var(--bad-bg); color: var(--bad); }
.nat { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.nat input { width: 220px; padding: 12px 14px; font-size: 1.25rem !important; border-radius: 11px; border: 2px solid var(--line); background: var(--bg); color: var(--ink); font-size: 1.05rem; }
.feedback { margin-top: 12px; padding: 12px 16px; border-radius: 10px; font-weight: 700; font-size: 1.15rem; }
.feedback.ok { background: var(--ok-bg); color: var(--ok); } .feedback.bad { background: var(--bad-bg); color: var(--bad); }
.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding: 14px 18px; border-top: 1px solid var(--line); background: var(--panel2); }
.actions .sp { flex: 1; }
.kbd { font-size: .75rem; color: var(--muted); }
.solution { border-top: 1px solid var(--line); padding: 18px; animation: rise .25s ease; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.keybox { display: inline-flex; gap: 10px; align-items: center; padding: 10px 16px; border-radius: 12px; background: var(--ok-bg); color: var(--ok); font-weight: 700; margin-bottom: 12px; font-size: 1.3rem; }
.mm { background: var(--warn-bg); color: var(--warn); padding: 8px 12px; border-radius: 9px; margin-bottom: 12px; font-size: .9rem; }
.credit { font-size: .82rem; color: var(--muted); margin-top: 10px; }
.notes textarea { width: 100%; min-height: 70px; margin-top: 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); padding: 10px; font: inherit; }
.side { position: sticky; top: 74px; display: grid; gap: 14px; }
.side .card { padding: 14px; }
.palette { display: grid; grid-template-columns: repeat(6, 1fr); gap: 5px; max-height: 46vh; overflow: auto; padding: 2px; }
.palette a { display: grid; place-items: center; height: 30px; border-radius: 7px; font-size: .78rem; font-weight: 600; background: var(--panel2); color: var(--ink); position: relative; }
.palette a.ok { background: var(--ok); color: #fff; } .palette a.bad { background: var(--bad); color: #fff; } .palette a.seen { outline: 1px solid var(--muted); }
.palette a.cur { box-shadow: 0 0 0 2px var(--brand); }
.palette a.bm::after { content: ""; position: absolute; top: 2px; right: 2px; width: 6px; height: 6px; border-radius: 50%; background: var(--star); }
.legend { display: flex; flex-wrap: wrap; gap: 8px; font-size: .75rem; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }
.timer { font-variant-numeric: tabular-nums; font-weight: 700; }
.stats-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px; }
.stat b { display: block; font-size: 1.6rem; }
.stat small { color: var(--muted); }
.heat { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
.heat a { padding: 10px; border-radius: 10px; color: var(--ink); text-align: center; font-weight: 700; border: 1px solid var(--line); }
.heat a small { display: block; font-weight: 500; color: var(--muted); }
.mock-result { text-align: center; padding: 26px; }
.mock-result .score { font-size: 3rem; font-weight: 800; color: var(--brand); }
.zoom { position: fixed; inset: 0; background: rgba(0,0,0,.75); display: grid; place-items: center; z-index: 50; cursor: zoom-out; padding: 20px; overflow: auto; }
.zoom img { max-width: 96vw; background: #fff; border-radius: 8px; }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 10px; z-index: 60; font-weight: 600; }
.empty { text-align: center; padding: 40px; color: var(--muted); }
@media (max-width: 900px) {
  .practice { grid-template-columns: 1fr; } .side { position: static; } .hero { grid-template-columns: 1fr; }
  .top { flex-wrap: wrap; gap: 10px; padding: 10px 16px; } .search { width: 100%; order: 5; } main { padding: 16px 16px 70px; }
}

/* text size control */
.zoomctl { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.zoomctl button { border: none; background: var(--panel); padding: 3px 10px; font-weight: 700; }
.zoomctl button:hover { background: var(--panel2); }
.zoomctl span { padding: 3px 8px; font-size: .8rem; color: var(--muted); border-left: 1px solid var(--line); border-right: 1px solid var(--line); min-width: 48px; text-align: center; }

/* calculator */
.calc-btn { border: 1px solid var(--line); background: var(--panel); border-radius: 9px; height: 36px; padding: 0 12px; font-weight: 600; white-space: nowrap; }
.calc-btn.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.calc { position: fixed; top: 64px; right: 20px; z-index: 40; width: 470px; max-width: calc(100vw - 16px); background: #e9edf3; color: #1d2433;
  border: 1px solid #9aa6bb; border-radius: 10px; box-shadow: 0 12px 40px rgba(0,0,0,.35); user-select: none; font-size: 13px; }
.calc-bar { display: flex; align-items: center; gap: 8px; padding: 7px 10px; background: #2f5597; color: #fff; border-radius: 9px 9px 0 0; cursor: move; }
.calc-bar b { flex: 1; font-size: 13px; }
.calc-help { width: 18px; height: 18px; border-radius: 50%; background: rgba(255,255,255,.25); display: grid; place-items: center; font-size: 11px; cursor: help; }
.calc-x { border: none; background: none; color: #fff; font-size: 15px; padding: 0 2px; }
.calc-screen { margin: 10px; background: #fff; border: 1px solid #9aa6bb; border-radius: 4px; padding: 6px 10px; text-align: right; font-family: Consolas, "SF Mono", Menlo, monospace; }
.calc-expr { min-height: 20px; color: #4b556b; font-size: 14px; word-break: break-all; }
.calc-val { font-size: 24px; font-weight: 700; min-height: 32px; word-break: break-all; }
.calc-keys { display: grid; grid-template-columns: repeat(8, 1fr); gap: 5px; padding: 0 10px 10px; }
.calc-keys button { height: 32px; border: 1px solid #a9b3c4; border-radius: 4px; background: linear-gradient(#fdfdfe, #e1e6ee); color: #1d2433; font-size: 12.5px; padding: 0; }
.calc-keys button:hover { border-color: #2f5597; }
.calc-keys button:active { background: #cdd6e4; }
.calc-keys button.num { background: linear-gradient(#ffffff, #eef1f6); font-weight: 700; font-size: 14px; }
.calc-keys button.eq { background: linear-gradient(#4f7ed6, #2f5597); color: #fff; font-weight: 700; grid-column: span 4; }
.calc-keys button.clr { background: linear-gradient(#f6d7d7, #e9b3b3); }
.calc-keys button.on { background: linear-gradient(#8fb0ec, #5f86d4); color: #fff; }
@media (max-width: 900px) { .calc-btn span { display: none; } }

.tag.marks { font-weight: 700; color: var(--ink); }
.tag.marks.m1 { background: color-mix(in srgb, var(--brand) 14%, var(--panel)); border-color: color-mix(in srgb, var(--brand) 40%, var(--line)); }
.tag.marks.m2 { background: color-mix(in srgb, #9b5de5 20%, var(--panel)); border-color: color-mix(in srgb, #9b5de5 50%, var(--line)); }

.lockrow { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-top: 12px; }
#checkBtn:disabled { opacity: .45; }

/* weightage */
.wtab { border-collapse: separate; border-spacing: 3px; font-size: .85rem; width: 100%; }
.wtab th { font-weight: 600; color: var(--muted); padding: 4px 6px; white-space: nowrap; }
.wtab tbody th { text-align: left; } .wtab tbody th a { color: var(--ink); }
.wtab tr.sel th a { color: var(--brand); font-weight: 800; }
.wcell { text-align: center; border-radius: 5px; min-width: 34px; padding: 5px 2px; font-variant-numeric: tabular-nums; }
.wavg { text-align: center; font-weight: 800; padding: 5px 8px; background: var(--panel2); border-radius: 5px; }
/* due today */
.quick a.hot { border-color: var(--warn); box-shadow: 0 0 0 2px var(--warn-bg); }
/* mock statuses (GATE colours) */
.ms { display: inline-grid; place-items: center; min-width: 22px; height: 20px; border-radius: 4px; font-style: normal; font-size: .72rem; font-weight: 700; margin-right: 6px; color: #fff; }
.ms-answered, .mpal a.ms-answered { background: #2e9e4f !important; color: #fff !important; }
.ms-notans, .mpal a.ms-notans { background: #d64545 !important; color: #fff !important; }
.ms-notvis, .mpal a.ms-notvis { background: var(--panel2); color: var(--ink); border: 1px solid var(--line); }
.ms-marked, .mpal a.ms-marked { background: #7048c2 !important; color: #fff !important; border-radius: 50%; }
.ms-ansmarked, .mpal a.ms-ansmarked { background: #7048c2 !important; color: #fff !important; border-radius: 50%; box-shadow: inset 0 -4px 0 #2e9e4f; }
.tag.ms-marked { border-radius: 999px; }
.mlegend { display: grid; gap: 4px; font-size: .78rem; color: var(--muted); margin-top: 8px; }
.btn.mk { border-color: #7048c2; color: #7048c2; }
.sumtab { width: 100%; border-collapse: collapse; margin: 10px 0; } .sumtab td { padding: 6px 4px; border-bottom: 1px solid var(--line); } .sumtab td:last-child { text-align: right; }

/* ---------- phone ---------- */
.drawer-btn, .drawer-close { display: none; }
@media (max-width: 700px) {
  body { font-size: 15px; }
  .top { padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top)); gap: 8px; }
  .brand-txt small { display: none; }
  .tabs { order: 4; width: 100%; overflow-x: auto; scrollbar-width: none; }
  .tabs a { padding: 6px 10px; white-space: nowrap; }
  .search { order: 5; }
  .calc-btn { margin-left: auto; padding: 0 10px; }
  main { padding: 10px 4px calc(96px + env(safe-area-inset-bottom)); }
  .crumbs, h1, h2, .toolbar, .hero, .quick, .grid, .list, .years, .stats-row, .heat { margin-left: 6px; margin-right: 6px; }
  .qcard { border-radius: 10px; }
  h1 { font-size: 1.3rem; } h2 { font-size: 1.1rem; }
  .toolbar { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
  .chip-btn { white-space: nowrap; }
  .tile:hover { transform: none; }
  .quick { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .grid { grid-template-columns: 1fr; gap: 10px; }
  .years { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .list .mini-bar { display: none; }

  .drawer-btn { display: inline-block; padding: 5px 10px; font-size: .85rem; }
  .qhead { padding: 10px 12px; gap: 6px; }
  .qhead .qno { display: none; }
  .qhead .tag { font-size: .72rem; padding: 2px 7px; }
  .zoomctl button { padding: 3px 8px; }
  .qbody { padding: 4px 2px; }
  .zoom { overflow: auto; touch-action: pinch-zoom pan-x pan-y; }
  .zoom img { max-width: none; width: 200vw; }
  .answer { padding: 12px; }
  .opts { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
  .opt { width: auto; height: 58px; }
  .lockrow { margin-top: 10px; } .lockrow .btn { flex: 1; padding: 13px; font-size: 1.05rem; } .lockrow .kbd { width: 100%; }
  .nat input { width: 100%; } .nat .btn { width: 100%; padding: 13px; }
  .feedback { font-size: 1rem; }
  .actions { position: sticky; bottom: 0; z-index: 30; gap: 8px; padding: 10px; padding-bottom: max(10px, env(safe-area-inset-bottom)); box-shadow: 0 -6px 16px rgba(0,0,0,.12); }
  .actions .kbd, .actions .sp { display: none; }
  .actions .btn { flex: 1; padding: 12px 6px; }
  .solution { padding: 12px; }

  /* question list becomes a slide-up drawer */
  .practice { display: block; }
  .side { position: fixed; left: 0; right: 0; bottom: 0; top: auto; z-index: 45; max-height: 78vh; overflow: auto; padding: 10px 10px max(10px, env(safe-area-inset-bottom));
    background: var(--bg); border-radius: 16px 16px 0 0; box-shadow: 0 -10px 40px rgba(0,0,0,.4); transform: translateY(105%); transition: transform .22s ease; }
  body.drawer .side { transform: none; }
  body.drawer::after { content: ""; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 44; }
  .drawer-close { display: inline-block; padding: 4px 10px; font-size: .85rem; }
  .palette { grid-template-columns: repeat(7, 1fr); max-height: 40vh; }
  .palette a { height: 36px; }

  .calc { left: 0 !important; right: 0 !important; top: auto !important; bottom: 0; width: 100%; max-width: none; border-radius: 14px 14px 0 0; padding-bottom: env(safe-area-inset-bottom); }
  .calc-bar { border-radius: 13px 13px 0 0; }
  .calc-keys button { height: 38px; font-size: 12px; }
  .zoom { padding: 6px; place-items: start; }
  .hero .card { padding: 14px; }
}
