/*
 * Responsive adapter for the separately deployed Listening Lab application.
 * Its React source is not on this server; keep the Vite bundle untouched.
 * Scope every rule to the body marker set by tool-navigation.js. Structural
 * selectors below match the 2026-09-10 build: root > app > header / main /
 * footer, with brand / nav / tools as the header's three children.
 * Recheck all three TTS tabs after replacing that build. The shared site
 * navigation lives outside #root and is intentionally not styled here.
 */

body.zh-tool-tts #root {
  min-width: 0;
}

body.zh-tool-tts #root main .flex > *,
body.zh-tool-tts #root main .grid > * {
  min-width: 0;
}

body.zh-tool-tts #root main {
  overflow-wrap: anywhere;
}

body.zh-tool-tts #root :is(button, a, input, select, textarea):focus-visible {
  outline: 2px solid #a5b4fc;
  outline-offset: 3px;
}

/* Long news titles need to shrink inside their flex parent, not crop the
 * entire page. Keep the full title available and allow normal wrapping. */
body.zh-tool-tts #root main h1 + div {
  align-items: flex-start;
}

body.zh-tool-tts #root main h1 + div > :is(svg, span) {
  flex-shrink: 0;
}

body.zh-tool-tts #root main h1 + div > a {
  min-width: 0;
  max-width: 100%;
  white-space: normal;
  overflow: visible;
  align-items: flex-start;
}

body.zh-tool-tts #root main h1 + div > a > span {
  min-width: 0;
}

body.zh-tool-tts #root > div > footer > div > div:last-child {
  flex-wrap: wrap;
  justify-content: center;
  column-gap: 16px;
  row-gap: 6px;
}

body.zh-tool-tts #root > div > footer > div > div:last-child > * {
  margin-left: 0;
  overflow-wrap: anywhere;
}

/* Connection settings is a sibling of the header's main container. Keep it
 * below both app-header rows and within the viewport, including at 320px. */
body.zh-tool-tts #root > div > header > div.absolute {
  top: 100%;
  right: 12px;
  width: 384px;
  max-width: calc(100vw - 24px);
  max-height: calc(100dvh - 240px);
  overflow-y: auto;
  overflow-wrap: anywhere;
}

/* Voice settings can exceed a short phone viewport. Scroll the panel while
 * keeping its close button and all options inside the visible overlay. */
body.zh-tool-tts #root .fixed.inset-0 > div[class~="max-w-lg"] {
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
}

/* Keep every app tab and every utility control reachable on narrow screens.
 * The shared site bar scrolls normally; the existing app header remains sticky.
 */
@media (max-width: 960px) {
  body.zh-tool-tts #root > div > header > div:first-child {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px 12px;
    height: auto;
    padding: 12px 16px 10px;
  }

  body.zh-tool-tts #root > div > header > div:first-child > div:first-child {
    min-width: 0;
    gap: 8px;
  }

  body.zh-tool-tts #root > div > header > div:first-child > div:first-child > div:first-child {
    width: 34px;
    height: 34px;
    flex-shrink: 0;
  }

  body.zh-tool-tts #root > div > header > div:first-child > div:first-child > div:last-child {
    min-width: 0;
    margin-left: 0;
  }

  body.zh-tool-tts #root > div > header > div:first-child > div:first-child > div:last-child > div {
    flex-wrap: wrap;
    gap: 3px 6px;
  }

  body.zh-tool-tts #root > div > header > div:first-child > div:first-child > div:last-child > div > span {
    margin-left: 0;
  }

  body.zh-tool-tts #root > div > header > div:first-child > div:first-child > div:last-child > div > span:first-child {
    font-size: 16px;
    line-height: 1.25;
  }

  body.zh-tool-tts #root > div > header > div:first-child > nav {
    grid-column: 1 / -1;
    grid-row: 2;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    min-width: 0;
  }

  body.zh-tool-tts #root > div > header > div:first-child > nav > button {
    justify-content: center;
    gap: 6px;
    min-width: 0;
    min-height: 44px;
    margin-left: 0;
    padding: 9px 4px;
    font-size: 13px;
    white-space: nowrap;
  }

  body.zh-tool-tts #root > div > header > div:first-child > nav > button > svg {
    flex-shrink: 0;
  }

  body.zh-tool-tts #root > div > header > div:first-child > nav > button > span {
    margin-left: 0;
  }

  body.zh-tool-tts #root > div > header > div:first-child > div:last-child {
    grid-column: 2;
    grid-row: 1;
    gap: 4px;
  }

  body.zh-tool-tts #root > div > header > div:first-child > div:last-child > * {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    min-height: 40px;
    margin-left: 0;
    padding: 8px;
  }
}

@media (max-width: 639px) {
  body.zh-tool-tts #root > div > header > div:first-child {
    column-gap: 8px;
    padding-right: 12px;
    padding-left: 12px;
  }

  body.zh-tool-tts #root main > div {
    padding: 20px 12px;
  }

  body.zh-tool-tts #root main > div > div[class~="rounded-3xl"],
  body.zh-tool-tts #root main div[class~="rounded-2xl"][class~="p-6"] {
    padding: 18px 16px;
  }

  body.zh-tool-tts #root main h1 {
    font-size: clamp(21px, 5.8vw, 27px);
    line-height: 1.3;
  }

  body.zh-tool-tts #root main h1 + div {
    flex-wrap: wrap;
    gap: 6px;
  }

  body.zh-tool-tts #root main h1 + div > * {
    margin-left: 0;
  }

  body.zh-tool-tts #root main h1 + div > a {
    flex-basis: 100%;
  }

  /* The three lesson sections stay on one legible row at 320px. */
  body.zh-tool-tts #root main > div > div.flex.border-b {
    display: grid;
    grid-template-columns: 1.3fr 1fr 1fr;
    gap: 8px;
    font-size: 12px;
  }

  body.zh-tool-tts #root main > div > div.flex.border-b > button {
    justify-content: center;
    min-height: 44px;
    margin-left: 0;
    padding: 8px 0;
  }

  /* Preserve reading width inside the nested dialogue cards. */
  body.zh-tool-tts #root main .flex[class~="gap-3.5"][class~="p-4"] {
    gap: 9px;
    padding: 12px;
  }

  body.zh-tool-tts #root main .flex[class~="gap-3.5"] > div:first-child > div {
    width: 26px;
    height: 26px;
  }

  body.zh-tool-tts #root main audio + div > div:last-child {
    flex-wrap: wrap;
    gap: 4px;
  }

  body.zh-tool-tts #root main audio + div > div:last-child > button {
    min-height: 36px;
    margin-left: 0;
  }

  body.zh-tool-tts #root main input:not([type="range"]),
  body.zh-tool-tts #root :is(textarea, select) {
    font-size: 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  body.zh-tool-tts #root *,
  body.zh-tool-tts #root *::before,
  body.zh-tool-tts #root *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
