/* NEB GPA calculator. One centred column: stream, marks, GPA, in reading
   order. Same palette as the rest of widemath.com (slate greys, WideMath
   green), with a dark version that follows the device setting.
   Every colour is a token below; the dark block only re-points the tokens. */

:root {
  color-scheme: light dark;
  --bg: #f8fafc; --surface: #fff; --field: #fff; --seg-on: #fff;
  --ink: #0f172a; --ink-2: #334155; --muted: #475569; --ink-3: #64748b; --ink-4: #8492a6;
  --line: #e2e8f0; --line-2: #cbd5e1; --field-line: #8492a6; --soft: #f1f5f9;
  --green: #15803d; --green-ink: #166534; --green-soft: #f0fdf4; --green-line: #bbf7d0; --green-hover: #dcfce7;
  --red: #b91c1c; --red-soft: #fef2f2; --red-line: #fca5a5;
  --on-ink: #fff; --ink-hover: #1e293b;
  --card-shadow: 0 4px 16px rgba(15, 23, 42, .05); --pop-shadow: 0 24px 64px rgba(15, 23, 42, .3);
  --backdrop: rgba(15, 23, 42, .45);
  --font: 'Segoe UI', system-ui, -apple-system, 'Nirmala UI', 'Noto Sans Devanagari', sans-serif;
}
@media screen and (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220; --surface: #111a2b; --field: #0c1424; --seg-on: #22304a;
    --ink: #e6ebf2; --ink-2: #cbd5e1; --muted: #aab6c6; --ink-3: #94a3b8; --ink-4: #7d8ba1;
    --line: #1e2a3d; --line-2: #34435a; --field-line: #6a7b98; --soft: #182338;
    --green: #4ade80; --green-ink: #86efac; --green-soft: rgba(34, 197, 94, .10); --green-line: rgba(74, 222, 128, .32); --green-hover: rgba(34, 197, 94, .18);
    --red: #fca5a5; --red-soft: rgba(239, 68, 68, .14); --red-line: rgba(248, 113, 113, .55);
    --on-ink: #0b1220; --ink-hover: #ffffff;
    --card-shadow: 0 1px 0 rgba(255, 255, 255, .03); --pop-shadow: 0 24px 64px rgba(0, 0, 0, .6);
    --backdrop: rgba(2, 6, 15, .7);
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); line-height: 1.6; }
a { color: var(--green); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }

/* ---- nav (matches /blog/) -------------------------------------------- */
.nav { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 40; }
.nav-inner { max-width: 1160px; margin: 0 auto; padding: 12px 24px; display: flex; align-items: center; gap: 16px; }
.nav-logo { font-weight: 700; color: var(--green); }
.nav-links { margin-left: auto; display: flex; gap: 18px; font-size: .85rem; }
.nav-links a { color: var(--muted); font-weight: 500; }
.nav-links a.active { color: var(--green); }

/* ---- header ------------------------------------------------------------ */
header.top { max-width: 720px; margin: 0 auto; padding: 32px 16px 16px; display: flex; gap: 16px; align-items: flex-start; justify-content: space-between; }
header.top h1 { font-size: clamp(1.6rem, 4vw, 1.95rem); line-height: 1.15; letter-spacing: -.02em; margin: 0 0 8px; font-weight: 800; }
header.top p { margin: 0; color: var(--muted); }
.lang { flex: none; border: 1px solid var(--field-line); background: var(--surface); border-radius: 999px; padding: 4px 14px; font-size: .9rem; font-weight: 600; cursor: pointer; transition: background .15s; }
.lang:hover { background: var(--soft); }

/* ---- the card ---------------------------------------------------------- */
.tool { max-width: 720px; margin: 0 auto; padding: 0 16px 48px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 24px; box-shadow: var(--card-shadow); }
.note { display: flex; gap: 12px; align-items: center; justify-content: space-between; background: var(--green-soft); color: var(--green-ink); border-radius: 10px; padding: 8px 8px 8px 16px; margin: 0 0 16px; font-size: .92rem; }
.note.bad { background: var(--red-soft); color: var(--red); }
.note-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px; }
.note .quiet { color: inherit; font-weight: 600; }

