/* Game 1 (Meiosis and Mating): this page's own layout. Loaded last, after zora.css, clinic.css and
   meiosis.css. Colours come from the variables in clinic.css; the chromosome, ring and cell colours
   are data colours drawn by zora-meiosis-view.js and are not themed.

   The screen is a bento of framed cells that fills the window:
     title | parents on the lab stage, with their buttons | Mate and the babies
     Parent 1's meiosis board          | Parent 2's meiosis board
   Below 900px wide the cells stack and the page scrolls. */

.game1-body { padding: 6px; min-height: 0; }

.game1-page {
  --gap: 6px;
  --stage-min: 196px;                       /* least height of the top row */
  /* Height the boards row needs when a board is as wide as its cell allows (see --u below). */
  --board-need: calc((50vw - 45px) * 580 / 930 + 168px);
  max-width: none; margin: 0;
  height: calc(100vh - 12px); height: calc(100dvh - 12px); min-height: 600px;
  display: grid; gap: var(--gap);
  grid-template-columns: 170px minmax(0, 1fr) 440px;
  grid-template-rows: minmax(0, 1fr) min(var(--board-need), calc(100% - var(--stage-min) - var(--gap)));
  grid-template-areas: "title parents babies" "boards boards boards";
}
.game1-page .title-cell { grid-area: title; }
.game1-page .parents-cell { grid-area: parents; }
.game1-page .babies-cell { grid-area: babies; }
.game1-page .boards { grid-area: boards; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--gap); min-height: 0; }

/* The frame art keeps its 24px (8 art pixels) scale but takes only 16px of room: the frame itself
   is 12px thick, so the contents may sit closer to it than the full border width. */
.game1-page .panel { border-width: 16px; padding: 2px; min-width: 0; min-height: 0; }
.game1-page dialog.px-popup { border-width: 18px; padding: 4px 8px 8px; }

.game1-page h1, .game1-page h2, .game1-page h3 { margin: 0; text-align: left; }
.game1-page h2 { font-size: 0.95rem; }
.game1-page h3 { font-size: 0.85rem; }

