/* IVF game screen. Loaded after zora.css, meiosis.css and clinic.css; colours come from clinic.css's variables.
   On a wide window the page is a "bento": a grid of framed cells that fills the window and never scrolls.
   Below 960px the cells stack and the page scrolls normally. */

[hidden] { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
body.ivf { padding: 8px 12px; min-height: 0; }
.ivf-page { max-width: none; margin: 0 auto; display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; }

/* Frames: the art's border is 24px wide but only its outer half is drawn on, so the contents start 16px in. */
.ivf-page .panel { border-width: 15px; padding: 1px 3px; margin: 0; min-width: 0; }
body.ivf dialog.px-popup { border-width: 18px; padding: 2px 6px; }

.ivf-page h1 { margin: 0; font-size: 1.35rem; line-height: 1; text-align: left; white-space: nowrap; }
.ivf-page h2 { margin: 0; font-size: 1.05rem; }
.ivf-page h3 { margin: 0; font-size: 0.9rem; }
.ivf-page h1, .ivf-page h2 { display: flex; align-items: center; gap: 8px; }
.ivf-page p { margin: 0; }
.ivf-page .px-popup p { margin-bottom: 8px; }
.ivf-page ul { list-style: none; margin: 0; padding: 0; }
.ivf-page [tabindex="-1"]:focus-visible { outline-offset: 4px; }

/* Buttons: an icon and a label side by side. (zora.css's hover lift and glow belong to the old look.) */
#ivf button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; transition: none; }
#ivf button:hover { transform: none; box-shadow: none; }
#ivf button .px-icon { flex: none; margin: -8px 0 -6px; }
#ivf button:disabled .px-icon { opacity: 0.55; }
#ivf button.link { min-height: 40px; gap: 6px; font-weight: 700; }
#ivf button.link .px-icon { width: 16px; height: 16px; margin: 0; }
#ivf button.link:hover { color: var(--gold); }
#ivf .icon-btn { min-width: 44px; padding-left: 0; padding-right: 0; }

/* ---- Top bar ---- */
.topbar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 18px; }
.tb-title { display: flex; flex-direction: column; align-items: flex-start; }
.tb-title h1 .px-icon { width: 32px; height: 32px; margin: -6px 0; }
.target { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; min-width: 0; flex: 1 1 100%; }
.target h2 { white-space: nowrap; }
.target h3 { white-space: nowrap; }
.target-line { display: contents; }
.target .px-chip { color: var(--cream); }
.totals { display: grid; grid-template-columns: auto auto; justify-content: start; align-items: end; gap: 0 22px; }
.totals .figure { display: flex; flex-direction: column; line-height: 1.05; }
.totals .label { font-size: 0.8rem; font-weight: 700; color: var(--mint); white-space: nowrap; }
.totals .value { font-size: 2rem; font-weight: 800; color: var(--cream); }
/* The note never widens the block: it takes the width the two figures have. */
.totals .save-note { grid-column: 1 / -1; width: 0; min-width: 100%; font-size: 0.72rem; line-height: 1.2; color: var(--dim); }
.bill { display: grid; grid-template-columns: auto auto; justify-content: start; align-items: center; gap: 0 10px; }
.bill h2 { font-size: 0.85rem; white-space: nowrap; }
.bill h2 .px-icon { width: 16px; height: 16px; }
.bill .total { font-size: 1.5rem; font-weight: 800; line-height: 1.1; }
.bill .breakdown { grid-column: 1 / -1; font-size: 0.78rem; color: var(--dim); }
.topbar #restart { margin-left: auto; }

/* ---- Message line ---- */
.status-line { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; min-height: 44px; padding: 0 12px;
  background: var(--ink); border: 3px solid var(--edge); }
.message { flex: 1 1 12rem; min-height: 1.4em; color: var(--ice); line-height: 1.3; }
.status-line .message:empty::before { content: '…'; color: var(--edge); }

/* ---- Main cells ---- */
.main { display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; min-height: 0; }
.cell-head { display: flex; align-items: center; gap: 8px; min-width: 0; }
.cell-head h2 { margin-right: auto; }
.deck-count { color: var(--dim); font-size: 0.85rem; text-align: right; }

/* The deck: the top card on the left, a strip of every card underneath showing to its right. game-ivf.js
   (layoutDeck) sets each card's left, top, bottom, width and z-index. */
.deck-cell { display: grid; grid-template-rows: auto 480px; gap: 4px; }
.deck { position: relative; min-height: 0; min-width: 0; }
#ivf .adult { position: absolute; top: 0; bottom: 0; left: 0; width: 100%; margin: 0; min-width: 0;
  border: 14px solid transparent; border-image: url(clinic/card.png) 8 fill / 24px stretch; image-rendering: pixelated; }
