:root {
  color-scheme: light;
  font-family: "Hiragino Kaku Gothic ProN", "Noto Sans JP", system-ui, sans-serif;
  color: #202020;
  background: #fff;
  --ink: #8d2355;
  --ink-deep: #6d1c43;
  --muted: #555;
  --edge: #d7d7d7;
  --panel: #fff;
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; }
h1, p, dl, dd { margin: 0; }
button, select { font: inherit; }
button, select, summary { cursor: pointer; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }

.workspace { width: min(100% - 52px, 1080px); margin-inline: auto; padding-block: 14px 44px; }
.page-nav {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap;
  column-gap: 16px; border-bottom: 1px solid var(--edge);
}
.intro { margin: clamp(18px, 3vw, 34px) 0 12px; }
.intro h1 {
  font: 650 clamp(1.85rem, 4.7vw, 3.35rem)/1.15 "Yu Mincho", "Hiragino Mincho ProN", "Noto Serif CJK JP", Georgia, serif;
  letter-spacing: -.045em;
}
.intro-subtitle { margin-top: 7px; color: var(--muted); font-size: clamp(1rem, 2vw, 1.2rem); font-weight: 650; }
.intro-copy { max-width: 46rem; margin-bottom: 18px; line-height: 1.65; }
.model-overview { padding-block: 10px 12px; border-block: 1px solid var(--edge); }
.model-overview h2 { margin: 0 0 7px; font-size: .95rem; }
.model-equations {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
  margin: 0; padding: 0; list-style: none;
}
.model-equations li { padding: 3px 10px; text-align: center; }
.model-equations li + li { border-inline-start: 1px solid var(--edge); }
.model-equations span { color: var(--muted); font-size: .82rem; font-weight: 650; }
.model-equations math { margin-top: 4px; font-size: clamp(1.05rem, 2vw, 1.35rem); }
.stage-prompt { margin-block: 14px 8px; font-weight: 650; }

