/* fit-s.css: final build, area Studio / advanced mode (builder S). Loaded after fit.css (concept A).
   S1  the Studio composer (text, voice, Speak) and the Delivery | Sound settings never leave the screen while you read
       old takes: stuck under the header (narrow screens: composer, then the settings row, both stuck; wide screens: the
       composer sticks in its column at every height, the settings column already does)
   S2  Delivery in three groups: Voice open, "Pace and level" and "Recording" folded to one line that says what's set
   S3  "Advanced" on the home pill (index.html); "Studio · ‹ Simple" inside the card where the title row is hidden
   S4  the small-phone card top row: Write | Stress | Timing never runs over the language; the language reads at the
       voice chip's size; ellipses at 280-344 px
   S5  Timing: "Loading word lengths…" / "Couldn't load timing." + Try again, always visible at the editor's foot
   S6  "Keep this voice": a small quiet pill
   No fades, no transitions added. Every id kept. */

/* ---------- S1: what sticks, and where ---------- */
:root { --sst: calc(var(--barh, 64px) + 8px); --sgap: 12px; --spt: calc(var(--sst) + var(--scomph, 0px) + var(--sgap)); }
@media (pointer: coarse) and (max-height: 500px) { :root { --sst: 8px; } }  /* (landscape phones: the header scrolls away) */

/* narrow (the stacked Studio): composer, then the Delivery | Sound row, both stuck under the header; the takes scroll
   beneath them. Open, the settings fill the screen under the composer (their own scroll only if they don't fit) */
@media (max-width: 567px), (max-width: 899px) and (min-height: 501px), (max-width: 899px) and (pointer: fine) {  /* (merge: 567 = fit.css narrow query, after fit-l) */
  html:not([data-fold]) .studio.m-speak:not([data-mode="vtv"]) > .work > .g-studio.panel.composer {
    position: sticky; top: var(--sst); z-index: 6; align-self: start;
    box-shadow: 0 0 0 var(--sgap) var(--paper), 0 calc(-1 * var(--sgap)) 0 var(--sgap) var(--paper); }
  html:not([data-fold]) .studio.m-speak:not([data-mode="vtv"]) > #sidePanel {
    position: sticky; top: var(--spt); z-index: 6; align-self: start;
    box-shadow: 0 var(--sgap) 0 var(--sgap) var(--paper); }
  /* (the gap between the two stuck boxes, square: the rounded paper edges left the corners of takes peeking through) */
  html:not([data-fold]) .studio.m-speak:not([data-mode="vtv"]) > #sidePanel::before { content: ""; position: absolute; z-index: -1;
    left: calc(-1 * var(--sgap)); right: calc(-1 * var(--sgap)); bottom: calc(100% + 1px); height: var(--sgap); background: var(--paper); }
  /* the two stuck boxes move as one: the composer's margin reaches down past the settings (the settings pull back up
     over it), so at the end of a short page both leave together instead of the settings sliding over the composer */
  html:not([data-fold]) .studio.m-speak:not([data-mode="vtv"]) > .work > .g-studio.panel.composer { margin-bottom: calc(var(--sph, 0px) + var(--sgap)); }
  html:not([data-fold]) .studio.m-speak:not([data-mode="vtv"]) > #sidePanel { margin-top: calc(-1 * (var(--sph, 0px) + var(--sgap))); }
  html:not([data-fold]) .studio.m-speak:not([data-mode="vtv"]) > .work > #takes { margin-top: 0; }  /* (the paper under the stuck row = the gap above the takes: no take is covered at rest) */
  html:not([data-fold]) .studio.m-speak:not([data-mode="vtv"]) > #sidePanel[data-open="1"] { display: flex; flex-direction: column;
    max-height: var(--sdmax, calc(100vh / var(--pz) - var(--spt) - 12px)); max-height: var(--sdmax, calc(100dvh / var(--pz) - var(--spt) - 12px)); }
  html:not([data-fold]) .studio.m-speak:not([data-mode="vtv"]) > #sidePanel[data-open="1"] > .sseg { flex: none; }
  html:not([data-fold]) .studio.m-speak:not([data-mode="vtv"]) > #sidePanel[data-open="1"] > .sidebody { flex: 1 1 auto; min-height: 0;
    overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; }
  /* the Studio's status ("Type something for Grey to say.") floats right under the stuck settings, where you look */
  html:not([data-fold]) .studio.m-speak:not([data-mode="vtv"]) > .work > #speakStatus:not(:empty) {
    position: sticky; top: calc(var(--spt) + var(--sph, 60px) + 2 * var(--sgap) + 2px); z-index: 7; justify-self: center; align-self: start;
    margin: 0; padding: 7px 16px; border-radius: 999px; background: var(--g-soft); box-shadow: 0 0 0 6px var(--paper); text-align: center; }
  /* a shorter editor where the height is short, so the stuck part leaves room for the takes */
  .g-studio { --edh: 170px; }
}
@media (max-width: 640px) { .g-studio { --edh: 150px; } }
@media (max-width: 640px) and (max-height: 700px) { .g-studio { --edh: 120px; } }
@media (max-width: 640px) and (max-height: 600px) { .g-studio { --edh: 104px; } }
@media (max-width: 899px) and (min-width: 641px) and (max-height: 900px) { .g-studio { --edh: 130px; } }

