/* Melo pilot: layout/accessibility fixes only. The scene renderer owns motion.
   The player measures its header into --melo-player-height so wrapped controls
   and recovery messages never cover the scrolling lesson. */
:root {
  --melo-player-height: 6.6rem;
  --melo-footer-space: calc(4.5rem + env(safe-area-inset-bottom, 0px));
}

body {
  padding-top: var(--melo-player-height);
  padding-bottom: var(--melo-footer-space);
}

html.lesson-flow-active #lesson-main {
  top: var(--melo-player-height);
  /* Reserve the actual viewport, not only end padding: a focused answer may
     otherwise be considered visible while its centre is under the footer. */
  bottom: var(--melo-footer-space);
}

html.lesson-flow-active #lesson-main > :is(.lesson-hero, .lesson-section) {
  padding-bottom: 1rem;
  scroll-padding-block: 1rem;
}

.lesson-section {
  scroll-margin-top: calc(var(--melo-player-height) + 1rem);
}

.lesson-nav {
  padding-top: env(safe-area-inset-top, 0px);
}

.nav-main,
.media-timeline,
.audio-recovery {
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
}

.voice-controls {
  min-width: 0;
  max-width: 100%;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.audio-recovery {
  display: flex;
  width: min(100% - 1rem, 72rem);
  margin: 0 auto;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.65rem;
  padding-bottom: 0.5rem;
}

.audio-recovery:empty {
  display: none;
}

.audio-recovery #audio-message {
  min-width: 0;
  margin: 0;
  flex: 1 1 15rem;
  color: var(--cream-muted);
  font-size: 0.8125rem;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.audio-recovery button {
  min-width: 44px;
  min-height: 44px;
  max-width: 100%;
  white-space: normal;
}

/* A narrow modal scrolls internally while keeping its close control visible. */
.transcript-dialog {
  max-height: calc(100dvh - 2rem - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  overflow-y: auto;
  overscroll-behavior: contain;
}

.transcript-dialog .dialog-head {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-raised);
}

.transcript-dialog .dialog-head h2 {
  min-width: 0;
}

#transcript-close {
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  font-size: 1.5rem;
  line-height: 1;
}

.transcript-dialog > p {
  overflow-wrap: anywhere;
}

@media (max-width: 720px), (max-height: 500px), (pointer: coarse) {
  /* Touch users cannot discover controls via pointer hover at the top edge. */
  .lesson-nav.is-auto-hidden:not(:focus-within) {
    transform: none;
  }

  .brand {
    display: inline-flex;
    min-width: 44px;
    min-height: 44px;
    align-items: center;
  }

  .player-icon,
  .player-skip,
  .player-speed,
  .nav-button,
  .lesson-page-button {
    min-width: 44px;
    min-height: 44px;
  }

  .player-icon,
  .lesson-page-button {
    width: 44px;
    height: 44px;
  }

  #audio-scrubber,
  #cos-value {
    min-height: 44px;
  }

  .media-timeline {
    grid-template-columns: 2.35rem minmax(0, 1fr) 2.35rem;
    align-items: start;
  }

  .media-timeline .timecode {
    display: flex;
    height: 44px;
    align-items: center;
  }

  .media-timeline .audio-state {
    display: none;
  }

  .scrubber-wrap {
    min-width: 0;
  }

  /* Tiny, overlapping dots cannot be reliable touch targets. Keep exact seek
     times as a local, scrollable row; their full captions remain accessible. */
  .cue-markers {
    position: static;
    display: flex;
    min-width: 0;
    height: auto;
    gap: 0.3rem;
    padding: 0.25rem;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    pointer-events: auto;
    scrollbar-width: thin;
    touch-action: pan-x;
  }

  .cue-markers:empty {
    display: none;
  }

  .cue-marker {
    position: static;
    display: grid;
    width: auto;
    min-width: 44px;
    height: 44px;
    flex: 0 0 auto;
    place-items: center;
    padding: 0 0.5rem;
    border-radius: 8px;
    background: var(--surface-raised);
    color: var(--cream-muted);
    box-shadow: inset 0 0 0 1px var(--line);
    font-size: 0.75rem;
    font-variant-numeric: tabular-nums;
    opacity: 1;
    transform: none;
  }

  .cue-marker::after {
    content: attr(data-time-label);
  }

  .cue-marker:hover,
  .cue-marker:focus-visible {
    background: var(--surface-soft);
    color: var(--cream);
    transform: none;
  }
}

@media (max-width: 720px) {
  .nav-main {
    grid-template-columns: auto minmax(0, 1fr);
    gap: 0.3rem;
  }

  .voice-controls {
    gap: 0;
    border-radius: 16px;
  }

  #transcript-toggle,
  #voice-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding-inline: 0.5rem;
  }

  .player-skip {
    width: 44px;
  }

  .lesson-page-navigation {
    min-width: 0;
    flex: 1;
  }

  .lesson-page-navigation .lesson-page-hint {
    min-width: 0;
    max-width: none;
    flex: 1;
  }

  .lesson-page-button,
  .lesson-page-count {
    flex-shrink: 0;
  }

  .dialog-head {
    gap: 0.5rem;
    padding: 0.75rem;
  }

  .transcript-dialog > p {
    padding: 1rem;
  }

  .lesson-admin-head,
  .lesson-admin-footer {
    gap: 0.5rem;
    padding-inline: 0.75rem;
  }

  .lesson-admin-footer {
    flex-wrap: wrap;
  }
}

@media (max-width: 359px) {
  .voice-controls {
    display: grid;
    width: 100%;
    grid-template-columns: repeat(3, minmax(44px, 1fr));
    justify-items: stretch;
  }

  .voice-controls .player-icon,
  .voice-controls .player-skip {
    width: 100%;
  }
}

/* Low landscape screens keep scrollable content at full readable scale. */
@media (max-height: 500px) {
  .lesson-hero,
  .lesson-section {
    padding-top: 1rem;
  }

  .lesson-admin-dialog {
    max-height: calc(100dvh - 1rem);
  }

  .lesson-admin-head,
  .lesson-admin-footer {
    padding-block: 0.4rem;
  }
}
