/* Compact reading UI. Reading text keeps its independent font size. */
body { --text-2xs: 13px; --text-xs: 13px; --ui-control-size: 16px; }
.beta-badge, .eyebrow, .shelf-book-completion { font-size: var(--text-xs); }
.shelf-book-completion { color: var(--text-muted); line-height: 1.6; }
body[data-ui-size="large"] { --text-2xs: 15px; --text-xs: 15px; --text-sm: 16px; --text-base: 17px; --text-md: 18px; --ui-control-size: 18px; }
:is(.tools-dialog,.settings-panel,.shelf-filters,.shelf-source-selects) :is(input:not([type=range]):not([type=checkbox]),select,textarea) { font-size: var(--ui-control-size); }
.header-icon-stats { display: block !important; }
.header-icon-tools { display: none !important; }
.shelf-shell > .eyebrow, .shelf-intro { display: none; }
.shelf-heading { margin: 0; gap: 16px; }
.shelf-heading .shelf-title { font-size: 1.7rem; }
.shelf-heading .shelf-view-tabs { margin: 0; flex-shrink: 0; }
.shelf-heading .shelf-actions { margin-left: auto; }
.shelf-heading-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.shelf-library-heading:has(.shelf-heading-hidden) { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); margin: 0; }
#shelf-resume { margin-top: 12px; }
#shelf-resume .shelf-resume-inline { display: grid; grid-template-columns: 44px minmax(0,1fr) auto 44px; align-items: center; gap: 12px; padding: 10px 14px; border-radius: 14px; min-height: 86px; }
#shelf-resume .shelf-inline-cover { display: block; width: 44px; height: 62px; overflow: hidden; padding: 0; border: 0; background: transparent; cursor: pointer; }
#shelf-resume .shelf-inline-cover .shelf-feature-cover { height: 100%; }
#shelf-resume .shelf-resume-inline h2 { margin: 0; font: 600 1.1rem/1.5 var(--font-serif); -webkit-line-clamp: 2; text-wrap: initial; }
#shelf-resume .shelf-resume-inline .shelf-feature-place { margin: 2px 0 0; font-size: var(--text-xs); line-height: 1.6; -webkit-line-clamp: 1; }
#shelf-resume .shelf-resume-inline .shelf-feature-button { min-height: 44px; margin: 0; padding: 8px 14px; gap: 12px; }
.shelf-resume-details { position: relative; }
.shelf-resume-details > summary, .shelf-quick-more > summary { display: flex; align-items: center; justify-content: center; gap: 6px; min-width: 44px; min-height: 44px; list-style: none; cursor: pointer; color: var(--text-soft); font: 500 var(--text-xs)/1.6 var(--font-ui); }
.shelf-resume-details > summary { font-size: 22px; }
.shelf-resume-details > summary::-webkit-details-marker, .shelf-quick-more > summary::-webkit-details-marker { display: none; }
.shelf-resume-details .shelf-more-menu p { padding: 10px 14px; font: 400 var(--text-xs)/1.7 var(--font-ui); color: var(--text-soft); }
.shelf-other-reading > summary { padding-block: 8px; min-height: 44px; cursor: pointer; color: var(--text-soft); font: 400 var(--text-xs)/1.6 var(--font-ui); }
.shelf-quick-more { position: relative; margin-left: auto; }
#shelf-shortcuts { overflow: visible; flex-wrap: nowrap; gap: 4px; padding-block: 4px; margin-top: 4px; }
#shelf-shortcuts > button { padding: 6px 10px; font-size: var(--text-xs); }
#shelf-shortcuts .shelf-more-menu { z-index: var(--z-dropdown); }
#shelf-shortcuts .shelf-more-menu button { width: 100%; justify-content: flex-start; text-align: left; }
.shelf-source-selects { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }
.shelf-source-selects label { display: grid; gap: 4px; flex: 1 1 180px; min-width: 0; color: var(--text-soft); font: 400 var(--text-xs)/1.6 var(--font-ui); }
.shelf-source-selects select { width: 100%; min-height: 44px; padding: 8px 12px; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--surface); color: var(--text); }
.shelf-filters { margin-top: 8px; }
.shelf-device-controls { margin: 0; align-self: end; }
.shelf-device-chip { margin: 4px 0 0; min-height: 32px; font-size: var(--text-xs); }
.shelf-shell .shelf-grid { margin-top: 12px; }
.shelf-journal.is-compact { min-height: 36px; margin-top: 2px; padding: 0; gap: 8px; }
.shelf-journal.is-compact .btn-link { min-height: 36px; padding: 4px 0; }
.series-info { margin-top: 12px; }
.series-info > summary { min-height: 44px; padding-block: 10px; cursor: pointer; color: var(--text-soft); font: 500 var(--text-xs)/1.7 var(--font-ui); }
.series-info[open] > :not(summary) { margin-top: 10px; }
.journal-filter-controls { display: flex; align-items: end; gap: 10px; margin-top: 12px; }
.journal-filter-controls label { flex: 1; min-width: 0; }
.journal-filter-controls button { min-height: 46px; margin-bottom: 16px; }
.journal-extra { padding: 10px 0; }
.journal-extra > summary { min-height: 44px; cursor: pointer; line-height: 1.7; }
.book-group-picker { padding: 12px; border: 1px solid var(--line); border-radius: 12px; min-width: 0; }
.book-group-chips, .book-group-suggestions { display: flex; flex-wrap: wrap; gap: 6px; }
.book-group-picker button { min-height: 44px; max-width: 100%; padding: 8px 12px; border: 1px solid var(--line-strong); border-radius: 12px; background: var(--surface); color: var(--text); font: 400 var(--text-xs)/1.6 var(--font-ui); overflow-wrap: anywhere; cursor: pointer; }
.book-group-chips button { background: var(--surface-2); }
.workbench-home-panel { min-height: 0; overflow-y: auto; padding: 0 24px 24px; overscroll-behavior: contain; touch-action: pan-y pinch-zoom; }
.workbench-home-panel label { display: grid; gap: 6px; font: 500 var(--text-sm)/1.7 var(--font-ui); }
.workbench-home-panel input { width: 100%; padding: 12px; border: 1px solid var(--line-strong); border-radius: 12px; background: var(--surface); color: var(--text); font: 400 var(--ui-control-size)/1.6 var(--font-ui); }
.workbench-home-panel h3 { font: 600 var(--text-sm)/1.7 var(--font-ui); margin: 18px 0 8px; }
.workbench-home-quick { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 8px; }
.workbench-home-action { display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; min-width: 0; min-height: 46px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--text); font: 500 var(--text-sm)/1.7 var(--font-ui); text-align: left; cursor: pointer; overflow-wrap: anywhere; }
.workbench-home-action span { color: var(--text-muted); }
#workbench-all > summary { min-height: 44px; padding-block: 12px; margin-top: 14px; cursor: pointer; font: 500 var(--text-sm)/1.7 var(--font-ui); }
#workbench-all section button { margin-top: 6px; }
.workbench-return { flex-shrink: 0; }
.shelf-view-tabs button:focus-visible, .shelf-quick-more summary:focus-visible, .shelf-resume-details summary:focus-visible, .workbench-home-action:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }
@media (max-width:600px) {
  .shelf-heading { gap: 6px; }
  .shelf-heading .shelf-title { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .shelf-heading .shelf-view-tabs { flex: 1; min-width: 0; gap: 2px; padding: 3px; }
  .shelf-heading .shelf-view-tabs button { min-width: 0; flex: 1; padding: 6px; font-size: var(--text-xs); }
  .shelf-heading .shelf-actions { gap: 4px; }
  .shelf-heading #btn-import-ebook { width: 44px; padding: 0; gap: 0; font-size: 0; justify-content: center; }
  .shelf-heading #btn-import-ebook svg { margin: 0; }
  #shelf-resume .shelf-resume-inline { grid-template-columns: 36px minmax(0,1fr) 44px 44px; gap: 6px; padding: 8px; }
  #shelf-resume .shelf-inline-cover { width: 36px; height: 50px; }
  #shelf-resume .shelf-resume-inline h2 { font-size: 1rem; }
  #shelf-resume .shelf-resume-inline .shelf-feature-button { width: 44px; padding: 8px; justify-content: center; }
  .shelf-resume-button-text { display: none; }
  .shelf-resume-details > summary { min-width: 44px; }
  #shelf-shortcuts > button { padding-inline: 7px; gap: 0; }
  #shelf-shortcuts > button > svg, #shelf-shortcuts > button > .shelf-shortcut-count { display: none; }
  .shelf-quick-more > summary { padding-inline: 5px; }
  .shelf-filters { gap: 8px; }
  #shelf-filter-toggle { min-width: 44px; padding: 10px; justify-content: center; }
  #shelf-filter-toggle span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .shelf-source-selects label { flex-basis: 120px; }
  .journal-dialog .journal-body { padding-inline: 16px; }
  .workbench-home-panel { padding-inline: 16px; }
  body[data-ui-size="large"] #shelf-shortcuts > button { padding-inline: 4px; }
}

/* One control row above the books: search, source, layout and a filter
   panel that stays closed until asked for, on every screen size. */
.shelf-filters { grid-template-columns: minmax(0, 1fr); gap: 10px; }
.shelf-search-row { align-items: stretch; }
.shelf-search-row .shelf-source-selects { flex: 0 1 auto; flex-wrap: nowrap; gap: 8px; margin: 0; }
.shelf-search-row .shelf-source-selects[hidden] { display: none; }
.shelf-search-row .shelf-source-selects label { flex: 0 1 200px; }
.shelf-select-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
#shelf-filter-toggle { display: flex; }
.shelf-advanced-filters { display: none; grid-template-columns: repeat(4, minmax(0, 1fr)); padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.shelf-advanced-filters.is-expanded { display: grid; }
.shelf-actions > .shelf-journal.is-compact { display: flex; min-height: 0; margin: 0; padding: 0; border: 0; background: none; }
.shelf-actions #shelf-journal-open { display: inline-flex; align-items: center; gap: 8px; }

/* Three books a row on wide screens, so a large shelf can be scanned. */
@media (min-width: 1100px) {
  .shelf-shell .shelf-grid:not(.is-covers) { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
  .shelf-grid:not(.is-covers) .shelf-card { min-height: 0; padding: 18px; gap: 16px; }
  .shelf-grid:not(.is-covers) .shelf-cover { width: 104px; flex-basis: 104px; }
  .shelf-grid:not(.is-covers) .shelf-card-title, .shelf-grid:not(.is-covers) .shelf-card-title.is-long { font-size: 1.2rem; -webkit-line-clamp: 2; line-height: 1.35; }
  .shelf-grid:not(.is-covers) .shelf-card-description { -webkit-line-clamp: 2; font-size: var(--text-xs); }
}

@media (max-width: 600px) {
  .shelf-search-row { flex-wrap: wrap; }
  .shelf-search-row input { flex: 1 1 0; min-width: 0; }
  .shelf-search-row .shelf-source-selects { order: 5; flex: 1 1 100%; }
  .shelf-search-row .shelf-source-selects label { flex: 1 1 0; }
  .shelf-advanced-filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .shelf-actions #shelf-journal-open { width: 44px; padding: 0; justify-content: center; }
  .shelf-actions #shelf-journal-open span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
}
.shelf-quick-more > summary svg { transition: transform 0.2s var(--steps-3); }
.shelf-quick-more[open] > summary svg { transform: rotate(180deg); }
.shelf-change-pick svg, .shelf-remove-reading svg { display: block; }
.shelf-card-action svg, .shelf-discovery-title svg { display: inline-block; vertical-align: -3px; margin-left: 2px; }
.shelf-more-menu .shelf-menu-action > span { flex: 1; }
@media (max-width: 360px) {
  .shelf-quick-more > summary { gap: 2px; padding-inline: 2px; }
  /* The journal is also in the "⋯" menu; on the narrowest phones the tabs need the room. */
  .shelf-actions > .shelf-journal.is-compact { display: none; }
}
.workbench-home-action svg { flex: none; color: var(--text-muted); }

/* Phones: the header icons carry a word, so "biểu đồ" reads as Thống kê and
   the sliders as Cài đặt. The reader keeps its compact icon-only header. */
.header-btn-label { display: none; }
@media (max-width: 600px) {
  body:not([data-view="reader"]) .header-actions .header-btn { flex-direction: column; gap: 2px; width: auto; min-width: 52px; height: 52px; padding: 4px 2px; }
  body:not([data-view="reader"]) .header-btn-label { display: block; font: 500 11px/1.2 var(--font-ui); white-space: nowrap; }
  body:not([data-view="reader"]) .header-actions .header-btn svg { width: 20px; height: 20px; }
}
