:root {
  color-scheme: light dark;
  --bg: #f6f4fb;
  --panel: #ffffff;
  --text: #1d1530;
  --muted: #625b73;
  --border: #ddd8ea;
  --accent: #7b5cff;
  --accent-text: #ffffff;
  --error-bg: #fde8ee;
  --error-text: #9b1c46;
  /* Stage behind sprites: light in both themes, because sprites have dark outlines. */
  --stage: #eef1f6;
  --stage-checker: #dde3ec;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15121d;
    --panel: #1f1b2a;
    --text: #ece8f6;
    --muted: #a59fb6;
    --border: #353048;
    --accent: #9a82ff;
    --accent-text: #120d22;
    --error-bg: #3a1624;
    --error-text: #ffb3c9;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, sans-serif;
}

header {
  padding: 20px 24px 4px;
}

h1 {
  margin: 0;
  font-size: 24px;
}

header p {
  margin: 4px 0 0;
  color: var(--muted);
}

a.nav {
  color: var(--accent);
  font-weight: 600;
}

/* The pages' nav: the same links in the same order on every page; the page you are on is marked. */
.links {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  margin-left: auto;
}

/* The page itself; or its section, as on the Animation Reference (part 2 of the tutorial). */
.links a[aria-current='page'],
.links a[aria-current='true'] {
  color: var(--text);
  text-decoration: none;
  border-bottom: 2px solid var(--accent);
}

/* The Lab and the guide: the title and the nav on one line, the intro below. */
.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 20px;
}

.page-head > p {
  flex-basis: 100%;
}

/* A file picker's list shows titles, which can be long. */
.file-pick select {
  max-width: 20em;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

main {
  display: grid;
  grid-template-columns: minmax(240px, 300px) 1fr;
  gap: 16px;
  padding: 16px 24px 32px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  min-width: 0;
}

.wide {
  grid-column: 1 / -1;
}

h2 {
  margin: 0 0 8px;
  font-size: 15px;
}

.controls h2:not(:first-child) {
  margin-top: 16px;
}

/* The main action of a page or a box: Start, Play, Add, Copy link. */
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

/* A pack's name over its characters (Starter pack, Gumdrops…): a whole row of the list it heads. */
.pack-name {
  flex-basis: 100%;
  grid-column: 1 / -1;
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.pack-name:first-child {
  margin-top: 0;
}

.note,
.info {
  color: var(--muted);
  font-weight: normal;
}

.info {
  margin: 8px 0 0;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.row h2 {
  margin: 0;
}

.buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

button {
  font: inherit;
  font-size: 14px;
  min-height: 32px;
  padding: 4px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
}

/* A picture of code, drawn by the real pen (src/studio/pictures.ts): 96 × 96
   character pixels plus a little room, on the light stage the characters use. */
.code-picture {
  flex: none;
  width: 104px;
  height: 104px;
  border-radius: 8px;
  background: var(--stage);
}

/* How many right answers a climb needs (src/game/ui/estimate.ts): it says
   what the energy numbers mean, so it stands a little apart. */
.estimate {
  border-left: 3px solid var(--accent);
  padding-left: 10px;
}

/* An action that cannot be taken back: leave a game, end a game. */
button.danger {
  border-color: var(--error-text);
  color: var(--error-text);
}

button[aria-pressed='true'] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

button:disabled {
  opacity: 0.5;
  cursor: default;
}

button:focus-visible,
select:focus-visible,
input:focus-visible,
canvas:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.options {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.options label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.options .check {
  justify-content: flex-start;
}

select {
  font: inherit;
  min-height: 30px;
}

.status {
  margin: 14px 0 0;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--error-bg);
  color: var(--error-text);
  font-size: 13px;
  white-space: pre-wrap;
}

#preview {
  display: block;
  width: 100%;
  height: 300px;
  border-radius: 8px;
  background: var(--stage);
}

.sheet-scroll {
  overflow: auto;
  max-height: 420px;
  border-radius: 8px;
  /* Checkerboard so transparent pixels are visible. */
  background: repeating-conic-gradient(var(--stage-checker) 0 25%, var(--stage) 0 50%) 0 0 / 16px 16px;
}

#sheet {
  display: block;
}

#field {
  display: block;
  width: 100%;
  height: 380px;
  border-radius: 8px;
  margin-top: 8px;
}

@media (max-width: 720px) {
  main {
    grid-template-columns: 1fr;
    padding: 12px 16px 24px;
  }
}

/* ---- formulas (MathML from src/game/ui/math.ts) ---------------------------
   A math font draws roots, stretchy brackets and limits well. The installed
   one is used when there is one; otherwise the bundled copy (SIL OFL 1.1,
   see fonts/OFL.txt) loads on first use. */
@font-face {
  font-family: 'STIX Two Math';
  src: local('STIX Two Math'), url('fonts/STIXTwoMath-Regular.otf') format('opentype');
  font-display: swap;
}

math {
  font-family: 'STIX Two Math', math;
  font-size: 1.12em;
}

/* MathML Core ignores mathvariant="bold" and columnalign, so classes do it. */
math .tex-bold {
  font-weight: bold;
}

math mtable.tex-left mtd {
  text-align: left;
}

math[display='block'] {
  margin: 0.4em 0;
}

.math-raw {
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  font-size: 0.9em;
  color: var(--error-text);
  text-decoration: underline dotted;
}

/* In questions and choices, fractions and limits are drawn full size, as in a textbook. */
.prompt math,
.choice math,
.feedback math,
#cheats math {
  math-style: normal;
}

/* Energy rules (start screen and room form): number fields side by side, then "Usual numbers". */
.energy-fields {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px 12px;
  align-items: end;
}

.energy-field {
  display: grid;
  gap: 4px;
  font-size: 14px;
}

.energy-field input {
  font: inherit;
  width: 100%;
  box-sizing: border-box;
}

.energy-fields > button {
  justify-self: start;
}

.energy-box {
  margin: 0 0 12px;
}

.energy-box > summary {
  cursor: pointer;
  font-weight: 600;
}

/* Hover hints (src/app/hints.ts): one small box, next to the element. */
.hint-tip {
  position: fixed;
  z-index: 1000;
  max-width: min(300px, calc(100vw - 16px));
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--text);
  color: var(--bg);
  font-size: 13px;
  line-height: 1.35;
  box-shadow: 0 4px 14px rgb(0 0 0 / 0.25);
  pointer-events: none;
}

/* Step-by-step guides (host page, join box). */
.guide {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel);
  padding: 8px 14px;
  margin: 0 0 12px;
}

.guide > summary {
  cursor: pointer;
  font-weight: 700;
}

.guide-steps {
  margin: 8px 0 4px;
  padding-left: 1.4em;
  display: grid;
  gap: 6px;
}

/* The step to take next: a soft pulse that stops for reduced motion. */
.next-step {
  box-shadow: 0 0 0 3px var(--accent);
  animation: next-step 1.4s ease-in-out infinite;
}

@keyframes next-step {
  50% {
    box-shadow: 0 0 0 6px color-mix(in srgb, var(--accent) 35%, transparent);
  }
}

@media (prefers-reduced-motion: reduce) {
  .next-step {
    animation: none;
  }
}
