/* ==========================================================================
   Embryo Atlas — 3D Transcript Localization
   A minimalist, editorial base in monochrome; colour blooms on interaction.
   ========================================================================== */

:root {
  --bg:        #fafbfc;
  --surface:   #ffffff;
  --ink:       #0b0d13;
  --ink-2:     #3c4453;
  --ink-soft:  #8a91a2;
  --line:      #e7e9ef;
  --line-2:    #eef0f4;
  --accent:    #3b82f6;          /* overridden per stage */
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto,
          Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
          "Liberation Mono", monospace;
  --ease:    cubic-bezier(.22, .68, .25, 1);
  --spring:  cubic-bezier(.34, 1.56, .5, 1);
  --maxw: 880px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }

/* ==========================================================================
   Ambient drifting cells
   ========================================================================== */
.ambient {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}
/* Each ambient cell drifts upward and divides once along the way.
   The container handles the drift; its two pseudo-element "daughters"
   handle the mitosis, synced to the same duration/delay via `inherit`. */
.ambient .acell {
  position: absolute;
  bottom: -16vh;
  opacity: 0;
  animation: drift linear infinite;
}
.ambient .acell::before,
.ambient .acell::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1.5px solid var(--line);
  animation-name: mitosis;
  animation-timing-function: ease-in-out;
  animation-iteration-count: infinite;
  animation-duration: inherit;     /* sync with the parent's drift */
  animation-delay: inherit;
}
.ambient .acell::before { --dir: -1; }
.ambient .acell::after  { --dir:  1; }

@keyframes drift {
  0%   { opacity: 0; transform: translateY(0) translateX(0); }
  12%  { opacity: .5; }
  88%  { opacity: .5; }
  100% { opacity: 0; transform: translateY(-130vh) translateX(var(--dx)); }
}
/* one cell  ->  elongate  ->  pinch  ->  two cells */
@keyframes mitosis {
  0%, 30%   { transform: translateX(0) scale(1); }
  46%       { transform: translateX(0) scaleX(1.16) scaleY(.86); }
  60%       { transform: translateX(calc(var(--dir) * 16%))
                         scaleX(.92) scaleY(.98); }
  74%, 100% { transform: translateX(calc(var(--dir) * 42%)) scale(.72); }
}

/* ==========================================================================
   Topbar
   ========================================================================== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.6rem;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex;
  align-items: center;
  gap: .55rem;
  font-weight: 700;
  font-size: .98rem;
  letter-spacing: -.01em;
}
.brand-dot {
  width: 11px; height: 11px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 55%, transparent);
  animation: beacon 3.2s var(--ease) infinite;
}
@keyframes beacon {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb,var(--accent) 50%,transparent); }
  50%      { box-shadow: 0 0 0 7px color-mix(in srgb,var(--accent) 0%,transparent); }
}
.brand-name { transition: letter-spacing .3s var(--ease); }
.brand:hover .brand-name { letter-spacing: .01em; }
.topbar-meta {
  font-family: var(--mono);
  font-size: .74rem;
  letter-spacing: .04em;
  color: var(--ink-soft);
}

/* ==========================================================================
   Layout shell
   ========================================================================== */
.landing {
  position: relative;
  z-index: 1;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 1.6rem 5rem;
}

/* ==========================================================================
   Hero
   ========================================================================== */
.hero { padding: 5.5rem 0 4rem; }
.eyebrow {
  font-family: var(--mono);
  font-size: .76rem;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 1.5rem;
}
.hero-title {
  font-size: clamp(2.1rem, 5.8vw, 3.7rem);
  font-weight: 800;
  line-height: 1.06;
  letter-spacing: -.035em;
  max-width: 20ch;
}
.hero-accent {
  background-image: linear-gradient(
    100deg, #6366f1, #0ea5e9, #14b8a6, #22c55e, #f59e0b);
  background-size: 220% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  /* `alternate` sweeps the gradient forward then back — no instant
     wrap-around, so the colours never jump. */
  animation: hue-pan 11s ease-in-out infinite alternate;
}
@keyframes hue-pan {
  from { background-position:   0% 50%; }
  to   { background-position: 100% 50%; }
}
.hero-sub {
  margin-top: 1.5rem;
  font-size: clamp(1.02rem, 1.6vw, 1.2rem);
  color: var(--ink-2);
  max-width: 52ch;
}

/* ==========================================================================
   Stages section
   ========================================================================== */
.stages { margin-top: 1.5rem; }
.stages-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding-bottom: .85rem;
  border-bottom: 1px solid var(--line);
}
.stages-head h2 {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -.01em;
}
.stages-count {
  font-family: var(--mono);
  font-size: .78rem;
  color: var(--ink-soft);
  letter-spacing: .03em;
}

/* ----- the list container ----- */
.stage-list {
  margin-top: 1.4rem;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  overflow: hidden;
}

