@font-face {
  font-family: "Computer Modern Serif";
  src: url("./fonts/cmunrm.woff") format("woff");
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Computer Modern Serif";
  src: url("./fonts/cmunbx.woff") format("woff");
  font-weight: bold;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Computer Modern Serif";
  src: url("./fonts/cmunti.woff") format("woff");
  font-weight: normal;
  font-style: italic;
  font-display: swap;
}

@font-face {
  font-family: "Computer Modern Typewriter";
  src: url("./fonts/cmuntt.woff") format("woff");
  font-display: swap;
}

@font-face {
  font-family: "Latin Modern Math";
  src: url("./fonts/latinmodern-math.otf") format("opentype");
  font-display: swap;
}

:root {
  --bg: #000000;
  --fg: #f4f4f2;
  --muted: rgba(244, 244, 242, 0.62);
  --line: rgba(244, 244, 242, 0.16);
  --soft: rgba(244, 244, 242, 0.06);
  --serif: "Computer Modern Serif", "Latin Modern Roman", Georgia, serif;
  --mono: "Computer Modern Typewriter", "Latin Modern Mono", monospace;
  --math: "Latin Modern Math", "STIX Two Math", math;
  --column: 42rem;
  --max: 72rem;
  --gutter: clamp(1.25rem, 4vw, 3rem);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: clip;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--serif);
  font-size: 1.15rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  counter-reset: figure equation;
}

a {
  color: inherit;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
}

h1,
h2,
h3 {
  font-family: var(--serif);
  margin: 0;
}

/* LaTeX article: \section and \subsection are set in bold extended */
h2 {
  font-weight: bold;
  font-size: 1.55rem;
  line-height: 1.2;
  margin-bottom: 1rem;
}

h3 {
  font-weight: bold;
  font-size: 1.2rem;
  line-height: 1.25;
}

.secnum {
  margin-right: 0.9em;
}

p {
  margin: 0;
  text-align: justify;
  hyphens: auto;
  -webkit-hyphens: auto;
}

p + p {
  text-indent: 1.5em;
}

math {
  font-family: var(--math);
  font-size: 1.08em;
  color: var(--fg);
}

em {
  font-style: italic;
}

.smallcaps,
.byline,
button,
.sim-meta {
  font-variant-caps: all-small-caps;
  letter-spacing: 0.06em;
}

/* —— Title —— */
.hero {
  position: relative;
  z-index: 2;
  cursor: grab;
  /* Horizontal swipes turn the crystal; vertical ones still scroll */
  touch-action: pan-y;
  min-height: 100svh;
  display: grid;
  align-items: end;
  justify-items: center;
}

.hero.turning {
  cursor: grabbing;
  user-select: none;
}

.hero-front {
  /* Above the heading: only arms nearer than the text are drawn here */
  pointer-events: none;
}