#ivf .adult.top { display: flex; flex-direction: column; padding: 0 2px 2px; container: card / size; }
#ivf .adult.under { display: block; padding: 0; min-height: 0; font: inherit; color: var(--cream); text-shadow: none;
  cursor: pointer; filter: brightness(0.78); }
#ivf .adult.under:hover, #ivf .adult.under:focus-visible { filter: none; }
@keyframes deal { from { transform: translateX(22px); opacity: 0.5; } }
#ivf .adult.dealt { animation: deal 0.16s ease-out; }
@media (prefers-reduced-motion: reduce) { #ivf .adult.dealt { animation: none; } }

.strip { position: absolute; top: 0; bottom: 0; right: -8px; width: 36px; display: flex; flex-direction: column;
  align-items: center; gap: 6px; overflow: hidden; }
.strip .zora-box { width: 34px; flex: none; aspect-ratio: 1 / 1; }
.strip-name { writing-mode: vertical-rl; font: 700 0.9rem var(--heading-font); color: var(--gold); white-space: nowrap; letter-spacing: 0.04em; }
.more-tag { margin-top: auto; margin-bottom: 4px; font: 700 0.8rem var(--heading-font); color: var(--cream); background: var(--ink);
  padding: 1px 4px; box-shadow: 0 0 0 2px var(--edge); white-space: nowrap; }
.role-tag { font: 700 0.72rem var(--heading-font); color: var(--ink); background: var(--gold); padding: 1px 6px;
  box-shadow: 0 0 0 2px var(--ink); white-space: nowrap; }

.card-head { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin: -3px 0 5px; flex: none; }
.card-head h3 { font-size: 1.15rem; color: var(--gold); }
.card-scroll { flex: 1 1 auto; min-height: 0; overflow-x: hidden; overflow-y: auto; padding-right: 2px; }
.card-look { display: grid; grid-template-columns: minmax(92px, 40%) minmax(0, 1fr); gap: 8px; align-items: start; }
.card-look .zora-box { width: 100%; aspect-ratio: 1 / 1; }
/* A tall card with nothing screened yet has room for a big picture above the features. */
@container card (min-height: 500px) {
  .card-look.roomy { grid-template-columns: minmax(0, 1fr); justify-items: center; }
  .card-look.roomy .zora-box { width: min(100%, 220px); }
  .card-look.roomy .features { justify-self: stretch; }
}
.features { font-size: 0.85rem; line-height: 1.25; color: var(--cream); }
.features li { padding: 1px 0; overflow-wrap: anywhere; }
p.features { margin-top: 6px; color: var(--dim); }
#ivf .card-screen { width: 100%; margin-top: 8px; }
.adult .gtable { font-size: 0.78rem; max-width: 100%; margin-top: 4px; }
.adult .gtable th, .adult .gtable td { padding: 2px 6px; }
.adult .gtable .chr-head { padding-top: 5px; }
.adult .karyotype { max-width: 100%; overflow-x: auto; }
.role-buttons { display: flex; gap: 6px; margin-top: 6px; flex: none; }
#ivf .role-buttons button { flex: 1 1 0; min-width: 0; padding-left: 4px; padding-right: 4px; font-size: 0.85rem; }
#ivf .role-buttons button[aria-pressed="true"] { border-image-source: url(clinic/btn_down.png); color: var(--cream); text-shadow: 1px 1px 0 var(--ink); }
#ivf .role-buttons button[aria-pressed="true"]::before { content: '✓'; color: var(--gold); }

/* The stage: the two chosen parents on platforms, and the main action. */
.stage-cell { display: grid; grid-template-rows: auto auto; gap: 6px; min-height: 0; }
.ivf-page .stage:not(.board .stage) { min-height: 0; min-width: 0; container-type: size; }
.stage-cell .stage { aspect-ratio: 2 / 1; }
/* A platform is a square that fits the stage both ways, so a zora's feet always land on it. */
@supports (height: 1cqh) {
  .ivf-page .stage .pedestal { height: min(86cqh, 46cqw); max-width: none; }
  .ivf-page .stage.solo .pedestal { height: min(86cqh, 90cqw); }
}
#ivf .stand { position: absolute; inset: 0; width: 100%; height: 100%; display: block; padding: 0; min-height: 0;
  border: 0; border-image: none; background: none; cursor: pointer; }
