:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  background: #f5f1e8;
  color: #1d2430;
  --ink: #1d2430;
  --paper: #fffdf8;
  --plum: #5b2a86;
  --plum-dark: #32134f;
  --mint: #9ee7c5;
  --orange: #ff9c5b;
  --line: #d8d0c1;
  --muted: #5e6672;

  /* Type scale. Every font-size in this file is one of these steps. The page
     previously carried nine sizes between 0.68rem and 0.9rem, several of them
     a hundredth of a rem apart, which reads as a mistake rather than as a
     distinction; a new one-off here should be treated the same way. */
  --text-xs: 0.7rem;
  --text-sm: 0.75rem;
  --text-base: 0.8rem;
  --text-md: 0.9rem;
  --text-lg: 1.1rem;
  --text-xl: clamp(1.05rem, 2vw, 1.35rem);
  --text-2xl: clamp(2rem, 4vw, 3.6rem);
  --text-3xl: clamp(2.7rem, 7vw, 6.4rem);

  --radius-xs: 0.2rem;
  --radius-sm: 0.35rem;
  --radius-md: 0.6rem;
  --radius-lg: 0.9rem;
  --radius-xl: 1.25rem;

  /* The editor and the mirror its pointer position is measured against must
     agree on every value that can move a glyph. Sharing them from one place is
     what keeps hover pointing at the character under the pointer; two rules
     drifting apart would silently aim it at the wrong name. */
  --editor-font: "SFMono-Regular", Consolas, ui-monospace, monospace;
  --editor-padding: 1rem;
  --editor-line-height: 1.55;
  --editor-tab-size: 4;

  --editor-bg: #151822;
  --editor-fg: #f5f7ff;
  --editor-surface: #1e2233;
  --editor-border: #3a4159;
  --editor-accent: #3a4670;
  --editor-strong: #e7ebff;
  --editor-muted: #9aa4c4;
  --editor-faint: #7f8bb0;
}

* {
  box-sizing: border-box;
}

body {
  min-block-size: 100vh;
  margin: 0;
  line-height: 1.55;
}

button,
select,
textarea {
  font: inherit;
}

button,
select {
  min-block-size: 2.75rem;
  border: 1px solid var(--ink);
  border-radius: var(--radius-md);
  background: var(--paper);
  color: var(--ink);
}

button {
  padding-block: 0.55rem;
  padding-inline: 0.9rem;
  cursor: pointer;
}

button:hover,
button:focus-visible {
  box-shadow: 0 0 0 3px var(--mint);
}

button:disabled {
  cursor: wait;
  opacity: 0.6;
}

.primary {
  border-color: var(--plum-dark);
  background: var(--plum);
  color: white;
  font-weight: 750;
}

.skip-link {
  position: fixed;
  inset-block-start: 0.5rem;
  inset-inline-start: 0.5rem;
  z-index: 10;
  translate: 0 -160%;
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius-sm);
  background: var(--paper);
  color: var(--plum-dark);
}

.skip-link:focus {
  translate: 0;
}

.site-header,
main,
footer {
  inline-size: min(92rem, calc(100% - 2rem));
  margin-inline: auto;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-block-size: 5rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--ink);
  font-size: var(--text-lg);
  font-weight: 800;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  inline-size: 2.25rem;
  block-size: 2.25rem;
  place-items: center;
  padding: 0.3rem;
  border-radius: var(--radius-sm);
  background: var(--plum);
  color: var(--mint);
  --kofun-face: var(--plum-dark);
}

.direction-control {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: var(--text-md);
}

.direction-control select {
  padding-inline: 0.5rem;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(16rem, 0.7fr);
  gap: clamp(2rem, 7vw, 7rem);
  align-items: center;
  padding-block: clamp(3rem, 9vw, 8rem);
}

h1,
h2,
h3,
h4,
p {
  margin-block-start: 0;
}

h1 {
  max-inline-size: 13ch;
  margin-block-end: 1.25rem;
  font-size: var(--text-3xl);
  line-height: 0.96;
  letter-spacing: -0.055em;
}

h2 {
  font-size: var(--text-2xl);
  line-height: 1.05;
  letter-spacing: -0.035em;
}

.hero-copy {
  max-inline-size: 58ch;
  font-size: var(--text-xl);
}

