/* home.css: what only the home page needs, on top of site.css. The first
   screen's layout, the classes Fig. 1 (the frog) draws with, and the
   taped-in card for each model with its small sketch. Every colour is a
   token from site.css, so the drawings follow light and dark by
   themselves, except four washes the plant cell sketch copies from the
   model's own drawing (see the sketch below). */

/* ---------- the first screen ----------
   Wide: the writing on the left, the taped-in figure on the right, beside
   both the heading and the sections. Narrow: one column, in reading order. */

.home {
  display: grid;
  grid-template-columns: minmax(20rem, 1fr) minmax(0, 37.5rem);
  grid-template-rows: auto 1fr;
  column-gap: 3rem;
  align-items: start;
}

.intro {
  grid-column: 1;
  grid-row: 1;
}

.plate {
  grid-column: 2;
  grid-row: 1 / span 2;
}

.entries {
  grid-column: 1;
  grid-row: 2;
}

.intro .note {
  margin-bottom: 0;
}

@media (max-width: 64rem) {
  .home {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: none;
  }

  .intro,
  .plate,
  .entries {
    grid-column: 1;
    grid-row: auto;
  }

  .plate {
    max-width: 37.5rem;
    margin-top: 2.5rem;
  }
}

/* ---------- Fig. 1 ---------- */

/* overflow: a label that a reader's own text spacing (WCAG 1.4.12) makes
   wider runs on into the card's margin instead of being cut off at the
   drawing's edge. The drawing itself is cut at its frame in the SVG. */
.plate svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

/* ---------- drawing classes ---------- */

