/**
 * Welcome page + site chrome.
 *
 * The two subject viewers ship their own stylesheets and run inside iframes, so nothing
 * here reaches them: the only surfaces this file owns are the welcome page, the top bar
 * shown while a viewer is open, and the loading state between the two.
 */

:root {
  color-scheme: dark;

  /* Lilyrose: a rose gradient over near-black, with the physics viewer's amber kept as
     the secondary accent so the site and that app do not read as two different products. */
  --ink: #0a0609;
  --ink-2: #140b11;
  --cream: #fdf3f6;
  --muted: rgb(253 243 246 / 62%);
  --muted-2: rgb(253 243 246 / 42%);

  --rose: #e8547f;
  --rose-soft: #f9a8c0;
  --rose-deep: #9d1745;
  --gold: #f0c58a;

  --panel: rgb(255 255 255 / 4.5%);
  --panel-2: rgb(255 255 255 / 2%);
  --line: rgb(255 255 255 / 10%);
  --line-strong: rgb(255 255 255 / 18%);

  --bar-h: 56px;
  --radius: 18px;

  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Inter, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--ink);
  color: var(--cream);
  font: 400 16px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}

[hidden] {
  display: none !important;
}

:where(a, button):focus-visible {
  outline: 2px solid var(--rose-soft);
  outline-offset: 3px;
}

/* ===========================================================================
   The logo. Petals, centre and leaf are all CSS boxes — no image, no SVG and no
   font file, so it renders identically offline and at any size. Everything scales
   off --mark, which is the only value the two sizes below change.
   =========================================================================== */

.logo {
  display: inline-flex;
  align-items: center;
  gap: 0.62em;
  text-decoration: none;
  color: inherit;
  font-size: var(--mark);
}

.logo-lg {
  --mark: 46px;
  align-self: flex-start;
}

.logo-sm {
  --mark: 30px;
}

.mark {
  position: relative;
  flex: none;
  width: var(--mark);
  height: var(--mark);
  /* Keeps the leaf's negative z-index inside the mark rather than behind the page. */
  isolation: isolate;
}

/* The bloom behind the petals. */
.mark::before {
  content: "";
  position: absolute;
  inset: -34%;
  border-radius: 50%;
  background: radial-gradient(circle, rgb(232 84 127 / 34%) 0%, transparent 68%);
}

/* A single leaf, tucked *under* the bloom at the lower left — hence the z-index, since
   ::after would otherwise paint over the petal it is meant to sit behind. */
