/* Fonts are hosted with the site (SIL Open Font License; see assets/fonts/). */
@font-face { font-family: "Chakra Petch"; font-weight: 600; font-display: swap; src: url("/assets/fonts/chakra-petch-latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: "Chakra Petch"; font-weight: 700; font-display: swap; src: url("/assets/fonts/chakra-petch-latin-700-normal.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Sans"; font-weight: 400; font-display: swap; src: url("/assets/fonts/ibm-plex-sans-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Sans"; font-weight: 600; font-display: swap; src: url("/assets/fonts/ibm-plex-sans-latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Sans"; font-weight: 700; font-display: swap; src: url("/assets/fonts/ibm-plex-sans-latin-700-normal.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Mono"; font-weight: 400; font-display: swap; src: url("/assets/fonts/ibm-plex-mono-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Mono"; font-weight: 600; font-display: swap; src: url("/assets/fonts/ibm-plex-mono-latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: "Atkinson Hyperlegible"; font-weight: 400; font-display: swap; src: url("/assets/fonts/atkinson-hyperlegible-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "Atkinson Hyperlegible"; font-weight: 700; font-display: swap; src: url("/assets/fonts/atkinson-hyperlegible-latin-700-normal.woff2") format("woff2"); }

:root {
  color-scheme: light dark;
  --font-body: "IBM Plex Sans", system-ui, sans-serif;
  --font-display: "Chakra Petch", "IBM Plex Sans", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, Consolas, monospace;
  --bg: #eef0f8;
  --card: #ffffff;
  --text: #141838;
  --muted: #4d5478;
  --accent: #27348f;
  --accent-text: #ffffff;
  --link: #2b3ba6;
  --border: #c6cbe2;
  --soft: #e2e5f4;
  --band: rgb(226 229 244 / 0.75);
  /* Run buttons and other main actions. A chosen accent colour replaces it. */
  --ignite: #ff8c26;
  --action: var(--ignite);
  --action-text: #201000;
  --pass: #156b34;
  --fail: #b3261e;
  --edge: 0.75rem;
  --cut: 0.7rem;
  --grid: rgb(39 52 143 / 0.08);
  --star-white: rgb(104 114 156 / 0.6);
  --star-blue: rgb(45 88 214 / 0.75);
  --star-yellow: rgb(206 142 0 / 0.85);
  --star-orange: rgb(224 104 12 / 0.75);
  --star-red: rgb(194 52 32 / 0.65);
  --planet-glow: 0.9;
  --viz-bar: #257de0;
  --day-0: #e2e5f4;
  --day-1: #b6d5f8;
  --day-2: #6aabf1;
  --day-3: #257de0;
  --day-4: #1757ac;
  /* Mercury to Neptune, then Pluto: the colour strip and the topic colours. */
  --mercury: #9c9a97;
  --venus: #e6bd6a;
  --earth: #3f7fd8;
  --mars: #d1552f;
  --jupiter: #d49457;
  --saturn: #e0c97f;
  --uranus: #6fcdd4;
  --neptune: #3d55cf;
  --pluto: #c7a188;
  --spectrum: linear-gradient(90deg, var(--mercury) 0 11.1%, var(--venus) 0 22.2%, var(--earth) 0 33.3%, var(--mars) 0 44.4%,
    var(--jupiter) 0 55.5%, var(--saturn) 0 66.6%, var(--uranus) 0 77.7%, var(--neptune) 0 88.8%, var(--pluto) 0);
}
:root[data-font="readable"] { --font-body: "Atkinson Hyperlegible", system-ui, sans-serif; --font-display: "Atkinson Hyperlegible", system-ui, sans-serif; }
:root[data-font="system"] { --font-body: system-ui, Arial, sans-serif; --font-display: system-ui, Arial, sans-serif; --font-mono: ui-monospace, Consolas, monospace; }

/* Accent colours a signed-in demo user can choose. */
:root[data-accent="teal"] { --accent: #0f766e; --link: #0f766e; --action: #0f766e; --action-text: #ffffff; --accent-text: #ffffff; }
:root[data-accent="purple"] { --accent: #6d28d9; --link: #6d28d9; --action: #6d28d9; --action-text: #ffffff; --accent-text: #ffffff; }
:root[data-accent="orange"] { --accent: #b45309; --link: #9a4707; --action: #b45309; --action-text: #ffffff; --accent-text: #ffffff; }
:root[data-accent="pink"] { --accent: #be185d; --link: #be185d; --action: #be185d; --action-text: #ffffff; --accent-text: #ffffff; }

/* Dark theme: follows the device unless a theme has been chosen. */
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"]))[data-accent="teal"] { --link: #5eead4; }
  :root:where(:not([data-theme="light"]))[data-accent="purple"] { --link: #c4b5fd; }
  :root:where(:not([data-theme="light"]))[data-accent="orange"] { --link: #fdba74; }
  :root:where(:not([data-theme="light"]))[data-accent="pink"] { --link: #f9a8d4; }
  :root:where(:not([data-theme="light"])) {
    --bg: #0a0d22;
    --card: #131833;
    --text: #eceefb;
    --muted: #a7add0;
    --accent: #97a6ff;
    --accent-text: #0a0d22;
    --link: #a5b4ff;
    --border: #2d3564;
    --soft: #1c2249;
    --band: rgb(28 34 73 / 0.72);
    --ignite: #ff9d42;
    --pass: #6fd18f;
    --fail: #ff8a80;
    --grid: rgb(151 166 255 / 0.09);
    --star-white: rgb(255 255 255 / 0.85);
    --star-blue: rgb(155 176 255 / 0.9);
    --star-yellow: rgb(255 224 130 / 0.9);
    --star-orange: rgb(255 178 107 / 0.85);
    --star-red: rgb(255 128 104 / 0.8);
    --planet-glow: 0.95;
    --viz-bar: #338ced;
    --day-0: #22284e;
    --day-1: #0e3d7e;
    --day-2: #1b64be;
    --day-3: #338ced;
    --day-4: #84b9f3;
  }
}
:root:where([data-theme="dark"])[data-accent="teal"] { --link: #5eead4; }
:root:where([data-theme="dark"])[data-accent="purple"] { --link: #c4b5fd; }
:root:where([data-theme="dark"])[data-accent="orange"] { --link: #fdba74; }
:root:where([data-theme="dark"])[data-accent="pink"] { --link: #f9a8d4; }
:root:where([data-theme="dark"]) {
  --bg: #0a0d22;
  --card: #131833;
  --text: #eceefb;
  --muted: #a7add0;
  --accent: #97a6ff;
  --accent-text: #0a0d22;
  --link: #a5b4ff;
  --border: #2d3564;
  --soft: #1c2249;
  --band: rgb(28 34 73 / 0.72);
  --ignite: #ff9d42;
  --pass: #6fd18f;
  --fail: #ff8a80;
  --grid: rgb(151 166 255 / 0.09);
  --star-white: rgb(255 255 255 / 0.85);
  --star-blue: rgb(155 176 255 / 0.9);
  --star-yellow: rgb(255 224 130 / 0.9);
  --star-orange: rgb(255 178 107 / 0.85);
  --star-red: rgb(255 128 104 / 0.8);
  --planet-glow: 0.95;
  --viz-bar: #338ced;
  --day-0: #22284e;
  --day-1: #0e3d7e;
  --day-2: #1b64be;
  --day-3: #338ced;
  --day-4: #84b9f3;
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

/* Large screens: all sizes below are in rem, so the whole interface scales with this. */
@media (min-width: 1600px) and (min-height: 850px) {
  :root { font-size: clamp(16px, 0.9vw, 32px); }
}
/* Detected televisions (see tv.js): larger text and a margin for screens that crop edges. */
:root[data-tv] {
  font-size: clamp(20px, 1.3vw, 50px);
  --edge: 2.5vw;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
:focus-visible { outline: 0.2rem solid var(--link); outline-offset: 0.15rem; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: var(--font-body);
  line-height: 1.55;
  background: transparent;
  color: var(--text);
}
html { background: var(--bg); }

a { color: var(--link); }
h1 { font-size: 1.9rem; line-height: 1.15; }
h2 { font-size: 1.25rem; line-height: 1.25; }
h3 { line-height: 1.3; }
h1, h2, h3, .brand { font-family: var(--font-display); font-weight: 700; }
main { flex: 1; width: 100%; max-width: 48rem; margin: 0 auto; padding: 1.5rem var(--edge) 3rem; }

.icon {
  width: 1.15em;
  height: 1.15em;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
i[data-icon] { display: inline-flex; }

/* Header: one line. Footer: a calm site map. Both are built from the same pages. */
.brand { display: flex; align-items: center; gap: 0.45rem; text-decoration: none; color: var(--text); white-space: nowrap; }
.brand .icon { color: var(--mars); width: 1.5em; height: 1.5em; }
.demo { padding: 0.05rem 0.5rem; border: 1px solid var(--border); font: 0.7rem/1.5 var(--font-mono); text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); white-space: nowrap; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }

.topbar {
  position: relative;
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 1rem;
  padding: 0.5rem var(--edge) calc(0.5rem + 3px);
  background: var(--card);
}
.topbar::after, .sitemap::before { content: ""; position: absolute; inset: auto 0 0; height: 3px; background: var(--spectrum); }
.topbar ul { list-style: none; margin: 0; padding: 0; }
.primary ul { display: flex; gap: 0.1rem; }
.extras { display: flex; align-items: center; gap: 0.5rem; margin-left: auto; }
.primary a, .menu summary, .account {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.6rem;
  font-family: var(--font-display);
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}
.primary a:hover, .menu summary:hover, .account:hover { background: var(--soft); color: var(--text); }
.primary a[aria-current="page"], .menu.current summary, .account[aria-current="page"] { color: var(--text); box-shadow: inset 0 -0.2rem 0 var(--ignite); }
.account { border: 1px solid var(--border); color: var(--text); height: 2.4rem; }
.account span:last-child { max-width: 9rem; overflow: hidden; text-overflow: ellipsis; }
/* The theme and language buttons are always the same size, in the header and the footer. */
.menu.display > summary, .menu.languages > summary { width: 6.75rem; height: 2.4rem; justify-content: space-between; border: 1px solid var(--border); font-size: 0.9rem; }
.burger { display: none; }
.topbar.compact { gap: 0.5rem; }
.topbar.compact .primary { display: none; }
.topbar.compact .burger { display: block; }
/* No room: the language choice and demo label move into the menu button. */
.topbar.compact .extras > .demo, .topbar.compact .extras > .languages, .topbar.compact .extras > .display { display: none; }
.topbar.compact .brand { white-space: normal; line-height: 1.2; min-width: 0; }
.topbar.compact .account span:last-child:not(.avatar) { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.topbar.compact .extras { gap: 0.3rem; }

.menu { position: relative; margin: 0; }
.menu summary { list-style: none; }
.menu summary::-webkit-details-marker { display: none; }
.menu[open] summary > .icon:last-child:not(:only-of-type) { transform: rotate(180deg); }
.drop {
  position: absolute;
  top: calc(100% + 0.4rem);
  left: 0;
  z-index: 20;
  min-width: 13rem;
  max-height: 75vh;
  overflow-y: auto;
  padding: 0.35rem;
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: 0 0.75rem 2rem rgb(0 0 0 / 0.25);
}
.drop.end { left: auto; right: 0; }
.drop a, .drop button {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  min-height: 2.3rem;
  padding: 0.4rem 0.6rem;
  border: 0;
  background: transparent;
  box-shadow: none;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}
.drop a:hover, .drop button:hover, .drop a[aria-current="page"] { background: var(--soft); }
.drop p { margin: 0.4rem 0.6rem 0.15rem; font-size: 0.75rem; color: var(--muted); max-width: 14rem; }

.sitemap { position: relative; background: #0c1029; color: #b3bade; padding: 2.75rem var(--edge) 1.25rem; }
.sitemap::before { inset: 0 0 auto; }
.sitemap > div { max-width: 72rem; margin-inline: auto; }
.sitemap .columns { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 2rem; }
.sitemap .lead { display: flex; flex-direction: column; align-items: flex-start; gap: 0.7rem; max-width: 19rem; font-size: 0.9rem; }
.sitemap p { margin: 0; }
.sitemap .brand, .sitemap .brand .icon { color: #ffffff; }
.sitemap .demo { color: #b3bade; border-color: #3a437a; }
.sitemap a { color: #c9d1ff; }
.sitemap nav { display: grid; grid-template-columns: repeat(5, minmax(6rem, auto)); gap: 1.5rem 2.75rem; align-content: start; }
.sitemap h2 { margin: 0 0 0.6rem; font-size: 0.8rem; color: #ffffff; text-transform: uppercase; letter-spacing: 0.08em; }
.sitemap ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.55rem; }
.sitemap nav a { display: inline-flex; align-items: center; gap: 0.4rem; color: #b3bade; text-decoration: none; font-size: 0.9rem; }
.sitemap nav a:hover, .sitemap nav a[aria-current="page"] { color: #ffffff; text-decoration: underline; text-underline-offset: 0.3rem; }
.sitemap .legal { display: flex; flex-direction: column; gap: 0.4rem; margin-top: 2rem; padding-top: 1rem; border-top: 1px solid #272f5c; font-size: 0.8rem; }
.sitemap .legal strong { color: #ffffff; font-weight: 600; }
.sitemap .baseline { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 0.6rem; margin-top: 1rem; }
.sitemap .menu summary, .sitemap .link-button { color: #dfe3fa; border-color: #3a437a; background: transparent; }
.sitemap .menu summary:hover, .sitemap .link-button:hover { background: #1b2150; color: #ffffff; }
.sitemap .drop { top: auto; bottom: calc(100% + 0.4rem); }
.sitemap .drop a { color: var(--text); }

/* Buttons */
.button, button, select, input[type="number"] {
  font: inherit;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
}
.button, button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-height: 2.4rem;
  padding: 0.4rem 1rem;
  font-family: var(--font-display);
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.button, button.primary, .segmented, .card, .joined, .problem, .notice { border-radius: var(--cut) 0.15rem; corner-shape: bevel; }
.button:hover, button:hover:not(:disabled) { border-color: var(--link); background: var(--soft); }
.button.primary, button.primary { background: var(--action); border-color: var(--action); color: var(--action-text); box-shadow: inset 0 -0.2rem 0 rgb(0 0 0 / 0.2); }
.button.primary:hover, button.primary:hover:not(:disabled) { background: var(--action); border-color: var(--action); filter: brightness(1.08); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
.icon-button { width: 2.5rem; height: 2.5rem; padding: 0; }
.link-button { font-size: 0.9rem; }
select, input[type="number"] { min-height: 2.4rem; padding: 0.4rem 0.5rem; background: var(--bg); }

/* Switchers: a deck of tabs; the chosen one is filled and underlined. */
.segmented {
  display: inline-flex;
  flex-wrap: wrap;
  justify-self: start;
  align-self: flex-start;
  gap: 0.3rem;
  padding: 0.3rem;
  background: var(--soft);
  border: 1px solid var(--border);
}
.segmented button { border: 0; background: transparent; color: var(--muted); padding: 0.35rem 0.9rem; border-radius: 0.5rem 0.1rem; corner-shape: bevel; }
.segmented button:hover:not(:disabled) { color: var(--text); background: var(--card); }
.segmented button[aria-selected="true"], .segmented button[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-text);
  box-shadow: inset 0 -0.2rem 0 var(--ignite);
}
.switcher { margin: 1rem 0 0.75rem; }

.back {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  min-height: 2.5rem;
  padding: 0.3rem 0.8rem 0.3rem 0.5rem;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font: 600 0.95rem var(--font-display);
  text-decoration: none;
}
.back:hover { border-color: var(--link); }

.card { background: var(--card); border: 1px solid var(--border); padding: 1rem 1.15rem; }
.card-link { display: flex; gap: 0.9rem; align-items: flex-start; color: var(--text); text-decoration: none; }
li.card:has(.card-link:hover) { border-color: var(--link); }
.muted { color: var(--muted); font-size: 0.9rem; }
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.05rem 0.55rem;
  border: 1px solid currentColor;
  border-radius: 1rem;
  font-size: 0.8rem;
  font-weight: 600;
}
details { margin-bottom: 0.6rem; }
.card summary { cursor: pointer; font-weight: 600; }
.stack { display: flex; flex-direction: column; gap: 0.75rem; padding: 0; list-style: none; }
.stack h2, .stack p { margin: 0 0 0.35rem; }
.actions { display: flex; flex-wrap: wrap; gap: 0.5rem 0.75rem; align-items: center; }
.price { font-size: 2rem; font-weight: 700; margin: 0.25rem 0; }
.price small { font-size: 0.9rem; font-weight: 400; color: var(--muted); }
.features { list-style: none; padding: 0; }
.features li { display: flex; gap: 0.5rem; align-items: center; padding: 0.2rem 0; }
canvas.share { width: 100%; height: auto; border-radius: 0.5rem; border: 1px solid var(--border); }

/* Pictures */
figure { margin: 0; }
figure img, .picture { display: block; width: 100%; height: auto; border-radius: var(--cut) 0.15rem; corner-shape: bevel; }
figcaption { margin-top: 0.3rem; font-size: 0.75rem; color: var(--muted); }
.banner img { aspect-ratio: 3 / 1; object-fit: cover; }
main.broad { max-width: 80rem; }
.thumb { width: 10rem; height: auto; flex: none; border-radius: 0.5rem; }
.heading { display: flex; align-items: center; gap: 0.6rem; }
.heading > .icon, h1 > i, h2 > i, h1 .icon, h2 .icon { color: var(--link); }
h1, h2 { display: flex; align-items: center; gap: 0.5rem; }
.pane h2 { display: flex; }

/* Pricing: four plans side by side, or one column when there isn't room. */
.plans { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0; margin-top: 0.75rem; padding: 0; overflow: hidden; }
.plan { display: flex; flex-direction: column; gap: 0.5rem; padding: 1rem; border-left: 1px solid var(--border); }
.plan:first-child { border-left: 0; }
.plan h2, .plan p { margin: 0; }
.plan .features { flex: 1; margin: 0; }
.plan .features li { align-items: flex-start; }
.plan .features .icon { margin-top: 0.2em; color: var(--pass); }

/* Problems are always explained. */
.problem { display: flex; gap: 0.6rem; align-items: flex-start; padding: 0.6rem 0.8rem; border: 1px solid var(--fail); border-radius: 0.5rem; background: var(--card); }
.problem .icon { color: var(--fail); width: 1.4em; height: 1.4em; }
.problem p { margin: 0; }
#view-message { position: absolute; inset: 0; z-index: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.5rem; padding: 1rem; text-align: center; color: #ffffff; background: #10141c; overflow: auto; }
#view-message .icon { color: #ff8a80; width: 2.5rem; height: 2.5rem; }

.fields { display: grid; grid-template-columns: 1fr 10rem; gap: 0.6rem 1rem; align-items: center; }

dialog.egg { max-width: 26rem; color: var(--text); }
dialog.egg::backdrop { background: rgb(0 0 0 / 0.7); }
dialog.egg button { float: right; }

.verdict { font-weight: 700; font-size: 1.15rem; }
.pass { color: var(--pass); }
.fail { color: var(--fail); }
.scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { text-align: left; padding: 0.3rem 0.5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
textarea, pre, code { font-family: var(--font-mono); font-size: 0.92rem; }
pre { margin: 0; padding: 0.65rem; background: var(--bg); border-radius: 0.4rem; white-space: pre-wrap; overflow-wrap: anywhere; }

/*
 * Challenge page: fills the screen. Either two halves or one panel, never more.
 * Each half has its own switcher.
 */
/* The workspace fills the screen below the header; the footer is further down. */
.app main {
  flex: none;
  height: calc(100vh - var(--header-height, 3.5rem));
  height: calc(100dvh - var(--header-height, 3.5rem));
  min-height: 24rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  max-width: none;
  padding: 0.6rem var(--edge);
}
.challenge-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem 0.8rem; }
.challenge-bar h1 { margin: 0; font-size: 1.1rem; }
.challenge-bar .spacer { flex: 1; }
.toolbar { display: flex; align-items: center; gap: 0.4rem; padding: 0.3rem; border: 1px solid var(--border); background: var(--soft); }
.toolbar button { height: 2.5rem; }
#run, #stop { min-width: 9rem; font-size: 1.05rem; text-transform: uppercase; letter-spacing: 0.06em; }
.workspace {
  flex: 1;
  min-height: 18rem;
  display: grid;
  gap: 0 0.75rem;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
}
/* Each switcher is the head of its panel: full width, joined to the content below. */
.workspace .tabbar { justify-self: stretch; align-self: stretch; flex-wrap: nowrap; border-bottom: 0; border-radius: var(--cut) var(--cut) 0 0; corner-shape: bevel bevel square square; }
.workspace .tabbar button { flex: 1 1 0; min-width: 0; }
.workspace .pane { border-top: 0.2rem solid var(--accent); border-radius: 0 0 0.15rem var(--cut); corner-shape: square square bevel bevel; }
.tabbar { grid-row: 1; }
.tabbar[data-side="left"] { grid-column: 1; }
.tabbar[data-side="right"] { grid-column: 2; }
.pane {
  grid-row: 2;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  overflow: auto;
}
.pane[data-side="left"] { grid-column: 1; }
.pane[data-side="right"] { grid-column: 2; }
.pane h2, .pane p { margin: 0; }
.workspace[data-mode="single"] { grid-template-columns: minmax(0, 2fr) minmax(0, 4fr); column-gap: 0.4rem; }
.workspace[data-mode="single"] .pane { grid-column: 1 / -1; }

textarea {
  width: 100%;
  min-height: 8rem;
  flex: 1;
  resize: none;
  padding: 0.75rem;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  tab-size: 4;
}
/* The code editor is a dark console in both themes. */
#code { background: #10142f; color: #e6e9ff; border-color: #333c74; line-height: 1.65; caret-color: #ffb066; }
#output { flex: none; max-height: 30%; overflow: auto; }
#results, #answer { display: flex; flex-direction: column; gap: 0.6rem; }
#view { flex: 1; min-height: 12rem; position: relative; border-radius: 0.4rem; overflow: hidden; background: #10141c; }
#view canvas { display: block; position: absolute; inset: 0; }
#view > p { padding: 0.75rem; color: #e9ebee; }
.slider { display: grid; grid-template-columns: 8rem 1fr 6rem; gap: 0.25rem 1rem; align-items: center; }
.slider output { font: 600 0.95rem var(--font-mono); text-align: right; }
.slider .ends { grid-column: 2; display: flex; justify-content: space-between; font: 0.72rem var(--font-mono); color: var(--muted); }
/* Sliders are drawn by the site, so the knob sits flush with both ends of the track. --at runs from 0 to 1. */
input[type="range"] { --at: 0; --knob: 1.35rem; appearance: none; width: 100%; min-width: 0; height: 2rem; margin: 0; padding: 0; background: transparent; cursor: pointer; }
input[type="range"]::-webkit-slider-runnable-track {
  height: 0.6rem;
  border: 1px solid var(--border);
  background: linear-gradient(to right, var(--accent) calc(var(--at) * (100% - var(--knob)) + var(--knob) / 2), var(--soft) 0);
}
input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: var(--knob);
  height: var(--knob);
  margin-top: calc((0.6rem - var(--knob)) / 2 - 1px);
  border: 0.2rem solid var(--card);
  border-radius: 0.2rem;
  background: var(--ignite);
  box-shadow: 0 0 0 1px var(--text);
}
input[type="range"]::-moz-range-track { height: 0.6rem; border: 1px solid var(--border); background: var(--soft); }
input[type="range"]::-moz-range-progress { height: 0.6rem; background: var(--accent); }
input[type="range"]::-moz-range-thumb { width: calc(var(--knob) - 0.4rem); height: calc(var(--knob) - 0.4rem); border: 0.2rem solid var(--card); border-radius: 0.2rem; background: var(--ignite); box-shadow: 0 0 0 1px var(--text); }
.view-controls { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.toggle[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); box-shadow: inset 0 -0.2rem 0 var(--ignite); }
.toggle[aria-pressed="true"]:hover:not(:disabled) { background: var(--accent); }
input[type="checkbox"] { width: 1.1em; height: 1.1em; }

/* Narrow screens always show one panel. */
@media (max-width: 860px) {
  .app main { height: auto; }
  .sitemap nav { grid-template-columns: repeat(2, minmax(0, 1fr)); width: 100%; }
  .thumb { width: 5.5rem; }
  .workspace[data-mode="single"] { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto auto; }
  .workspace[data-mode="single"] .tabbar { grid-column: 1; }
  .workspace[data-mode="single"] .tabbar[data-side="right"] { grid-row: 2; }
  .workspace[data-mode="single"] .pane { grid-row: 3; height: 70vh; }
  /* Every tab keeps its name, under the icon. */
  .workspace .tabbar button { flex-direction: column; gap: 0.15rem; min-height: 3.2rem; padding: 0.35rem 0.2rem; font-size: 0.75rem; }
  .workspace[data-mode="single"] .tabbar[data-side="right"] { border-radius: 0; }
  .toolbar .label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  #run, #stop { min-width: 6rem; }
  .slider { grid-template-columns: 6.5rem 1fr 4.5rem; }
  .fields { grid-template-columns: 1fr 7rem; }
  #mode { display: none; }
}
@media (max-width: 999px) {
  .plans { grid-template-columns: minmax(0, 1fr); }
  .plan { border-left: 0; border-top: 1px solid var(--border); }
  .plan:first-child { border-top: 0; }
}

/* Show one language version of a page. */
html[lang="en"] [data-lang="ms"], html[lang="ms"] [data-lang="en"] { display: none; }

/* Forms, notices and avatars */
main.narrow { max-width: 34rem; }
main.full { max-width: 90rem; }
.form { display: flex; flex-direction: column; gap: 0.85rem; }
.form label, .form fieldset { display: flex; flex-direction: column; gap: 0.3rem; }
.form fieldset { border: 1px solid var(--border); border-radius: 0.15rem; padding: 0.6rem 0.8rem; margin: 0; }
.form input:not([type="checkbox"], [type="radio"]), .form select, .form textarea {
  font: inherit; width: 100%; flex: none; min-height: 0; padding: 0.5rem 0.6rem;
  border: 1px solid var(--border); border-radius: 0.15rem; background: var(--bg); color: var(--text);
}
.form input[readonly] { color: var(--muted); }
label.check, .form label.check { display: flex; flex-direction: row; align-items: center; gap: 0.5rem; }
label.option { padding: 0.35rem 0; }
.form button[type="submit"], .form > button { align-self: flex-start; }
.choices { display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; align-items: center; }
.swatch { width: 1.1rem; height: 1.1rem; border-radius: 50%; background: #2447a6; }
.swatch.teal { background: #0f766e; }
.swatch.purple { background: #6d28d9; }
.swatch.orange { background: #b45309; }
.swatch.pink { background: #be185d; }
.preset { font-size: 1.4rem; width: 3rem; height: 3rem; padding: 0; }
.error { padding: 0.6rem 0.8rem; border: 1px solid var(--fail); border-radius: 0.5rem; color: var(--fail); background: var(--card); }
.notice { display: flex; gap: 0.6rem; align-items: flex-start; padding: 0.6rem 0.8rem; border: 1px dashed var(--border); border-radius: 0.5rem; background: var(--card); }
.notice .icon { margin-top: 0.2em; color: var(--link); }
.avatar { display: inline-flex; align-items: center; justify-content: center; flex: none; object-fit: cover; background: var(--accent); color: var(--accent-text); font-weight: 700; }
.avatar.circle { border-radius: 50%; }
.avatar.rounded { border-radius: 24%; }
.avatar.square { border-radius: 0; }
.avatar.small { width: 1.5rem; height: 1.5rem; font-size: 0.8rem; }
.avatar.large { width: 5rem; height: 5rem; font-size: 2.2rem; }
.profile-head { display: flex; flex-wrap: wrap; gap: 1rem; align-items: center; }
.profile-head > div { flex: 1; min-width: 10rem; overflow-wrap: anywhere; }
.profile-head h1, .profile-head p { margin: 0; }

/* Checkout */
.steps { display: flex; flex-wrap: wrap; gap: 0.4rem; padding: 0; list-style: none; counter-reset: step; }
.steps li { counter-increment: step; display: flex; align-items: center; gap: 0.4rem; padding: 0.25rem 0.7rem; border-radius: 1rem; background: var(--soft); color: var(--muted); font-size: 0.85rem; }
.steps li::before { content: counter(step); font-weight: 700; }
.steps li.done::before { content: "✔"; }
.steps li[aria-current="step"] { background: var(--accent); color: var(--accent-text); }
#stage { display: flex; flex-direction: column; gap: 0.75rem; }
#stage h2, #stage p { margin: 0; }
.bank { display: flex; flex-direction: column; gap: 0.75rem; padding: 1rem; border: 2px dashed var(--muted); border-radius: 0.5rem; }
canvas.qr { width: min(100%, 15rem); height: auto; align-self: center; border: 1px solid var(--border); }
main.narrow > .back { margin-bottom: 0.5rem; }
main.narrow > details { margin-top: 0.75rem; }

/* Home page: every section has the same width, padding and heading. */
.brochure { max-width: none; padding: 0; }
.brochure > section { margin: 0; padding: 3.5rem max(var(--edge), calc(50% - 34rem)); }
.brochure .tinted { background: var(--band); }
.brochure .hero, .brochure .split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 2.5rem; align-items: center; }
.brochure .hero {
  min-height: min(34rem, 78vh);
  background-image: linear-gradient(var(--grid) 1px, transparent 0), linear-gradient(90deg, var(--grid) 1px, transparent 0);
  background-size: 2.5rem 2.5rem;
}
.brochure h1 { font-size: clamp(2.1rem, 5vw, 3.4rem); margin: 0 0 1rem; }
.brochure .head { display: flex; flex-direction: column; align-items: center; gap: 0.5rem; margin-bottom: 2rem; text-align: center; }
.brochure .head h2 { margin: 0; justify-content: center; font-size: 1.75rem; }
.brochure .head p { margin: 0; max-width: 40rem; color: var(--muted); }
.brochure .head::after { content: ""; width: 7rem; height: 3px; background: var(--spectrum); }
.brochure .switch-row { display: flex; justify-content: center; margin-bottom: 2rem; }
.brochure .split > div > :first-child { margin-top: 0; }
.brochure .split > div > :last-child { margin-bottom: 0; }
.brochure .split picture, .brochure .split img, .brochure .hero img { max-height: 24rem; object-fit: cover; }
.brochure h3 { font-size: 1.35rem; }
.lead { font-size: 1.15rem; }
.button.large { min-height: 3rem; padding: 0.6rem 1.5rem; font-size: 1.1rem; }
.timeline, .ticks { list-style: none; margin: 0; padding: 0; }
.timeline { display: flex; flex-direction: column; gap: 1.25rem; }
.timeline li { display: flex; gap: 1rem; align-items: flex-start; }
.timeline li > i { display: flex; align-items: center; justify-content: center; width: 3rem; height: 3rem; flex: none; background: var(--accent); color: var(--accent-text); }
.timeline h3, .timeline p { margin: 0; }
.ticks li { display: flex; gap: 0.6rem; align-items: flex-start; padding: 0.4rem 0; }
.ticks .icon { margin-top: 0.2em; color: var(--link); }
.ticks + .button { margin-top: 1rem; }
.brochure .questions { display: flex; flex-direction: column; gap: 0.75rem; width: 100%; max-width: 46rem; margin: 0 auto; }
.brochure .questions details { margin: 0; }
.final { display: flex; flex-direction: column; align-items: center; gap: 1.25rem; text-align: center; }
.final h2 { margin: 0; justify-content: center; font-size: 1.75rem; }

/* Learning matrix: a column per field when wide, one chosen field otherwise. */
.matrix { display: grid; gap: 0.6rem; grid-template-columns: minmax(0, 1fr); }
.domain { display: none; flex-direction: column; gap: 0.5rem; }
.domain.chosen { display: flex; }
.domain h2 { margin: 0; padding: 0.4rem 0; font-size: 0.95rem; border-bottom: 0.2rem solid var(--accent); }
.technique-cell { flex-direction: column; align-items: flex-start; gap: 0.1rem; width: 100%; text-align: left; border-left-width: 0.4rem; }
.technique-cell small { color: var(--muted); }
.technique-cell em { font-size: 0.75rem; color: var(--muted); font-style: normal; }
[data-state="none"] { border-left-color: var(--muted) !important; }
[data-state="learning"] { border-left-color: #d9971c !important; }
[data-state="practised"] { border-left-color: #2e9e57 !important; }
[data-state="confident"] { border-left-color: var(--accent) !important; }
[data-state="planned"] { border-style: dashed !important; }
.legend { display: flex; flex-wrap: wrap; gap: 0.4rem 1.2rem; list-style: none; padding: 0; font-size: 0.85rem; }
.legend li { display: flex; align-items: center; gap: 0.35rem; }
.dot { display: inline-block; width: 0.4rem; height: 1rem; border-left: 0.4rem solid; }
dialog.technique { width: min(32rem, 92vw); color: var(--text); }
dialog.technique::backdrop { background: rgb(0 0 0 / 0.6); }
dialog.technique label { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin-bottom: 0.75rem; }
@media (min-width: 1100px) {
  .matrix { grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr)); }
  .domain { display: flex; }
  #domains { display: none; }
}

.glossary dt { font-weight: 700; }
.glossary dd { margin: 0 0 0.75rem; }
.simple { padding: 0.5rem 0.7rem; border-left: 0.25rem solid var(--accent); background: var(--bg); }

/* Phones: the home page is a single column, picture above its text. */
@media (max-width: 860px) {
  .brochure .split, .brochure .hero { grid-template-columns: minmax(0, 1fr); gap: 1.5rem; }
  .brochure > section { padding-block: 2.5rem; }
  .brochure .switch-row .segmented { align-self: stretch; }
  .brochure .switch-row .segmented button { flex: 1 1 40%; }
}

/* ---------- Spacing: one rhythm for every ordinary page ---------- */
body:not(.app) main:not(.brochure) > * { margin-block: 0; }
body:not(.app) main:not(.brochure) > * + * { margin-top: 1.25rem; }
body:not(.app) main:not(.brochure) > h2 { margin-top: 2.25rem; }
body:not(.app) main:not(.brochure) > h2 + * { margin-top: 0.75rem; }
body:not(.app) main > [role="tabpanel"] > * + * { margin-top: 1rem; }
body:not(.app) main > .stack, body:not(.app) main > [role="tabpanel"].stack > * + * { gap: 1rem; margin-bottom: 0; }
body:not(.app) main > [role="tabpanel"].stack > * { margin-block: 0; }
.card > :first-child { margin-top: 0; }
.card > :last-child { margin-bottom: 0; }
.form p { margin: 0; }
main.narrow > .back { margin-bottom: 0; }

:root[data-large-text]:not([data-tv]) { font-size: clamp(19px, 1.1vw, 38px); }

/* Background particles and confetti never get in the way of clicks. */
canvas.particles, canvas.confetti { position: fixed; inset: 0; pointer-events: none; }
canvas.particles { opacity: var(--planet-glow); }
canvas.particles { z-index: -1; }
canvas.confetti { z-index: 50; }

/* Quick theme and sound controls */
.drop button[aria-pressed="true"] { background: var(--soft); font-weight: 600; }
.drop .sound { display: flex; align-items: center; gap: 0.5rem; padding: 0.45rem 0.6rem; color: var(--text); font-size: 1rem; }
.drop .sound select { flex: 1; min-width: 8rem; }

/* Accordions */
details.accordion { padding: 0; margin: 0; }
.accordion > summary { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0.8rem 1rem; list-style: none; font-weight: 600; }
.accordion > summary::-webkit-details-marker { display: none; }
.accordion > summary::before { content: "▸"; color: var(--link); }
.accordion[open] > summary::before { content: "▾"; }
.accordion > summary span { flex: 1; }
.accordion > summary small { font-weight: 400; color: var(--muted); }
.accordion-body { padding: 0 1rem 1rem; }
.accordion-body > ul.stack { margin: 0; }

/* Filters and search */
.filters { display: grid; grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr)); gap: 0.75rem; align-items: end; }
.filters .wide { grid-column: 1 / -1; }
.filters label, label.search { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.9rem; }
input[type="search"], .actions input, .actions select, .filters input, .filters select {
  font: inherit; min-width: 0; min-height: 2.4rem; padding: 0.45rem 0.6rem; border: 1px solid var(--border); border-radius: 0.15rem; background: var(--bg); color: var(--text);
}
.actions input[type="checkbox"] { padding: 0; }

/* Challenge picker: floats over the page, so the layout doesn't move. */
.picker { position: relative; display: flex; align-items: center; min-width: 0; }
.joined { display: flex; align-items: stretch; min-width: 0; border: 1px solid var(--border); background: var(--card); }
.joined button { border: 0; background: transparent; height: 2.5rem; }
.joined h1 { margin: 0; min-width: 0; border-inline: 1px solid var(--border); }
#pick { max-width: 100%; font-size: 1.1rem; font-weight: 700; }
#title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picker-panel { position: absolute; top: calc(100% + 0.4rem); left: 0; z-index: 30; width: min(32rem, calc(100vw - 2 * var(--edge))); max-height: min(40rem, calc(100dvh - 9rem)); overflow-y: auto; box-shadow: 0 1rem 2.5rem rgb(0 0 0 / 0.35); display: flex; flex-direction: column; gap: 0.9rem; padding: 1.1rem; }
.picker-panel > * { flex: none; }
.picker-panel p { margin: 0; }
.picker-panel .segmented { align-self: stretch; }
.picker-panel .segmented button { flex: 1 0 auto; font-size: 0.85rem; padding-inline: 0.6rem; }
#picker-list { display: flex; flex-direction: column; gap: 0.6rem; }
.choice { display: grid; grid-template-columns: 5.5rem minmax(0, 1fr) auto; gap: 0.9rem; align-items: center; width: 100%; text-align: left; padding: 0.55rem 0.7rem; border-color: var(--border); }
.choice img { width: 100%; height: auto; }
.choice strong { display: block; }
.choice small { display: block; font: 400 0.8rem var(--font-body); color: var(--muted); }
.choice[aria-current="true"] { background: var(--soft); border-color: var(--accent); box-shadow: inset 0 -0.2rem 0 var(--ignite); }

td.kind { color: var(--muted); font-size: 0.8rem; }

/* Statistics */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)); gap: 0.75rem; margin: 0; }
.tile { background: var(--card); border: 1px solid var(--border); border-top: 0.2rem solid var(--accent); padding: 0.75rem 1rem; }
.tile dt { color: var(--muted); font-size: 0.85rem; }
.tile dd { margin: 0; font: 700 1.8rem var(--font-display); }
figure.chart { margin: 0; display: flex; flex-direction: column; gap: 0.6rem; }
.chart figcaption { margin: 0; font-size: 1rem; font-weight: 600; color: var(--text); }
.chart p { margin: 0; }
.calendar { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 0.8rem); grid-auto-columns: 0.8rem; gap: 0.2rem; width: max-content; padding: 0.15rem; }
.day { display: inline-block; width: 0.8rem; height: 0.8rem; border-radius: 0.15rem; background: var(--day-0); }
.day[data-level="1"] { background: var(--day-1); }
.day[data-level="2"] { background: var(--day-2); }
.day[data-level="3"] { background: var(--day-3); }
.day[data-level="4"] { background: var(--day-4); }
.calendar-key { display: flex; align-items: center; gap: 0.25rem; }
.bars { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.45rem; }
.bars li { display: grid; grid-template-columns: minmax(6rem, 10rem) 1fr 4.5rem; gap: 0.75rem; align-items: center; font-size: 0.9rem; }
.bars li:hover { background: var(--soft); }
.track { height: 0.7rem; border-left: 1px solid var(--border); }
.bar-fill { display: block; height: 100%; background: var(--viz-bar); border-radius: 0 0.25rem 0.25rem 0; }
.bars .value { text-align: right; font-variant-numeric: tabular-nums; }

.trace { display: flex; flex-direction: column; gap: 0.4rem; margin: 0; padding-left: 1.4rem; }
.narrow-card { max-width: 34rem; }
code { overflow-wrap: anywhere; }
#entries td:last-child { font-family: var(--font-mono); }

@media (max-width: 860px) {
  .picker, .joined { flex: 1 1 100%; }
  .joined h1 { flex: 1; }
  #pick { width: 100%; }
  .picker-panel { max-height: 65vh; padding: 0.8rem; }
  .choice { grid-template-columns: 4rem minmax(0, 1fr) auto; }
  .bars li { grid-template-columns: 6.5rem 1fr 4rem; }
}

/* Pip, the mascot, flies behind the page. It never covers text or takes clicks. */
.mascot { position: fixed; top: 0; left: 0; z-index: -1; width: clamp(5rem, 9vw, 8.5rem); pointer-events: none; animation: mascot-fly 56s linear -7s infinite; }
.mascot svg { display: block; width: 100%; height: auto; animation: mascot-bob 3.2s ease-in-out infinite alternate; }
.mascot .flame { transform-origin: 18px 62px; animation: mascot-flame 0.35s ease-in-out infinite alternate; }
@keyframes mascot-fly {
  0% { transform: translate(-12vw, 70vh) rotate(-10deg); }
  22% { transform: translate(6vw, 28vh) rotate(6deg); }
  48% { transform: translate(112vw, 52vh) rotate(-6deg); }
  48.1% { transform: translate(112vw, 18vh) scaleX(-1); }
  74% { transform: translate(82vw, 66vh) scaleX(-1) rotate(-8deg); }
  100% { transform: translate(-20vw, 30vh) scaleX(-1) rotate(6deg); }
}
@keyframes mascot-bob { to { transform: translateY(0.6rem); } }
@keyframes mascot-flame { to { transform: scaleX(0.6); } }

/* "Tap to continue the music", shown only when the browser is holding sound back. */
.music-hint { position: fixed; left: var(--edge); bottom: var(--edge); z-index: 40; background: var(--card); box-shadow: 0 0.5rem 1.5rem rgb(0 0 0 / 0.3); }

/* The one-time welcome note */
dialog.welcome { width: min(38rem, calc(100vw - 1.5rem)); max-height: calc(100dvh - 1.5rem); padding: 0; color: var(--text); background: var(--card); border: 1px solid var(--border); border-radius: 1.25rem 0.2rem; corner-shape: bevel; }
dialog.welcome::backdrop { background: rgb(5 7 20 / 0.75); }
.welcome::before { content: ""; display: block; height: 5px; background: var(--spectrum); }
.welcome > div { display: flex; flex-direction: column; gap: 0.85rem; padding: 1.5rem; }
.welcome h2, .welcome p { margin: 0; }
.welcome .actions { margin-top: 0.25rem; }
.welcome .sign { font-family: var(--font-display); color: var(--muted); }

/* Pages of a long list */
.pager { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 0.35rem; margin-top: 1rem; }
.pager button { min-width: 2.5rem; padding-inline: 0.6rem; }
.pager button[aria-current="page"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); opacity: 1; }
.pager .of { width: 100%; text-align: center; font: 0.75rem var(--font-mono); color: var(--muted); }

/* Topic colours on challenge cards */
[data-topic] .icon { color: var(--topic, var(--link)); }
[data-topic="Structures"] { --topic: var(--mercury); }
[data-topic="Rovers"] { --topic: var(--mars); }
[data-topic="Satellites"] { --topic: var(--earth); }
[data-topic="Telescopes"] { --topic: var(--jupiter); }
[data-topic="Deep space"] { --topic: var(--neptune); }
[data-topic="Drones"] { --topic: var(--uranus); }

/* Progress and community pages */
.posts { display: flex; flex-direction: column; gap: 1rem; margin: 0; padding: 0; list-style: none; }
.post h2, .post p { margin: 0 0 0.5rem; }
.post .body { white-space: pre-wrap; overflow-wrap: anywhere; }
.form textarea.long { min-height: 10rem; resize: vertical; }
.links { display: flex; flex-wrap: wrap; gap: 0.6rem; }

