/* ==========================================================================
   Mathematics Genie — ZAZTEK design system
   navy #0B2545 · red #cc0000 · Sora + DM Sans
   ========================================================================== */

:root {
  --navy: #0B2545;
  --navy-2: #163B69;
  --red: #cc0000;
  --red-dark: #a30000;
  --paper: #F5F7FA;
  --surface: #FFFFFF;
  --surface-2: #EEF1F7;
  --text: #16233A;
  --muted: #5C6779;
  --rule: #DCE2EC;
  --ok: #0E7A52;
  --ok-bg: #E6F4EE;
  --warn: #A2660A;
  --warn-bg: #FDF3E2;
  --bad: #B3261E;
  --bad-bg: #FCEEED;
  --info: #215E9E;

  --display: "Sora", system-ui, -apple-system, "Segoe UI", sans-serif;
  --body: "DM Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  --radius: 10px;
  --shadow-sm: 0 1px 2px rgba(11, 37, 69, .06);
  --shadow: 0 1px 2px rgba(11, 37, 69, .06), 0 10px 30px -20px rgba(11, 37, 69, .35);
  --gutter: 20px;
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  /* The toolbar is sticky, so anything scrolled to must clear it — otherwise
     the answer and its verification badge land underneath it. */
  scroll-padding-top: 78px;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--text);
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { font-family: var(--display); color: var(--navy); margin: 0; text-wrap: balance; }
a { color: var(--info); }
button { font-family: inherit; font-size: inherit; }

.wrap { max-width: 1080px; margin-inline: auto; padding-inline: var(--gutter); }