#ivf .stand:hover .zora-box, #ivf .stand:focus-visible .zora-box { filter: drop-shadow(0 0 6px var(--gold)); }
#ivf .stand:focus-visible { outline-offset: -3px; }
.ivf-page .stage .pedestal .empty { position: absolute; left: 48%; top: 60%; transform: translate(-50%, -50%); margin: 0;
  white-space: nowrap; padding: 4px 10px; background: var(--ink); box-shadow: 0 0 0 2px var(--edge); }
.ivf-page .stage .pedestal .empty.warn { color: var(--pink); }
.generate-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 6px 18px; }
.pair { color: var(--cream); font-weight: 700; }
#ivf #generate { min-height: 48px; min-width: min(300px, 100%); font-size: 1rem; }

/* The "Fertilized eggs" cell: counts, the newest eggs, and the way into the egg menu. */
.incubator { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 6px 12px; }
.incubator-info { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 14px; min-width: 0; }
.incubator-count { display: flex; flex-wrap: wrap; gap: 0 14px; font-size: 0.9rem; }
.count-total { font-weight: 700; }
.incubator-tiles { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; min-height: 48px; align-items: center; }
.incubator-tiles .empty { grid-column: 1 / -1; }
.empty { color: var(--dim); }

/* Egg tiles (the menu's list and the main screen's cell): real buttons drawn as flat tiles. */
#ivf .tile, #ivf .mini { display: flex; justify-content: flex-start; gap: 8px; flex: none; min-height: 48px; min-width: 0;
  padding: 2px 8px 2px 3px; text-align: left; font: inherit; font-size: 0.85rem; line-height: 1.2; color: var(--cream); text-shadow: none;
  background: var(--wall-2); border: 3px solid var(--edge); border-image: none; }
#ivf .tile:hover:not(:disabled), #ivf .mini:hover:not(:disabled) { border-color: var(--mint); color: var(--cream); }
#ivf .tile[aria-pressed="true"] { border-color: var(--gold); background: var(--wall-3); }
#ivf .tile:disabled, #ivf .mini:disabled { color: var(--dim); background: var(--wall); cursor: not-allowed; }
#ivf .tile:focus-visible, #ivf .mini:focus-visible { outline-offset: -3px; }
.tile .zora-box, .mini .zora-box, .tile-icon { width: 38px; height: 38px; flex: none; }
.tile-icon { display: flex; align-items: center; justify-content: center; }
#ivf .tile-icon .px-icon { margin: 0; }
.tile-words { display: flex; flex-direction: column; min-width: 0; }
.tile-name { font-weight: 700; overflow-wrap: anywhere; }
.status { font-size: 0.8rem; color: var(--ice); }
button:disabled .status { color: var(--dim); }

/* ---- Pop-ups ---- */
.px-popup .popup-head h2 { font-size: 1.2rem; }
.px-popup .popup-head h2 .px-icon, .incubator h2 .px-icon { flex: none; }
dialog.briefing { width: min(720px, 94vw); }
.intro, .intro-line { color: var(--cream); }
.hint-sample { color: var(--mint); }
.price-list { margin: 4px 0 10px; }
.price-list li { display: flex; align-items: center; gap: 8px; padding: 2px 0; }
.price-list .px-icon { flex: none; }
.briefing-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin-top: 12px; }
#ivf .briefing-foot .primary { min-width: 120px; }

dialog.embryo-menu { width: min(1320px, 96vw); max-width: none; height: auto; }
.embryo-menu .message { flex: none; margin: 0 0 6px; }
.menu-body { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; min-height: 0; }
.embryos { display: flex; flex-direction: column; gap: 5px; max-height: 34vh; min-height: 60px; overflow-y: auto; padding: 4px;
  background: var(--ink); border: 3px solid var(--edge); }
