/* Readable study controls. Load after style.css; retain the class colour palette. */
.control-button,
.gear-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-width: 48px;
  min-height: 52px;
  width: auto;
  height: auto;
  padding: 10px 14px;
  border: 1px solid #dca8c75c;
  border-radius: 12px;
  background: #ffffff08;
  color: inherit;
  font-size: 14px;
  font-weight: 650;
  line-height: 1.25;
  text-align: center;
  flex-shrink: 0;
}
.control-icon {
  display: block;
  width: 26px;
  height: 26px;
  flex: 0 0 26px;
}
.control-label {
  display: inline;
  font-size: 14px;
  font-weight: 650;
  line-height: 1.25;
}
.gear-button {
  min-width: 56px;
  min-height: 56px;
  border-color: #e3b2d480;
  background: linear-gradient(135deg, #dca8c726, #bca2e315);
  box-shadow: inset 0 0 0 1px #e3b2d40a;
  color: #f5dfef;
}
.gear-button .control-icon {
  width: 32px;
  height: 32px;
  flex-basis: 32px;
}
.control-button:hover:not(:disabled),
.gear-button:hover:not(:disabled) {
  background-color: #dca8c720;
  border-color: #e4b7d1;
}
.control-button:focus-visible,
.gear-button:focus-visible {
  outline: 3px solid #a5e0d7;
  outline-offset: 3px;
}
.control-button[aria-pressed="true"] {
  background: #dca8c730;
  border-color: #e4b7d1;
}
.topbar > .top-settings {
  width: auto;
  min-width: 56px;
  min-height: 56px;
  height: auto;
  padding: 10px 13px;
  border-radius: 14px;
}

/* The dock keeps its labels; narrow screens receive another row. */
#audio-player {
  width: min(1000px, calc(100% - 32px));
  padding: 16px 18px 14px;
  border-radius: 18px;
  bottom: max(14px, env(safe-area-inset-bottom));
}
#audio-player .audio-heading {
  display: grid;
  grid-template-columns: 8px minmax(90px, 1fr) auto auto 48px;
  align-items: center;
  gap: 12px;
}
#audio-player .audio-heading > div:first-of-type {
  min-width: 0;
}
#audio-player #audio-title {
  font-size: 15px;
  line-height: 1.4;
}
#audio-player #audio-subtitle {
  font-size: 13px;
  line-height: 1.4;
  margin-top: 3px;
}
#audio-player .audio-heading > .audio-countdown {
  min-width: 145px;
  padding: 9px 12px;
}
#audio-player .audio-countdown small {
  font-size: 11px;
}
#audio-player .audio-countdown strong {
  font-size: 26px;
}
#audio-player .countdown-orbit {
  width: 30px;
  height: 30px;
  flex-basis: 30px;
}
#audio-player .audio-heading > .audio-expand {
  display: inline-flex;
  min-width: 48px;
  width: auto;
  height: auto;
  min-height: 52px;
  padding: 10px 12px;
  gap: 8px;
  border: 1px solid #dca8c75c;
  border-radius: 12px;
  background: #ffffff08;
  font-size: 14px;
}
#audio-player .audio-heading > [data-action="audio-close"] {
  width: 48px;
  min-width: 48px;
  min-height: 48px;
  height: 48px;
  font-size: 30px;
  border: 1px solid #dca8c735;
  background: #ffffff05;
}
#audio-player .audio-track {
  height: 3px;
  margin: 14px 0 12px;
}
#audio-player .audio-transport,
#reader-viewer .viewer-transport {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
#audio-player .audio-transport > button,
#reader-viewer .viewer-transport > button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 48px;
  min-height: 52px;
  width: auto;
  height: auto;
  padding: 10px 13px;
  border: 1px solid #dca8c75c;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 650;
  line-height: 1.25;
}
#audio-player .audio-transport > .audio-play,
#reader-viewer .viewer-transport > .audio-play {
  min-height: 56px;
  min-width: 120px;
  background: #ebbed7;
  color: #342238;
  border-color: #f2cde2;
  box-shadow: 0 4px 14px #0a051b33;
}
#audio-player .audio-transport > .gear-button,
#reader-viewer .viewer-transport > .gear-button {
  min-height: 56px;
  min-width: 56px;
  border-color: #e3b2d480;
  background: linear-gradient(135deg, #dca8c726, #bca2e315);
}
#audio-player .audio-transport > [aria-pressed="true"],
#reader-viewer .viewer-transport > [aria-pressed="true"] {
  border-color: #e4b7d1;
  background: #dca8c730;
}
#audio-player .audio-transport #audio-position {
  flex: 0 0 auto;
  margin: 0;
  color: #dfcfe7;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
