/* Narration bar. Scoped under #voiceRoot, deck colours only. */

/*
 * Strict start gate. Transparent viewport shield above every deck layer
 * (#voiceRoot is 10060, the portrait hint 10050, the loader 1000) so no click,
 * touch or wheel can reach the page before the explicit Play. The loading
 * screen stays visible through it; only the round button is painted.
 */
.voice-gate {
  position: fixed;
  inset: 0;
  z-index: 10070;
  background: transparent;
  pointer-events: auto;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.34s ease;
}
.voice-gate[hidden] {
  display: none;
}
/*
 * The instruction block is one unit: it appears only after the loader has
 * fully faded (the gate adds .voice-gate-ready on the same readiness signal
 * that reveals Play). Nothing is painted while loading is still on screen.
 */
.voice-gate.voice-gate-ready {
  background: rgba(6, 6, 9, 0.68);
}
/*
 * Play -> deck: native audio has already started in the same gesture, while
 * the cover fades over ~340ms with the capture guard still active. The fade is
 * purely visual; no timer gates the sound.
 */
.voice-gate.voice-gate-leaving {
  background-color: rgba(6, 6, 9, 0);
}
.voice-gate-leaving .voice-play {
  opacity: 0;
  transition: opacity 0.34s ease;
}
/* The portrait hint belongs after the explicit start, not under its button. */
html.voice-gate-locked #rotateHint {
  display: none !important;
}

#voiceRoot {
  position: fixed;
  /* No transform here: it would become the containing block for the centered
     Play button and pin it to this strip instead of the viewport. */
  left: 0;
  right: 0;
  margin-inline: auto;
  bottom: clamp(18px, 3.2vh, 38px);
  /* #screenModal is 10000, the portrait rotate hint is 10050: the Play
     fallback must stay reachable on a phone held upright too. */
  z-index: 10060;
  width: min(720px, calc(100vw - 280px));
  pointer-events: none;
  font-family: 'DM Sans', system-ui, sans-serif;
  color: #f5f5f7;
  -webkit-font-smoothing: antialiased;
}

/*
 * Speaker mode has no permanent panel. The only default child is a screen
 * reader live region, absolutely positioned so an empty #voiceRoot keeps a
 * zero-sized, non-interactive box that never covers slide content.
 */
#voiceRoot .voice-live {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/*
 * Center Play fallback. Present only while the browser refuses autoplay for a
 * real, playable current step. Fixed to the viewport (not to the #voiceRoot
 * strip) so it reads as the one obvious action on both desktop and phone.
 */
#voiceRoot .voice-play,
.voice-gate .voice-play {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 80px;
  height: 80px;
  padding: 0;
  border: 1px solid rgba(240, 198, 116, 0.55);
  border-radius: 50%;
  background: rgba(8, 8, 12, 0.82);
  color: #f0c674;
  font: inherit;
  cursor: pointer;
  pointer-events: auto;
  box-shadow: 0 18px 46px rgba(0, 0, 0, 0.5), 0 0 24px rgba(212, 168, 87, 0.14);
  backdrop-filter: blur(14px);
  transition: transform 0.2s ease, border-color 0.25s ease, box-shadow 0.25s ease;
}
#voiceRoot .voice-play[hidden],
.voice-gate .voice-play[hidden] {
  display: none;
}
#voiceRoot .voice-play:hover,
.voice-gate .voice-play:hover {
  border-color: rgba(240, 198, 116, 0.85);
  box-shadow: 0 18px 46px rgba(0, 0, 0, 0.55), 0 0 30px rgba(212, 168, 87, 0.26);
  transform: translate(-50%, -50%) scale(1.02);
}
#voiceRoot .voice-play:focus-visible,
.voice-gate .voice-play:focus-visible {
  outline: 2px solid #f0c674;
  outline-offset: 3px;
}
#voiceRoot .voice-play-icon,
#voiceRoot .voice-play-icon svg,
.voice-gate .voice-play-icon,
.voice-gate .voice-play-icon svg {
  display: block;
  width: 32px;
  height: 32px;
}

/*
 * Repeat help. The "?" takes the free top-right corner: below/next to the
 * language pill on desktop and clear of the mobile home/nav controls. The
 * bottom centre is reserved for the listening lock's next/back arrows.
 */