.embryos .empty { padding: 8px; }
.detail { min-width: 0; min-height: 0; }
.detail > h2 { font-size: 1.2rem; margin-bottom: 4px; }
.detail-scroll { min-height: 0; min-width: 0; }
.detail-scroll > p { margin-bottom: 4px; }
.detail-facts { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px 18px; align-items: start; margin-top: 4px; }
.detail-looks .stage, .born-body .stage { width: 100%; aspect-ratio: 4 / 3; margin-bottom: 6px; }
.detail-genes .gtable { font-size: 0.85rem; max-width: 30rem; }
.baby-message { margin-top: 4px; color: var(--cream); }
.mark.good { color: var(--mint-bright); font-weight: 700; }
.mark.bad { color: var(--pink); font-weight: 700; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.embryo-actions { padding-top: 8px; border-top: 3px solid var(--edge); }
.boards { display: flex; flex-wrap: wrap; gap: 12px 24px; margin-top: 10px; }
.board-box { overflow-x: auto; max-width: 100%; padding-bottom: 6px; }
.board-box > .board { width: max-content; }

dialog.born-popup { width: min(860px, 94vw); }
.born-popup .popup-head { min-height: 44px; }   /* the same with and without the close button */

/* The hatch. clinic/egg_hatch.png is a row of 12 frames, each 48x56 art pixels with the egg's base at the bottom
   centre; --frame (set by game-ivf.js) picks one. The egg stands where a zora's feet would: on the platform. */
.egg { --egg-px: 4px; position: absolute; left: 48%; bottom: 5%; width: calc(48 * var(--egg-px)); height: calc(56 * var(--egg-px));
  transform: translateX(-50%); image-rendering: pixelated;
  background: url(clinic/egg_hatch.png) calc(var(--frame, 0) * -48 * var(--egg-px)) 0 / calc(576 * var(--egg-px)) 100% no-repeat; }
@container (max-height: 290px) { .egg { --egg-px: 3px; } }
@container (max-height: 195px) { .egg { --egg-px: 2px; } }
.egg.still { filter: grayscale(0.8) brightness(0.55); transition: filter 0.6s; }
.stage.hatching { cursor: pointer; }
.ivf-page .stage .pedestal .egg ~ .empty { top: 10%; }
@keyframes hatch-in { from { opacity: 0; transform: scale(0.5); } }
.ivf-page .stage .pedestal .zora-box.appear { transform-origin: 48% 94%; animation: hatch-in 0.45s ease-out both; }
@media (prefers-reduced-motion: reduce) {
  .ivf-page .stage .pedestal .zora-box.appear { animation: none; }
  .egg.still { transition: none; }
}
.skip-hint { color: var(--dim); }
.born-body { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px 18px; align-items: start; }
.born-text .features { font-size: 0.95rem; }
.verdict { margin-top: 6px; font-weight: 700; }
.choice { margin-top: 12px; padding: 8px 12px 10px; background: var(--wall-2); border: 3px solid var(--edge); }
.choice .actions { margin-top: 8px; }
#ivf .choice button { flex: 1 1 14rem; }
.complete { margin-top: 12px; padding: 8px 12px 10px; background: var(--wall-2); border: 3px solid var(--gold); }
.complete h2 { display: block; font-size: 1.05rem; line-height: 1.35; }
.complete h2 .px-icon { margin-right: 8px; }

/* ---- Shared pieces ---- */
/* The meiosis board calls its rows ".stage" too; clinic.css and the stage rules above leave those alone.
   The floating hints are moved into the open pop-up by game-ivf.js and sit above its contents. */
body.ivf .zora-tip { z-index: 30; }
body.ivf .hint-tip { z-index: 31; }

/* Cells that scroll inside themselves show a scrollbar all the time, so it is plain that there is more. */
.card-scroll::-webkit-scrollbar, .embryos::-webkit-scrollbar, .detail-scroll::-webkit-scrollbar, .board-box::-webkit-scrollbar,
dialog.px-popup::-webkit-scrollbar { width: 12px; height: 12px; }
.card-scroll::-webkit-scrollbar-track, .embryos::-webkit-scrollbar-track, .detail-scroll::-webkit-scrollbar-track,
.board-box::-webkit-scrollbar-track, dialog.px-popup::-webkit-scrollbar-track { background: var(--ink); }
.card-scroll::-webkit-scrollbar-thumb, .embryos::-webkit-scrollbar-thumb, .detail-scroll::-webkit-scrollbar-thumb,
.board-box::-webkit-scrollbar-thumb, dialog.px-popup::-webkit-scrollbar-thumb { background: var(--edge); border: 3px solid var(--ink); }
.card-scroll::-webkit-scrollbar-thumb:hover, .embryos::-webkit-scrollbar-thumb:hover, .detail-scroll::-webkit-scrollbar-thumb:hover,
.board-box::-webkit-scrollbar-thumb:hover, dialog.px-popup::-webkit-scrollbar-thumb:hover { background: var(--mint); }
@supports not selector(::-webkit-scrollbar) {
  .card-scroll, .embryos, .detail-scroll, .board-box, dialog.px-popup { scrollbar-color: var(--edge) var(--ink); }
}

/* ---- Wide windows: the bento ---- */
@media (min-width: 960px) {
  .ivf-page { height: calc(100vh - 16px); min-height: 590px; grid-template-rows: auto auto minmax(0, 1fr); }

  /* Two rows: the figures above, the target's chips below. */
  .topbar { display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; gap: 4px 0;
    grid-template-areas: "title totals bill restart" "target target target target"; }
  .tb-title { grid-area: title; }
  .target { grid-area: target; }
  .totals { grid-area: totals; justify-self: end; }
  .bill { grid-area: bill; }
  .topbar #restart { grid-area: restart; margin-left: 18px; }
  .totals, .bill { padding: 0 18px; border-left: 3px solid var(--edge); align-self: stretch; align-content: center; }

  .main { grid-template-columns: minmax(410px, 37%) minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto;
    grid-template-areas: "deck stage" "deck incubator"; }
  .deck-cell { grid-area: deck; grid-template-rows: auto minmax(0, 1fr); }
  .stage-cell { grid-area: stage; grid-template-rows: minmax(0, 1fr) auto; }
  .stage-cell .stage { aspect-ratio: auto; }
  .incubator { grid-area: incubator; }

  dialog.embryo-menu { height: min(900px, 92vh); }
  dialog.embryo-menu[open] { display: grid; grid-template-rows: auto auto minmax(0, 1fr); overflow: hidden; }
  .menu-body { grid-template-columns: minmax(250px, 320px) minmax(0, 1fr); }
  .embryos { max-height: none; min-height: 0; }
  .detail { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }
  .detail > .empty { grid-row: 1 / -1; align-self: center; text-align: center; }
  .detail-scroll { overflow: auto; padding-right: 6px; }
  .detail-facts { grid-template-columns: minmax(230px, 330px) minmax(0, 1fr); }
  .embryo-actions { margin-top: 0; }
  .born-body { grid-template-columns: minmax(240px, 340px) minmax(0, 1fr); }
  /* The pop-up keeps one size from the first wobble to the result. */
  .born-body { align-items: stretch; }
  .born-body .stage { aspect-ratio: auto; height: 100%; min-height: 340px; margin: 0; }
  .born-text { min-height: 26rem; }
}

/* A tall window has room for a bigger picture of the selected embryo. */
@media (min-width: 960px) and (min-height: 840px) {
  .detail-facts { grid-template-columns: minmax(230px, 420px) minmax(0, 1fr); }
}

/* Very wide: one row, the target between the title and the figures, unless its chips need too many lines (.split). */
@media (min-width: 1400px) {
  .topbar:not(.split) { grid-template-columns: auto minmax(0, 1fr) auto auto auto; grid-template-areas: "title target totals bill restart"; }
  .topbar:not(.split) .target { padding: 0 18px; align-self: center; }
  .topbar:not(.split) .bill .breakdown { max-width: 11.5rem; }
}
/* Between the two: Restart moves down beside the target so that the figures have the first row to themselves. */
@media (min-width: 960px) and (max-width: 1199px) {
  .topbar { grid-template-columns: auto minmax(0, 1fr) auto; grid-template-areas: "title totals bill" "target target restart"; }
  .topbar #restart { align-self: start; }
}
@media (min-width: 960px) and (max-width: 1399px) {
  .incubator-tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  #ivf .incubator-tiles .mini:nth-child(n + 4) { display: none; }
}

/* ---- Narrow windows: stacked ---- */
@media (max-width: 959px) {
  .totals .value { font-size: 1.6rem; }
  .incubator-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .incubator { grid-template-columns: minmax(0, 1fr); }
  #ivf #open-menu { justify-self: start; }
}
@media (max-width: 480px) {
  body.ivf { padding: 6px 8px; }
  .incubator-tiles { grid-template-columns: minmax(0, 1fr); }
  .ivf-page .stage .plate { font-size: 0.68rem; padding: 2px 4px; }
  .ivf-page .stage .pedestal .empty { font-size: 0.7rem; padding: 3px 5px; }
}

/* The Zoraclon logo sits at the far left of the top bar's first row; the target's chips keep the full width below. */
@media (min-width: 960px) {
  .topbar .brand { grid-area: brand; align-self: center; margin-right: 18px; }
  .topbar { grid-template-columns: auto auto minmax(0, 1fr) auto auto;
    grid-template-areas: "brand title totals bill restart" "target target target target target"; }
}
@media (min-width: 1400px) {
  .topbar:not(.split) { grid-template-columns: auto auto minmax(0, 1fr) auto auto auto;
    grid-template-areas: "brand title target totals bill restart"; }
}
/* Up to 1399px wide the first row has no room for Restart as well: it moves down to the end of the target's row. */
@media (min-width: 960px) and (max-width: 1399px) {
  .topbar { grid-template-columns: auto auto minmax(0, 1fr) auto auto;
    grid-template-areas: "brand title totals bill bill" "target target target target restart"; }
  .topbar #restart { align-self: start; }
}