/* (app.css gives the text box min-height: 170px from 680 px wide, which beat A's --edh: Write would be taller than
   Stress / Timing and Speak would move on a mode switch) */
.work .g-studio.composer textarea#text { min-height: var(--edh); }

/* the "Studio · ‹ Simple" row above the composer paints over the composer's paper edge (that edge only hides takes
   scrolling under it) */
.g-studiohead { position: relative; z-index: 7; }

/* wide (>= 900, landscape phones): the composer sticks in its column at every height (A: only 900 px+ tall) */
@media (min-width: 900px), (pointer: coarse) and (max-height: 500px) and (min-width: 568px) {  /* (merge: 568 = fit.css wide query, after fit-l) */
  html:not([data-fold]) .studio.m-speak:not([data-mode="vtv"]) .g-studio.panel.composer { position: sticky; top: var(--stick); z-index: 4;
    box-shadow: 0 0 0 16px var(--paper), 0 -16px 0 16px var(--paper), 0 24px 14px 2px var(--paper); }
  /* room under the last take, so reading it (scrolled to the middle of the screen) never pushes the stuck settings
     column up and out (under the header) at the end of the page */
  html:not([data-fold]) .studio.m-speak:not([data-mode="vtv"]) > .work:has(> #takes:not(:empty))::after { content: ""; display: block; flex: none;
    height: max(0px, calc(var(--sph, 0px) + var(--stick) + 16px - 50vh / var(--pz))); }
}
/* (merge) a take scrolled into view (a link, the browser, a script) lands below the stuck composer, not under its foot:
   the same idea as fit-l.css's landscape / short-window scroll-padding, measured (--scomph from next.js) */
@media (min-width: 900px) {
  html:not([data-fold]):has(body[data-view="voices"] .studio.m-speak:not([data-mode="vtv"])) { scroll-padding-top: calc(var(--stick) + var(--scomph, 300px) + 16px); }
}
@media (min-width: 900px) and (max-height: 860px) { .g-studio { --edh: 150px; } }
@media (min-width: 900px) and (max-height: 660px), (max-height: 520px) { .g-studio { --edh: 104px; } }

/* the keyboard up on a landscape phone (<= 260 px of screen left; iOS: html.kb): the stuck card keeps the text and the
   voice + Speak row, the Write | Stress | Timing row waits until the keyboard goes down (scrolling can't help a stuck card) */
@media (pointer: coarse) and (max-height: 260px) {
  .studio.m-speak:not([data-mode="vtv"]) .g-studio > .g-stop { display: none; }
  .studio.m-speak:not([data-mode="vtv"]) .g-studio { --edh: clamp(56px, calc(100vh / var(--pz) - var(--sst) - 96px), 150px);
    --edh: clamp(56px, calc(100dvh / var(--pz) - var(--sst) - 96px), 150px); }
}
@media (pointer: coarse) and (max-height: 500px) {
  html.kb .studio.m-speak:not([data-mode="vtv"]) .g-studio > .g-stop { display: none; }
  html.kb .studio.m-speak:not([data-mode="vtv"]) .g-studio { --edh: clamp(56px, calc(100vh / var(--pz) - var(--kb) - var(--sst) - 96px), 150px); }
}