.voice-help-toggle {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 10040;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid rgba(212, 168, 87, 0.5);
  border-radius: 50%;
  background: rgba(6, 6, 10, 0.86);
  color: #f0c674;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
  font-family: 'Unbounded', system-ui, sans-serif;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.25s, border-color 0.25s, background-color 0.25s;
}
.voice-help-toggle[hidden] {
  display: none;
}
.voice-help-toggle:hover {
  color: #f0c674;
  border-color: rgba(240, 198, 116, 0.7);
  background: rgba(12, 12, 18, 0.9);
}
.voice-help-toggle:focus-visible {
  outline: 2px solid #f0c674;
  outline-offset: 3px;
}
/* Full-screen service layers own the viewport and their own close control. */
html:has(#rotateHint.on) .voice-help-toggle,
html:has(#screenModal.open) .voice-help-toggle {
  display: none;
}

.voice-help {
  position: fixed;
  inset: 0;
  z-index: 10090;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(4, 4, 7, 0.66);
}
.voice-help[hidden] {
  display: none;
}
.voice-help-panel {
  position: relative;
  width: min(520px, 100%);
  max-height: calc(100vh - 36px);
  overflow-y: auto;
  padding: 22px 24px 20px;
  border: 1px solid rgba(212, 168, 87, 0.34);
  border-radius: 16px;
  background: rgba(10, 10, 15, 0.97);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.6);
  text-align: left;
  animation: voiceHelpIn 0.22s ease both;
}
.voice-help-title {
  margin: 0 44px 12px 0;
  font-family: 'Unbounded', system-ui, sans-serif;
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 0.01em;
  color: #f5f5f7;
}
.voice-help-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 8px;
}
.voice-help-item {
  position: relative;
  padding-left: 16px;
  font-family: 'DM Sans', system-ui, sans-serif;
  font-size: 14.5px;
  line-height: 1.45;
  color: rgba(245, 245, 247, 0.9);
}
.voice-help-item::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0.62em;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: rgba(240, 198, 116, 0.7);
}
.voice-help-item[hidden] {
  display: none;
}
.voice-help-close {
  position: absolute;
  top: 10px;
  right: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid rgba(245, 245, 247, 0.3);
  border-radius: 50%;
  background: rgba(245, 245, 247, 0.06);
  color: #f5f5f7;
  font-family: 'DM Sans', system-ui, sans-serif;
  font-size: 19px;
  line-height: 1;
  cursor: pointer;
}
.voice-help-close:hover {
  color: #f0c674;
  border-color: rgba(240, 198, 116, 0.65);
}
.voice-help-close:focus-visible {
  outline: 2px solid #f0c674;
  outline-offset: 2px;
}
@media (pointer: coarse) {
  .voice-help-toggle {
    width: 38px;
    height: 38px;
    top: 8px;
    right: 8px;
  }
  .voice-help-close {
    width: 42px;
    height: 42px;
  }
}
@keyframes voiceHelpIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Short landscape phones: the single Play stays comfortably tappable. */
@media (max-height: 500px) {
  .voice-gate .voice-play {
    width: 72px;
    height: 72px;
  }
  .voice-gate .voice-play-icon,
  .voice-gate .voice-play-icon svg {
    width: 28px;
    height: 28px;
  }
  .voice-help {
    padding: 10px;
  }
  .voice-help-panel {
    max-height: calc(100vh - 20px);
    padding: 16px 18px 14px;
  }
  .voice-help-title {
    margin-bottom: 8px;
    font-size: 14px;
  }
  .voice-help-list {
    gap: 5px;
  }
  .voice-help-item {
    font-size: 12.5px;
    line-height: 1.38;
  }
  .voice-help-toggle {
    top: 8px;
    right: 8px;
  }
}

/* Phones (portrait or landscape): the same one Play at 72px. */
@media (max-width: 560px) {
  .voice-gate .voice-play {
    width: 72px;
    height: 72px;
  }
  .voice-gate .voice-play-icon,
  .voice-gate .voice-play-icon svg {
    width: 28px;
    height: 28px;
  }
}

#voiceRoot .voice-bar {
  pointer-events: auto;
  display: grid;
  grid-template-columns: auto auto auto minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  padding: 8px 10px 8px 8px;
  border: 1px solid rgba(212, 168, 87, 0.28);
  border-radius: 16px;
  background: rgba(8, 8, 12, 0.86);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(16px);
  transition: border-color 0.35s ease, box-shadow 0.35s ease;
}