#audio-player .audio-transport #audio-status {
  min-width: 0;
  max-width: none;
  flex: 1 1 150px;
  color: #ddcfe5;
  font-size: 13px;
  line-height: 1.4;
}
.has-audio {
  padding-bottom: 225px;
}
.has-audio #toast {
  bottom: 225px;
}

/* Study selection and actions use the same generous touch areas. */
.reader .reader-actions {
  gap: 10px;
  padding-top: 18px;
  padding-bottom: 18px;
}
.reader .reader-actions > button,
.reader .question-actions > button,
.reader .followup > button,
.reader .class-answer > button,
.reader .extra-question button,
.reader .from-slide > .text-button,
.viewer-section-heading button,
#reader-viewer .viewer-questions .mini {
  min-height: 48px;
  font-size: 14px;
  padding: 11px 15px;
  line-height: 1.4;
  border-radius: 10px;
}
.reader .reader-actions > .text-button {
  margin: 0;
}
.reader .section-tabs {
  gap: 10px;
}
.reader .section-tab {
  min-width: 0;
  min-height: 58px;
  padding: 12px 11px;
  gap: 9px;
  border-radius: 9px;
  font-size: 14px;
  line-height: 1.35;
  overflow-wrap: break-word;
}
.reader .section-tab b {
  display: grid;
  place-items: center;
  width: 27px;
  min-width: 27px;
  height: 27px;
  font-size: 13px;
}
.reader .listen-section {
  min-height: 48px;
  padding: 10px 14px;
  border: 1px solid #b89bac80;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 650;
  color: #704562;
  background: #f7e7f0;
}
.reader .reader-nav {
  gap: 10px;
  font-size: 13px;
}
.reader .reader-nav button {
  min-height: 48px;
  padding: 10px 12px;
  font-size: 14px;
  font-weight: 650;
  border: 1px solid #c7a9bd80;
  border-radius: 9px;
}
.library-sidebar .search-field input,
.library-sidebar select {
  min-height: 48px;
  font-size: 14px;
}
.library-sidebar .filter-fav {
  min-height: 48px;
  font-size: 14px;
}
.library-sidebar .topic-item > span:first-child {
  font-size: 14px;
  line-height: 1.4;
}
.library-sidebar .topic-item small {
  font-size: 12px;
  line-height: 1.4;
}

/* Enlarged text reader: large section tabs and the same transport. */
#reader-viewer .viewer-tab {
  min-height: 50px;
  padding: 11px 14px;
  gap: 9px;
  font-size: 14px;
}
#reader-viewer .viewer-tab b {
  width: 27px;
  min-width: 27px;
  height: 27px;
  font-size: 13px;
}
#reader-viewer .viewer-shrink {
  min-width: 48px;
  min-height: 52px;
  padding: 11px 14px;
}
#reader-viewer .viewer-shrink span {
  display: inline;
  font-size: 14px;
}
#reader-viewer .viewer-player {
  padding: 16px 22px 18px;
}
#reader-viewer .viewer-player p {
  font-size: 13px;
  line-height: 1.45;
}
#reader-viewer .viewer-player-top .eyebrow {
  font-size: 11px;
}
#reader-viewer .viewer-player .audio-countdown small {
  font-size: 11px;
}