/* ---------- S2: Delivery in groups; a folded group is one line that says what's set in it ---------- */
#sidePanel .g-dh { margin: 0; padding: 0; font: inherit; letter-spacing: 0; text-transform: none; color: inherit; }
#sidePanel .g-dh-voice { margin-top: 4px; }
#sidePanel .g-dh:has(> .g-dg[aria-expanded="false"]) { border-bottom: 1px solid var(--wash); }
#sidePanel .g-dh-rec:has(> .g-dg[aria-expanded="false"]) { border-bottom: 0; }
#sidePanel .g-dg { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 44px; margin: 0; padding: 10px 0 6px; border: 0; border-radius: 0;
  background: none; color: var(--g-text3); text-align: left; font: inherit; cursor: pointer; }
#sidePanel .g-dg[aria-expanded="false"] { padding: 10px 0; }
#sidePanel .g-dg > span:first-child { flex: none; font: 600 11.5px var(--body); letter-spacing: .06em; text-transform: uppercase; color: var(--g-text3); }
#sidePanel .g-dgs { flex: 1 1 auto; min-width: 0; text-align: right; font: 400 13px var(--body); color: var(--g-text2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#sidePanel .g-dg[aria-expanded="true"] .g-dgs { visibility: hidden; }
#sidePanel .g-dg::after { content: ""; flex: none; width: 7px; height: 7px; margin: -4px 4px 0 0; border-right: 1.6px solid var(--g-text3); border-bottom: 1.6px solid var(--g-text3);
  transform: rotate(45deg); }
