/* V9 reader controls. Load after article-actions-v6.css and the V8 profile CSS.
   Text actions share their content spacing; glyph-only/segmented controls keep
   their established compact targets. Native states and focus styles are retained. */
.article-tools,
.article-bottom-actions {
  --reader-button-inset: 20px;
  --reader-button-gap: 8px;
  --reader-button-height: 48px;
}

.article-tools :is(#listen-toggle, #listen-stop, #summary-read-toggle, #article-share),
.article-support .article-bottom-actions > [data-support-button],
.article-bottom-actions #copy-citation,
.article-bottom-actions .article-back-to-top {
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: max-content;
  min-width: max-content;
  max-width: none;
  height: auto;
  min-height: var(--reader-button-height);
  padding: 10px var(--reader-button-inset);
  gap: var(--reader-button-gap);
  white-space: nowrap;
}

.article-tools[data-summary-audio-tools] {
  flex-wrap: wrap;
}

.article-tools[data-summary-audio-tools] .listen-tools {
  min-width: 0;
  flex-wrap: wrap;
  gap: 8px;
}

.article-tools[data-summary-audio-tools] .share-anchor {
  margin-inline-start: auto;
}

/* Equal flexible side tracks keep the support button on the article axis even
   when its label/count changes. Neither side is allowed to squeeze its text. */
.article-bottom-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) max-content minmax(0, 1fr);
  align-items: center;
  column-gap: 0;
  row-gap: 8px;
}

.article-bottom-actions #copy-citation {
  grid-column: 1;
  grid-row: 1;
  justify-self: start;
  /* The padded hit area extends into the gutter; the icon stays on the text edge. */
  margin-inline-start: calc(-1 * var(--reader-button-inset));
}

.article-support .article-bottom-actions > [data-support-button] {
  grid-column: 2;
  grid-row: 1;
  justify-self: center;
}

.article-bottom-actions .article-back-to-top {
  grid-column: 3;
  grid-row: 1;
  justify-self: end;
  margin-inline-end: 0;
}

.article-bottom-actions .support-count {
  flex: 0 0 auto;
  min-width: 1ch;
  font-variant-numeric: tabular-nums;
}

/* ResizeObserver chooses this only when the intrinsic content would collide. */
.article-bottom-actions:is([data-v9-action-layout="stacked"], [data-v9-action-layout="three-row"]) {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.article-bottom-actions:is([data-v9-action-layout="stacked"], [data-v9-action-layout="three-row"]) > [data-support-button] {
  grid-column: 1 / -1;
  grid-row: 2;
}

.article-bottom-actions:is([data-v9-action-layout="stacked"], [data-v9-action-layout="three-row"]) .article-back-to-top {
  grid-column: 2;
}

.article-bottom-actions[data-v9-action-layout="three-row"] .article-back-to-top {
  grid-column: 1 / -1;
  grid-row: 3;
}

@media (max-width: 760px) {
  .article-tools,
  .article-bottom-actions {
    --reader-button-inset: 16px;
  }

  /* Real content widths decide wrapping, including pending/playing states.
     This replaces the inherited six-column grid with its 2px gaps. */
  .article-tools[data-summary-audio-tools][data-compact-ready="true"]:has(.summary-read-toggle) {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
  }

  .article-tools[data-summary-audio-tools][data-compact-ready="true"] :is(.listen-tools, .share-anchor, .reader-size-disclosure) {
    display: contents;
  }

  /* Play and share remain purposeful icon-only controls, with native names. */
  .article-tools[data-summary-audio-tools][data-compact-ready="true"] :is(#listen-toggle, #article-share) {
    width: 44px;
    min-width: 44px;
    height: 44px;
    min-height: 44px;
    padding: 0;
    gap: 0;
  }

  .article-tools[data-summary-audio-tools][data-compact-ready="true"] #summary-read-toggle {
    flex: 0 0 auto;
    width: 72px;
    min-width: 72px;
    max-width: 72px;
    height: var(--reader-button-height);
    min-height: var(--reader-button-height);
    /* Book 20 + gap 8 + arrow 12 + inset 16 on each side = 72px. */
    padding: 14px 16px;
    gap: 8px;
    font-size: 14px;
  }

  .article-tools[data-summary-audio-tools] .summary-read-label {
    flex: 0 0 auto;
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  .article-tools[data-summary-audio-tools] .summary-read-toggle > .disclosure-chevron {
    display: flex;
    flex: 0 0 12px;
    width: 12px;
    height: 12px;
  }

  .article-tools[data-summary-audio-tools] .summary-read-toggle > .disclosure-chevron > .ui-icon {
    width: 12px;
    height: 12px;
  }

  .article-tools[data-summary-audio-tools][data-compact-ready="true"] #listen-details-toggle {
    box-sizing: border-box;
    width: max-content;
    min-width: max-content;
    height: auto;
    min-height: 44px;
    padding: 10px var(--reader-button-inset);
    gap: var(--reader-button-gap);
  }

  .article-tools[data-summary-audio-tools][data-compact-ready="true"] #reader-size-toggle {
    margin-inline-start: auto;
  }

  .article-tools[data-summary-audio-tools][data-compact-ready="true"] .mobile-tool-panel {
    position: static;
    flex: 0 0 100%;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    margin-top: 0;
    box-shadow: none;
  }

  .article-tools[data-summary-audio-tools][data-compact-ready="true"] .mobile-playback-actions {
    gap: 8px;
  }

  .article-tools[data-summary-audio-tools][data-compact-ready="true"] .mobile-playback-panel :is(#listen-stop, #listen-prev, #listen-next) {
    box-sizing: border-box;
    flex: 0 0 auto;
    width: max-content;
    min-width: max-content;
    height: auto;
    min-height: var(--reader-button-height);
    padding: 10px var(--reader-button-inset);
    gap: var(--reader-button-gap);
    white-space: nowrap;
  }
}