/* step 1: stream and input type */
.streams { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; background: var(--soft); border: 1px solid var(--field-line); border-radius: 12px; padding: 3px; }
.streams button { border: 0; background: transparent; border-radius: 9px; min-height: 44px; font-weight: 600; color: var(--muted); cursor: pointer; transition: background .15s, color .15s; }
.streams button:hover { color: var(--ink); }
.streams button[aria-pressed="true"] { background: var(--seg-on); color: var(--green-ink); box-shadow: inset 0 0 0 1.5px var(--green), 0 1px 3px rgba(15, 23, 42, .14); }
.mode { display: flex; align-items: center; justify-content: flex-end; gap: 12px; margin: 16px 0 0; font-size: .9rem; color: var(--ink-3); }
.toggle { display: inline-flex; border: 1px solid var(--field-line); border-radius: 999px; padding: 2px; }
.toggle button { border: 0; background: none; border-radius: 999px; padding: 4px 14px; font-weight: 600; color: var(--muted); cursor: pointer; }
.toggle button[aria-pressed="true"] { background: var(--ink); color: var(--on-ink); }
.hint { color: var(--ink-3); font-size: .9rem; margin: 12px 0 0; }

/* step 2: subjects */
.head, .row { display: grid; grid-template-columns: minmax(0, 1fr) 128px 128px 48px; gap: 4px 12px; align-items: center; }
.head { margin-top: 16px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: .75rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-3); }
.head span:last-child { text-align: center; }
.row { padding: 8px 0; border-bottom: 1px solid var(--line); }
.subj { min-width: 0; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.name { font-weight: 600; line-height: 1.3; }
/* A swappable subject: its name, a chevron and a dashed underline; the real
   <select> covers it invisibly so the native picker opens on tap. */
.pick { position: relative; display: inline-flex; align-items: center; max-width: 100%; padding: 2px 20px 2px 0; border-bottom: 1.5px dashed var(--ink-4); cursor: pointer; transition: border-color .15s; }
.pick::after { content: ''; position: absolute; right: 5px; top: 50%; width: 6px; height: 6px; border-right: 2px solid var(--green); border-bottom: 2px solid var(--green); transform: translateY(-70%) rotate(45deg); pointer-events: none; }
.pick:hover { border-bottom-color: var(--green); }
.pick:focus-within { outline: 2px solid var(--green); outline-offset: 2px; border-radius: 2px; }
.pick-text { font-weight: 600; line-height: 1.3; }
.pick select { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; font-size: 1rem; }
.x { border: 0; background: none; padding: 0; font-size: .8rem; color: var(--ink-3); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.x:hover { color: var(--red); }
.mark { position: relative; display: block; }
.mark input, .f select { width: 100%; height: 44px; border: 1px solid var(--field-line); border-radius: 8px; background: var(--field); color: var(--ink); font-size: 1.05rem; font-variant-numeric: tabular-nums; transition: border-color .15s, box-shadow .15s; }
.mark input { padding: 0 40px 0 12px; }
/* The heading row (desktop) and the caption above each box (phones) name the
   boxes, so the placeholder stays invisible: a label that vanishes on the first
   keystroke is the one kind of label a form should not rely on. */
.mark input::placeholder { color: transparent; }
.f select { padding: 0 8px; font-weight: 600; }
.cap { display: none; }
.mark input:focus, .f select:focus { border-color: var(--green); box-shadow: 0 0 0 3px var(--green-line); outline: none; }
.mark .full { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); color: var(--ink-3); font-size: .85rem; pointer-events: none; }
.mark input.bad, .f select.bad { border-color: var(--red-line); background: var(--red-soft); }
.fg { text-align: center; }
.fg b { display: inline-block; min-width: 40px; border-radius: 8px; padding: 4px 6px; background: var(--soft); color: var(--ink-2); font-size: .95rem; }
.fg b.hi { background: var(--green-soft); color: var(--green-ink); }
.fg b.ng { background: var(--red-soft); color: var(--red); }
.fg b.part { background: none; color: var(--ink-3); box-shadow: inset 0 0 0 1px var(--line-2); } /* only one part typed so far */
.msg { grid-column: 1 / -1; margin: 0; font-size: .82rem; color: var(--red); }
.msg:empty { display: none; }

.more { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 0 0; }
.add { border: 1px dashed var(--green); background: var(--green-soft); color: var(--green-ink); border-radius: 999px; min-height: 40px; padding: 0 16px; font-weight: 600; cursor: pointer; transition: background .15s; }
.add:hover { background: var(--green-hover); }
.quiet { border: 0; background: none; color: var(--ink-3); font-size: .88rem; cursor: pointer; padding: 4px 8px; }
.quiet:hover { color: var(--ink); text-decoration: underline; text-underline-offset: 3px; }

/* step 3: the answer, directly under the marks */
.result { margin: 24px -24px -24px; padding: 24px; border-top: 1px solid var(--green-line); background: var(--green-soft); border-radius: 0 0 16px 16px; }
.r-top { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 16px; }
.r-label { width: 100%; font-size: .8rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--green-ink); }
.r-gpa { font-size: 3.6rem; line-height: 1; font-weight: 800; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.r-grade { font-size: 1.05rem; color: var(--ink-2); }
.r-grade b { background: var(--surface); color: var(--green-ink); border-radius: 8px; padding: 2px 10px; margin-right: 4px; }
.r-note { margin: 12px 0 0; color: var(--ink-2); font-size: .95rem; }
.r-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.btn { min-height: 44px; padding: 0 20px; border-radius: 999px; border: 1px solid var(--ink); background: var(--ink); color: var(--on-ink); font-weight: 600; cursor: pointer; transition: background .15s; }
.btn:hover { background: var(--ink-hover); }
.btn.ghost { background: var(--surface); color: var(--ink); border-color: var(--field-line); }
.btn.ghost:hover { background: var(--soft); }
.result.is-empty { background: var(--soft); border-top-color: var(--line); }
.result.is-empty .r-gpa { color: var(--line-2); }
.result.is-empty .r-label { color: var(--ink-3); }
.result.is-partial .r-gpa { color: var(--ink-2); }
.result.is-ng { background: var(--red-soft); border-top-color: var(--red-line); }
.result.is-ng .r-gpa, .result.is-ng .r-label, .result.is-ng .r-note strong { color: var(--red); }

/* ---- toast & dialog ------------------------------------------------------ */
.toast { position: fixed; left: 50%; bottom: 24px; z-index: 60; display: flex; align-items: center; gap: 12px; max-width: calc(100vw - 32px);
  transform: translate(-50%, 16px); opacity: 0; visibility: hidden; background: var(--ink); color: var(--on-ink); padding: 8px 16px; border-radius: 999px;
  font-size: .9rem; transition: opacity .2s, transform .2s, visibility 0s .2s; pointer-events: none; }
.toast:empty { display: none; }
.toast.on { opacity: 1; transform: translate(-50%, 0); visibility: visible; pointer-events: auto; transition: opacity .2s, transform .2s; }
.toast button { border: 0; background: none; color: inherit; font-weight: 700; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; padding: 4px; }
dialog.add-dlg { border: 0; border-radius: 16px; padding: 0; width: min(560px, calc(100vw - 24px)); max-height: min(680px, calc(100vh - 48px)); background: var(--surface); color: var(--ink); box-shadow: var(--pop-shadow); }
dialog.add-dlg::backdrop { background: var(--backdrop); }
.add-box { padding: 20px 24px 24px; }
.add-top { display: flex; justify-content: space-between; align-items: center; }
.add-top h2 { margin: 0; font-size: 1.2rem; }
.add-search { width: 100%; height: 44px; margin: 12px 0 4px; border: 1px solid var(--field-line); border-radius: 8px; padding: 0 12px; font-size: 1rem; background: var(--field); }
.add-box h3 { font-size: .75rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-3); margin: 16px 0 8px; }
.add-list { display: flex; flex-wrap: wrap; gap: 8px; }
.add-item { border: 1px solid var(--line-2); background: var(--surface); border-radius: 999px; padding: 6px 14px; cursor: pointer; transition: border-color .15s, background .15s; }
.add-item:hover { border-color: var(--green); background: var(--green-soft); }
.custom { margin-top: 8px; padding-top: 4px; border-top: 1px solid var(--line); }
.custom-row { display: flex; gap: 8px; }
.custom-row input { flex: 1; min-width: 0; height: 44px; border: 1px solid var(--field-line); border-radius: 8px; padding: 0 12px; background: var(--field); }
.custom-row select { height: 44px; border: 1px solid var(--field-line); border-radius: 8px; padding: 0 8px; background: var(--field); }