#voiceRoot .voice-bar[data-state="playing"] {
  border-color: rgba(240, 198, 116, 0.6);
  box-shadow: 0 0 26px rgba(212, 168, 87, 0.16), 0 14px 40px rgba(0, 0, 0, 0.55);
}
/* Screens without voice hooks stay visually clean; only hooked FinFlow shows controls. */
#voiceRoot .voice-bar[data-state="no-slide"] {
  display: none;
}
#voiceRoot .voice-bar[data-state="unavailable"],
#voiceRoot .voice-bar[data-state="blocked"],
#voiceRoot .voice-bar[data-state="error"] {
  border-color: rgba(212, 168, 87, 0.42);
}
#voiceRoot .voice-bar[data-state="unsupported"],
#voiceRoot .voice-bar[data-state="data-error"] {
  border-color: rgba(212, 112, 122, 0.55);
}

#voiceRoot .voice-primary {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 38px;
  padding: 7px 13px 7px 10px;
  border: 1px solid rgba(212, 168, 87, 0.38);
  border-radius: 999px;
  background: linear-gradient(160deg, rgba(212, 168, 87, 0.16), rgba(212, 168, 87, 0.04));
  color: #f0c674;
  cursor: pointer;
  font: inherit;
  transition: border-color 0.25s, box-shadow 0.25s, transform 0.2s, opacity 0.2s;
}
#voiceRoot .voice-primary:hover:not(:disabled) {
  border-color: rgba(240, 198, 116, 0.8);
  box-shadow: 0 0 22px rgba(212, 168, 87, 0.22);
  transform: translateY(-1px);
}
#voiceRoot .voice-primary:disabled {
  cursor: default;
  opacity: 0.62;
}
#voiceRoot .voice-primary-icon,
#voiceRoot .voice-primary-icon svg {
  display: block;
  width: 16px;
  height: 16px;
}
#voiceRoot .voice-primary-label {
  font-family: 'Unbounded', sans-serif;
  font-size: 9.5px;
  font-weight: 500;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  white-space: nowrap;
}

#voiceRoot .voice-repeat,
#voiceRoot .voice-off,
#voiceRoot .voice-expand {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid rgba(245, 245, 247, 0.14);
  border-radius: 10px;
  background: rgba(245, 245, 247, 0.04);
  color: rgba(245, 245, 247, 0.7);
  cursor: pointer;
  transition: color 0.25s, border-color 0.25s, opacity 0.25s;
}
#voiceRoot .voice-expand {
  display: none;
  font-family: 'Unbounded', sans-serif;
  font-size: 7.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
#voiceRoot .voice-repeat:hover:not(:disabled),
#voiceRoot .voice-off:hover,
#voiceRoot .voice-expand:hover {
  color: #f0c674;
  border-color: rgba(240, 198, 116, 0.5);
}
#voiceRoot .voice-repeat:disabled {
  opacity: 0.28;
  cursor: default;
}
#voiceRoot .voice-repeat svg,
#voiceRoot .voice-off svg {
  display: block;
  width: 16px;
  height: 16px;
}
#voiceRoot .voice-off[aria-pressed="true"] {
  color: rgba(245, 245, 247, 0.42);
  border-color: rgba(245, 245, 247, 0.1);
}

#voiceRoot .voice-copy {
  min-width: 0;
  padding: 0 5px 0 3px;
}
#voiceRoot .voice-status {
  display: block;
  font-family: 'Unbounded', sans-serif;
  font-size: 8.5px;
  font-weight: 500;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: rgba(240, 198, 116, 0.72);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#voiceRoot .voice-transcript {
  margin-top: 3px;
  display: block;
  max-height: 4.26em;
  overflow-y: auto;
  font-size: 12.5px;
  line-height: 1.42;
  color: rgba(245, 245, 247, 0.8);
}
#voiceRoot .voice-transcript[hidden] {
  display: none;
}
#voiceRoot .voice-bar:not(.has-text) .voice-copy {
  padding-top: 0;
}