.mark::after {
  content: "";
  position: absolute;
  z-index: -1;
  left: -8%;
  bottom: -6%;
  width: 46%;
  height: 26%;
  border-radius: 100% 0 100% 0;
  background: linear-gradient(120deg, #5b937a, #244a3c);
  transform: rotate(16deg);
}

/* Five petals, 72° apart, each pushed out along its own rotated axis. */
.mark i {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 42%;
  height: 56%;
  margin: -28% 0 0 -21%;
  border-radius: 50% 50% 46% 46%;
  background: linear-gradient(165deg, var(--rose-soft) 0%, var(--rose) 46%, var(--rose-deep) 100%);
  box-shadow: inset 0 -0.06em 0.12em rgb(157 23 69 / 45%), inset 0 0.05em 0.1em rgb(255 255 255 / 35%);
  /* translateY is a share of the petal's own height, so this pushes each petal ~26% of
     its length out along its own axis — enough to open the bloom, tight enough that the
     petals still overlap the way a rose's do. */
  transform: rotate(var(--a)) translateY(-26%);
  transform-origin: 50% 50%;
}

.mark i:nth-child(1) { --a: 0deg; }
.mark i:nth-child(2) { --a: 72deg; opacity: 0.94; }
.mark i:nth-child(3) { --a: 144deg; opacity: 0.88; }
.mark i:nth-child(4) { --a: 216deg; opacity: 0.88; }
.mark i:nth-child(5) { --a: 288deg; opacity: 0.94; }

/* The centre. */
.mark b {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 26%;
  height: 26%;
  margin: -13% 0 0 -13%;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 30%, #fff6e2 0%, var(--gold) 55%, #c9905a 100%);
  box-shadow: 0 0 0.14em rgb(10 6 9 / 55%);
}

.wordmark {
  display: flex;
  flex-direction: column;
  line-height: 1;
  gap: 0.16em;
}

.wordmark strong {
  font: 400 0.58em/1 var(--serif);
  letter-spacing: 0.005em;
  color: var(--rose-soft); /* fallback wherever background-clip: text is unsupported */
  background: linear-gradient(96deg, #fff1f5 8%, var(--rose-soft) 52%, var(--rose) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.wordmark em {
  font: 500 0.2em/1 var(--sans);
  font-style: normal;
  letter-spacing: 0.36em;
  text-transform: uppercase;
  color: var(--muted);
  padding-left: 0.12em;
}

.logo .mark {
  transition: transform 420ms cubic-bezier(0.22, 1, 0.36, 1);
}

.logo:hover .mark {
  transform: rotate(-18deg) scale(1.06);
}

/* ===========================================================================
   Site chrome, shown only while a viewer is open.
   =========================================================================== */

.bar {
  position: fixed;
  inset: 0 0 auto;
  z-index: 5;
  height: var(--bar-h);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 clamp(12px, 2.4vw, 22px);
  background: linear-gradient(180deg, #100910 0%, #0b0609 100%);
  border-bottom: 1px solid var(--line);
}

.bar-home {
  display: inline-flex;
  align-items: center;
  padding: 4px 6px;
  margin-left: -6px;
  border: 0;
  border-radius: 12px;
  background: none;
  cursor: pointer;
}

.bar-home:hover {
  background: var(--panel);
}

.bar-title {
  flex: 1;
  min-width: 0;
  margin: 0;
  font: 400 15px/1 var(--serif);
  letter-spacing: 0.02em;
  color: var(--muted);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bar-back {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: none;
  height: 36px;
  padding: 0 15px 0 11px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--panel);
  color: var(--cream);
  font: 500 13.5px/1 var(--sans);
  cursor: pointer;
  transition: border-color 160ms ease, background-color 160ms ease, transform 160ms ease;
}

.bar-back svg {
  width: 17px;
  height: 17px;
  fill: currentColor;
}

.bar-back:hover {
  border-color: rgb(232 84 127 / 60%);
  background: rgb(232 84 127 / 14%);
}

.bar-back:active {
  transform: translateY(1px);
}

/* ===========================================================================
   Welcome page
   =========================================================================== */

.home {
  position: relative;
  z-index: 1;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  padding: clamp(20px, 3vh, 30px) clamp(20px, 5vw, 60px) clamp(28px, 5vh, 56px);
  overflow: hidden auto;
  background:
    radial-gradient(1200px 720px at 82% -8%, rgb(157 23 69 / 26%) 0%, transparent 62%),
    radial-gradient(900px 620px at 4% 106%, rgb(232 84 127 / 14%) 0%, transparent 64%),
    linear-gradient(168deg, var(--ink) 0%, var(--ink-2) 52%, var(--ink) 100%);
}

/* Two slow rose blooms behind the content. Purely decorative. */
.glow {
  position: absolute;
  z-index: -1;
  border-radius: 50%;
  filter: blur(70px);
  pointer-events: none;
}

.glow-a {
  width: 46vmax;
  height: 46vmax;
  top: -20vmax;
  right: -12vmax;
  background: rgb(232 84 127 / 15%);
  animation: drift 26s ease-in-out infinite alternate;
}

.glow-b {
  width: 38vmax;
  height: 38vmax;
  bottom: -18vmax;
  left: -10vmax;
  background: rgb(240 197 138 / 8%);
  animation: drift 34s ease-in-out -8s infinite alternate-reverse;
}

@keyframes drift {
  to {
    transform: translate3d(4vmax, 3vmax, 0) scale(1.14);
  }
}

.home-inner {
  width: min(1120px, 100%);
  margin: auto;
  padding: clamp(28px, 6vh, 60px) 0 0;
}

/* The headline and the model share a row on a wide screen. On a narrow one the grid
   collapses to a single column and the model lands under the headline, which is where
   the markup already puts it. */
.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 0.82fr);
  align-items: center;
  gap: clamp(20px, 3vw, 54px);
  margin-bottom: clamp(26px, 4.2vh, 46px);
}

.eyebrow {
  margin: 0 0 14px;
  font: 500 12px/1 var(--sans);
  letter-spacing: 0.26em;
  text-transform: uppercase;
  color: var(--muted-2);
}

.eyebrow::before {
  content: "";
  display: inline-block;
  width: 26px;
  height: 1px;
  margin: 0 12px 4px 0;
  background: linear-gradient(90deg, transparent, var(--rose));
  vertical-align: middle;
}

/* Sized off both axes: on a short laptop window the width alone would pick a 66px
   headline and push the buttons under the fold. */
.headline {
  margin: 0; /* the hero grid owns the spacing on both axes */
  max-width: 21ch;
  font: 400 clamp(32px, min(5.4vw, 7.4vh), 66px) / 1.08 var(--serif);
  letter-spacing: -0.015em;
  text-wrap: balance;
}

.headline-accent {
  display: block;
  color: var(--rose-soft); /* fallback */
  background: linear-gradient(100deg, #ffe7ef 0%, var(--rose-soft) 34%, var(--rose) 72%, var(--gold) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  font-style: italic;
}

/* --- the endoplasmic reticulum ------------------------------------------- */

.hero-model {
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

/* Deliberately unstyled: no border, no background, no shadow. The canvas is the box —
   invisible until you press inside it and the model turns. */
#hero-canvas {
  display: block;
  width: 100%;
  height: clamp(220px, 34vh, 340px);
  cursor: grab;
  /* Vertical drags stay with the page so the model never traps a phone's scroll;
     horizontal ones reach OrbitControls and spin it. */
  touch-action: pan-y;
}

#hero-canvas.grabbing {
  cursor: grabbing;
}

.hero-fallback {
  margin: 0;
  padding: 0 12px;
  font-size: 13px;
  color: var(--muted-2);
  text-align: center;
}

.hero-model figcaption {
  text-align: center;
  max-width: 42ch;
}

.hero-model figcaption h2 {
  margin: 0 0 6px;
  font: 400 clamp(19px, 1.7vw, 24px) / 1.2 var(--serif);
  letter-spacing: 0.01em;
  color: #ffeef4;
}

.hero-model figcaption p {
  margin: 0;
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--muted-2);
}