#sidePanel .g-dg[aria-expanded="true"]::after { transform: rotate(-135deg); margin-top: 4px; }
#sidePanel .g-dg:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; border-radius: 6px; }
@media (hover: hover) { #sidePanel .g-dg:hover > span:first-child, #sidePanel .g-dg:hover .g-dgs { color: var(--ink); } }
#sidePanel .g-dg:active { background: none; }
#sidePanel .g-dpart:has(.g-dg[data-g="voice"][aria-expanded="false"]) :is(.sl[data-k="style"], .sl[data-k="mood"], .sl[data-k="dominance"], .g-whisper) { display: none; }
#sidePanel .g-dpart:has(.g-dg[data-g="pace"][aria-expanded="false"]) :is(.sl[data-k="speed"], .sl[data-k="volume"], #lengthRow > .sl) { display: none; }
#sidePanel .g-dpart:has(.g-dg[data-g="rec"][aria-expanded="false"]) :is(#cleanRow > .sl, #cleanHint) { display: none; }
#sidePanel .g-dpart:has(.g-dg[data-g="rec"][aria-expanded="true"]) #cleanRow > .sl { border-bottom: 0; }
/* a wide drawer (tablets, Duo, narrow windows): the sliders two to a row, not 700 px long. (A's @container rule sat on
   .g-dpart itself, which can't query its own width, so it never applied: the container is now the drawer body) */
#sidePanel > .sidebody { container-type: inline-size; }
@container (min-width: 540px) {
  #sidePanel .g-dpart { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  #sidePanel .g-dpart > :is(.g-dh, #lockHint, #cleanHint) { grid-column: 1 / -1; }
}

/* ---------- S3: "Studio · ‹ Simple" inside the card where the title row is hidden (landscape phones, flip fold) ---------- */
.g-shere { display: none; align-items: center; gap: 2px; margin-left: auto; white-space: nowrap; }
.g-shere > b { font: 600 16px/1 var(--display); color: var(--ink); letter-spacing: -.01em; padding-right: 4px; }
.g-shere > .g-tosimple { height: 40px; padding: 0 10px 0 8px; }
@media (pointer: coarse) and (max-height: 500px) {
  .studio.m-speak:not([data-mode="vtv"]) .g-shere { display: inline-flex; }
  /* (merge: not on a portrait phone with its keyboard up, where the language keeps row 1, nor beside the narrow landscape
     card under 710 px: there the title row sits above the card, as on portrait phones) */
  @media (orientation: portrait), (max-width: 709px) { .studio.m-speak:not([data-mode="vtv"]) .g-shere { display: none; } }
  .studio.m-speak:not([data-mode="vtv"]) .g-stop > .g-grow { display: none; }
  .studio.m-speak:not([data-mode="vtv"]) .g-stop > #lineStudio { margin-right: auto; }
  .studio.m-speak:not([data-mode="vtv"]) .g-stop > #lineStudio.idle { display: none; }
}
/* (merge) landscape phones up to 709 px: the card is too narrow for "Studio ‹ Simple" beside Write | Stress | Timing and the
   language, so the title row is back above it (fit.css hides it on landscape phones); it scrolls away, the card sticks */
@media (pointer: coarse) and (max-height: 500px) and (orientation: landscape) and (max-width: 709px) {
  html:not([data-fold]) .studio.m-speak:not([data-mode="vtv"]) > .work > .g-studiohead { display: flex; min-height: 44px; margin: -6px 0 -4px; }
  html.kb:not([data-fold]) .studio.m-speak:not([data-mode="vtv"]) > .work > .g-studiohead { display: none; }
}
@media (pointer: coarse) and (max-height: 260px) {
  html:not([data-fold]) .studio.m-speak:not([data-mode="vtv"]) > .work > .g-studiohead { display: none; }
}
html[data-fold="v"] .studio.m-speak:not([data-mode="vtv"]) .g-shere { display: inline-flex; }
@media (max-width: 640px) and (min-height: 501px) {  /* (a flip phone's card has no room beside Write | Stress | Timing and the language) */
  html[data-fold="v"] .studio.m-speak:not([data-mode="vtv"]) .g-shere { display: none; }
}
/* (merge) ... so on a flip phone the title row heads the top half, above the takes (fit.css had hidden it there); the
   bottom half keeps the card and the settings exactly as they were */
@media (max-width: 640px) and (min-height: 501px) {
  html[data-fold="v"] .wrap.studio.m-speak:not([data-mode="vtv"]) { grid-template-rows: 48px calc(var(--a) - var(--barh, 64px) - 48px) var(--gap) auto minmax(0, 1fr); }
  html[data-fold="v"] .studio.m-speak:not([data-mode="vtv"]) > .work > .g-studiohead { display: flex; grid-row: 1; order: 0; height: 48px; min-height: 0; margin: 0; }
  html[data-fold="v"] .studio.m-speak:not([data-mode="vtv"]) > .work > #takes { grid-row: 2; }
  html[data-fold="v"] .studio.m-speak:not([data-mode="vtv"]) > .work > .g-studio { grid-row: 4; }
  html[data-fold="v"] .studio.m-speak:not([data-mode="vtv"]) > .work > #speakStatus, html[data-fold="v"] .studio.m-speak:not([data-mode="vtv"]) > #sidePanel { grid-row: 5; }
}

/* ---------- S4: the phone card's top row: [Write | Stress | Timing] .... [Language]; never overlapping ---------- */
@media (max-width: 640px), (pointer: coarse) and (max-height: 500px) and (orientation: landscape) and (min-width: 710px) and (max-width: 759px) {  /* (merge: + fit-l's landscape phone card from 710 px, where row 1 has room for "Studio ‹ Simple") */
  .studio.m-speak:not([data-mode="vtv"]) .g-studio.panel.composer { grid-template-columns: minmax(0, max-content) minmax(0, 1fr) auto; }
  .studio.m-speak:not([data-mode="vtv"]) .g-studio #textModes { grid-column: 1; }
  .studio.m-speak:not([data-mode="vtv"]) .g-studio .g-sbot #lang { grid-column: 2 / 4; justify-self: end; min-width: 0; max-width: calc(100% - 10px);
    overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  .studio.m-speak:not([data-mode="vtv"]) .g-studio .g-sbot #chosen { grid-column: 1 / 3; }
  .studio.m-speak:not([data-mode="vtv"]) .g-studio .g-sbot :is(#speakGo, #vtvGo) { grid-column: 3; }
  .studio.m-speak:not([data-mode="vtv"]) .g-studio .g-shere { grid-row: 1; grid-column: 2 / 4; justify-self: end; margin: 0 6px 0 0; }
}
@media (pointer: coarse) and (max-height: 500px) and (orientation: landscape) and (min-width: 710px) and (max-width: 759px) {  /* (the landscape card beside the settings column, 710-759 px: the language joins the voice row, "Studio ‹ Simple" has row 1. merge: was max-width 640 + coarse + max-height 500, from when 568-699 px had the full-width card) */
  .studio.m-speak:not([data-mode="vtv"]) .g-studio .g-sbot #lang { grid-row: 3; grid-column: 2; justify-self: start; margin: 0; }
  .studio.m-speak:not([data-mode="vtv"]) .g-studio .g-sbot #chosen { grid-column: 1; }
}
@media (max-width: 399px) { .studio.m-speak:not([data-mode="vtv"]) .g-studio #textModes button { padding: 0 10px; } }
@media (max-width: 299px) {
  .studio.m-speak:not([data-mode="vtv"]) .g-studio #textModes button { padding: 0 7px; font-size: 14.5px; }
  .studio.m-speak:not([data-mode="vtv"]) .g-studio .g-sbot #speakGo { padding: 0 16px 0 13px; }
}
/* the language reads at the voice chip's size (iOS Safari zooms into a field under 16 px on focus: it keeps 16) */
@supports not (-webkit-touch-callout: none) {
  @media (pointer: coarse) and (max-height: 500px) and (orientation: landscape), (pointer: coarse) and (max-width: 560px) {
    html .studio .g-sbot #lang { font-size: 15px !important; }
  }
}

/* ---------- S5: Timing: loading and failure, readable, at the editor's foot; nothing moves ---------- */
.g-studio .emphview.tall > .emph-hint { position: sticky; bottom: 0; z-index: 1; gap: 10px; align-items: center; background: var(--g-card);
  box-shadow: 0 -14px 12px -2px var(--g-card); }  /* (words scrolling behind it fade out instead of showing cut glyphs) */
.g-studio .emphview.tfail .wt { opacity: .45; }
.g-studio .emphview.tfail > .emph-hint { color: var(--g-text2); }
.emph-retry { flex: none; height: 34px; padding: 0 14px; border-radius: 999px; border: 0; background: var(--g-card); color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--g-line); font: 500 13px var(--body); cursor: pointer; }
@media (hover: hover) { .emph-retry:hover { box-shadow: inset 0 0 0 1px var(--g-text3); } }
@media (pointer: coarse) {  /* (a fingertip target, the same small pill: a transparent border) */
  .emph-retry { height: 48px; border: 7px solid transparent; background-clip: padding-box; margin: -7px 0; }
}
.emph-retry:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }

/* ---------- S6: "Keep this voice": a small quiet pill (the row's own actions stay play and download) ---------- */
#takes .g-keepv { height: 30px; padding: 0 12px; gap: 6px; border: 0; border-radius: 999px; background: transparent; color: var(--g-text2);
  font: 500 13px var(--body); box-shadow: inset 0 0 0 1px var(--g-line); }
