/* ===========================================================================
   Calm layer (2026-11) — the last word on shape, colour use and type rhythm.

   Why: the UI read as a Material-3 template — every control a full pill,
   a lavender-grey "tonal" fill on buttons, segments and the nav indicator
   sitting on teal-grey surfaces, dashed placeholder boxes, letter-spaced
   CJK labels and a second and third accent hue (mint, pink) on chips.
   A reading app wants quiet chrome: one accent, used sparingly; neutral
   surfaces; one corner radius for every control; text that carries the
   hierarchy instead of fills.

   Rules this layer enforces on every page, theme and platform:
   - Controls (buttons, fields, selects, segmented controls, chips, menus)
     share one small radius. Only switches, avatars, progress bars and
     single-glyph round affordances (scroll-to-top) stay round.
   - Selection is a faint accent tint with normal text, never a separate
     lavender container. The filled accent is reserved for the primary
     action of a view.
   - Secondary buttons are outlined and neutral, not tonal.
   - Status chips are neutral; the word carries the meaning.
   - No letter-spacing on Chinese UI text; labels are medium, not bold.
   - Empty states are plain muted text, not dashed boxes.
   It only overrides tokens and existing selectors, so removing this file
   (and its @import in style.css) restores the previous look exactly.
   ======================================================================== */

/* Tokens live on body, like foundation.css, so they can read the --ds-* values. */
body {
  --calm-radius: var(--ds-radius-sm);
  --ds-on-accent-soft: var(--ds-text);
  /* 不认识 color-mix 的旧内核（Android 9 WebView 等）用中性的悬停色，不留空 */
  --calm-selected: var(--ds-state-hover);
  --calm-selected-text: var(--ds-text);
  --calm-outline: var(--ds-border-strong);
}

/* Issue #476：阅读器浮层上按阅读配色重新算一次（见 foundation.css 的同名说明）。 */
[data-reader-theme] {
  --ds-on-accent-soft: var(--ds-text);
  --calm-selected: var(--ds-state-hover);
  --calm-selected-text: var(--ds-text);
  --calm-outline: var(--ds-border-strong);
}

@supports (color: color-mix(in srgb, red 50%, transparent)) {
  body,
  [data-reader-theme] {
    --ds-accent-soft: color-mix(in srgb, var(--ds-accent) 13%, var(--ds-surface-card));
    --calm-selected: color-mix(in srgb, var(--ds-accent) 13%, transparent);
  }
}

/* ---------------------------------------------------------------------------
   Type rhythm
   ------------------------------------------------------------------------ */
.section-title,
.field-label,
.settings-card-title,
.accent-button,
.ghost-button,
.danger-button,
.history-action,
.update-action-button,
.format-toggle-button,
.tabbar .nav-item,
.status-pill,
.meta-chip,
.discover-chip {
  letter-spacing: 0;
}

.field-label {
  font-weight: var(--ds-weight-medium);
}

/* The card title is the one strong label inside a settings card. */
.settings-card-title,
.settings-card > .field > .field-label.settings-card-title {
  color: var(--ds-text);
  font-size: var(--ds-text-title-sm);
  font-weight: var(--ds-weight-strong);
}

/* ---------------------------------------------------------------------------
   Controls — one radius, neutral secondary buttons
   ------------------------------------------------------------------------ */
body :is(
  .accent-button,
  .ghost-button,
  .danger-button,
  .history-action,
  .update-action-button,
  .theme-toggle,
  .language-select,
  .text-input,
  .text-area,
  select.text-input,
  .path-display,
  .path-picker,
  .format-toggle,
  .discover-chip,
  .bookshelf-toolbar,
  .bookshelf-toolbar > .ghost-button,
  .bookshelf-batch-actions,
  .bookshelf-batch-actions > button,
  .bookshelf-card-actions,
  .bookshelf-card-actions button,
  .official-bookshelf-more,
  .official-sync-pending,
  .settings-card .path-picker > .ghost-button,
  .settings-fold-chevron,
  .title-variant,
  .status-pill,
  .meta-chip
) {
  border-radius: var(--calm-radius);
}

body #searchKeywordInput,
body .search-box input,
body input[type="search"].text-input {
  border-radius: var(--calm-radius);
}