/* A no-JavaScript fallback for the narrowest supported phone width. At375/390
   the observer retains a single row whenever the actual font/content fits. */
@media (max-width: 374px) {
  .article-bottom-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .article-support .article-bottom-actions > [data-support-button] {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .article-bottom-actions .article-back-to-top {
    grid-column: 2;
  }
}

/* Aa uses the editor card and close-button classes for the shared visual frame.
   Its wrapper has no desktop box, so the original inline control stays intact. */
.reader-size-popover-content-v9 { display: contents; }
.reader-size-popover-dismiss-v9[hidden] { display: none !important; }

@media (max-width: 760px) {
  #reader-size-panel.reader-size-popover-v9 {
    position: fixed;
    inset: auto;
    top: var(--editor-popover-top, 0px);
    left: var(--editor-popover-left, 0px);
    z-index: 20;
    display: block;
    flex: none;
    width: min(224px, calc(100vw - 24px));
    max-width: none;
    margin: 0;
    padding: 0;
  }

  #reader-size-panel.reader-size-popover-v9[hidden] { display: none; }

  #reader-size-panel.reader-size-popover-v9 .reader-size-popover-content-v9 {
    display: grid;
    gap: 12px;
    padding: 16px;
    max-height: var(--reader-size-popover-max-height, calc(100dvh - 24px));
    overflow-y: auto;
    box-sizing: border-box;
  }

  #reader-size-panel.reader-size-popover-v9 .mobile-panel-title {
    display: block;
    margin: 0;
    padding-inline-end: 44px;
    color: var(--ink);
    font: 500 14px/1.5 var(--font);
  }

  #reader-size-panel.reader-size-popover-v9 .reader-size-inline {
    display: flex;
    flex-wrap: nowrap;
    width: 100%;
    max-width: none;
    height: 48px;
    gap: 0;
    margin: 0;
  }

  #reader-size-panel.reader-size-popover-v9 .reader-size-inline button {
    flex: 1 1 0;
    width: auto;
    min-width: 48px;
    height: 48px;
    min-height: 48px;
  }

  #reader-size-panel.reader-size-popover-v9 [data-reader-reset] {
    flex: 0 0 64px;
    min-width: 64px;
    padding-inline: 8px;
  }
}

@media print {
  #reader-size-panel.reader-size-popover-v9 { display: none !important; }
}

/* Longest native rate label + 12px left + 8px gap + 12px arrow + 12px right.
   The JS font measurement freezes this width for every option, not each value. */
@media (max-width:760px) {
  .article-tools[data-compact-ready=true] .listen-tools > .ui-select-shell {
    --select-text-inset:12px;
    --select-icon-inset:12px;
    --select-chevron-lane:32px;
    flex:0 0 var(--listen-rate-width,92px);
    width:var(--listen-rate-width,92px);
    min-width:var(--listen-rate-width,92px);
  }
  .article-tools[data-compact-ready=true] .listen-tools > .ui-select-shell > #listen-rate {
    box-sizing:border-box;
    width:var(--listen-rate-width,92px);
    min-width:var(--listen-rate-width,92px);
    max-width:var(--listen-rate-width,92px);
    padding-inline:12px 32px;
  }
  .article-tools[data-compact-ready=true] .listen-tools > .ui-select-shell > .ui-icon {
    width:12px; height:12px; inset-inline-end:12px;
  }
  .article-tools[data-compact-ready=true] .listen-tools > .ui-select-shell > .ui-select-visible-value {display:none}
}
