:root {
  --bg: #f9f9f7; --surface: #fcfcfb; --ink: #0b0b0b; --ink-2: #52514e; --muted: #6f6d68;
  --grid: #e1e0d9; --axis: #c3c2b7; --ring: rgba(11,11,11,.10);
  --series-1: #00843d; --series-2: #e0352b; --chip: #edf1ec;
  --primary: #00733a; --on-primary: #ffffff;
  --flag-red: #d52b1e; --flag-white: #ffffff; --flag-green: #008a3e;
  --good: #006300; --bad: #c62a22;
  --sans: "IBM Plex Sans Arabic", system-ui, "Segoe UI", Tahoma, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1512; --surface: #16201b; --ink: #f0f2ec; --ink-2: #c4cabf; --muted: #a0a89c;
    --grid: #26332c; --axis: #3b4a41; --ring: rgba(255,255,255,.10);
    --series-1: #2fa56a; --series-2: #cf3a30; --chip: #1f2c25;
    --primary: #1c7d4c; --on-primary: #ffffff;
    --good: #3ec27a; --bad: #f08a80; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--sans); font-size: 16px; line-height: 1.7; }
[hidden] { display: none !important; }
.page {
  max-width: 980px; margin-inline: auto; display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px;
  padding: 32px 16px 48px;
}
h1 { margin: 0; font-size: 2rem; line-height: 1.25; text-wrap: balance; }
h2 { margin: 0; font-size: 1.05rem; }
p { margin: 0; }
.lede { color: var(--ink-2); max-width: 62ch; }
header { display: grid; gap: 6px; }
.panel { background: var(--surface); border: 1px solid var(--ring); border-radius: 8px; padding: 18px; min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.field { display: grid; gap: 6px; }
label { font-weight: 500; }
input {
  font-family: var(--mono); font-size: 1.1rem; padding: 8px 12px;
  border: 1px solid var(--axis); border-radius: 6px; background: var(--bg); color: var(--ink);
}
#seq { width: 100%; }
button { font: inherit; color: var(--ink); cursor: pointer; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips button {
  font-size: .9rem; background: var(--chip); border: 1px solid transparent;
  border-radius: 6px; padding: 5px 10px; min-height: 36px;
  display: inline-flex; align-items: center; gap: 8px;
}
.chips button:hover, .example:hover { border-color: var(--axis); }
.chips button[aria-pressed="true"] { border-color: var(--series-1); box-shadow: inset 0 0 0 1px var(--series-1); }
.chips small { font-family: var(--mono); color: var(--ink-2); font-size: .8rem; }
:focus-visible { outline: 2px solid var(--series-1); outline-offset: 2px; }
.verdict { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.verdict-main { display: grid; gap: 4px; min-width: 0; }
.eyebrow { color: var(--muted); font-size: .85rem; }
#vName { font-size: 1.9rem; font-weight: 700; line-height: 1.3; }
#vFormula { font-family: var(--mono); font-size: 1.25rem; font-weight: 500; text-align: right; overflow-wrap: anywhere; }
#vReturn { font-family: var(--mono); color: var(--ink-2); font-size: .9rem; text-align: right; overflow-wrap: anywhere; }
#vNote { color: var(--ink-2); }
.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; min-width: 0; }
.steps li { display: flex; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--grid); padding-block: 4px; }
.steps li:last-child { border-bottom: 0; }
.state { font-weight: 500; white-space: nowrap; }
.state.yes { color: var(--good); }
.state.no { color: var(--bad); }
.state.skip { color: var(--muted); font-weight: 400; }
.two { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.chart-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.hint { color: var(--ink-2); font-size: .9rem; }
.legend { display: flex; gap: 16px; font-size: .9rem; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.key { display: inline-block; width: 18px; height: 0; border-top: 2px solid var(--series-1); }
.key-next { border-top: 2px dashed var(--series-2); }
.chart { width: 100%; overflow: hidden; }
.chart svg { display: block; width: 100%; direction: ltr; }
.chart text { font-family: var(--mono); font-size: 12px; }
.t-axis { fill: var(--muted); }
.t-label { fill: var(--ink); font-weight: 500; }
.l-grid { stroke: var(--grid); stroke-width: 1; fill: none; }
.l-base { stroke: var(--axis); stroke-width: 1; fill: none; }
.hit { fill: transparent; cursor: pointer; outline: none; }
.hit:focus-visible, .hit:hover { fill: var(--ring); }
.draw { stroke-dasharray: 1; animation: draw .7s ease-out both; }
@keyframes draw { from { stroke-dashoffset: 1; } to { stroke-dashoffset: 0; } }
.empty { color: var(--muted); padding-block: 40px; text-align: center; }
.next-row { color: var(--ink-2); font-size: .95rem; }
.next-row bdi { font-family: var(--mono); color: var(--ink); font-weight: 500; }
.calc-row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
#calcN { width: 110px; }
#gameInput { width: 140px; }
.calc-out { display: flex; flex-wrap: wrap; gap: 8px 32px; margin: 0; margin-inline-start: 12px; min-width: 0; }
.calc-out div { min-width: 0; }
.calc-out dt { color: var(--muted); font-size: .85rem; }
.calc-out dd { margin: 0; font-family: var(--mono); font-size: 1.2rem; font-weight: 500; text-align: right; overflow-wrap: anywhere; }
.tablewrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th { font-weight: 500; color: var(--ink-2); text-align: start; font-size: .9rem; }
th, td { padding: 6px 10px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
td { font-family: var(--mono); }
tr:last-child td { border-bottom: 0; }
.terms { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-start; }
.terms span {
  font-family: var(--mono); font-size: 1.25rem; font-weight: 500; min-width: 56px; text-align: center;
  padding: 8px 10px; border-radius: 6px; background: var(--chip);
}
.terms .blank { background: transparent; border: 2px dashed var(--series-2); padding: 6px 8px; }
.primary { background: var(--primary); color: var(--on-primary); border: 0; border-radius: 6px; padding: 8px 18px; min-height: 40px; font-weight: 500; }
.primary:hover { filter: brightness(1.1); }
#gameResult { min-height: 1.7em; }
#tip {
  position: fixed; z-index: 20; pointer-events: none; background: var(--surface); color: var(--ink);
  border: 1px solid var(--axis); border-radius: 6px; padding: 6px 10px; font-size: .9rem; line-height: 1.5; max-width: 240px;
}
#tip strong { display: block; font-family: var(--mono); font-size: 1rem; }
#tip span { color: var(--ink-2); }
h3 { margin: 0; font-size: 1rem; }
h4 { margin: 8px 0 0; font-size: .9rem; color: var(--ink-2); font-weight: 500; }
select {
  font: inherit; padding: 8px 10px; border: 1px solid var(--axis); border-radius: 6px;
  background: var(--bg); color: var(--ink); min-width: 0;
}
.params { font-family: var(--mono); color: var(--ink-2); }
.law-tools { display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; min-width: 0; }
.work { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; min-width: 0; align-content: start; }
.law-tools > .work, .law-tools > .two { padding-top: 16px; border-top: 1px solid var(--grid); }
.steps-math { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; min-width: 0; overflow-x: auto; }
.steps-math div { text-align: right; padding-block: 2px; }
/* The laws use Arabic symbols, so each equation reads from right to left */
.katex .katex-html { direction: rtl; }
.steps-math div:last-child:not(:first-child) { font-weight: 700; }
.short { width: 96px; }
.tool-grid { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 8px 12px; align-items: center; }
.tool-grid input { width: 100%; }
.laws summary { cursor: pointer; font-weight: 500; }
.laws { min-width: 0; padding-top: 12px; border-top: 1px solid var(--grid); }
.laws > * + * { margin-top: 8px; }
.laws[open] summary { margin-bottom: 8px; }
.laws td { font-family: var(--sans); white-space: normal; min-width: 150px; }
.laws td.law { text-align: right; white-space: nowrap; }
@media (max-width: 680px) {
  .verdict, .two { grid-template-columns: minmax(0, 1fr); }
  h1 { font-size: 1.6rem; }
  .calc-out { margin-inline-start: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .draw { animation: none; stroke-dasharray: none; }
}

/* Tabs, tools and activities */
.flag-stripe {
  height: 12px;
  background: linear-gradient(to bottom,
    var(--flag-red) 0 33.4%, var(--flag-white) 33.4% 66.7%, var(--flag-green) 66.7% 100%);
}
.tabs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.tabs button {
  background: var(--surface); border: 1px solid var(--ring); border-radius: 6px;
  padding: 10px 8px; min-height: 46px; font-weight: 500;
}
.tabs button:hover { border-color: var(--axis); }
.tabs button[aria-selected="true"] { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.tab-panel { display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; min-width: 0; }
.tool-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; align-items: start; }
.tool-list .tool:last-child { grid-column: 1 / -1; }
.law-line { text-align: center; overflow-x: auto; padding-block: 6px; min-width: 0; }
.tool-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.example {
  background: var(--chip); border: 1px solid transparent; border-radius: 6px;
  padding: 5px 10px; min-height: 36px; font-size: .9rem;
}
.hint.error { color: var(--bad); font-weight: 500; }
.work-flow { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; min-width: 0; }
.work-step { display: grid; grid-template-columns: minmax(0, 1fr); gap: 2px; min-width: 0; }
.work-step h4 { margin: 0; }
.work-step + .work-step h4::before { content: "← "; color: var(--muted); }
input[type="range"] { accent-color: var(--primary); padding: 0; border: 0; background: transparent; }
.activity-list { display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; }
.activity b { font-weight: 700; }
.badge { background: var(--chip); color: var(--ink-2); border-radius: 6px; padding: 2px 10px; font-size: .85rem; }
.activity-results { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; min-width: 0; border-top: 1px solid var(--grid); padding-top: 12px; }
.activity-results .calc-out { margin-inline-start: 0; }
.activity-results .calc-out dd { font-family: var(--sans); text-align: start; }
.activity-steps { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; min-width: 0; }
.activity-notes { display: grid; gap: 4px; }
.question { background: var(--chip); border-radius: 6px; padding: 10px 14px; display: grid; gap: 2px; }
.question summary { cursor: pointer; color: var(--ink-2); font-size: .9rem; }
.mural-box { display: flex; justify-content: center; }
.mural { width: 100%; max-width: 260px; display: block; }
.mural-empty { fill: var(--chip); stroke: var(--axis); stroke-width: 1; }
.mural-part { stroke: var(--axis); stroke-width: 1; }
footer { border-top: 1px solid var(--grid); padding-top: 14px; text-align: center; color: var(--ink-2); font-size: .95rem; }
@media (max-width: 680px) {
  .tabs { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tool-list, .activity-steps { grid-template-columns: minmax(0, 1fr); }
}

/* Answers and encouragement */
.cheer-switch { display: inline-flex; align-items: center; gap: 8px; justify-self: start; font-weight: 400; color: var(--ink-2); font-size: .95rem; }
.cheer-switch input { accent-color: var(--primary); width: 18px; height: 18px; margin: 0; }
.answer-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.answer-row input { flex: 1 1 110px; min-width: 0; }
.check {
  background: transparent; border: 1px solid var(--primary); border-radius: 6px;
  padding: 6px 12px; min-height: 40px; font-weight: 500;
}
.check:hover { background: var(--chip); }
.coach { background: var(--chip); border-radius: 6px; padding: 8px 12px; }
.result-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-start; min-width: 0; }
.result-row .work-flow { flex: 1 1 230px; min-width: 0; }
.result-row .work-flow:empty { display: none; }
.result-row .cheer-box { flex: 1 1 170px; max-width: 240px; min-width: 0; }
.cheer {
  position: relative; display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px;
  border: 1px solid var(--axis); border-radius: 8px; padding: 10px 12px; font-size: .95rem; line-height: 1.6;
}
.cheer p { margin: 0; }
.cheer.praise { background: var(--chip); border-color: var(--flag-green); font-weight: 500; animation: cheer-in .35s ease-out both; }
.cheer.plain { color: var(--ink-2); }
.cheer-flag { width: 36px; height: 24px; display: block; outline: 1px solid var(--axis); }
.cheer i {
  position: absolute; top: 18px; inset-inline-start: 24px; width: 6px; height: 6px; border-radius: 1px;
  background: var(--flag-red); opacity: 0; pointer-events: none; animation: cheer-spark .8s ease-out both;
}
.cheer i:nth-of-type(3n) { background: var(--flag-green); }
.cheer i:nth-of-type(3n+1) { background: var(--flag-white); outline: 1px solid var(--axis); }
.cheer i:nth-of-type(1) { --x: -44px; --y: -12px; }
.cheer i:nth-of-type(2) { --x: -22px; --y: -26px; }
.cheer i:nth-of-type(3) { --x: 12px; --y: -28px; }
.cheer i:nth-of-type(4) { --x: 40px; --y: -14px; }
.cheer i:nth-of-type(5) { --x: -36px; --y: 14px; }
.cheer i:nth-of-type(6) { --x: 34px; --y: 16px; }
@keyframes cheer-in { from { transform: scale(.94); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes cheer-spark {
  0% { opacity: 1; transform: translate(0, 0) rotate(0); }
  100% { opacity: 0; transform: translate(var(--x), var(--y)) rotate(160deg); }
}
@media (max-width: 680px) {
  .result-row .cheer-box { max-width: none; flex-basis: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  .cheer.praise { animation: none; }
  .cheer i { display: none; }
}

/* The school band: identity, credits and contact in one horizontal strip.
   Dark green from the flag, gold names and a red badge; it looks the same in light and dark themes */
.school-band {
  --gold: #f6c453;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px 22px;
  padding: 14px clamp(16px, 3vw, 32px);
  color: #fff;
  background:
    radial-gradient(circle at 10% 125%, rgba(213, 43, 30, .32), transparent 42%),
    radial-gradient(circle at 92% -30%, rgba(255, 255, 255, .14), transparent 40%),
    linear-gradient(115deg, #032c18 0%, #05462a 48%, #00733a 100%);
}
.sb-id { display: flex; align-items: center; gap: 12px; }
.sb-logo { width: 68px; height: 68px; border-radius: 50%; background: #fff; padding: 3px; box-shadow: 0 0 0 3px rgba(246, 196, 83, .55), 0 4px 14px rgba(0, 0, 0, .3); flex: none; }
.sb-titles { display: grid; gap: 2px; justify-items: start; }
.sb-gov { margin: 0; font-size: .78rem; color: rgba(255, 255, 255, .8); }
.sb-gov i { font-style: normal; color: var(--gold); padding: 0 2px; }
.sb-school { margin: 0; font-size: 1.3rem; font-weight: 700; line-height: 1.35; }
.sb-pill { font-size: .78rem; font-weight: 700; padding: 1px 12px; border-radius: 999px; background: #d52b1e; color: #fff; }
.sb-credits { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.sb-credits li { display: grid; justify-items: center; padding: 4px 11px 2px; border-radius: 12px; background: rgba(255, 255, 255, .08); border: 1px solid rgba(255, 255, 255, .14); }
.sb-credits li.sb-lead { background: rgba(246, 196, 83, .14); border-color: rgba(246, 196, 83, .45); }
.sb-credits span { font-size: .7rem; color: rgba(255, 255, 255, .75); white-space: nowrap; }
.sb-credits b { font-family: "Aref Ruqaa", var(--sans); font-weight: 700; font-size: 1.05rem; color: var(--gold); white-space: nowrap; line-height: 1.6; }
.sb-contact { display: grid; gap: 6px; justify-items: end; }
.sb-contact a { display: inline-flex; align-items: center; gap: 7px; color: #fff; text-decoration: none; font-size: .88rem; padding: 3px 10px; border-radius: 8px; background: rgba(255, 255, 255, .1); }
.sb-contact a:hover { background: rgba(255, 255, 255, .2); }
.sb-contact a:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.sb-contact svg { width: 15px; height: 15px; fill: var(--gold); flex: none; }
@media (max-width: 1700px) {
  .school-band { grid-template-columns: minmax(0, 1fr) auto; }
  .sb-credits { grid-column: 1 / -1; grid-row: 2; }
}
@media (max-width: 700px) {
  .school-band { grid-template-columns: minmax(0, 1fr); padding: 12px 16px; }
  .sb-contact { justify-items: start; grid-auto-flow: column; justify-content: start; overflow-x: auto; }
  .sb-credits { flex-wrap: nowrap; justify-content: flex-start; overflow-x: auto; scroll-snap-type: x mandatory; padding-bottom: 4px; }
  .sb-credits li { scroll-snap-align: start; }
  .sb-school { font-size: 1.15rem; }
}
@media print { .school-band { display: none; } }