/* Segments sit flush inside their track, so their inner corners follow it. */
body .format-toggle {
  overflow: hidden;
}

body .format-toggle-button {
  border-radius: 0;
}

body .format-toggle-button.active,
body .format-toggle-button[aria-pressed="true"],
body .format-toggle-button[aria-selected="true"] {
  background: var(--calm-selected);
  color: var(--calm-selected-text);
  font-weight: var(--ds-weight-medium);
}

/* Windows keeps its inset marker (light surfaces need it), on the calm tint. */
body.windows-shell .format-toggle-button.active,
body.windows-shell .format-toggle-button[aria-pressed="true"] {
  background: var(--calm-selected);
  color: var(--calm-selected-text);
  box-shadow: inset 0 -2px 0 var(--ds-accent);
}

body .window-control {
  border-radius: var(--calm-radius);
}

/* Secondary actions: outlined and neutral on every platform. */
body .ghost-button,
body.platform-android .ghost-button,
body.android-shell .ghost-button,
body.ios-shell .ghost-button {
  border: 1px solid var(--calm-outline);
  background: transparent;
  color: var(--ds-text);
  box-shadow: none;
}

body .ghost-button:hover:not(:disabled) {
  background: var(--ds-state-hover);
}

/* The primary action stays the only filled accent; no glow, no lift. */
body .accent-button {
  box-shadow: none;
  filter: none;
}

body .accent-button:hover:not(:disabled) {
  box-shadow: none;
}