/* --- the three statements ------------------------------------------------- */

.pillars {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(14px, 1.6vw, 20px);
  margin-bottom: clamp(26px, 4vh, 42px);
}

.pillar {
  position: relative;
  padding: clamp(20px, 2.2vw, 28px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(158deg, var(--panel) 0%, var(--panel-2) 100%);
  overflow: hidden;
  transition: border-color 200ms ease, transform 260ms cubic-bezier(0.22, 1, 0.36, 1);
}

/* A rose hairline along the top edge, brightening on hover. */
.pillar::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--rose) 34%, var(--gold) 100%);
  opacity: 0.5;
  transition: opacity 200ms ease;
}

.pillar:hover {
  border-color: rgb(232 84 127 / 34%);
  transform: translateY(-3px);
}

.pillar:hover::before {
  opacity: 1;
}

.pillar h2 {
  margin: 0 0 10px;
  font: 400 clamp(18px, 1.5vw, 21px) / 1.2 var(--serif);
  letter-spacing: 0.005em;
  color: #ffeef4;
}

.pillar p {
  margin: 0;
  font-size: clamp(13.5px, 1.02vw, 15px);
  line-height: 1.62;
  color: var(--muted);
}

/* --- the two subject buttons --------------------------------------------- */

.launch {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(14px, 1.6vw, 20px);
}

.subject {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  padding: clamp(16px, 1.8vw, 22px);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: linear-gradient(150deg, rgb(255 255 255 / 7%) 0%, rgb(255 255 255 / 2%) 100%);
  color: var(--cream);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: transform 220ms cubic-bezier(0.22, 1, 0.36, 1), border-color 200ms ease,
    box-shadow 220ms ease;
}

.subject-biology {
  --tint: #63dcae;
}

.subject-physics {
  --tint: #ffb547;
}

.subject:hover {
  transform: translateY(-3px);
  border-color: color-mix(in srgb, var(--tint) 62%, transparent);
  box-shadow: 0 16px 40px rgb(6 3 6 / 55%), 0 0 0 1px color-mix(in srgb, var(--tint) 18%, transparent);
}

.subject:active {
  transform: translateY(-1px);
}

.subject[aria-busy="true"] {
  pointer-events: none;
  opacity: 0.72;
}

.subject-icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 50px;
  height: 50px;
  border-radius: 14px;
  border: 1px solid color-mix(in srgb, var(--tint) 34%, transparent);
  background: color-mix(in srgb, var(--tint) 12%, transparent);
}