/* ---- explainer -------------------------------------------------------------- */
.guide { max-width: 760px; margin: 0 auto; padding: 16px 16px 72px; }
.guide h2 { font-size: 1.45rem; letter-spacing: -.01em; margin: 48px 0 12px; padding-bottom: 8px; border-bottom: 2px solid var(--line); scroll-margin-top: 80px; }
.guide h3 { font-size: 1.1rem; margin: 28px 0 8px; }
.guide p, .guide li { color: var(--ink-2); }
.guide .lead { font-size: 1.08rem; }
.guide strong { color: var(--ink); }
.table-wrap { overflow-x: auto; margin: 16px 0; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.guide table { width: 100%; border-collapse: collapse; font-size: .9rem; font-variant-numeric: tabular-nums; }
.guide th { background: var(--soft); text-align: left; padding: 8px 12px; font-size: .75rem; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-2); }
.guide td { padding: 8px 12px; border-top: 1px solid var(--line); vertical-align: top; color: var(--ink-2); }
.guide tr.grp td { background: var(--green-soft); color: var(--green-ink); font-weight: 700; font-size: .78rem; letter-spacing: .04em; text-transform: uppercase; }
.formula { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 16px; text-align: center; margin: 16px 0; }
.work { background: var(--green-soft); border: 1px solid var(--green-line); border-radius: 10px; padding: 16px 20px; margin: 16px 0; }
.work p:last-child { margin-bottom: 0; }
code, .code { font-family: ui-monospace, 'Cascadia Mono', Consolas, monospace; font-size: .86em; background: var(--soft); color: var(--ink); border-radius: 4px; padding: 1px 5px; word-break: break-all; }
pre.code { display: block; padding: 12px 16px; white-space: pre-wrap; border: 1px solid var(--line); }
.try { display: inline-block; font-size: .82rem; font-weight: 600; background: var(--green-soft); border: 1px solid var(--green-line); border-radius: 999px; padding: 2px 10px; margin: 2px 4px 2px 0; }
.faq details { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 12px 16px; margin: 8px 0; }
.faq summary { cursor: pointer; font-weight: 600; }
.faq .faq-body { margin: 8px 0 0; color: var(--ink-2); }
footer { border-top: 1px solid var(--line); padding: 32px 24px 48px; text-align: center; font-size: .85rem; color: var(--ink-3); }
footer p { margin: 6px auto; max-width: 820px; }
.tm-disclaimer { font-size: .75rem; color: var(--ink-3); }
#gpa-sheet { display: none; }