/* Destructive actions read by their colour, not by a red slab. */
body .danger-button {
  border: 1px solid color-mix(in srgb, var(--m3-error, #b3261e) 55%, transparent);
  background: transparent;
  color: var(--m3-error, #b3261e);
  box-shadow: none;
}

body .danger-button:hover:not(:disabled) {
  background: color-mix(in srgb, var(--m3-error, #b3261e) 10%, transparent);
}

/* Confirm dialogs keep a solid destructive button so the final step is clear. */
body :is(.modal, .dialog, [role="dialog"], [role="alertdialog"]) .danger-button {
  border-color: var(--m3-error, #b3261e);
  background: var(--m3-error, #b3261e);
  color: var(--m3-on-error, #fff);
}

body .update-action-button {
  border: 1px solid var(--calm-outline);
  background: transparent;
  color: var(--ds-text-muted);
  box-shadow: none;
}

body .language-select {
  background: transparent;
}

/* Pressing scales nothing; the colour change is feedback enough. */
.accent-button:active:not(:disabled),
.ghost-button:active:not(:disabled),
.danger-button:active:not(:disabled),
.history-action:active:not(:disabled) {
  transform: none;
}

/* ---------------------------------------------------------------------------
   Chips and badges — neutral; one accent at most
   ------------------------------------------------------------------------ */
/* Status words (已完结, 连载中, 下载中) are plain muted text; errors keep their colour. */
body .status-pill,
body .status-pill.info,
body .status-pill.success {
  border: 0;
  background: transparent;
  color: var(--ds-text-muted);
  box-shadow: none;
}

body .status-pill.error,
body .status-pill.danger {
  border: 0;
  background: transparent;
  color: var(--m3-error, #b3261e);
}

body .meta-chip {
  border: 1px solid var(--ds-border);
  background: transparent;
  color: var(--ds-text-muted);
}

body .discover-chip {
  border: 1px solid var(--ds-border);
  background: transparent;
  color: var(--ds-text-muted);
}

body :is(.discover-chip.active, .discover-chip[aria-pressed="true"], .discover-chip[aria-selected="true"]) {
  border-color: color-mix(in srgb, var(--ds-accent) 45%, var(--ds-border));
  background: var(--calm-selected);
  color: var(--calm-selected-text);
}

/* New-chapter counts: a small accent number, not a filled sticker. */
body .bookshelf-new-badge {
  border-radius: var(--ds-radius-xs);
  box-shadow: none;
}

/* ---------------------------------------------------------------------------
   Navigation — tint + accent icon, no pill indicator
   ------------------------------------------------------------------------ */
body .nav-item.active .nav-icon {
  background: transparent;
  color: var(--ds-accent);
}

body .nav-item.active > span:last-child {
  font-weight: var(--ds-weight-medium);
}

body.desktop-shell .tabbar .nav-item {
  border-radius: var(--calm-radius);
}

body.desktop-shell .tabbar .nav-item.active {
  background: var(--calm-selected);
  color: var(--ds-text);
  font-weight: var(--ds-weight-medium);
}

body.desktop-shell .tabbar .nav-item.active .nav-icon,
body.desktop-shell .tabbar .nav-item.active svg {
  color: var(--ds-accent);
}

body.desktop-shell .tabbar .nav-icon,
body.desktop-shell .tabbar .nav-item.active .nav-icon {
  background: transparent;
}

body.mobile-shell .tabbar .nav-icon,
body.mobile-shell .tabbar .nav-item.active .nav-icon,
body.android-shell .tabbar .nav-item.active .nav-icon,
body.mobile-shell.ios-shell .tabbar .nav-item.active .nav-icon,
body.android-shell .tabbar .nav-item.active:active .nav-icon {
  background: transparent;
  box-shadow: none;
}

body.mobile-shell .tabbar .nav-item {
  color: var(--ds-text-muted);
  font-size: 11px;
  letter-spacing: 0;
}

body.mobile-shell .tabbar .nav-item.active {
  color: var(--ds-accent);
  font-weight: var(--ds-weight-medium);
}

body.mobile-shell .tabbar .nav-item:active .nav-icon {
  background: transparent;
}

/* ---------------------------------------------------------------------------
   Phone bottom navigation (portrait phones, every shell)

   One geometry for every item: the icon box is the same size whether the
   item is active or not, so icons and labels sit on one line. (The
   Material rule in components.css grows only the active icon box to
   64x32; with its fill made transparent above, the active item's icon and
   label used to drop 8-16px below the others.) The active item is marked
   by the accent colour and a faint accent tint behind the icon, the same
   treatment as selection elsewhere; pressing shows a neutral press tint.
   The plain web GUI on a phone browser (no mobile-shell class) gets the
   same compact bar instead of the old 80px panel with 14px icons.
   Android keeps its 46px bar (--android-bottomnav-h), iOS its 49pt bar
   without the tint, as the platform convention.
   ------------------------------------------------------------------------ */
@media (max-width: 720px) and (min-height: 501px) {
  body {
    --calm-nav-h: 56px;
    --calm-nav-icon-w: 48px;
    --calm-nav-icon-h: 28px;
    --calm-nav-glyph: 22px;
  }

  body.ios-shell {
    --calm-nav-icon-w: 26px;
    --calm-nav-icon-h: 26px;
    --calm-nav-glyph: 24px;
  }

  body.android-shell {
    --calm-nav-h: var(--android-bottomnav-h, 46px);
    --calm-nav-icon-w: 44px;
    --calm-nav-icon-h: 26px;
    --calm-nav-glyph: 20px;
  }

  :root body .tabbar .nav-item {
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none;
    user-select: none;
  }

  :root body .tabbar .nav-item > span:last-child {
    max-width: 100%;
    line-height: 14px;
  }

  :root body .tabbar .nav-item .nav-icon,
  :root body .tabbar .nav-item.active .nav-icon {
    display: inline-grid;
    flex: 0 0 var(--calm-nav-icon-h);
    place-items: center;
    width: var(--calm-nav-icon-w);
    max-width: 100%;
    height: var(--calm-nav-icon-h);
    border-radius: var(--calm-radius);
    background: transparent;
    box-shadow: none;
    color: inherit;
    transition: background var(--ds-motion-fast) var(--ds-ease);
  }

  :root body .tabbar .nav-item .nav-icon svg {
    width: var(--calm-nav-glyph);
    height: var(--calm-nav-glyph);
  }

  :root body .tabbar .nav-item.active {
    background: transparent;
    color: var(--ds-accent);
    font-weight: var(--ds-weight-medium);
  }

  :root body .tabbar .nav-item.active > span:last-child {
    color: var(--ds-accent);
    font-weight: var(--ds-weight-medium);
  }

  :root body:not(.ios-shell) .tabbar .nav-item.active .nav-icon {
    background: var(--calm-selected);
  }

  :root body:not(.ios-shell) .tabbar .nav-item:active .nav-icon,
  :root body:not(.ios-shell) .tabbar .nav-item.active:active .nav-icon {
    background: var(--ds-state-press);
  }

  /* Web GUI in a phone browser: same bar as the app shells. */
  :root body:not(.mobile-shell) .app-shell {
    padding-bottom: calc(var(--ds-space-4) + var(--calm-nav-h) + var(--mobile-nav-inset-bottom));
  }

  :root body:not(.mobile-shell) .app-shell > .tabbar.panel-shell {
    align-items: stretch;
    gap: 0;
    min-height: 0;
    height: auto;
    padding: 0 var(--safe-area-right) var(--mobile-nav-inset-bottom) var(--safe-area-left);
    border: 0;
    border-top: 1px solid var(--ds-border);
    border-radius: 0;
    background: var(--m3-surface-container);
    box-shadow: none;
  }

  :root body:not(.mobile-shell) .tabbar .nav-item {
    flex-direction: column;
    justify-content: center;
    gap: 2px;
    height: var(--calm-nav-h);
    min-height: var(--calm-nav-h);
    padding: 0 2px;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: var(--ds-text-muted);
    font-size: 11px;
  }

  :root body:not(.mobile-shell) .tabbar .nav-item.active {
    color: var(--ds-accent);
  }

  :root body:not(.mobile-shell) .scroll-top-fab {
    bottom: calc(var(--ds-space-4) + var(--calm-nav-h) + var(--mobile-nav-inset-bottom));
  }
}

/* Settings category tabs follow the same selection treatment. */
body .settings-tab {
  border-radius: var(--calm-radius);
  letter-spacing: 0;
}

body .settings-tab.active {
  background: var(--calm-selected);
  color: var(--ds-text);
  font-weight: var(--ds-weight-medium);
}

/* ---------------------------------------------------------------------------
   Surfaces — flat, hairline-separated, no glow
   ------------------------------------------------------------------------ */
body :is(.settings-card, .panel-shell, .bookshelf-card, .result-card, .history-card, .discover-card) {
  box-shadow: none;
}

/* Empty and loading states: plain muted text, not a dashed placeholder box. */
body :is(.empty-state, .book-detail-empty, .loading-state) {
  border: 0;
  background: transparent;
}

/* ---------------------------------------------------------------------------
   Inline icons (replace the emoji that used to sit in buttons)
   ------------------------------------------------------------------------ */
.ui-icon {
  display: inline-block;
  width: 1.1em;
  height: 1.1em;
  flex: none;
  fill: currentColor;
  vertical-align: -0.18em;
}

.player-lock-button .ui-icon {
  width: 22px;
  height: 22px;
  vertical-align: middle;
}

/* ===========================================================================
   Interaction feedback: no browser tap flash, no stray focus rings
   ---------------------------------------------------------------------------
   WebViews paint a translucent blue box over anything tapped and draw the
   default focus outline on elements focused by mouse or touch; long-press
   or double-tap on buttons and cards also selects their text in blue. The
   app's own pressed state replaces all three. Keyboard focus keeps a ring
   in the theme accent via :focus-visible. Reader text, comments and form
   fields stay selectable.
   ======================================================================== */
html,
body,
*,
*::before,
*::after {
  -webkit-tap-highlight-color: transparent;
}

:where(*):focus:not(:focus-visible) {
  outline: none;
}

:where(button, a[href], summary, select, [role="button"], [role="tab"], [role="switch"], [role="menuitem"], [role="option"], [tabindex]:not([tabindex="-1"]), input[type="checkbox"], input[type="radio"], input[type="range"]):focus-visible {
  outline: 2px solid color-mix(in srgb, var(--ds-accent) 72%, transparent);
  outline-offset: 2px;
}

:where(input:not([type="checkbox"], [type="radio"], [type="range"]), textarea):focus-visible {
  outline: none;
}

:where([tabindex="-1"], dialog, [role="dialog"], .overlay, .reader-content, main, section):focus,
:where([tabindex="-1"], dialog, [role="dialog"], .overlay, .reader-content, main, section):focus-visible {
  outline: none;
}

:where(button, [role="button"], [role="tab"], [role="switch"], summary, label.switch-row, .nav-item, .chip, .segmented-control, .segment, .tabbar, .toolbar, .reader-controls, .reader-navigation, .player-footer, .player-header, .settings-tab, .section-head, .badge, .status-pill, .meta-chip) {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

:where(.reader-content, .reader-content *, .comment-text, .para-comment-text, input, textarea, [contenteditable="true"]) {
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
}

::selection {
  background: color-mix(in srgb, var(--ds-accent) 28%, transparent);
}

@media (hover: none) {
  /* Touch: cards and rows behave like buttons, so they must not select. */
  :where(.result-card, .bookshelf-card, .media-card, .history-table tr, .job-card, .settings-card .switch-row, .discover-card, .rank-item, .comment-item, .media-episode, .comic-chapter-item, .toc-item, .reader-toc li) {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
  }

  :where(.result-card, .bookshelf-card, .media-card, .history-table tbody tr, .job-card):active {
    box-shadow: inset 0 0 0 100vmax var(--ds-state-press);
  }

  :where(button, [role="button"], .nav-item, .settings-tab, .segment):active:not(:disabled) {
    filter: brightness(0.96);
  }

  html:not([data-theme="light"]) :where(button, [role="button"], .nav-item, .settings-tab, .segment):active:not(:disabled) {
    filter: brightness(1.12);
  }
}

/* ===========================================================================
   Settings rows: label on the left, switch on the right
   ---------------------------------------------------------------------------
   The switch used to sit in front of its label like a checkbox, so a column
   of switches read as a ragged left gutter. Rows now read like a settings
   list on every platform: the label and its hint start at the card's text
   edge and the switches line up on the right.
   ======================================================================== */
.settings-card .switch-row:has(> input + span),
.reader-settings-dialog .switch-row:has(> input + span),
.rx-dialog .switch-row:has(> input + span) {
  display: flex;
  flex-direction: row-reverse;
  align-items: center;
  justify-content: space-between;
  gap: var(--ds-space-4);
  width: 100%;
  min-height: 44px;
  cursor: pointer;
}

.settings-card .switch-row:has(> input + span) > span,
.reader-settings-dialog .switch-row:has(> input + span) > span,
.rx-dialog .switch-row:has(> input + span) > span {
  flex: 1 1 auto;
  min-width: 0;
}

.settings-card .switch-row:has(> input + span) > input,
.reader-settings-dialog .switch-row:has(> input + span) > input,
.rx-dialog .switch-row:has(> input + span) > input {
  flex: 0 0 auto;
  margin: 0;
}

.settings-card .switch-row + .settings-hint {
  margin-top: calc(var(--ds-space-2) * -1);
  padding-right: 64px;
}

/* Desktop settings: the panel no longer stretches past its content, so the
   header actions line up with the cards instead of floating 250px to the
   right of them. Cards may use the width up to a readable measure. */
@media (min-width: 1100px) {
  :root body .view[data-view-panel="settings"] {
    max-width: 1120px;
  }

  :root body .settings-grid {
    max-width: 880px;
  }
}

/* ===========================================================================
   Wide desktops (1600-2560)
   ---------------------------------------------------------------------------
   At 2560px the shelf became an 18-column wall of 123px covers, the history
   title column ran 1170px wide, the detail synopsis ran 1200px per line and
   settings sat flush left with 1200px of nothing beside it. Content now
   keeps a readable measure and sits in the middle of the free space.
   ======================================================================== */
.detail-content-shell {
  max-width: 1080px;
}

@media (min-width: 1600px) {
  :root body .view[data-view-panel="settings"] {
    margin-inline: auto;
    width: 100%;
  }

  :root body .view-history .history-panel {
    width: 100%;
    max-width: 1600px;
    margin-inline: auto;
  }

  :root body .bookshelf-grid {
    grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  }

  :root body.bookshelf-compact .bookshelf-grid {
    grid-template-columns: repeat(auto-fill, minmax(136px, 1fr));
  }
}

@media (min-width: 2200px) {
  :root body .bookshelf-grid {
    grid-template-columns: repeat(auto-fill, minmax(188px, 1fr));
  }

  :root body.bookshelf-compact .bookshelf-grid {
    grid-template-columns: repeat(auto-fill, minmax(152px, 1fr));
  }
}

/* ===========================================================================
   Phones: layouts designed for the width, not a squeezed desktop
   ======================================================================== */
@media (max-width: 720px) {
  /* Search (小说 / 短剧 / 漫画): one row, the field wide and the button compact. */
  :root body .search-form > .inline-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: var(--ds-space-2);
    align-items: stretch;
  }

  :root body .search-form > .inline-form > input {
    grid-column: auto;
    min-width: 0;
    padding-inline: 14px;
    text-overflow: ellipsis;
  }

  :root body .search-form > .inline-form > button {
    width: auto;
    min-width: 0;
    padding-inline: var(--ds-space-3);
    white-space: nowrap;
  }

  :root body .discover-search-panel .discover-tools {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--ds-space-2);
  }

  :root body .discover-search-panel .discover-tools > button {
    width: 100%;
    min-width: 0;
    white-space: nowrap;
  }

  :root body .discover-search-panel .discover-tools > .search-mode-toggle {
    width: 100%;
    min-width: 0;
  }

  /* Two-column action grids (book detail etc.): labels such as 移出本地书架
     fit a half-width cell on a 320px phone instead of breaking in two. */
  :root body .button-row > :is(.ghost-button, .accent-button, .danger-button) {
    padding-inline: var(--ds-space-2);
    white-space: nowrap;
  }

  /* Book detail: cover beside the title, like a store page. */
  :root body .detail-layout {
    display: grid;
    grid-template-columns: 84px minmax(0, 1fr);
    column-gap: var(--ds-space-4);
    row-gap: var(--ds-space-3);
    align-items: start;
  }

  :root body .detail-layout > .detail-intro {
    display: contents;
  }

  :root body .detail-layout > .detail-cover {
    grid-column: 1;
    grid-row: 1 / span 2;
    width: 84px;
    max-width: 84px;
    margin: 0;
  }

  :root body .detail-layout > .detail-intro > .detail-top {
    grid-column: 2;
    grid-row: 1;
    min-width: 0;
  }

  :root body .detail-layout > .detail-intro > .chip-row {
    grid-column: 2;
    grid-row: 2;
    min-width: 0;
    align-self: start;
  }

  :root body .detail-layout > .detail-intro > :not(.detail-top, .chip-row) {
    grid-column: 1 / -1;
    min-width: 0;
  }

  /* History counters: one compact row of four instead of a 2x2 block. */
  :root body .summary-row {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: var(--ds-space-2);
  }

  :root body .summary-row .summary-chip {
    display: flex;
    flex-direction: column-reverse;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-width: 0;
    min-height: 56px;
    padding: var(--ds-space-2) var(--ds-space-1);
    text-align: center;
  }

  :root body .summary-row .summary-chip > .summary-chip-label {
    max-width: 100%;
    overflow: hidden;
    font-size: 11px;
    line-height: 14px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  :root body .summary-row .summary-chip > .summary-chip-value {
    font-size: 18px;
    line-height: 22px;
  }

  /* Reader toolbar: an even 6-column grid (4 on the narrowest phones)
     instead of eleven buttons wrapping into four ragged rows. Most-used
     actions come first. */
  :root body #readerOverlay .reader-controls {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: var(--ds-space-1);
    width: 100%;
    justify-content: stretch;
  }

  :root body #readerOverlay .reader-controls > button {
    width: 100%;
    min-width: 0;
    height: 44px;
    min-height: 44px;
    padding: 0 2px;
    overflow: hidden;
    font-size: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  :root body #readerOverlay .reader-controls > #readerTocToggleButton { order: 1; }
  :root body #readerOverlay .reader-controls > #readerParaCommentsButton { order: 2; }
  :root body #readerOverlay .reader-controls > #readerListenButton { order: 3; }
  :root body #readerOverlay .reader-controls > #readerThemeSettingsButton { order: 4; }
  :root body #readerOverlay .reader-controls > #readerExtrasButton { order: 5; }
  :root body #readerOverlay .reader-controls > #readerAutoButton { order: 6; }
  :root body #readerOverlay .reader-controls > #readerFontDecButton { order: 7; }
  :root body #readerOverlay .reader-controls > #readerFontIncButton { order: 8; }
  :root body #readerOverlay .reader-controls > #readerLineHeightButton { order: 9; grid-column: span 2; }
  :root body #readerOverlay .reader-controls > #readerPageModeButton { order: 10; }
  :root body #readerOverlay .reader-controls > #readerImmersiveButton { order: 11; }

  /* Short-drama player footer: play button and progress share the first
     row; the seven actions get the full width of the second row as one
     swipeable strip, so long labels (Комментарии, Bullet comments) keep
     their natural width and a 44px target instead of piling up. */
  :root body .player-footer {
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    row-gap: var(--ds-space-1);
    column-gap: var(--ds-space-2);
  }

  :root body .player-footer > .player-icon-button {
    grid-column: 1;
    grid-row: 1;
  }

  :root body .player-footer > .player-footer-progress {
    grid-column: 2;
    grid-row: 1;
    min-width: 0;
  }

  :root body .player-footer > .player-footer-actions {
    display: flex;
    grid-column: 1 / -1;
    grid-row: 2;
    justify-content: flex-start;
    gap: var(--ds-space-1);
    min-width: 0;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
  }

  :root body .player-footer > .player-footer-actions::-webkit-scrollbar {
    display: none;
  }

  :root body .player-footer-actions > .player-icon-button {
    flex: 1 0 auto;
    padding-inline: 6px;
    white-space: nowrap;
  }
}

@media (max-width: 359px) {
  :root body #readerOverlay .reader-controls {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

/* Segmented controls on phones: four labels such as 跟随系统 / 原来的方式
   share one card row, so the labels keep to one line and the padding, not
   the text, gives way. */
@media (max-width: 480px) {
  :root body .format-toggle > .format-toggle-button {
    padding-inline: 4px;
    white-space: nowrap;
  }
}

@media (max-width: 400px) {
  :root body .format-toggle > .format-toggle-button {
    font-size: 12px;
  }
}

.player-icon-button {
  white-space: nowrap;
}

/* ===========================================================================
   Hit targets
   ---------------------------------------------------------------------------
   Touch screens: every control is at least 44px tall (Apple HIG / Material
   48dp), including the compact chrome that later layers had pulled back to
   32px. The “小” option size stays a deliberate opt-out. Text-only actions
   in comment rows (like / reply / sort) grow their hit area without growing
   a visible box. Desktop keeps compact sizes but nothing under 28px.
   ======================================================================== */
.para-filter-clear {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  min-height: 24px;
  padding: 0;
  border-radius: var(--ds-radius-full);
}

.media-comment-like,
.media-comment-reply-toggle,
.media-comments-sort,
.media-comment-score {
  min-height: 28px;
}

.media-comment-like,
.media-comment-reply-toggle {
  display: inline-flex;
  align-items: center;
  padding-inline: 6px;
  white-space: nowrap;
}

/* Nav labels are clipped (overflow: hidden) for long translations, and at
   line-height 1 the clip also cut into descenders (Library, Settings) and
   the CJK glyph box. Same specificity as shell.css so the phone bars keep
   their own rules. */
.nav-item > span {
  line-height: 1.25;
}

/* Reader theme swatches: English / Russian names (Paper white, Белая
   бумага) broke onto two lines inside a fixed-height swatch. */
:root body .reader-theme-choice {
  font-size: var(--ds-text-sm, 13px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bookshelf-card-actions > button {
  padding-inline: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Bare fields in settings cards and the listening panel had no height of
   their own and rendered 21-23px tall on desktop. */
:root :is(.settings-card, .listen-panel, .reader-settings-dialog, .rx-dialog) :is(select, input:not([type="checkbox"], [type="radio"], [type="range"], [type="color"], [type="file"], [type="hidden"])) {
  min-height: var(--ds-control-sm);
}

#listenBar .listen-icon {
  width: var(--ds-control-touch);
  padding: 0;
}

@media (pointer: coarse) {
  :root body:not(.app-option-size-small) :is(
    .ghost-button,
    .accent-button,
    .danger-button,
    .primary-button,
    .history-action,
    .update-action-button,
    .comment-action-button,
    .format-toggle-button,
    .directory-root-button,
    .player-icon-button,
    .language-select,
    .text-input,
    .settings-fold-summary,
    .settings-tab,
    .theme-toggle,
    .menu-item,
    .directory-item,
    .listen-bar-info,
    summary,
    select,
    input:not([type="checkbox"], [type="radio"], [type="range"], [type="color"], [type="file"], [type="hidden"])
  ) {
    /* A floor, not a size: later layers pin some of these to 32–36px with
       id or four-class selectors, and the user's “大” option size is
       taller still. */
    min-height: max(var(--ds-control-touch), var(--app-option-min-height, 0px)) !important;
  }

  :root body:not(.app-option-size-small) :is(
    .player-icon-button,
    .listen-panel-play,
    .format-toggle-button,
    .theme-toggle
  ) {
    min-width: var(--ds-control-touch) !important;
  }

  :root body .media-comment-like,
  :root body .media-comment-reply-toggle,
  :root body .media-comments-sort,
  :root body .media-comment-score,
  :root body .listen-panel select,
  :root body .listen-field select {
    min-height: var(--ds-control-touch);
  }

  :root body .media-comment-like,
  :root body .media-comment-reply-toggle {
    min-width: var(--ds-control-touch);
    justify-content: center;
  }

  :root body .para-filter-chip {
    min-height: var(--ds-control-touch);
    padding-block: 0;
  }

  :root body .para-filter-clear {
    min-width: var(--ds-control-touch);
    min-height: var(--ds-control-touch);
    margin-block: -2px;
    margin-right: -6px;
  }

}

/* ===========================================================================
   Web on a landscape phone (short viewport, no native shell)
   ---------------------------------------------------------------------------
   The browser build keeps the desktop frame here: a fixed-height grid whose
   lists scroll inside their panels. At 390px tall the title bar, tab row and
   panel headers left the lists 0-5px, so the bookshelf, results, settings and
   history could not be reached at all. Like the native landscape shell, the
   page now scrolls as one document, the title bar collapses to one row and
   the tab row stays pinned at the top.
   ======================================================================== */
@media (max-width: 980px) and (max-height: 500px) {
  body:not(.mobile-shell):not(.desktop-shell) {
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
    overflow-y: auto;
  }

  body:not(.mobile-shell):not(.desktop-shell) .app-shell {
    height: auto;
    max-height: none;
    min-height: 100vh;
    min-height: 100dvh;
    grid-template-rows: auto auto auto auto auto;
    align-content: start;
    overflow: visible;
  }

  :root body:not(.mobile-shell):not(.desktop-shell) .app-shell > .topbar {
    padding: 6px 10px;
  }

  body:not(.mobile-shell):not(.desktop-shell) .topbar-main {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: var(--ds-space-2);
  }

  body:not(.mobile-shell):not(.desktop-shell) .topbar-main > .brand-block {
    grid-column: 1;
    grid-row: 1;
  }

  body:not(.mobile-shell):not(.desktop-shell) .topbar-main > .topbar-status {
    grid-column: 2;
    grid-row: 1;
    width: auto;
    padding: 0;
    border: 0;
    background: transparent;
  }

  body:not(.mobile-shell):not(.desktop-shell) .topbar-status > :first-child:not(.update-action-button) {
    display: none;
  }

  body:not(.mobile-shell):not(.desktop-shell) .tabbar {
    position: sticky;
    top: 0;
    z-index: 30;
  }

  body:not(.mobile-shell):not(.desktop-shell) :is(
    .view-stack,
    .view.active,
    .view.active .panel-shell,
    .view.active .panel-shell > :is(#bookshelfList, #searchResults, .settings-grid, #historyTableWrap, #bookDetailPanel, #dramaDetailPanel, #comicDetailPanel)
  ) {
    height: auto;
    max-height: none;
    overflow: visible;
    /* clip, not hidden: wide carousels stay inside the panel without making
       it a scroll container again */
    overflow-x: clip;
    flex: 0 0 auto;
  }
}

@media (max-width: 720px) {
  :root body #readerOverlay .reader-controls > #readerBookmarkButton,
  :root body #readerOverlay .reader-controls > #readerInBookSearchButton,
  :root body #readerOverlay .reader-controls > #readerChapterHotButton { order: 2; }
}