/* ----- a single stage row (a button) ----- */
.stage-row {
  position: relative;
  display: flex;
  align-items: stretch;
  gap: 1.4rem;
  width: 100%;
  padding: 1.7rem 1.7rem;
  text-align: left;
  background: transparent;
  border: none;
  border-top: 1px solid var(--line-2);
  cursor: pointer;
  isolation: isolate;
  transition: background .35s var(--ease);
  /* entrance */
  opacity: 0;
  transform: translateY(18px);
  animation: rise .65s var(--ease) forwards;
  animation-delay: calc(var(--d, 0) * .07s + .2s);
}
.stage-row:first-child { border-top: none; }
.stage-row:hover,
.stage-row:focus-visible {
  background: color-mix(in srgb, var(--accent) 4.5%, var(--surface));
  outline: none;
}

/* left accent bar that grows on hover */
.stage-row::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--accent);
  transform: scaleY(0);
  transform-origin: top;
  transition: transform .4s var(--spring);
}
.stage-row:hover::before,
.stage-row:focus-visible::before { transform: scaleY(1); }

/* cursor-following colour spotlight */
.row-spot {
  position: absolute;
  inset: 0;
  z-index: -1;
  opacity: 0;
  transition: opacity .4s var(--ease);
  background: radial-gradient(
    200px circle at var(--mx, 50%) var(--my, 50%),
    color-mix(in srgb, var(--accent) 16%, transparent), transparent 72%);
}
.stage-row:hover .row-spot { opacity: 1; }

/* ----- row body ----- */
.row-body { flex: 1 1 auto; min-width: 0; }
.row-eyebrow {
  font-family: var(--mono);
  font-size: .73rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--ink-soft);
  transition: color .3s var(--ease);
}
.stage-row:hover .row-eyebrow { color: var(--accent); }
.row-idx { font-weight: 600; }
.row-name {
  margin-top: .5rem;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -.02em;
}
.row-desc {
  margin-top: .55rem;
  color: var(--ink-2);
  font-size: .96rem;
  max-width: 54ch;
}
.row-divider {
  height: 1px;
  margin: 1.15rem 0 .9rem;
  background: var(--line);
  transition: background .35s var(--ease);
}
.stage-row:hover .row-divider {
  background: color-mix(in srgb, var(--accent) 40%, var(--line));
}
.row-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.row-count {
  font-family: var(--mono);
  font-size: .76rem;
  letter-spacing: .04em;
  color: var(--ink-soft);
}
.row-cta {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  font-family: var(--mono);
  font-size: .76rem;
  letter-spacing: .04em;
  color: var(--ink-soft);
  opacity: 0;
  transform: translateX(-6px);
  transition: opacity .3s var(--ease), transform .35s var(--spring),
              color .3s var(--ease);
}
.stage-row:hover .row-cta,
.stage-row:focus-visible .row-cta {
  opacity: 1;
  transform: translateX(0);
  color: var(--accent);
}
.cta-arrow { transition: transform .35s var(--spring); }
.stage-row:hover .cta-arrow { transform: translateX(4px); }

/* ----- the cell-division icon ----- */
.row-icon {
  flex: 0 0 auto;
  width: 64px; height: 64px;
}
.row-icon .cluster {
  width: 100%; height: 100%;
  overflow: visible;
  transition: filter .4s var(--ease);
}
.stage-row:hover .row-icon .cluster {
  filter: drop-shadow(0 2px 9px
          color-mix(in srgb, var(--accent) 55%, transparent));
}
/* each daughter cell — at rest the pair overlaps into one outlined circle;
   on hover the pair separates ("divides") and fills with the stage colour. */
.daughter {
  fill: color-mix(in srgb, var(--accent) 0%, transparent);
  stroke: var(--ink-soft);
  stroke-width: 1.6;
  transform-box: fill-box;
  transform-origin: center;
  transition:
    transform .62s var(--spring),
    fill .4s var(--ease),
    stroke .4s var(--ease);
  transition-delay: calc(var(--i, 0) * .045s);
}
.stage-row:hover .daughter,
.stage-row:focus-visible .daughter {
  transform: translate(var(--tx, 0), var(--ty, 0)) scale(.7);
  fill: var(--accent);
  stroke: var(--accent);
}

/* ----- click ripple ----- */
.ripple {
  position: absolute;
  border-radius: 50%;
  background: color-mix(in srgb, var(--accent) 38%, transparent);
  transform: translate(-50%, -50%) scale(0);
  pointer-events: none;
  z-index: 5;
  animation: ripple .62s var(--ease) forwards;
}
@keyframes ripple {
  to { transform: translate(-50%, -50%) scale(1); opacity: 0; }
}

/* ==========================================================================
   Stage states (loading / empty / error)
   ========================================================================== */
.stage-state {
  margin-top: 1.4rem;
  padding: 2.4rem 1.7rem;
  border: 1px dashed var(--line);
  border-radius: 16px;
  text-align: center;
  color: var(--ink-soft);
  font-size: .94rem;
}
.stage-state strong { display: block; color: var(--ink-2); margin-bottom: .3rem; }
.stage-state code {
  font-family: var(--mono);
  font-size: .85em;
  background: var(--line-2);
  padding: .1em .4em;
  border-radius: 4px;
  color: var(--ink-2);
}
.stage-state.error { color: #c0392b; border-color: #f0c8c2; }
.dots { display: inline-flex; gap: .3rem; margin-right: .5rem; }
.dots i {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--ink-soft);
  animation: blink 1.1s var(--ease) infinite;
}
.dots i:nth-child(2) { animation-delay: .15s; }
.dots i:nth-child(3) { animation-delay: .3s; }
@keyframes blink {
  0%, 100% { opacity: .25; transform: translateY(0); }
  50%      { opacity: 1;   transform: translateY(-3px); }
}