#takes .g-keepv svg { width: 12px; height: 12px; }
@media (hover: hover) { #takes .g-keepv:hover { color: var(--ink); box-shadow: inset 0 0 0 1px var(--g-text3); background: transparent; } }
@media (pointer: coarse) and (min-width: 561px) and (min-height: 501px) {  /* (tablets: a 44 px target, the same small pill) */
  #takes .g-keepv { height: 44px; border: 7px solid transparent; background-clip: padding-box; margin: -7px 0 -7px -7px; }
}

/* ---------- phones under the 80 % zoom: type floor and fingertip targets for the new bits ---------- */
@media (pointer: coarse) and (max-width: 560px), (pointer: coarse) and (max-height: 500px) and (orientation: landscape) {
  #sidePanel .g-dg { min-height: 54px; }
  #sidePanel .g-dg > span:first-child { font-size: 14px; }
  #sidePanel .g-dgs { font-size: 15px; }
  .g-studio .emph-hint:has(> .emph-reset[hidden]), .g-studio .emph-hint:not(:has(> .emph-reset)), .emph-retry { font-size: 14px; }
  .emph-retry { height: 52px; padding: 0 14px; border-width: 8px; margin: -8px 0; }
  .g-shere > b { font-size: 18px; }
  .g-shere > .g-tosimple { height: 52px; }
  #takes .g-keepv { height: 50px; padding: 0 14px; border: 9px solid transparent; background-clip: padding-box; margin: -9px 0 -9px -9px; font-size: 14px; }
  #takes .g-keepv svg { width: 14px; height: 14px; }
}