/* Honest "not connected / loading / failed" state: no dead controls. */
#voiceRoot .voice-bar[data-state="no-slide"],
#voiceRoot .voice-bar[data-state="loading"],
#voiceRoot .voice-bar[data-state="data-error"] {
  grid-template-columns: 1fr;
}
#voiceRoot .voice-bar[data-state="no-slide"] .voice-repeat,
#voiceRoot .voice-bar[data-state="no-slide"] .voice-off,
#voiceRoot .voice-bar[data-state="no-slide"] .voice-expand,
#voiceRoot .voice-bar[data-state="no-slide"] .voice-copy,
#voiceRoot .voice-bar[data-state="loading"] .voice-repeat,
#voiceRoot .voice-bar[data-state="loading"] .voice-off,
#voiceRoot .voice-bar[data-state="loading"] .voice-expand,
#voiceRoot .voice-bar[data-state="loading"] .voice-copy,
#voiceRoot .voice-bar[data-state="data-error"] .voice-repeat,
#voiceRoot .voice-bar[data-state="data-error"] .voice-off,
#voiceRoot .voice-bar[data-state="data-error"] .voice-expand,
#voiceRoot .voice-bar[data-state="data-error"] .voice-copy {
  display: none;
}
#voiceRoot .voice-bar[data-state="no-slide"] .voice-primary,
#voiceRoot .voice-bar[data-state="loading"] .voice-primary,
#voiceRoot .voice-bar[data-state="data-error"] .voice-primary {
  border-color: transparent;
  background: transparent;
  opacity: 0.72;
}
#voiceRoot .voice-bar[data-state="unsupported"] .voice-status {
  white-space: normal;
  line-height: 1.45;
  letter-spacing: 0.08em;
}
#voiceRoot .voice-bar[data-state="unsupported"] .voice-repeat {
  display: none;
}

#voiceRoot .voice-primary:focus-visible,
#voiceRoot .voice-repeat:focus-visible,
#voiceRoot .voice-off:focus-visible,
#voiceRoot .voice-expand:focus-visible {
  outline: 2px solid #f0c674;
  outline-offset: 2px;
}

@media (max-width: 760px) {
  #voiceRoot {
    left: 48px;
    right: 48px;
    bottom: 12px;
    width: auto;
  }
  #voiceRoot .voice-play,
  .voice-gate .voice-play {
    width: 72px;
    height: 72px;
  }
  #voiceRoot .voice-play-icon,
  #voiceRoot .voice-play-icon svg,
  .voice-gate .voice-play-icon,
  .voice-gate .voice-play-icon svg {
    width: 28px;
    height: 28px;
  }
  #voiceRoot .voice-bar {
    grid-template-columns: minmax(0, 1fr) auto auto auto;
    gap: 5px;
    padding: 5px 6px;
    border-radius: 12px;
  }
  #voiceRoot .voice-copy {
    display: none;
    grid-column: 1 / -1;
    grid-row: 2;
    padding: 2px 3px 3px;
  }
  #voiceRoot .voice-bar.expanded .voice-copy {
    display: block;
  }
  #voiceRoot .voice-primary {
    justify-content: center;
    min-width: 0;
    min-height: 32px;
    padding: 5px 9px 5px 8px;
  }
  #voiceRoot .voice-primary-label {
    font-size: 8px;
    letter-spacing: 0.06em;
  }
  #voiceRoot .voice-repeat,
  #voiceRoot .voice-off,
  #voiceRoot .voice-expand {
    width: 30px;
    height: 30px;
    border-radius: 8px;
  }
  #voiceRoot .voice-expand {
    display: inline-flex;
    font-size: 7px;
  }
  #voiceRoot .voice-transcript {
    font-size: 11.5px;
    -webkit-line-clamp: 3;
  }
  #voiceRoot .voice-bar.expanded .voice-transcript {
    -webkit-line-clamp: unset;
    max-height: 30vh;
    overflow-y: auto;
  }
  #voiceRoot .voice-bar:not(.has-text) .voice-expand {
    display: none;
  }
  #voiceRoot .voice-bar[data-state="no-slide"] .voice-primary-label,
  #voiceRoot .voice-bar[data-state="loading"] .voice-primary-label,
  #voiceRoot .voice-bar[data-state="data-error"] .voice-primary-label {
    white-space: normal;
    text-align: left;
  }
  #voiceRoot .voice-bar[data-state="no-slide"],
  #voiceRoot .voice-bar[data-state="loading"],
  #voiceRoot .voice-bar[data-state="data-error"] {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  .voice-gate,
  .voice-gate .voice-play,
  .voice-help-panel,
  .voice-help,
  .voice-help-toggle,
  #voiceRoot .voice-primary,
  #voiceRoot .voice-play,
  #voiceRoot .voice-bar {
    transition: none;
    animation: none;
  }
}