.subject-icon svg {
  width: 26px;
  height: 26px;
  fill: none;
  stroke: var(--tint);
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.subject-copy {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  flex: 1;
}

.subject-copy strong {
  font: 400 clamp(20px, 1.8vw, 25px) / 1.1 var(--serif);
  letter-spacing: 0.01em;
}

.subject-copy small {
  font-size: 13px;
  color: var(--muted);
}

.subject-go {
  display: grid;
  place-items: center;
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgb(255 255 255 / 6%);
  transition: transform 220ms cubic-bezier(0.22, 1, 0.36, 1), background-color 200ms ease;
}

.subject-go svg {
  width: 18px;
  height: 18px;
  fill: var(--muted);
}

.subject:hover .subject-go {
  transform: translateX(4px);
  background: color-mix(in srgb, var(--tint) 20%, transparent);
}

.subject:hover .subject-go svg {
  fill: var(--cream);
}

/* Only ever inserted by app.js when the page was opened from the filesystem. */
.diskwarning {
  margin: clamp(18px, 2.6vh, 26px) 0 0;
  max-width: 68ch;
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--gold);
}

/* ===========================================================================
   Stage — the frame each viewer runs in
   =========================================================================== */

.stage {
  position: fixed;
  inset: var(--bar-h) 0 0;
  z-index: 2;
  background: var(--ink);
}

.stage iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
}

/* Inactive viewers stay in the DOM so a second visit is instant. display:none stops the
   frame being rendered, which is what stops its animation loop from being served frames. */
.stage iframe:not(.active) {
  display: none;
}

.stage-loading {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 18px;
  background: linear-gradient(168deg, var(--ink) 0%, var(--ink-2) 60%, var(--ink) 100%);
}

.stage-loading p {
  margin: 0;
  font: 400 15px/1 var(--serif);
  letter-spacing: 0.03em;
  color: var(--muted);
}

.stage-spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2px solid rgb(255 255 255 / 12%);
  border-top-color: var(--rose);
  animation: spin 760ms linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(1turn);
  }
}

/* ===========================================================================
   Boot screen — held over the page until the hero model has drawn once
   =========================================================================== */

.boot {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 22px;
  background: linear-gradient(168deg, var(--ink) 0%, var(--ink-2) 52%, var(--ink) 100%);
  transition: opacity 460ms ease, visibility 460ms;
}

.boot.done {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.boot p {
  margin: 0;
  font: 400 13.5px/1 var(--sans);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted-2);
}

/* An indeterminate sweep: the model's own progress is one 424 KB request, so there is no
   honest percentage to show. */
.boot-track {
  position: relative;
  width: min(220px, 56vw);
  height: 2px;
  border-radius: 2px;
  background: rgb(255 255 255 / 10%);
  overflow: hidden;
}

.boot-track i {
  position: absolute;
  inset: 0 auto 0 0;
  width: 42%;
  border-radius: 2px;
  background: linear-gradient(90deg, transparent, var(--rose) 45%, var(--gold));
  animation: sweep 1.25s cubic-bezier(0.62, 0.06, 0.36, 0.96) infinite;
}

@keyframes sweep {
  from {
    transform: translateX(-108%);
  }
  to {
    transform: translateX(246%);
  }
}

/* ===========================================================================
   Responsive + motion
   =========================================================================== */

/* Laptop-height windows: trim the padding rather than the content, so the two subject
   buttons stay above the fold. */
@media (max-height: 820px) and (min-width: 901px) {
  .home-inner {
    padding-top: clamp(10px, 2.4vh, 28px);
  }

  .eyebrow {
    margin-bottom: 10px;
  }

  .pillar {
    padding: clamp(16px, 1.8vw, 22px);
  }

  .pillar p {
    font-size: 13.5px;
    line-height: 1.55;
  }

  .subject {
    padding: 15px;
  }

  #hero-canvas {
    height: clamp(190px, 28vh, 280px);
  }
}

@media (max-width: 900px) {
  /* Single column: the model falls under "Designing the Future of Education". */
  .hero {
    grid-template-columns: 1fr;
    justify-items: center;
  }

  .hero-copy {
    justify-self: stretch;
  }

  .pillars {
    grid-template-columns: 1fr;
  }

  .headline {
    max-width: none;
  }

  #hero-canvas {
    height: clamp(230px, 38vw, 320px);
  }
}

@media (max-width: 620px) {
  :root {
    --bar-h: 52px;
  }

  .launch {
    grid-template-columns: 1fr;
  }

  .bar-title {
    display: none;
  }

  .bar-back {
    margin-left: auto;
  }

  .logo-lg {
    --mark: 38px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