/* Voice settings remain usable inside both a modal and native fullscreen. */
#dialog .dialog-close {
  width: 48px;
  min-width: 48px;
  height: 48px;
  min-height: 48px;
  font-size: 30px;
}
#dialog:has(.voice-settings) {
  max-width: 710px;
  padding: 50px 30px 28px;
}
#dialog .voice-settings {
  margin: 0;
}
#dialog .voice-settings p,
#dialog .voice-settings label,
#dialog .voice-help summary {
  font-size: 14px;
  line-height: 1.6;
}
#dialog .voice-choice-grid {
  grid-template-columns: minmax(0, 1fr) 115px;
  gap: 16px;
}
#dialog .voice-accent-choice {
  grid-column: 1 / -1;
  margin-bottom: 0;
}
#dialog .voice-accent-choice small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
}
#dialog .voice-settings select {
  min-height: 50px;
  padding: 11px 12px;
  font-size: 14px;
}
#dialog .voice-actions {
  gap: 10px;
}
#dialog .voice-actions > button {
  min-height: 48px;
  padding: 11px 14px;
  font-size: 14px;
  line-height: 1.4;
}
#dialog #voice-study-sample {
  font-size: 16px;
  min-height: 100px;
}
#dialog .voice-help summary {
  display: list-item;
  min-height: 48px;
  padding: 10px 0;
}