/* Play and pause marks next to the control's visible label. */
.run { display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.run-icon { width: 10px; height: 12px; border-block: 6px solid transparent; border-left: 10px solid currentColor; }
.run[data-state="pause"] .run-icon { border: solid currentColor; border-width: 0 3px; }

.about { width: min(100% - 52px, 1080px); margin: 0 auto 56px; padding-top: 22px; border-top: 1px solid var(--edge); display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 18px 32px; }
.about h2 { margin: 0 0 6px; color: #262626; font-size: .98rem; }
.about p { color: var(--muted); font-size: .86rem; line-height: 1.85; }
@media (max-width: 720px) { .about { width: calc(100% - 32px); } }
@media (max-width: 520px) { .about { width: calc(100% - 24px); } }
.stage {
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 4px;
}
.stage-heading { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; padding: 9px 3px 7px; }
#scene { color: var(--muted); font-size: .88rem; font-weight: 680; }
.step-count { color: var(--muted); font-size: .84rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.paper {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--edge);
  background: #f7f7f7;
}
.paper .run { position: absolute; inset: 9px auto auto 9px; z-index: 1; }
#paper { display: block; width: 100%; aspect-ratio: 19 / 9; }
.stage-controls { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 9px 15px; padding-top: 8px; }
.playback { display: flex; flex-wrap: wrap; gap: 6px; }
.button {
  min-height: 44px;
  padding: 6px 14px;
  border: 1px solid var(--edge);
  border-radius: 3px;
  background: var(--panel);
  color: #303030;
  font-size: .87rem;
  font-weight: 650;
}
.button:hover { border-color: #b77c98; background: #faedf3; }
.primary { min-width: 98px; color: white; border-color: var(--ink); background: var(--ink); }
.primary:hover { color: white; border-color: var(--ink-deep); background: var(--ink-deep); }
.view-option { display: inline-flex; align-items: center; min-height: 44px; gap: 7px; color: var(--muted); font-size: .85rem; }
.view-option { padding-inline: 6px; cursor: pointer; }
.view-option select { min-height: 36px; max-width: 100%; padding: 3px 6px; color: #303030; background: var(--panel); border: 1px solid var(--edge); border-radius: 3px; }

@media (max-width: 720px) {
  .workspace { width: calc(100% - 32px); }
  .model-equations { grid-template-columns: 1fr; }
  .model-equations li {
    display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap;
    column-gap: 8px; min-height: 28px; padding: 2px 0; text-align: start;
  }
  .model-equations li + li { border-inline-start: 0; }
  .model-equations math { margin: 0; font-size: 1rem; }
  #paper { aspect-ratio: 12 / 9; }
}
@media (max-width: 520px) {
  .workspace { width: calc(100% - 24px); }
  .breadcrumb span { display: none; }
  .intro { margin-block: 14px 8px; }
  .intro-copy { margin-bottom: 12px; font-size: .94rem; line-height: 1.55; }
  .model-overview { padding-block: 6px 8px; }
  .stage-prompt { margin-block: 10px 6px; font-size: .94rem; }
  .stage { padding: 8px; }
  .stage-heading { padding: 7px 3px; }
  .stage-controls { gap: 4px 10px; }
  .playback .button { padding-inline: 8px; font-size: .8rem; }
  #paper { aspect-ratio: 1; }
  .view-option select { min-height: 44px; font-size: 1rem; }
}

/* Rules panel: beside the paper during the opening and at the end; hidden while
   the drawing is shown large. */
.stage-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(310px, 34vw, 365px);
  gap: 12px;
  align-items: start;
  transition: grid-template-columns .7s ease, gap .7s ease;
}
.stage[data-phase="wide"] .stage-body { grid-template-columns: minmax(0, 1fr) 0px; gap: 0; }
.stage:not([data-phase="wide"]) #paper { aspect-ratio: 4 / 3; }
.magic {
  min-width: 0;
  overflow: hidden;
  padding: 14px 14px 12px;
  border: 1px solid var(--edge);
  border-radius: 3px;
  background: #fff;
  transition: opacity .5s ease;
}
.stage[data-phase="wide"] .magic {
  height: 0; padding-block: 0; border-width: 0; opacity: 0; visibility: hidden;
  transition: opacity .3s ease, visibility 0s .7s;
}
.magic h2 { margin: 0 0 8px; color: #262626; font-size: 1rem; text-align: left; }
.magic-question {
  display: none;
  margin-bottom: 10px;
  padding: 9px 11px;
  border-radius: 3px;
  background: #fbe3ee;
  color: var(--ink-deep);
  font-size: .9rem;
  font-weight: 700;
  line-height: 1.6;
}
.stage[data-phase="final"] .magic-question { display: block; }
/* At the end the question leads the panel; the heading is left out. */
.stage[data-phase="final"] .magic h2 { display: none; }
.magic-close, .magic-open { display: none; }
.magic-answer { display: none; }
.stage[data-phase="final"] .magic-answer {
  display: block;
  padding: 13px 15px;
  border: 1px solid var(--edge);
  border-radius: 3px;
  background: #fff;
  color: #303030;
  font-size: .88rem;
  line-height: 1.75;
}
.magic-answer p + p { margin-top: 8px; }
.magic-answer .answer-key { color: var(--ink-deep); font-weight: 750; }
.emergence-word {
  color: #202020;
  font: 800 1.3em/1 "Yu Mincho", "Hiragino Mincho ProN", "Noto Serif CJK JP", Georgia, serif;
  letter-spacing: .04em;
}
@media (min-width: 721px) {
  /* The answer goes under the panel, beside the paper. */
  .paper { grid-row: 1 / span 2; }
  .magic { grid-column: 2; grid-row: 1; }
  .magic-answer { grid-column: 2; grid-row: 2; }
  .stage[data-phase="opening"] .spell math { display: none; }
}
.magic-list { margin: 0; padding: 0; list-style: none; }
.spell {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  padding: 9px 8px;
  border: 1.5px solid transparent;
  border-radius: 3px;
}
.spell + .spell { margin-top: 2px; }
.spell-icon { width: 38px; height: 38px; border-radius: 3px; background: #f4f4f4; }
.spell h3 { margin: 0; color: #262626; font-size: .86rem; }
.spell p { margin: 2px 0 0; color: var(--muted); font-size: .8rem; line-height: 1.5; }
.spell math { margin-top: 6px; color: #262626; font-size: 1.24rem; }
.spell-calc { margin-top: 3px; color: var(--ink-deep); font-size: .82rem; font-weight: 650; font-variant-numeric: tabular-nums; text-align: center; }
.spell-calc:empty, .stage[data-phase="final"] .spell-calc { display: none; }
.magic[data-active="1"] .spell[data-spell="1"],
.magic[data-active="2"] .spell[data-spell="2"],
.magic[data-active="3"] .spell[data-spell="3"] {
  --active-rule-display: block;
  background: #fde8f1;
  box-shadow: inset 0 0 0 1.5px #ec4396;
}
.magic-note { margin-top: 8px; color: var(--muted); font-size: .74rem; line-height: 1.6; }

@media (max-width: 720px) {
  .stage-body { display: block; position: relative; }
  .stage:not([data-phase="wide"]) #paper { aspect-ratio: 12 / 9; }
  .stage[data-phase="wide"] .magic { display: none; }
  .stage[data-phase="opening"] .magic {
    position: absolute; inset: auto 7px 7px; padding: 0;
    border: 0; background: none; pointer-events: none;
  }
  .stage[data-phase="opening"] .magic[data-active="0"],
  .stage[data-phase="opening"] .magic h2,
  .stage[data-phase="opening"] .magic-note,
  .stage[data-phase="opening"] .spell-icon,
  .stage[data-phase="opening"] .spell p:not(.spell-calc) { display: none; }
  .stage[data-phase="opening"] .spell { display: var(--active-rule-display, none); padding: 6px 9px; }
  .stage[data-phase="opening"] .spell + .spell { margin: 0; }
  .stage[data-phase="opening"] .spell-text {
    display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 3px 8px;
  }
  .stage[data-phase="opening"] .spell h3 { font-size: .78rem; }
  .stage[data-phase="opening"] .spell math { margin: 0 0 0 auto; font-size: .94rem; }
  .stage[data-phase="opening"] .spell-calc { flex-basis: 100%; margin: 0; font-size: .78rem; text-align: end; }
  /* At the end the question and the formulas sit over the bottom of the
     paper; the answer follows under it. */
  .stage[data-phase="final"] .magic {
    /* A see-through box the size of the paper; its content sits at the bottom. */
    position: absolute; inset: 0 0 auto; aspect-ratio: 12 / 9;
    display: flex; flex-direction: column; justify-content: flex-end;
    padding: 0 6px 6px; border: 0; background: none; pointer-events: none;
  }
  .stage[data-phase="final"] .magic > * { pointer-events: auto; }
  .stage[data-phase="final"] .magic-list { padding: 4px 4px 6px; background: #ffffffeb; border-radius: 0 0 3px 3px; }
  .stage[data-phase="final"][data-closed] .magic > :not(.magic-open) { display: none; }
  .stage[data-phase="final"][data-closed] .magic-open {
    display: block; align-self: flex-end; min-height: 36px; padding: 6px 13px;
    border: 1px solid var(--edge); border-radius: 3px; background: #ffffffeb;
    color: var(--ink-deep); font-size: .8rem; font-weight: 700; box-shadow: 0 1px 4px #0002;
  }
  .stage[data-phase="final"] .magic h2,
  .stage[data-phase="final"] .magic-note,
  .stage[data-phase="final"] .spell-icon,
  .stage[data-phase="final"] .spell p { display: none; }
  .stage[data-phase="final"] .magic-question { margin: 0; padding: 7px 10px; border-radius: 3px 3px 0 0; background: #fbe3eef2; font-size: .8rem; }
  .stage[data-phase="final"] .spell { display: block; padding: 2px 6px; }
  .stage[data-phase="final"] .spell-text { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
  .stage[data-phase="final"] .spell h3 { font-size: .74rem; white-space: nowrap; }
  .stage[data-phase="final"] .spell math { margin: 0; font-size: .86rem; }
  .stage[data-phase="final"] .magic-close {
    display: block; align-self: flex-end; width: 32px; height: 32px; margin-bottom: 4px;
    border: 0; border-radius: 50%; background: #ffffffeb; color: #6d5a64; font-size: 1.15rem; line-height: 1;
    box-shadow: 0 1px 4px #0002;
  }
  .stage[data-phase="final"] .magic-answer { margin-top: 10px; }
}
@media (max-width: 520px) {
  .stage:not([data-phase="wide"]) #paper,
  .stage[data-phase="final"] .magic { aspect-ratio: 1; }
}

.icon-defs { position: absolute; width: 0; height: 0; overflow: hidden; }
/* On phones the rule descriptions are available below the stage. */
.magic-help { display: none; }
@media (max-width: 720px) {
  .magic-help { display: block; margin-top: 13px; border-block: 1px solid var(--edge); }
  .magic-help summary { padding-block: 12px; color: #303030; font-size: .92rem; font-weight: 680; }
  .magic-help-list { margin: 0; padding: 0 0 6px; list-style: none; }
  .magic-help-list li { display: grid; grid-template-columns: 52px minmax(0, 1fr); gap: 10px; align-items: center; padding-block: 7px; }
  .magic-help-list h3 { margin: 0; color: #262626; font-size: .86rem; }
  .magic-help-list p { margin: 2px 0 0; color: var(--muted); font-size: .84rem; line-height: 1.6; }
  .magic-help-note { padding-bottom: 14px; color: var(--muted); font-size: .78rem; line-height: 1.6; }
}

.languages { display: flex; justify-content: flex-end; align-items: center; gap: .5em; color: var(--muted); font-size: .85rem; }
.languages a { display: inline-flex; align-items: center; min-height: 44px; color: #303030; }
.languages a[aria-current] { font-weight: bold; text-decoration: none; }
html:lang(en) .stage-heading .step-count { flex-shrink: 0; }
@media (max-width: 720px) {
  html:lang(en) .stage[data-phase="final"] .spell-text { flex-wrap: wrap; }
}

.breadcrumb { display: flex; align-items: baseline; flex-wrap: wrap; gap: .55em; color: var(--muted); font-size: .82rem; }
.breadcrumb a { display: inline-flex; align-items: center; min-height: 44px; color: #202020; font-weight: 700; text-underline-offset: 3px; }