.eyebrow,
.nav-title {
  margin-block-end: 0.6rem;
  color: var(--plum);
  font-size: var(--text-base);
  font-weight: 850;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.mascot-card {
  display: grid;
  grid-template-columns: minmax(7rem, 0.7fr) minmax(0, 1fr);
  gap: 1rem;
  align-items: center;
  padding: 1.4rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background: var(--paper);
  box-shadow: 0.8rem 0.8rem 0 var(--mint);
}

.mascot-card p:last-child {
  margin-block-end: 0;
}

.mascot-button {
  position: relative;
  display: grid;
  inline-size: 7.5rem;
  block-size: 7.5rem;
  margin-inline: auto;
  place-items: center;
  padding: 0.75rem;
  border-color: var(--line);
  border-radius: var(--radius-lg);
  background:
    linear-gradient(90deg, #32134f0d 1px, transparent 1px),
    linear-gradient(#32134f0d 1px, transparent 1px),
    #fffaf2;
  background-size: 0.75rem 0.75rem;
  box-shadow: 0.35rem 0.35rem 0 var(--orange);
}

.mascot-button:hover,
.mascot-button:focus-visible {
  box-shadow: 0.35rem 0.35rem 0 var(--orange), 0 0 0 3px var(--mint);
}

.kofun-kun {
  color: var(--orange);
  --kofun-face: var(--ink);
}

.kofun-kun-svg {
  display: block;
  inline-size: 100%;
  block-size: 100%;
  image-rendering: pixelated;
}

.kofun-kun-body {
  fill: currentColor;
}

.kofun-kun-face {
  fill: var(--kofun-face);
}

.kofun-kun-treat {
  fill: #4cbd78;
}

[dir="rtl"] .hero-kofun,
[dir="rtl"] .kofun-kun.mini {
  scale: -1 1;
}

.hero-kofun {
  inline-size: 5.25rem;
  block-size: 5.25rem;
  filter: drop-shadow(0.25rem 0.35rem 0 #32134f26);
}

.mascot-label {
  margin-block-end: 0.35rem;
  color: var(--plum);
  font-size: var(--text-base);
  font-weight: 850;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.mascot-hint {
  color: var(--muted);
  font-size: var(--text-sm);
}

.kofun-spark {
  position: absolute;
  inset-block-start: 0.25rem;
  inset-inline-end: 0.5rem;
  color: var(--plum);
  font-weight: 850;
  opacity: 0;
  pointer-events: none;
}

.mascot-button.is-hopping .hero-kofun {
  animation: kofun-hop 620ms ease-out;
}

.mascot-button.is-hopping .kofun-spark {
  animation: kofun-spark 620ms ease-out;
}

@keyframes kofun-hop {
  0% { transform: translateY(0) scale(1); }
  18% { transform: translateY(0) scale(1.14, 0.82); }
  48% { transform: translateY(-1.25rem) scale(0.92, 1.12); }
  75% { transform: translateY(0) scale(1.08, 0.9); }
  100% { transform: translateY(0) scale(1); }
}

@keyframes kofun-spark {
  0% { opacity: 0; transform: translateY(0) scale(0.6); }
  30% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-1.6rem) scale(1.15); }
}

.tour-shell {
  display: grid;
  grid-template-columns: minmax(13rem, 0.3fr) minmax(0, 1fr);
  overflow: clip;
  border: 1px solid var(--plum-dark);
  border-radius: var(--radius-xl);
  background: var(--paper);
  box-shadow: 0 1.5rem 5rem #32134f1f;
}

.step-nav {
  padding: 1.25rem;
  background: var(--plum-dark);
  color: white;
}

.step-nav .nav-title {
  color: var(--mint);
}

.nav-progress {
  margin-block-end: 1rem;
  color: #d8cde3;
  font-size: var(--text-sm);
}

.step-nav ol {
  display: grid;
  gap: 0.55rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.step-nav button {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 0.7rem;
  align-items: baseline;
  inline-size: 100%;
  border-color: transparent;
  background: transparent;
  color: white;
  text-align: start;
}

.step-number {
  color: #b9a7c8;
  font-family: var(--editor-font);
  font-size: var(--text-sm);
}

.step-label {
  font-weight: 700;
}

.step-nav button[aria-current="step"] {
  border-color: var(--mint);
  background: #ffffff14;
  color: var(--mint);
}

.lesson {
  min-inline-size: 0;
  padding: clamp(1rem, 3vw, 2.5rem);
}

.lesson-heading {
  max-inline-size: 66ch;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(18rem, 0.8fr);
  gap: 1rem;
  margin-block: 2rem 1rem;
}

.editor-panel,
.result-panel {
  min-inline-size: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: white;
}

.panel-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding-block: 0.7rem;
  padding-inline: 1rem;
  border-block-end: 1px solid var(--line);
  background: #f7f4ed;
}

.panel-heading h3 {
  margin: 0;
  font-size: var(--text-md);
}

.panel-heading span {
  color: var(--muted);
  font-size: var(--text-sm);
}

textarea,
pre,
code {
  font-family: var(--editor-font);
}

textarea {
  display: block;
  inline-size: 100%;
  min-block-size: 20rem;
  resize: block;
  padding: var(--editor-padding);
  border: 0;
  outline-offset: -3px;
  background: var(--editor-bg);
  color: var(--editor-fg);
  direction: ltr;
  line-height: var(--editor-line-height);
  tab-size: var(--editor-tab-size);
  text-align: start;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  padding: 0.8rem;
  border-block-start: 1px solid var(--line);
}

.status {
  min-block-size: 2.5rem;
  margin: 0;
  padding-block: 0.2rem 0.8rem;
  padding-inline: 0.9rem;
  color: var(--muted);
  font-size: var(--text-base);
}

.status[data-state="success"] {
  color: #17603f;
}

.status[data-state="error"] {
  color: #9a2c27;
}

.status[data-state="lesson"] {
  color: #805019;
}

.result-panel h4 {
  margin-block: 1rem 0.35rem;
  padding-inline: 1rem;
}

.stage {
  --result-hue: 210;
  --result-distance: 50%;
  position: relative;
  block-size: 12rem;
  overflow: hidden;
  border-block-end: 1px solid var(--line);
  background:
    radial-gradient(circle at 15% 25%, white 0 4%, transparent 4.5%),
    linear-gradient(hsl(var(--result-hue) 75% 78%), #fff 64%, #d8f0cd 65%);
}

.stage::after {
  position: absolute;
  inset-block-end: 1.3rem;
  inset-inline: 0;
  block-size: 0.3rem;
  background: #504235;
  content: "";
}

.finish {
  position: absolute;
  inset-block: 2rem 1.3rem;
  inset-inline-start: var(--finish-position, 50%);
  inline-size: 0.3rem;
  background: repeating-linear-gradient(white 0 0.45rem, var(--ink) 0.45rem 0.9rem);
}

.runner {
  position: absolute;
  inset-block-end: 1.55rem;
  inset-inline-start: 4%;
  z-index: 1;
}

.runner.is-running {
  animation: run-result 900ms cubic-bezier(0.22, 0.8, 0.25, 1) forwards;
}

.kofun-kun.mini {
  inline-size: 3.5rem;
  block-size: 3.5rem;
  color: hsl(var(--result-hue) 80% 55%);
  filter: drop-shadow(0.15rem 0.2rem 0 #1d24303d);
}

.runner.is-running .kofun-kun {
  animation: kofun-waddle 260ms ease-in-out 3;
}

@keyframes kofun-waddle {
  0%, 100% { rotate: -5deg; }
  50% { rotate: 5deg; }
}

@keyframes run-result {
  to {
    inset-inline-start: calc(var(--result-distance) - 3.5rem);
  }
}

@media (prefers-reduced-motion: reduce) {
  .runner.is-running,
  .runner.is-running .kofun-kun,
  .mascot-button.is-hopping .hero-kofun,
  .mascot-button.is-hopping .kofun-spark {
    animation-duration: 1ms;
  }
}

.kofun-feedback {
  min-block-size: 4.1rem;
  margin: 0;
  padding-block: 0.75rem;
  padding-inline: 1rem;
  border-block-end: 1px solid var(--line);
  background: #fff8e8;
  color: #68400f;
  font-size: var(--text-base);
}

.kofun-feedback::before {
  content: "Kofun-kun: ";
  font-weight: 850;
}

.output {
  min-block-size: 4.5rem;
  max-block-size: 10rem;
  margin: 0;
  overflow: auto;
  padding-block: 0.4rem 1rem;
  padding-inline: 1rem;
  color: #17603f;
  direction: ltr;
  white-space: pre-wrap;
}

.exercise,
.ownership,
.limits {
  margin-block-start: 1rem;
  padding: 1.2rem;
  border-radius: var(--radius-lg);
  background: #eefaf4;
}

.exercise h3,
.ownership h3 {
  margin-block-end: 0.35rem;
}

.exercise p,
.ownership p:last-child,
.limits p:last-child {
  margin-block-end: 0;
}

.ownership {
  background: #fff2e8;
}

.bug-callout {
  font-weight: 750;
}

.boundary-note,
.worse-note {
  padding-inline-start: 0.75rem;
  border-inline-start: 0.25rem solid var(--orange);
}

.guides,
.limits {
  margin-block-start: clamp(4rem, 10vw, 8rem);
}

.guide-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  margin-block-start: 2rem;
}

.guide-card {
  min-inline-size: 0;
  padding: clamp(1rem, 3vw, 1.7rem);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--paper);
}

.comparison {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.6rem;
}

.comparison h4 {
  margin-block-end: 0.25rem;
}

.comparison pre {
  min-block-size: 5rem;
  margin: 0;
  overflow: auto;
  padding: 0.75rem;
  border-radius: var(--radius-md);
  background: var(--editor-bg);
  color: var(--editor-fg);
  direction: ltr;
  font-size: var(--text-base);
  white-space: pre-wrap;
}

.limits {
  max-inline-size: 68rem;
  margin-inline: auto;
  background: #fff2e8;
}

footer {
  padding-block: 5rem 2rem;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 64rem) {
  .tour-shell,
  .workspace {
    grid-template-columns: 1fr;
  }

  .step-nav ol {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 46rem) {
  .site-header,
  .direction-control {
    align-items: stretch;
    flex-direction: column;
  }

  .site-header {
    justify-content: center;
    padding-block: 1rem;
  }

  .hero,
  .guide-list,
  .comparison,
  .step-nav ol {
    grid-template-columns: 1fr;
  }

  .hero {
    padding-block-start: 2rem;
  }

  .workspace {
    margin-block-start: 1rem;
  }

  textarea {
    min-block-size: 18rem;
  }
}

/* The mirror carries the same text, box, and typography as the textarea so a
   pointer position can be resolved to a source offset. Every value that could
   change wrapping is inherited rather than restated, because the two boxes
   disagreeing would move hover to the wrong name. */
.editor-surface {
  position: relative;
  isolation: isolate;
}

.editor-surface textarea {
  position: relative;
  z-index: 1;
  background: transparent;
}

.editor-mirror {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  padding: var(--editor-padding);
  background: var(--editor-bg);
  /* Only the textarea's own text is painted; the mirror exists to be measured
     and to carry the hover highlight behind it. */
  color: transparent;
  direction: ltr;
  font-family: var(--editor-font);
  line-height: var(--editor-line-height);
  tab-size: var(--editor-tab-size);
  text-align: start;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  pointer-events: none;
  user-select: none;
}

.editor-mirror mark {
  border-radius: var(--radius-xs);
  background: var(--editor-accent);
  color: transparent;
}

.completion {
  position: absolute;
  z-index: 3;
  max-block-size: 12rem;
  margin: 0;
  padding: 0.25rem;
  overflow-y: auto;
  border: 1px solid var(--editor-border);
  border-radius: var(--radius-md);
  background: var(--editor-surface);
  box-shadow: 0 0.6rem 1.4rem rgb(0 0 0 / 45%);
  list-style: none;
}

.completion li {
  display: flex;
  gap: 0.6rem;
  align-items: baseline;
  padding-block: 0.3rem;
  padding-inline: 0.5rem;
  border-radius: var(--radius-sm);
  color: var(--editor-strong);
  font-size: var(--text-base);
  cursor: pointer;
}

.completion li[aria-selected="true"] {
  background: var(--editor-accent);
}

.completion .completion-label {
  font-family: var(--editor-font);
}

.completion .completion-detail {
  margin-inline-start: auto;
  color: var(--editor-muted);
  font-size: var(--text-sm);
}

.completion .completion-kind {
  color: var(--editor-faint);
  font-size: var(--text-xs);
  text-transform: lowercase;
}

.hover-card {
  position: absolute;
  z-index: 2;
  max-inline-size: 22rem;
  padding-block: 0.45rem;
  padding-inline: 0.7rem;
  border: 1px solid var(--editor-border);
  border-radius: var(--radius-md);
  background: var(--editor-surface);
  color: var(--editor-strong);
  box-shadow: 0 0.5rem 1.2rem rgb(0 0 0 / 40%);
  font-size: var(--text-base);
  pointer-events: none;
}

.hover-card strong {
  display: block;
  font-family: var(--editor-font);
}

.hover-card span {
  color: var(--editor-muted);
}

.inspector {
  margin: 0;
  padding-block: 0.5rem;
  padding-inline: 1rem;
  border-block-start: 1px solid var(--line);
  color: var(--muted);
  font-size: var(--text-sm);
  min-block-size: 1.2rem;
}