/* ---- phones: subject on its own line, the two boxes and the grade below -- */
@media (max-width: 560px) {
  .nav-inner { padding: 12px 16px; }
  .nav-links { gap: 12px; }
  .nav-links .opt { display: none; }
  header.top { padding: 20px 16px 12px; }
  header.top p { font-size: .95rem; }
  .card { padding: 16px; border-radius: 14px; }
  .result { margin: 20px -16px -16px; padding: 20px 16px; border-radius: 0 0 14px 14px; }
  .head { display: none; }
  .row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 48px; grid-template-areas: "subj subj subj" "th pr fg" "msg msg msg"; gap: 8px; }
  .row .subj { grid-area: subj; }
  .row .f.th { grid-area: th; }
  .row .f.in { grid-area: pr; }
  .row .fg { grid-area: fg; }
  .row .msg { grid-area: msg; }
  .cap { display: block; font-size: .75rem; font-weight: 600; color: var(--ink-3); margin: 0 0 2px; }
  .row .fg { align-self: end; padding-bottom: 6px; }
  .mode { justify-content: space-between; }
  .r-gpa { font-size: 3.2rem; }
  .r-actions .btn { flex: 1 1 auto; }
  .custom-row { flex-wrap: wrap; }
  .custom-row input { flex-basis: 100%; }
  .custom-row select, .custom-row .btn { flex: 1; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; scroll-behavior: auto !important; } }

/* ---- print: only the grade sheet, always black on white -------------------- */
@media print {
  @page { size: A4; margin: 16mm; }
  body { background: #fff; color: #000; }
  body > *:not(#gpa-sheet) { display: none !important; }
  #gpa-sheet { display: block !important; color: #000; font-size: 11pt; }
  .ps-head { text-align: center; border-bottom: 2px solid #000; padding-bottom: 8px; margin-bottom: 12px; }
  .ps-brand { margin: 0; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; font-size: 9pt; }
  .ps-head h2 { margin: 4px 0 0; font-size: 15pt; }
  #gpa-sheet table { width: 100%; border-collapse: collapse; margin: 0 0 12px; }
  #gpa-sheet th, #gpa-sheet td { border: 1px solid #000; padding: 4px 8px; text-align: left; color: #000; }
  .ps-meta th { width: 14%; background: #f2f2f2; }
  .ps-meta td { height: 26px; }
  .ps-table th { background: #f2f2f2; font-size: 9pt; text-transform: uppercase; }
  .ps-table td:nth-child(n+2) { text-align: center; }
  .ps-table .fgc { font-weight: 700; vertical-align: middle; }
  .ps-table tfoot td { font-weight: 700; }
  .ps-table tfoot td:first-child { text-align: right; }
  .ps-note { font-size: 8.5pt; color: #333; }
}