.ln {
  fill: none;
  stroke: var(--ink);
  stroke-width: 2.25;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.ln-thin {
  fill: none;
  stroke: var(--ink);
  stroke-width: 1.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.f-water { fill: var(--water); }
.f-pad { fill: var(--rule-strong); }
.f-skin { fill: var(--leaf); }
.f-sedge { fill: var(--rule-strong); }
.f-tymp { fill: var(--rule-strong); }
.f-spot { fill: var(--pond-deep); }
.f-shade { fill: var(--pond-deep); opacity: 0.16; }
.f-throat { fill: var(--tape); }
.f-iris { fill: var(--tape); }
.f-pupil { fill: var(--ink); }
.f-glint { fill: var(--card); }
.f-dot { fill: var(--ink); }

.f-lid {
  fill: var(--leaf);
  stroke: var(--ink);
  stroke-width: 1.4;
  stroke-linejoin: round;
}

.ripple {
  fill: none;
  stroke: var(--pond);
  stroke-width: 1.5;
  stroke-linecap: round;
}

.vein {
  fill: none;
  stroke: var(--pond);
  stroke-width: 1.2;
  stroke-linecap: round;
  opacity: 0.6;
}

.hatch {
  fill: none;
  stroke: var(--pencil);
  stroke-width: 1.2;
  stroke-linecap: round;
}

.shine {
  fill: none;
  stroke: var(--card);
  stroke-width: 2;
  stroke-linecap: round;
}

.leader {
  fill: none;
  stroke: var(--pencil);
  stroke-width: 1.5;
  stroke-linecap: round;
}

.leader-dot { fill: var(--pencil); }

.label {
  font-family: var(--hand);
  font-weight: 600;
  font-size: 19px;
  fill: var(--ink);
}

/* On a phone the figure shrinks to about half size; the labels shrink less.
   Only up to 32rem: wider than that, 19px labels already render at 12px
   or more, and 25px ones would render larger than the running text. */
@media (max-width: 32rem) {
  .label { font-size: 25px; }

  /* Lettered at 25px, "webbed hind foot" ends near the drawing's right
     edge, where wider letter spacing would push it past the card. Here it
     is held by its right end instead, at x 617 (where it ends at 25px in
     Shantell Sans, its start at 392 as everywhere else), so added spacing
     grows it to the left, along the empty band below the lily pad. */
  .labels-wide .label-foot {
    text-anchor: end;
    transform: translateX(225px);
  }
}

/* The drawing carries two sets of the same five labels, and shows one.
   The wide set sits beside the parts. The phone set, for screens up to
   25rem, where a 25px label would render under 12px (the drawing is 640
   units wide), is lettered larger and laid out in the empty bands above
   the frog and below the lily pad: 32px renders at about 12.5px on a
   320px screen and 16.5px on a 400px one. Below 20rem it is lettered
   larger again: 37px renders at about 12px on a 280px screen (a folding
   phone's cover screen) and 14.5px on a 319px one.
   The set is laid out to fit both sizes. */
.labels-phone {
  display: none;
}

.labels-phone .label { font-size: 32px; }
.labels-phone .leader { stroke-width: 3.2; }

@media (max-width: 19.9375rem) {
  .labels-phone .label { font-size: 37px; }
}

@media (max-width: 25rem) {
  .labels-wide {
    display: none;
  }

  .labels-phone {
    display: inline;
  }

  /* a little less card around the drawing, so it can be drawn larger */
  .plate {
    padding-right: 0.5rem;
    padding-left: 0.5rem;
  }
}

/* At night the dark tokens and the light tokens swap places, so the few
   parts that must stay dark (a pupil) or light (a glint) pick another. */
@media screen and (prefers-color-scheme: dark) {
  .f-pupil { fill: var(--paper); }
  .f-glint { fill: var(--ink); }
  .f-dot { fill: var(--paper); }
  .shine { stroke: var(--pencil); }
  .f-throat { fill: var(--pencil); opacity: 0.45; }
  .vein { opacity: 0.45; }
}

/* Forced colours: each drawing is a picture, so it keeps its own colours
   on its own card, as an image would. The captions follow the system, and
   so does the ring around a model's card. */
@media (forced-colors: active) {
  .plate svg,
  .cell-sketch {
    forced-color-adjust: none;
    background: var(--card);
  }

  .model-card h3 a:focus-visible::after {
    outline-color: Highlight;
  }
}

/* ---------- the blink ----------
   The one thing on the page that moves by itself. A frog blinks upward:
   the lower lid rises over the eye. It blinks twice soon after the page
   opens, then keeps still: one run through the keyframes, 4 seconds long,
   starting a second after the page loads, so the blinks come at 1.6 and
   3.4 seconds. WCAG 2.2.2 allows something that moves by itself beside
   the text only for less than five seconds, unless the page gives a way
   to stop it. Open by default; it only moves when the device says motion
   is welcome. While the eye is open the lid is not drawn at all: squashed
   flat, its outline still left a hairline under the eye. Between a hidden
   and a visible keyframe a browser keeps the shape visible, so the lid
   shows for each whole blink (240 ms, 6% of the run) and at no other
   time, and after the run the eye stays open. */

.eyelid {
  transform-box: fill-box;
  transform-origin: 50% 100%;
  transform: scaleY(0);
  visibility: hidden;
}

@media (prefers-reduced-motion: no-preference) {
  .eyelid {
    animation: blink 4s ease-in-out 1s 1;
  }
}

@keyframes blink {
  0%, 15% { transform: scaleY(0); visibility: hidden; }
  18% { transform: scaleY(1); visibility: visible; }
  21%, 60% { transform: scaleY(0); visibility: hidden; }
  63% { transform: scaleY(1); visibility: visible; }
  66%, 100% { transform: scaleY(0); visibility: hidden; }
}

/* ---------- the models: one taped-in card each ----------
   A list, so the next model is one more card in it, below this one, with
   room between for its strip of tape. The card's
   heading is its one link, and the link's ::after is stretched over the
   whole card, so a click or tap anywhere on it opens the model. Keyboard
   focus rings the whole card. Narrow: the sketch on top, then the words.
   Wide enough for both: the sketch at the left, the words beside it. */

.models {
  display: grid;
  gap: 2.25rem;
  max-width: 36rem;
  margin: 1.5rem 0 1.25rem;
  padding: 0;
  list-style: none;
}

.model-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-content: start;
  padding: 0.875rem 1rem;
  transform: rotate(-0.75deg);
}

/* the strip of tape across the sketch's top corner, clear of the words */
.model-card::before {
  left: 1.5rem;
  width: 6rem;
  margin-left: 0;
  transform: rotate(-4deg);
}

.model-sketch {
  grid-row: 1;
  margin: 0;
}

.model-card h3 {
  grid-row: 2;
  margin: 0.625rem 0 0.25rem;
}

.model-card p {
  grid-row: 3;
  margin: 0;
}

.model-card h3 a::after {
  content: "";
  position: absolute;
  inset: 0;
}

.model-card h3 a:focus-visible {
  outline: none;
}

.model-card h3 a:focus-visible::after {
  outline: 3px solid var(--focus);
  outline-offset: 4px;
}

/* Side by side where the card is wide enough for a sketch and a few words
   a line: one column from 31rem, or beside the frog from 80rem. */
@media (min-width: 31rem) and (max-width: 64rem), (min-width: 80rem) {
  .model-card {
    grid-template-columns: 13.5rem minmax(0, 1fr);
    grid-template-rows: auto 1fr;
    column-gap: 1.25rem;
  }

  .model-sketch {
    grid-column: 1;
    grid-row: 1 / span 2;
  }

  .model-card h3 {
    grid-column: 2;
    grid-row: 1;
    margin-top: 0.125rem;
  }

  .model-card p {
    grid-column: 2;
    grid-row: 2;
  }
}

/* ---------- the plant cell sketch ----------
   Fig. 2 on the model page, drawn small from that drawing's own shapes.
   The cell wall, cytoplasm, vacuole, chloroplasts and membrane take the
   same tokens as there. The nucleus, mitochondria, endoplasmic reticulum
   and Golgi apparatus take the four washes of that drawing, copied from
   cell.css with their dark values (the page does not load cell.css); they
   only fill shapes, and no text sits on them. The lines are drawn heavier
   than there, since the sketch is drawn at about a third of the size. */

.cell-sketch {
  display: block;
  width: 100%;
  height: auto;
  --c-mito: #d4703a;
  --c-nuc: #9478c8;
  --c-er: #6386d0;
  --c-golgi: #3a978a;
}

@media screen and (prefers-color-scheme: dark) {
  .cell-sketch {
    --c-mito: #b8673a;
    --c-nuc: #7259a6;
    --c-er: #5577bf;
    --c-golgi: #2f8174;
  }
}

.cell-sketch path,
.cell-sketch rect {
  stroke: var(--ink);
  stroke-linecap: round;
  stroke-linejoin: round;
}

.cell-sketch .wall { fill: var(--tape); fill-rule: evenodd; stroke-width: 5.5; }
.cell-sketch .cyto { fill: var(--paper); stroke: none; }
.cell-sketch .vac { fill: var(--water); stroke-width: 5; }
.cell-sketch .nuc { fill: var(--c-nuc); stroke-width: 5; }
.cell-sketch .nucleolus { fill: var(--ink); fill-opacity: 0.4; stroke-width: 3.5; }
.cell-sketch .tube-ink { fill: none; stroke-width: 17; }
.cell-sketch .tube-fill { fill: none; stroke: var(--c-er); stroke-width: 10; }
.cell-sketch .er { fill: var(--c-er); stroke: none; }
/* the rough ER's two edges: open at the nucleus and where the smooth ER's
   tube runs on from it, with flat ends, as on the model page */
.cell-sketch .er-line { fill: none; stroke-width: 4.5; stroke-linecap: butt; }
.cell-sketch .butt { stroke-linecap: butt; }
.cell-sketch .golgi { fill: var(--c-golgi); stroke-width: 4; }
.cell-sketch .mito { fill: var(--c-mito); stroke-width: 4.5; }
.cell-sketch .crista { fill: var(--card); fill-opacity: 0.35; stroke-width: 2.5; }
.cell-sketch .chl { fill: var(--leaf); stroke-width: 4.5; }
.cell-sketch .grana { fill: var(--pond); stroke: none; }
.cell-sketch .mem { fill: none; stroke: var(--pond); stroke-width: 5; }

@media print {
  .home {
    display: block;
  }

  .plate {
    max-width: 30rem;
    margin-top: 1.5rem;
  }

  /* straight on paper, as site.css sets every taped-in object */
  .model-card {
    transform: none;
  }
}