/* Falling crystals released from the hero */
.snowfall {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

.hero-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  will-change: translate;
  -webkit-mask-image: linear-gradient(to bottom, #000 0%, #000 72%, transparent 100%);
  mask-image: linear-gradient(to bottom, #000 0%, #000 72%, transparent 100%);
}

.title-block {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: var(--gutter);
  padding-bottom: clamp(2.5rem, 9vh, 5.5rem);
  animation: rise 1.1s ease both;
  will-change: translate, opacity;
}

.title-block h1 {
  font-weight: normal;
  font-size: clamp(3.6rem, 12vw, 7.5rem);
  line-height: 1;
  letter-spacing: -0.005em;
}

.subtitle {
  margin-top: 0.9rem;
  font-style: italic;
  font-size: clamp(1.15rem, 2.4vw, 1.5rem);
  text-align: center;
}

.byline {
  margin-top: 0.6rem;
  color: var(--muted);
  font-size: 1.05rem;
  text-align: center;
}

.scroll-cue {
  display: inline-block;
  margin-top: 2rem;
  font-variant-caps: all-small-caps;
  letter-spacing: 0.1em;
  text-decoration: none;
  border-bottom: 1px solid var(--fg);
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(1.25rem);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* —— Paper column —— */
.paper {
  width: min(100% - 2 * var(--gutter), var(--column));
  margin-inline: auto;
}

.paper > section {
  padding-block: clamp(2.5rem, 7vh, 4.5rem);
}

.paper > section > p {
  margin-bottom: 1rem;
}

.abstract {
  padding-top: clamp(2.5rem, 6vh, 4rem);
  padding-inline: clamp(0rem, 4vw, 2.5rem);
}

.abstract h2 {
  font-size: 1rem;
  text-align: center;
  margin-bottom: 0.6rem;
}

.abstract p {
  font-size: 1.02rem;
}

.cite {
  text-decoration: none;
}

/* Sections that break out of the text column */
.wide {
  width: min(100vw - 2 * var(--gutter), var(--max));
  margin-left: 50%;
  translate: -50% 0;
}

.wide > h2,
.wide > p {
  max-width: var(--column);
  margin-inline: auto;
}

.wide > p {
  margin-bottom: 2rem;
}

/* —— Steps: same column width as the rest of the paper —— */
.steps {
  display: grid;
  gap: 3.25rem;
  margin-top: 2.5rem;
}

.step {
  display: grid;
  gap: 1.25rem;
  align-items: start;
}

.step-body {
  display: grid;
  gap: 0.8rem;
  min-width: 0;
}

.example {
  margin: 0;
  display: grid;
  justify-items: center;
  gap: 0.2rem;
  opacity: 0;
  transition: opacity 0.8s ease;
}

.example.ready {
  opacity: 1;
}

.example canvas {
  display: block;
  width: min(5rem, 100%);
  aspect-ratio: 1;
  height: auto;
}

.example figcaption {
  font-family: var(--math);
  font-size: 0.85rem;
  color: var(--muted);
  text-align: center;
}

.example figcaption::before {
  content: none;
}

.fig {
  margin: 1rem 0 0.4rem;
  display: grid;
  justify-items: center;
  gap: 0.35rem;
  counter-increment: figure;
  will-change: translate;
}

.fig svg {
  width: 100%;
  max-width: 320px;
  height: auto;
  overflow: visible;
}

figcaption {
  font-size: 0.92rem;
  color: var(--muted);
  text-align: center;
}

figcaption::before {
  content: "Figure " counter(figure) ": ";
  color: var(--fg);
}

.fig-cell {
  fill: none;
  stroke: var(--line);
  stroke-width: 1;
}

.fig-ice {
  fill: var(--fg);
  stroke: var(--fg);
  stroke-width: 1;
}

.fig-boundary {
  fill: none;
  stroke: var(--fg);
  stroke-width: 1;
  stroke-dasharray: 3 2.5;
}

.fig-focus {
  fill: none;
  stroke: var(--fg);
  stroke-width: 1.8;
}

.fig-vapor {
  fill: var(--fg);
  stroke: var(--line);
  stroke-width: 1;
}

.fig-arrow {
  fill: none;
  stroke: var(--fg);
  stroke-width: 1.1;
}

.fig-head {
  fill: var(--fg);
}

.fig-fill {
  fill: var(--fg);
  fill-opacity: 0.5;
}

.fig-strong {
  fill-opacity: 0.95;
}

.fig-ghost {
  fill: none;
  stroke: var(--fg);
  stroke-opacity: 0.6;
  stroke-width: 1;
  stroke-dasharray: 3 2.5;
}

.fig-math {
  font-family: var(--math);
  font-size: 16px;
  fill: var(--fg);
}

.fig-small {
  font-size: 13px;
  fill: var(--muted);
}

.fig-label {
  font-family: var(--serif);
  font-size: 11.5px;
  fill: var(--muted);
}

/* Display equations, numbered on the right like \begin{equation} */
.math-block {
  display: grid;
  grid-template-columns: 2.5rem 1fr 2.5rem;
  align-items: center;
  padding: 0.6rem 0;
  overflow-x: auto;
  counter-increment: equation;
}

.math-block math {
  grid-column: 2;
}

.math-block::after {
  content: "(" counter(equation) ")";
  grid-column: 3;
  text-align: right;
}

/* booktabs-style table */
.symbols {
  margin: 3.5rem auto 0;
  border-collapse: collapse;
  border-top: 1.5px solid var(--fg);
  border-bottom: 1.5px solid var(--fg);
  font-size: 1rem;
}

.symbols caption {
  caption-side: top;
  padding-bottom: 0.6rem;
}

.symbols td {
  padding: 0.35rem 1.25rem;
}

.symbols tr:first-child td {
  padding-top: 0.6rem;
}

.symbols tr:last-child td {
  padding-bottom: 0.6rem;
}

.symbols td:first-child {
  text-align: center;
}

/* —— Simulator —— */
.sim-layout {
  display: grid;
  gap: 1.5rem;
}

@media (min-width: 980px) {
  .sim-layout {
    grid-template-columns: minmax(0, 1.4fr) minmax(16rem, 0.7fr);
    align-items: start;
    gap: 2.5rem;
  }
}

.sim-stage {
  position: relative;
  aspect-ratio: 1 / 1;
  max-height: min(80vh, 46rem);
  background: var(--bg);
}

.sim-stage canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.sim-meta {
  position: absolute;
  left: 1rem;
  bottom: 1rem;
  font-size: 1rem;
  color: var(--muted);
}

.sim-panel {
  display: grid;
  gap: 1.25rem;
}

.presets,
.sim-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

button {
  font: inherit;
  font-size: 1.05rem;
  font-variant-caps: all-small-caps;
  color: var(--fg);
  background: transparent;
  border: 1px solid var(--line);
  padding: 0.4rem 0.85rem 0.5rem;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease;
}

button:hover,
button.active {
  background: var(--soft);
  border-color: rgba(244, 244, 242, 0.45);
}

.sliders {
  display: grid;
  gap: 0.65rem;
}

.slider-row {
  display: grid;
  grid-template-columns: 3rem 1fr 3rem;
  gap: 0.65rem;
  align-items: center;
  font-size: 0.9rem;
}

.slider-name {
  font-family: var(--math);
  font-style: italic;
  font-size: 1.15rem;
}

.slider-val {
  font-family: var(--mono);
  text-align: right;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 1px;
  background: var(--line);
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--fg);
  cursor: pointer;
}

input[type="range"]::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border: none;
  border-radius: 50%;
  background: var(--fg);
  cursor: pointer;
}

/* —— Gallery —— */
.hexgrid {
  position: relative;
  margin-inline: var(--gutter);
  /* Pull the grid up into the section's bottom padding, close to its caption */
  margin-top: calc(-1 * clamp(1.5rem, 5vh, 3.5rem));
  margin-bottom: clamp(3rem, 10vh, 6rem);
}

.hex-cell {
  position: absolute;
  top: 0;
  left: 0;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  opacity: 0;
  transition: opacity 1.2s ease;
}

.hex-cell:hover {
  background: none;
}

.hex-cell.ready {
  opacity: 1;
}

.hex-cell.growing.ready {
  opacity: 0.25;
}

.hex-cell canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* —— References —— */
.references {
  padding-block: 3rem 4rem;
  font-size: 0.98rem;
}

.references h2 {
  font-size: 1.3rem;
}

.references ol {
  list-style: none;
  margin: 0;
  padding: 0;
  counter-reset: ref;
  display: grid;
  gap: 0.6rem;
}

.references li {
  counter-increment: ref;
  position: relative;
  padding-left: 2.2rem;
}

/* The number sits in the margin; the entry (with its <em> titles) flows as one block */
.references li::before {
  content: "[" counter(ref) "]";
  position: absolute;
  left: 0;
}