/* Buttons: no lift or glow on hover; icons sit inside the 44px height. */
.game1-page button, .game1-page .px-btn { transition: none; }
.game1-page button:hover, .game1-page button:disabled { transform: none; box-shadow: none; }
.game1-page button .px-icon, .game1-page .px-btn .px-icon { margin: -8px 2px -6px -4px; flex: none; }
.game1-page button:disabled .px-icon { opacity: 0.5; }
.game1-page a.px-btn { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.game1-page a.px-btn:hover { border-image-source: url(clinic/btn2_hover.png); color: var(--ink); text-shadow: none; }
.game1-page a.px-btn:active { border-image-source: url(clinic/btn2_down.png); color: var(--cream); }

/* Parent colour key: the dark and the light shade of that parent's chromosomes. */
.game1-page { --p1-dark: #2f5fd0; --p1-light: #a9c3f5; --p2-dark: #d81b7a; --p2-light: #f8a8cf; }
.game1-page .swatch { display: inline-block; width: 14px; height: 12px; margin-right: 6px; vertical-align: -1px;
  background: linear-gradient(90deg, var(--dark) 50%, var(--light) 50%); box-shadow: 0 0 0 2px var(--ink); }
.game1-page .swatch.p1 { --dark: var(--p1-dark); --light: var(--p1-light); }
.game1-page .swatch.p2 { --dark: var(--p2-dark); --light: var(--p2-light); }

/* ---- Title cell ---- */
.game1-page .title-cell { display: flex; flex-direction: column; gap: 4px; }
.game1-page .title-cell h1 { font-size: 0.9rem; line-height: 1.2; margin: 2px 0 0 2px; }
.game1-page .title-tip { font-size: 0.78rem; line-height: 1.35; color: var(--dim); margin: 6px 2px 0; }
.game1-page .title-buttons { margin-top: auto; display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.game1-page .title-buttons > * { min-height: 40px; padding: 0 2px 3px; font-size: 0.8rem; min-width: 0; }
.game1-page .title-buttons > :active:not(:disabled) { padding: 3px 2px 0; }
.game1-page .title-buttons #random-match { grid-column: 1 / -1; }
.game1-page .title-buttons .px-icon { display: none; }
@media (max-height: 839px) { .game1-page .title-tip { display: none; } }

/* ---- Parents cell: buttons, the lab stage, buttons ---- */
.game1-page .parents-cell { display: flex; gap: 8px; }
.game1-page .parent-controls { flex: 0 0 144px; min-width: 0; display: flex; flex-direction: column; justify-content: center; gap: 4px; }
.game1-page .parent-controls h2 { text-align: center; white-space: nowrap; margin-bottom: 2px; }
.game1-page .parent-controls button { width: 100%; min-height: 40px; padding: 0 4px 3px; font-size: 0.8rem; }
.game1-page .parent-controls button:active:not(:disabled) { padding: 3px 4px 0; }
.game1-page .parent-controls .px-icon { display: none; }

/* The real stage. `.stage` is also the name zora-meiosis-view.js gives each row of a meiosis board
   (styled in meiosis.css), so the lab stage undoes those row rules here and the board rows undo the
   lab backdrop further down. */
.game1-page .lab.stage {
  display: flex; align-items: flex-end; grid-template-columns: none; border-top: 0;
  flex: 1 1 0; min-width: 0; container-type: size; padding-bottom: 8px;
}
/* A pedestal is always a square, as large as the stage's height or width allows. */
.game1-page .lab.stage .pedestal { height: min(90cqh, 46cqw); width: min(90cqh, 46cqw); max-width: none; flex: none; }
.game1-page .parents-cell .pedestal { cursor: pointer; }
.game1-page .baby-detail .lab.stage .pedestal { height: min(88cqh, 92cqw); width: min(88cqh, 92cqw); }   /* one zora: the whole width */
.game1-page .lab.stage .plate { font-size: 0.75rem; }
/* A baby that did not survive: the words on their own dark label, above the empty platform. */
.game1-page .zora-box.dead { display: grid; place-items: center; text-align: center; }
.game1-page .lab.stage .zora-box.dead { padding: 0 4% 30%; }
.game1-page .dead-note { color: var(--pink); }

/* ---- Babies cell: the Mate button, then the last three babies, newest first ---- */
.game1-page .babies-cell { display: grid; grid-template-columns: 84px minmax(0, 1fr); gap: 8px; }
.game1-page .mate-col { display: flex; flex-direction: column; gap: 4px; min-height: 0; }
.game1-page .mate-col h2 { text-align: center; }
.game1-page #mate { flex: 1 1 auto; min-height: 44px; max-height: 132px; margin: auto 0; padding: 0 2px 3px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 4px; font-size: 1rem; }
.game1-page #mate:active:not(:disabled) { padding: 3px 2px 0; }
.game1-page #mate .px-icon { margin: 0; }
.game1-page .baby-side { min-height: 0; display: flex; flex-direction: column; }
.game1-page .baby-list { list-style: none; flex: 1 1 auto; min-height: 0; overflow-y: auto; container-type: size;
  display: flex; flex-direction: column; gap: 4px; padding: 2px; }
.game1-page .baby-list:empty { display: none; }
.game1-page .babies-hint { display: none; margin: auto 8px; text-align: center; font-size: 0.85rem; line-height: 1.4; color: var(--dim); }
.game1-page .baby-list:empty + .babies-hint { display: block; }
.game1-page .baby-card {
  --row: calc((100cqh - 8px) / 3);           /* three cards fill the list */
  position: relative; flex: none; min-height: var(--row);
  display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 8px; align-items: center;
  background: var(--wall-2); border: 2px solid var(--edge); box-shadow: 0 0 0 2px var(--ink); padding: 0 6px 0 0;
}
.game1-page .baby-card.newest { border-color: var(--gold); }
.game1-page .baby-card:hover, .game1-page .baby-card:focus-within { background: var(--wall-3); }
.game1-page .baby-card .zora-box { height: min(var(--row) - 4px, 64px); width: auto; aspect-ratio: 1 / 1; outline: 0; }
.game1-page .baby-card .zora-box.dead { padding: 0 0 30%; }
.game1-page .baby-card .dead-note { font: 700 0.6rem/1.2 var(--heading-font); background: var(--wall); padding: 1px 2px; }
.game1-page .baby-card h3 { font-size: 0.85rem; line-height: 1.2; white-space: nowrap; }
.game1-page .baby-open { font: inherit; color: var(--ice); background: none; border: 0; border-image: none; min-height: 0; padding: 0;
  text-decoration: underline; text-shadow: none; cursor: pointer; }
.game1-page .baby-open:hover:not(:disabled) { color: var(--gold); }
.game1-page .baby-open:focus-visible { outline-offset: 0; }
.game1-page .baby-open::after { content: ''; position: absolute; inset: 0; }   /* the whole card is the click target */
.game1-page .newest-tag { color: var(--gold); font-weight: 400; font-size: 0.8rem; }
.game1-page .baby-card .baby-message { font-size: 0.72rem; line-height: 1.2; margin: 0; }
.game1-page .baby-message.warn { color: var(--pink); }

/* ---- Meiosis boards ----
   zora-meiosis-view.js draws each cell at a fixed size (190, 218 or 128 units) and stacks the eight
   stages. Here every stage is its own row, top to bottom (owner's request, 2026-11-23): the stage's
   name and count on the left, its cells on the right. The cells sit in four equal columns so that
   each cell is centred above the cells it divides into: one cell spans all four columns, each of
   two cells spans two, each of four cells spans one. The board scrolls inside its own cell.
   --u is CSS px per unit, chosen so that four 128-unit gametes fill the cells' width. */
.game1-page .board-cell { display: flex; }
.game1-page .board-fit { flex: 1 1 auto; min-width: 0; position: relative; container-type: size; overflow: auto; }
.game1-page .board-fit h2 { position: absolute; left: 2px; top: 0; line-height: 16px; white-space: nowrap; }
.game1-page .board-empty { display: none; position: absolute; inset: 0; margin: auto; height: max-content; width: max-content; max-width: 90%;
  text-align: center; color: var(--dim); font-size: 0.9rem; line-height: 1.4; }
.game1-page .board:empty + .board-empty { display: block; }
.game1-page .board:empty { display: none; }
.game1-page .board-fit h2 { position: sticky; top: 0; left: auto; z-index: 2; display: block; background: var(--wall); padding: 0 2px 2px; }
.game1-page .board {
  --title-w: 104px;
  --u: max(0.4px, min(0.9px, calc((100cqw - var(--title-w) - 24px) / 520)));
  display: grid; grid-template-columns: minmax(0, 1fr); row-gap: 2px; align-content: start; padding-bottom: 6px;
}
.game1-page .board .division { text-align: center; font-size: 11px; line-height: 14px; margin: 4px 0 0; padding: 2px 0 1px; }
.game1-page .board .division:first-child { margin: 0; }
.game1-page .board .stage {
  position: relative; display: grid; grid-template-columns: var(--title-w) minmax(0, 1fr); align-items: center; gap: 0 8px;
  padding: 2px 0; border-top: 1px solid var(--edge); background: none; outline: 0; overflow: visible;
}
.game1-page .board .stage-title { display: flex; flex-direction: column; align-items: flex-start; gap: 1px; white-space: normal; text-align: left; }
.game1-page .board .stagename { font-size: 13px; line-height: 16px; }
.game1-page .board .stagenote { line-height: 14px; font-size: 11px; }
.game1-page .board .count { margin: 0; text-align: left; line-height: 13px; }
/* "nondisjunction" stays beside the stage's name, under its count */
.game1-page .board .tag { position: static; transform: none; margin: 2px 0 0; background: var(--ink); border: 1px solid currentColor; padding: 0 4px; line-height: 13px; }
.game1-page .board .cells { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); justify-items: center; align-items: center; }
.game1-page .board .cells svg:only-child { grid-column: 1 / -1; }
.game1-page .board .cells svg:first-child:nth-last-child(2), .game1-page .board .cells svg:first-child:nth-last-child(2) + svg { grid-column: span 2; }
.game1-page .board .cells svg { width: calc(190 * var(--u)); height: calc(190 * var(--u)); margin: calc(-6 * var(--u)) 0; }
.game1-page .board .cells svg[width="218"] { width: calc(218 * var(--u)); height: calc(218 * var(--u)); }
.game1-page .board .cells svg[width="128"] { width: calc(128 * var(--u)); height: calc(128 * var(--u)); }

/* ---- Narrower windows that still fit the bento ---- */
/* The title becomes a bar above the parents, and the babies cell runs down the right. */
@media (max-width: 1179px) and (min-width: 900px) {
  .game1-page {
    --stage-min: 280px;
    grid-template-columns: minmax(0, 1fr) 330px;
    grid-template-rows: auto minmax(0, 1fr) min(var(--board-need), calc(100% - var(--stage-min) - var(--gap)));
    grid-template-areas: "title babies" "parents babies" "boards boards";
  }
  .game1-page .title-cell { flex-direction: row; align-items: center; gap: 8px; }
  .game1-page .title-cell h1 { flex: 1 1 auto; margin: 0 0 0 2px; }
  .game1-page .title-tip { display: none; }
  .game1-page .title-buttons { margin: 0; display: flex; }
  .game1-page .title-buttons > * { padding: 0 8px 3px; }
  .game1-page .title-buttons > :active:not(:disabled) { padding: 3px 8px 0; }
  .game1-page .parent-controls { flex-basis: 132px; }
  .game1-page .babies-cell { grid-template-columns: 70px minmax(0, 1fr); }
  .game1-page .baby-card .zora-box { height: min(var(--row) - 4px, 44px); }
  .game1-page .board .count { font-size: 10px; }
}

/* ---- Below 900px: stack the cells and let the page scroll ---- */
@media (max-width: 899px) {
  .game1-page { display: flex; flex-direction: column; height: auto; min-height: 0; }
  .game1-page .title-cell { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
  .game1-page .title-cell h1 { flex: 1 1 100%; font-size: 1rem; }
  .game1-page .title-tip { display: none; }
  .game1-page .title-buttons { margin: 0; flex: 1 1 100%; grid-template-columns: repeat(3, 1fr); }
  .game1-page .title-buttons #random-match { grid-column: auto; order: 3; }
  .game1-page .parents-cell { display: grid; grid-template-columns: 1fr 1fr; grid-template-areas: "stage stage" "c1 c2"; }
  .game1-page .parents-cell .lab.stage { grid-area: stage; height: 200px; }
  .game1-page .parent-controls { flex: none; }
  .game1-page #controls1 { grid-area: c1; }
  .game1-page #controls2 { grid-area: c2; }
  .game1-page .parent-controls button { min-height: 44px; }
  .game1-page .babies-cell { grid-template-columns: 1fr; }
  .game1-page .mate-col { flex-direction: row; align-items: center; justify-content: space-between; }
  .game1-page #mate { flex: 0 0 auto; flex-direction: row; padding: 0 12px 3px; }
  .game1-page .baby-list { container-type: normal; overflow: visible; }
  .game1-page .baby-card { --row: 72px; }
  .game1-page .boards { grid-template-columns: minmax(0, 1fr); }
  .game1-page .board-fit { container-type: inline-size; overflow: visible; min-height: 80px; }
  .game1-page .board-fit h2 { position: static; margin-bottom: 2px; }
  /* phones: the stage's name goes above its cells, so the cells get the whole width */
  .game1-page .board { --title-w: 0px; --u: max(0.4px, min(1px, calc((100cqw - 8px) / 520))); }
  .game1-page .board .stage { grid-template-columns: minmax(0, 1fr); }
  .game1-page .board .stage-title { flex-direction: row; flex-wrap: wrap; align-items: baseline; gap: 0 8px; }
  .game1-page .board-fit h2 { position: static; }
  .game1-page .alleles-body, .game1-page .baby-detail { grid-template-columns: minmax(0, 1fr); }
  .game1-page .alleles-side { flex-direction: row; flex-wrap: wrap; align-items: center; }
  .game1-page .alleles-side .zora-box { width: 96px; }
  .game1-page .alleles-side .note { flex: 1 1 120px; }
  .game1-page .baby-detail .lab.stage { height: 220px; }
  .game1-page .baby-alleles thead th { white-space: normal; vertical-align: bottom; }
  .game1-page .baby-alleles .chr-num { width: 2em; }
}
@media (max-width: 560px) {
  .game1-page .allele-picker { grid-template-columns: 1fr; }
}

/* Parent alleles pop-up (owner's request): a bigger picture of the parent, and a tighter picker.
   The Genotype / Copy A / Copy B headings show once at the top of each column instead of over
   every chromosome, the dropdowns are shorter, and the rows sit closer together. */
.game1-page .alleles-popup { width: min(960px, 96vw); }
@media (min-width: 900px) {
  .game1-page .alleles-body { grid-template-columns: 330px minmax(0, 1fr); gap: 18px; }
  .game1-page .alleles-side .zora-box { width: 100%; }
}
.game1-page .alleles-popup .allele-picker { gap: 4px 16px; align-content: start; }
.game1-page .alleles-popup .picker-group:nth-child(n+3) .picker-geno,
.game1-page .alleles-popup .picker-group:nth-child(n+3) .picker-col { display: none; }
.game1-page .alleles-popup .picker-head, .game1-page .alleles-popup .picker-row { grid-template-columns: 5.2rem 1fr 1fr; gap: 4px 6px; }
.game1-page .alleles-popup .picker-head { margin-bottom: 2px; }
.game1-page .alleles-popup .picker-row { margin-bottom: 3px; }
.game1-page .alleles-popup .picker-chr { font-size: 0.82rem; margin-top: 2px; }
.game1-page .alleles-popup .picker-gene { font-size: 0.82rem; line-height: 1.15; }
.game1-page .alleles-popup .picker-geno { font-size: 0.7rem; }
.game1-page .alleles-popup .picker-col { font-size: 0.62rem; }
.game1-page .alleles-popup select { min-height: 30px; padding: 2px 20px 2px 5px; font-size: 0.85rem; background-position: right 5px center; }
@media (max-width: 899px) {
  .game1-page .alleles-side .zora-box { width: 180px; }
}
@media (max-width: 560px) {
  /* one column of chromosomes: the headings show over the first chromosome only */
  .game1-page .alleles-popup .picker-group:nth-child(2) .picker-geno,
  .game1-page .alleles-popup .picker-group:nth-child(2) .picker-col { display: none; }
}

/* Baby pop-up (owner's request): a fixed-size window whose details scroll inside it, with
   Previous / Next baby buttons along the bottom to move between babies without closing it. */
.game1-page dialog.baby-popup[open] { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; height: min(640px, 92vh); overflow: hidden; }
.game1-page .baby-detail { min-height: 0; grid-template-rows: minmax(0, 1fr); }
.game1-page .baby-info { min-height: 0; align-self: stretch; overflow-y: auto; padding-right: 6px; }
.game1-page .baby-nav { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding-top: 8px; margin-top: 8px; border-top: 2px solid var(--edge); }
.game1-page .baby-nav button { display: inline-flex; align-items: center; gap: 6px; }
.game1-page .baby-nav .baby-pos { margin: 0; font-size: 0.9rem; color: var(--cream); text-align: center; }
@media (max-width: 899px) {
  /* one column: the picture and the details scroll together */
  .game1-page .baby-detail { overflow-y: auto; align-content: start; grid-template-rows: none; }
  .game1-page .baby-info { overflow: visible; }
}
@media (max-width: 480px) {
  .game1-page .baby-nav button { font-size: 0.75rem; padding: 0 6px 3px; }
}