@media (max-width: 1000px) and (min-width: 821px) {
  .topbar {
    gap: 10px;
    padding-left: 22px;
    padding-right: 22px;
  }
  .topbar > .top-settings {
    padding-left: 10px;
    padding-right: 10px;
  }
}
@media (max-width: 820px) {
  .topbar > .top-settings {
    order: 1;
    margin-left: 10px;
  }
  .library-sidebar #topic-list {
    max-height: 150px;
  }
  .library-sidebar .topic-item {
    flex-basis: 210px;
  }
}
@media (max-width: 700px) {
  #audio-player {
    width: calc(100% - 20px);
    padding: 12px 13px;
    bottom: max(10px, env(safe-area-inset-bottom));
    border-radius: 16px;
    max-height: calc(100dvh - 24px);
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  #audio-player .audio-heading {
    grid-template-columns: minmax(0, 1fr) auto 48px;
    gap: 9px;
  }
  #audio-player .audio-heading > .audio-light {
    display: none;
  }
  #audio-player .audio-heading > div:first-of-type {
    grid-column: 1 / 3;
    grid-row: 1;
  }
  #audio-player .audio-heading > [data-action="audio-close"] {
    grid-column: 3;
    grid-row: 1;
  }
  #audio-player .audio-heading > .audio-countdown {
    grid-column: 1;
    grid-row: 2;
    width: auto;
    min-width: 0;
    justify-content: center;
    padding: 8px 10px;
  }
  #audio-player .audio-heading > .audio-expand {
    grid-column: 2 / 4;
    grid-row: 2;
    width: 100%;
    min-height: 54px;
  }
  #audio-player .audio-heading .audio-countdown small {
    font-size: 11px;
  }
  #audio-player .audio-heading .countdown-orbit {
    width: 28px;
    height: 28px;
    flex-basis: 28px;
  }
  #audio-player .audio-transport,
  #reader-viewer .viewer-transport {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    align-items: stretch;
  }
  #audio-player .audio-transport > button,
  #reader-viewer .viewer-transport > button {
    flex-direction: column;
    gap: 5px;
    width: 100%;
    min-width: 0;
    min-height: 64px;
    padding: 8px 5px;
    font-size: 14px;
    line-height: 1.25;
  }
  #audio-player .audio-transport > [data-action="audio-prev"],
  #reader-viewer .viewer-transport > [data-action="audio-prev"] {
    grid-column: 1;
    grid-row: 1;
  }
  #audio-player .audio-transport > [data-action="audio-toggle"],
  #reader-viewer .viewer-transport > [data-action="audio-toggle"] {
    grid-column: 2;
    grid-row: 1;
    min-width: 0;
    width: 100%;
  }
  #audio-player .audio-transport > [data-action="audio-next"],
  #reader-viewer .viewer-transport > [data-action="audio-next"] {
    grid-column: 3;
    grid-row: 1;
  }
  #audio-player .audio-transport > .gear-button,
  #reader-viewer .viewer-transport > .gear-button {
    grid-column: 1;
    grid-row: 2;
    min-width: 56px;
    min-height: 64px;
  }
  #audio-player .audio-transport > [data-action="audio-repeat"],
  #reader-viewer .viewer-transport > [data-action="audio-repeat"] {
    grid-column: 2;
    grid-row: 2;
  }
  #audio-player .audio-transport > #audio-rate,
  #reader-viewer .viewer-transport > [data-expanded-rate] {
    grid-column: 3;
    grid-row: 2;
  }
  #audio-player .audio-transport #audio-position {
    grid-column: 1;
    grid-row: 3;
    align-self: center;
    text-align: center;
    padding: 2px 0;
  }
  #audio-player .audio-transport #audio-status {
    grid-column: 2 / 4;
    grid-row: 3;
    min-width: 0;
    align-self: center;
    padding: 2px 0;
  }
  #reader-viewer .viewer-transport > [data-action="audio-close"] {
    grid-column: 1 / -1;
    min-height: 48px;
    flex-direction: row;
  }
  .has-audio {
    padding-bottom: 345px;
  }
  .has-audio #toast {
    bottom: 340px;
  }
  #reader-viewer .viewer-player {
    padding: 13px 16px 15px;
  }
  #reader-viewer .viewer-player-top {
    gap: 12px;
  }
  #reader-viewer .viewer-player-top .eyebrow {
    font-size: 10px;
  }
  #reader-viewer .viewer-player .audio-countdown {
    min-width: 135px;
    padding: 8px 10px;
  }
  #reader-viewer .viewer-player .audio-countdown strong {
    font-size: 26px;
  }
  #reader-viewer .viewer-player .audio-countdown small {
    font-size: 10px;
  }
  #reader-viewer .viewer-fragment {
    display: block;
    margin: 2px 0 0;
  }
  .reader .section-tabs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }
  #dialog:has(.voice-settings) {
    width: calc(100% - 20px);
    max-height: calc(100dvh - 24px);
    padding: 52px 20px 22px;
  }
}
@media (max-width: 400px) {
  .topbar > .top-settings {
    gap: 6px;
    padding: 10px;
    margin-left: 0;
  }
  .topbar > .top-settings .control-label {
    font-size: 13px;
  }
  #audio-player {
    width: calc(100% - 16px);
    padding: 11px 10px;
  }
  #audio-player .audio-heading {
    gap: 7px;
  }
  #audio-player .audio-heading > .audio-countdown {
    padding: 8px 6px;
    gap: 6px;
  }
  #audio-player .audio-heading .countdown-orbit {
    display: none;
  }
  #audio-player .audio-heading > .audio-expand {
    padding: 10px;
    gap: 6px;
  }
  #reader-viewer .viewer-heading {
    padding: 14px;
    gap: 8px;
  }
  #reader-viewer .viewer-heading h2 {
    font-size: 20px;
  }
  #reader-viewer .viewer-shrink {
    flex-direction: column;
    gap: 3px;
    padding: 8px;
  }
  #reader-viewer .viewer-player {
    padding: 12px;
  }
  .reader .reader-actions > button {
    width: 100%;
    text-align: center;
    justify-content: center;
  }
  .reader .section-tabs {
    padding-left: 12px;
    padding-right: 12px;
  }
  .reader .section-tab {
    padding: 10px 8px;
    gap: 7px;
    font-size: 13px;
  }
  .reader .reader-nav {
    padding-left: 12px;
    padding-right: 12px;
    gap: 6px;
  }
  .reader .reader-nav button {
    padding: 10px 8px;
    font-size: 13px;
  }
  #dialog .voice-choice-grid {
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
  }
  #dialog .voice-settings select {
    font-size: 16px;
  }
  #dialog .voice-actions > button {
    flex: 1 1 120px;
  }
}
@media (max-height: 570px) and (orientation: landscape) {
  #audio-player {
    max-height: 52dvh;
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  #reader-viewer .viewer-heading {
    padding: 10px 16px;
  }
  #reader-viewer .viewer-player {
    max-height: 45dvh;
    overflow-y: auto;
    overscroll-behavior: contain;
  }
}

/* Single/double taps share the same navigation; unavailable directions are gray. */
button:is([data-action="audio-prev"], [data-action="audio-next"], [data-slide-action="prev"], [data-slide-action="next"]) {
  touch-action: manipulation;
  user-select: none;
}
button:is([data-action="audio-prev"], [data-action="audio-next"], [data-slide-action="prev"], [data-slide-action="next"]):disabled {
  filter: grayscale(1);
  opacity: .38;
  cursor: default;
}