/* ==========================================================================
   Footer
   ========================================================================== */
.footer {
  display: flex;
  align-items: center;
  gap: .8rem;
  margin-top: 3.5rem;
  padding-top: 1.4rem;
  border-top: 1px solid var(--line);
  font-family: var(--mono);
  font-size: .74rem;
  letter-spacing: .03em;
  color: var(--ink-soft);
}
.footer-sep {
  width: 4px; height: 4px;
  border-radius: 50%;
  background: var(--line);
}

/* ==========================================================================
   Viewer overlay
   ========================================================================== */
.viewer {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  opacity: 0;
  transform: scale(.985);
  transition: opacity .4s var(--ease), transform .4s var(--ease);
}
/* When hidden, fully remove it from the layout — otherwise this fixed,
   full-viewport overlay would sit on top of the landing and swallow every
   click and hover even at opacity 0. */
.viewer[hidden] { display: none; }
.viewer.open { opacity: 1; transform: scale(1); }

.viewer-bar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: .8rem 1.4rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.back-btn {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  padding: .5rem .9rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  cursor: pointer;
  font-size: .86rem;
  font-weight: 500;
  transition: border-color .25s var(--ease), background .25s var(--ease),
              transform .15s var(--ease);
}
.back-btn:hover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 7%, var(--surface));
  color: var(--accent);
}
.back-btn:active { transform: scale(.96); }
.back-arrow { transition: transform .3s var(--spring); }
.back-btn:hover .back-arrow { transform: translateX(-3px); }

.viewer-id {
  display: flex;
  align-items: baseline;
  gap: .6rem;
  flex: 1 1 auto;
  min-width: 0;
}
.viewer-dot {
  align-self: center;
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--accent);
  flex: 0 0 auto;
}
.viewer-phase {
  font-family: var(--mono);
  font-size: .72rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.viewer-name { font-weight: 700; letter-spacing: -.01em; }
.newtab {
  font-family: var(--mono);
  font-size: .74rem;
  letter-spacing: .03em;
  color: var(--ink-soft);
  white-space: nowrap;
  transition: color .25s var(--ease);
}
.newtab:hover { color: var(--accent); }

.viewer-body { position: relative; flex: 1 1 auto; }
.viewer-frame {
  width: 100%; height: 100%;
  border: none;
  display: block;
  background: var(--bg);
  opacity: 0;
  transition: opacity .5s var(--ease);
}
.viewer-frame.ready { opacity: 1; }

.viewer-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .9rem;
  background: var(--bg);
  transition: opacity .45s var(--ease);
}
.viewer-loading.hidden { opacity: 0; pointer-events: none; }
.viewer-loading p {
  font-weight: 600;
  font-size: 1rem;
}
.loader-hint {
  font-family: var(--mono);
  font-size: .74rem;
  letter-spacing: .04em;
  color: var(--ink-soft);
}
/* loader = a perpetually dividing cell */
.loader {
  position: relative;
  width: 56px; height: 56px;
}
.loader::before, .loader::after {
  content: "";
  position: absolute;
  top: 50%; left: 50%;
  width: 30px; height: 30px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  transform: translate(-50%, -50%);
  animation: mitosis 1.8s var(--ease) infinite;
}
.loader::after { animation-delay: .9s; }
@keyframes mitosis {
  0%   { transform: translate(-50%,-50%) translateX(0)    scale(1);   opacity: 1; }
  45%  { transform: translate(-50%,-50%) translateX(0)    scale(.62); opacity: 1; }
  75%  { transform: translate(-50%,-50%) translateX(-15px) scale(.7); opacity: 1; }
  100% { transform: translate(-50%,-50%) translateX(-26px) scale(.55); opacity: 0; }
}

/* ==========================================================================
   Entrance
   ========================================================================== */
.reveal {
  opacity: 0;
  transform: translateY(16px);
  animation: rise .8s var(--ease) forwards;
  animation-delay: calc(var(--d, 0) * .09s);
}
@keyframes rise {
  to { opacity: 1; transform: translateY(0); }
}

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 640px) {
  .topbar { padding: .85rem 1.1rem; }
  .topbar-meta { font-size: .66rem; }
  .landing { padding: 0 1.1rem 4rem; }
  .hero { padding: 3.5rem 0 2.8rem; }
  .stage-row { padding: 1.3rem 1.2rem; gap: .9rem; }
  .row-name { font-size: 1.25rem; }
  .row-icon { width: 48px; height: 48px; }
  .viewer-bar { padding: .7rem 1rem; gap: .7rem; }
  .newtab { display: none; }
}

/* Respect users who prefer less motion. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
  .reveal, .stage-row { opacity: 1; transform: none; }
}