/* ---------------------------------------------------------------- header */
.mg-top {
  background: var(--navy);
  color: #fff;
  border-bottom: 3px solid var(--red);
}
.mg-top .wrap {
  display: flex; align-items: center; gap: 18px;
  padding-block: 14px; flex-wrap: wrap;
}
.mg-brand { display: flex; align-items: center; gap: 11px; text-decoration: none; color: #fff; }
.mg-lamp {
  width: 34px; height: 34px; flex: none;
  display: grid; place-items: center;
  background: var(--red); border-radius: 9px;
  font-size: 18px;
}
.mg-brand b { font-family: var(--display); font-weight: 700; font-size: 1.06rem; letter-spacing: -.01em; }
.mg-brand span { display: block; font-size: .7rem; color: #9EB4D2; letter-spacing: .12em; text-transform: uppercase; font-family: var(--mono); }
.mg-top nav { margin-left: auto; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.mg-top nav a {
  color: #C9D8EC; text-decoration: none; font-size: .88rem;
  padding: 6px 10px; border-radius: 7px;
}
.mg-top nav a:hover { background: rgba(255,255,255,.1); color: #fff; }

/* ---------------------------------------------------------------- toolbar */
.mg-toolbar {
  background: var(--surface); border-bottom: 1px solid var(--rule);
  position: sticky; top: 0; z-index: 20;
}
.mg-toolbar .wrap {
  display: flex; gap: 12px 20px; align-items: center;
  padding-block: 10px; flex-wrap: wrap;
}
.mg-field { display: flex; align-items: center; gap: 8px; }
.mg-field > label {
  font-family: var(--mono); font-size: .68rem; text-transform: uppercase;
  letter-spacing: .1em; color: var(--muted);
}

.mg-seg { display: inline-flex; background: var(--surface-2); border-radius: 8px; padding: 3px; gap: 2px; }
.mg-seg button {
  border: 0; background: transparent; color: var(--muted);
  padding: 6px 11px; border-radius: 6px; cursor: pointer;
  font-size: .85rem; font-weight: 500; white-space: nowrap;
}
.mg-seg button[aria-pressed="true"] { background: var(--surface); color: var(--navy); box-shadow: var(--shadow-sm); }
.mg-seg button:focus-visible { outline: 2px solid var(--info); outline-offset: 1px; }

.mg-quota {
  margin-left: auto; font-family: var(--mono); font-size: .72rem;
  color: var(--muted); text-align: right; line-height: 1.4;
}

/* ---------------------------------------------------------------- layout */
main { padding-block: 24px 60px; }
.mg-grid { display: grid; gap: 20px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 900px) {
  .mg-grid.with-side { grid-template-columns: minmax(0, 1fr) 300px; align-items: start; }
}

.card {
  background: var(--surface); border: 1px solid var(--rule);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
  scroll-margin-top: 78px;
}
.card > header {
  padding: 14px 18px; border-bottom: 1px solid var(--rule);
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.card > header h2 { font-size: 1rem; font-weight: 600; }
.card > .body { padding: 18px; }
.card + .card { margin-top: 20px; }

.hint-text { font-size: .88rem; color: var(--muted); margin: 0; }

/* ---------------------------------------------------------------- tabs */
.mg-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--rule); padding: 6px 6px 0; overflow-x: auto; }
.mg-tabs button {
  border: 0; background: transparent; cursor: pointer;
  padding: 11px 15px; border-radius: 8px 8px 0 0;
  color: var(--muted); font-weight: 500; font-size: .92rem;
  display: flex; align-items: center; gap: 7px; white-space: nowrap;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.mg-tabs button[aria-selected="true"] { color: var(--navy); border-bottom-color: var(--red); }
.mg-tabs button:disabled { opacity: .45; cursor: not-allowed; }
/* A locked tab still opens — it explains itself rather than doing nothing. */
.mg-tabs button.locked { opacity: .6; }
.mg-tabs button.locked::after {
  content: "🔒"; font-size: .8rem; margin-left: 2px;
}
.mg-tabs .ico { font-size: 1.05rem; }

.panel { padding: 18px; }
.panel[hidden] { display: none !important; }

/* ---------------------------------------------------------------- inputs */
math-field {
  display: block; width: 100%;
  font-size: 1.5rem; padding: 14px 16px;
  border: 1px solid var(--rule); border-radius: 9px;
  background: var(--surface);
}
math-field:focus-within { border-color: var(--navy-2); box-shadow: 0 0 0 3px rgba(22, 59, 105, .12); }
math-field[read-only] { background: var(--surface-2); }

.mg-fallback-input {
  display: block; width: 100%; font-family: var(--mono); font-size: 1.1rem;
  padding: 14px 16px; border: 1px solid var(--rule); border-radius: 9px;
}

textarea.mg-prose {
  width: 100%; min-height: 92px; resize: vertical;
  font-family: var(--body); font-size: 1rem; padding: 12px 14px;
  border: 1px solid var(--rule); border-radius: 9px;
}

.chips { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 14px; }
.chip {
  border: 1px solid var(--rule); background: var(--surface);
  border-radius: 999px; padding: 6px 13px; cursor: pointer;
  font-size: .84rem; color: var(--muted);
}
.chip[aria-pressed="true"] { background: var(--navy); border-color: var(--navy); color: #fff; }

.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 16px; }
.row.end { justify-content: flex-end; }

.btn {
  border: 1px solid var(--navy); background: var(--navy); color: #fff;
  border-radius: 9px; padding: 11px 20px; cursor: pointer;
  font-weight: 500; display: inline-flex; align-items: center; gap: 8px;
}
.btn:hover { background: var(--navy-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--red); border-color: var(--red); }
.btn.primary:hover { background: var(--red-dark); }
.btn.ghost { background: transparent; color: var(--navy); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.small { padding: 7px 13px; font-size: .86rem; }
.btn:focus-visible { outline: 2px solid var(--info); outline-offset: 2px; }

select, input[type="text"], input[type="number"], input[type="datetime-local"] {
  font-family: var(--body); font-size: .92rem; padding: 8px 10px;
  border: 1px solid var(--rule); border-radius: 8px; background: var(--surface);
  color: var(--text);
}

/* ---------------------------------------------------------------- camera / ink */
.shot-area {
  border: 2px dashed var(--rule); border-radius: 10px;
  padding: 26px 18px; text-align: center; background: var(--surface-2);
}
.shot-area p { margin: 8px 0 0; color: var(--muted); font-size: .88rem; }
#shotPreview, #inkCanvas { max-width: 100%; border-radius: 9px; border: 1px solid var(--rule); background: #fff; }
#inkCanvas { touch-action: none; cursor: crosshair; width: 100%; height: 220px; }

.mic {
  width: 82px; height: 82px; border-radius: 50%;
  border: 0; background: var(--red); color: #fff; font-size: 1.9rem;
  cursor: pointer; display: grid; place-items: center; margin-inline: auto;
  box-shadow: 0 6px 20px -8px rgba(204, 0, 0, .7);
}
.mic[data-recording="1"] { animation: pulse 1.3s infinite; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(204, 0, 0, .5); }
  50% { box-shadow: 0 0 0 16px rgba(204, 0, 0, 0); }
}
@media (prefers-reduced-motion: reduce) { .mic[data-recording="1"] { animation: none; } }
.level { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; margin: 14px auto 0; max-width: 260px; }
.level i { display: block; height: 100%; width: 0; background: var(--red); transition: width .1s linear; }

/* ---------------------------------------------------------------- gate */
.gate { border-left: 3px solid var(--red); }
.gate .read-back {
  font-size: 1.4rem; padding: 14px 16px; background: var(--surface-2);
  border-radius: 9px; overflow-x: auto;
}

/* ---------------------------------------------------------------- badges */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--mono); font-size: .7rem; text-transform: uppercase;
  letter-spacing: .09em; font-weight: 600;
  padding: 4px 9px; border-radius: 5px;
}
.badge.ok { color: var(--ok); background: var(--ok-bg); }
.badge.warn { color: var(--warn); background: var(--warn-bg); }
.badge.bad { color: var(--bad); background: var(--bad-bg); }
.badge.plain { color: var(--muted); background: var(--surface-2); }

/* ---------------------------------------------------------------- answer */
.answer-box {
  background: linear-gradient(180deg, #fff, var(--surface-2));
  border: 1px solid var(--rule); border-radius: 10px;
  padding: 18px; text-align: center;
}
.answer-box .val { font-size: 1.7rem; overflow-x: auto; padding-block: 4px; }
.answer-box .lab {
  font-family: var(--mono); font-size: .68rem; letter-spacing: .12em;
  text-transform: uppercase; color: var(--muted); display: block; margin-bottom: 8px;
}
.answer-hidden { text-align: center; padding: 22px; color: var(--muted); }

/* ---------------------------------------------------------------- steps */
.steps { list-style: none; margin: 0; padding: 0; counter-reset: step; }
.step {
  display: grid; grid-template-columns: 30px minmax(0, 1fr); gap: 14px;
  padding: 16px 0; border-top: 1px solid var(--rule);
}
.step:first-child { border-top: 0; }
.step .n {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--navy); color: #fff;
  display: grid; place-items: center; font-family: var(--mono);
  font-size: .78rem; font-weight: 600; margin-top: 2px;
}
.step h4 { font-size: .93rem; font-weight: 600; margin-bottom: 5px; }
.step .math { font-size: 1.18rem; margin: 8px 0; overflow-x: auto; padding-block: 3px; }
.step .say { font-size: .95rem; color: var(--text); margin: 0; }
.step .why { font-size: .88rem; color: var(--muted); margin: 6px 0 0; }
.step .mistake {
  margin-top: 10px; font-size: .87rem; color: var(--warn);
  background: var(--warn-bg); border-radius: 7px; padding: 9px 12px;
}
.step .mistake b { color: var(--warn); }

.reveal-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 16px; }
.attempt-box { margin-top: 14px; padding: 14px; background: var(--surface-2); border-radius: 9px; }
.attempt-box p { margin: 0 0 10px; font-size: .9rem; color: var(--muted); }
.hint-out {
  margin-top: 12px; padding: 12px 14px; background: #fff;
  border: 1px dashed var(--rule); border-radius: 8px; font-size: .92rem;
}

/* ---------------------------------------------------------------- plot */
.plot-wrap { margin-top: 6px; overflow-x: auto; }
/* Height is set in script from the panel width (3:2-ish, 260-460px), because a
   frozen 260px was too small to read a curve on a laptop and too tall on a
   phone. The value here is only what shows before the first draw. */
canvas.plot { width: 100%; height: 300px; background: #fff; border: 1px solid var(--rule); border-radius: 9px; display: block; }
.plot-tools { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.plot-btn { font: inherit; font-size: .82rem; padding: 5px 11px; cursor: pointer;
  border: 1px solid var(--rule); border-radius: 7px; background: #fff; color: var(--ink, #0B2545); }
.plot-btn:hover { background: #F3F6FB; }
@media print { .plot-tools { display: none; } }

/* ---------------------------------------------------------------- practice */
.practice { display: grid; gap: 10px; }
.practice-item {
  display: flex; gap: 12px; align-items: center; justify-content: space-between;
  border: 1px solid var(--rule); border-radius: 9px; padding: 11px 14px;
  flex-wrap: wrap;
}
.practice-item .q { font-size: 1.05rem; overflow-x: auto; }

/* ---------------------------------------------------------------- side */
.side .card > .body { padding: 15px; }
.side h3 { font-size: .85rem; font-family: var(--mono); text-transform: uppercase; letter-spacing: .1em; color: var(--muted); font-weight: 600; }
.checklist { list-style: none; margin: 10px 0 0; padding: 0; font-size: .88rem; }
.checklist li { display: flex; gap: 8px; padding: 5px 0; color: var(--muted); }
.checklist li b { color: var(--text); font-weight: 500; }

.history-list { list-style: none; margin: 0; padding: 0; }
.history-list li { padding: 9px 0; border-top: 1px solid var(--rule); font-size: .9rem; }
.history-list li:first-child { border-top: 0; }
.history-list button { border: 0; background: none; padding: 0; cursor: pointer; text-align: left; color: var(--info); font-size: inherit; }

/* ---------------------------------------------------------------- misc */
.msg { padding: 12px 15px; border-radius: 9px; font-size: .92rem; margin-bottom: 14px; }
.msg.err { background: var(--bad-bg); color: var(--bad); }
.msg.info { background: var(--surface-2); color: var(--muted); }
.msg.warn { background: var(--warn-bg); color: var(--warn); }
.msg[hidden] { display: none !important; }

.spinner {
  width: 15px; height: 15px; border: 2px solid rgba(255,255,255,.35);
  border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }

.mg-foot {
  border-top: 1px solid var(--rule); background: var(--surface);
  padding-block: 22px; color: var(--muted); font-size: .85rem;
}
.mg-foot .wrap { display: flex; gap: 14px; justify-content: space-between; flex-wrap: wrap; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* Urdu reads better with a little more line height and a serif-ish face. */
[dir="rtl"], .lang-ur { line-height: 1.9; }
.lang-ur .say, .lang-ur .why { font-size: 1.02rem; }

/* ---------------------------------------------------------------- print */
@media print {
  .mg-top, .mg-toolbar, .mg-tabs, .row, .reveal-row, .side, .mg-foot { display: none !important; }
  body { background: #fff; }
  .card { border: 0; box-shadow: none; }
  .step { break-inside: avoid; }
}

/* The method chooser, shown only for simultaneous equations. */
.mg-chiplabel{font:700 11px ui-monospace,Menlo,monospace;letter-spacing:.12em;
  color:var(--muted);align-self:center;margin-right:.35rem}


/* ---------------------------------------------------------------- concepts
   The "Understand it" panel. Kept visually quieter than the solver: this is
   reading, not doing, and it should feel like a page rather than a console. */
.cc-list { display: grid; gap: 8px; }
.cc-item { display: flex; flex-direction: column; gap: 3px; text-align: left; cursor: pointer;
  padding: 11px 13px; border: 1px solid var(--rule); border-radius: 9px; background: #fff; font: inherit; }
.cc-item:hover { background: #F4F7FC; border-color: #B9C6DC; }
.cc-item-t { font-weight: 650; color: var(--ink, #0B2545); }
.cc-item-s { font-size: .8rem; opacity: .65; }

.cc-card { line-height: 1.62; }
.cc-back { font: inherit; font-size: .84rem; background: none; border: 0; padding: 0 0 10px;
  color: #0a58ca; cursor: pointer; }
.cc-title { font-size: 1.12rem; margin: 0 0 3px; }
.cc-meta { font-size: .8rem; opacity: .65; margin: 0 0 12px; }
.cc-idea { font-size: 1.02rem; font-weight: 600; padding: 11px 13px; border-radius: 9px;
  background: #EEF4FF; border-left: 3px solid #0B2545; margin: 0 0 16px; }
.cc-h { font-size: .95rem; margin: 18px 0 7px; color: var(--ink, #0B2545); }
.cc-recipe { padding-left: 1.3rem; }
.cc-recipe li { margin: .3rem 0; }

.cc-verified { font-size: .8rem; color: #1a7f37; margin: 0 0 12px; }
.cc-stale { font-size: .84rem; color: #9a3412; background: #FFF4ED; border-left: 3px solid #c2410c;
  padding: 9px 12px; border-radius: 7px; margin: 0 0 12px; }

.cc-eg { border: 1px solid var(--rule); border-radius: 9px; padding: 10px 12px; margin: 9px 0; }
.cc-eg-bad { border-color: #f0a882; background: #FFFAF7; }
.cc-eg-q code { font-size: .92rem; }
.cc-eg-a { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .92rem;
  margin-top: 5px; color: #0B2545; }
.cc-eg-n { font-size: .82rem; opacity: .72; margin-top: 5px; }
.cc-eg-warn { font-size: .82rem; color: #9a3412; margin-top: 6px; }
.cc-tag { font-size: .72rem; background: #EEF1F7; border-radius: 5px; padding: 1px 6px; opacity: .8; }
.cc-try, .cc-reveal, .cc-practice { font: inherit; font-size: .8rem; margin-top: 8px; cursor: pointer;
  padding: 5px 11px; border: 1px solid var(--rule); border-radius: 7px; background: #fff; }
.cc-try:hover, .cc-reveal:hover, .cc-practice:hover { background: #F3F6FB; }
.cc-practice { background: #0B2545; color: #fff; border-color: #0B2545; }
.cc-practice:hover { background: #163a63; }

.cc-mistake { background: #FFF7F5; border-left: 3px solid #c62828; padding: 10px 12px;
  border-radius: 7px; font-size: .94rem; }
.cc-check { border: 1px dashed var(--rule); border-radius: 9px; padding: 12px 14px; }
.cc-check-q { font-weight: 600; margin: 0 0 8px; }
.cc-check-a { margin: 8px 0 4px; }
.cc-check-w { font-size: .92rem; opacity: .86; margin: 0; }

/* --- the concept inventory ------------------------------------------- */

/* Where a card came from, next to its topic. Quiet, and never hidden. */
.cc-src { font-style: italic; }

.cc-ask { margin-top: 6px; }
.cc-askbtn {
  margin-top: 6px;
  padding: 9px 14px;
  border: 1px solid var(--line, #d8dee9);
  border-radius: 8px;
  background: #fff;
  font: inherit;
  cursor: pointer;
}
.cc-askbtn:hover:not(:disabled) { background: #f4f7fb; }
.cc-askbtn:disabled { opacity: .6; cursor: default; }
.cc-ask-n { font-size: .8rem; opacity: .7; margin: 8px 0 0; max-width: 56ch; }

/* --- the way out of the module ---------------------------------------- *

   Mathematics Genie sits inside zaztekinternational.com, and until now the
   only route back was a small uppercase line under the logo that reads as a
   tagline. People were using the browser's back button, which does not work
   at all for anybody who arrived on a direct link.

   So: a distinct first item in the nav, and a plain link in the footer for
   whoever has scrolled to the end of a long solution. Bordered rather than
   coloured, so it reads as "leave this module" and not as another page of it.
*/
.mg-top nav a.mg-home {
  border: 1px solid rgba(255,255,255,.34);
  border-radius: 7px;
  font-weight: 600;
}
.mg-top nav a.mg-home:hover {
  background: #fff;
  color: var(--navy, #001f3f);
  border-color: #fff;
}

/* The brand's second line is a link too. It never looked like one. */
.mg-brand a[href="/"]:hover { text-decoration: underline; color: #fff; }

.mg-foot a.mg-foot-home { color: inherit; text-decoration: none; border-bottom: 1px solid currentColor; }
.mg-foot a.mg-foot-home:hover { color: var(--navy, #001f3f); }

@media (max-width: 640px) {
  /* On a phone the nav wraps; the way home must not wrap to the bottom of it. */
  .mg-top nav { width: 100%; }
  .mg-top nav a.mg-home { order: -1; }
}
