/* Small-screen overrides load last; desktop layout and reader state are shared. */
.library-filter-options {
  display: contents;
}
.library-filter-options > summary {
  display: none;
}
.filter-options {
  display: contents;
}
.reader-more,
.mobile-comparison-tabs {
  display: none;
}
@media (max-width: 700px), (max-width: 950px) and (max-height: 500px) {
  html {
    scroll-padding-top: 10px;
  }
  body {
    overflow-x: clip;
  }
  .compact .topbar {
    height: 54px;
    padding: 0 max(12px, env(safe-area-inset-left));
    gap: 8px;
  }
  .identity {
    font-size: 12px;
    letter-spacing: 1.2px;
    gap: 8px;
  }
  .identity svg {
    width: 28px;
    height: 28px;
  }
  .top-actions {
    gap: 10px;
  }
  .top-actions .private {
    display: none;
  }
  .top-actions .theme-toggle {
    font-size: 0;
    width: 36px;
    min-height: 40px;
    padding: 0;
  }
  .theme-toggle::before {
    content: '◐';
    font-size: 23px;
  }
  .top-actions .icon-btn {
    width: 32px;
    height: 32px;
  }
  .compact .tabs {
    padding: 0 12px;
    gap: 20px;
  }
  .compact .tabs > .tab {
    height: 44px;
    font-size: 12px;
  }
  .compact .tabs .tab-tools {
    padding: 0 0 5px;
    gap: 8px;
  }
  .nav-menu > summary {
    min-height: 40px;
    font-size: 12px;
  }
  .nav-menu .workspace-links {
    left: 8px;
    right: 8px;
    max-height: calc(100dvh - 155px);
  }
  .compact .sidebar {
    min-height: 44px;
    padding: 2px 8px;
    border-bottom: 1px solid var(--line);
  }
  .compact .side {
    min-height: 40px;
    padding: 8px 10px;
    font-size: 11px;
  }
  .compact main {
    padding: 12px max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
  }
  .compact .hero {
    padding: 0 0 12px;
  }
  .compact .hero h1 {
    font-size: 25px;
    line-height: 1.15;
    margin-bottom: 5px;
  }
  .compact .hero .eyebrow,
  .compact .hero .library-help {
    display: none;
  }
  .compact .hero .intro {
    font-size: 12px;
    line-height: 1.5;
  }
  .compact .stats {
    display: none;
  }
  .compact .section-heading {
    margin-bottom: 10px;
    align-items: center;
  }
  .compact .section-heading h2 {
    font-size: 20px;
  }
  .section-heading p {
    font-size: 11px;
    line-height: 1.45;
  }
  .shelf-display {
    margin-left: auto;
    gap: 6px;
  }
  #pdf-library-compare {
    display: none;
  }
  #continue-reading {
    max-width: 155px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-height: 36px;
  }
  .view-toggle button {
    min-width: 36px;
    min-height: 34px;
    padding: 3px 8px;
  }
  .shelf-instruction {
    font-size: 11px;
    line-height: 1.5;
    margin-bottom: 10px;
  }
  .compact .filters {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    align-items: start;
    margin-bottom: 12px;
  }
  .compact .filters .search {
    min-width: 0;
    width: auto;
    height: 44px;
    order: 0;
    flex-basis: auto;
    grid-column: 1;
  }
  .search input {
    font-size: 16px;
    min-width: 0;
  }
  .search input::placeholder {
    font-size: 12px;
  }
  .library-filter-options {
    display: block;
    min-width: 0;
    grid-column: 2;
  }
  .library-filter-options > summary {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    border: 1px solid var(--line);
    border-radius: 3px;
    padding: 0 12px;
    cursor: pointer;
    font-size: 12px;
    list-style: none;
  }
  .library-filter-options > summary::-webkit-details-marker {
    display: none;
  }
  .library-filter-options[open] {
    grid-column: 1/-1;
  }
  .library-filter-options[open] > summary {
    justify-content: space-between;
    background: var(--lime);
  }
  .filter-options {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-top: 8px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 3px;
    background: var(--white);
  }
  .compact .filter-options select {
    min-width: 0;
    max-width: 100%;
    width: 100%;
    height: 44px;
    font-size: 12px;
    padding-left: 9px;
  }
  .filter-options select:last-child {
    grid-column: 1/-1;
  }
  .compact .shelf-grid:not(.list) {
    gap: 18px 12px;
  }
  .compact .card-title {
    font-size: 13px;
  }
  .compact .card-subtitle {
    font-size: 11px;
    line-height: 1.5;
  }
  .compact .card-meta {
    font-size: 9px;
    line-height: 1.5;
  }
  .card-actions button {
    min-width: 32px;
    min-height: 40px;
  }
  .compact button.availability,
  .web-card-action {
    font-size: 11px;
    min-height: 40px;
  }
  .compact .card-bottom {
    gap: 2px;
  }
  .compact .edition-count {
    font-size: 11px;
    min-height: 28px;
  }
  .web-cover-label,
  .web-cover-date {
    font-size: 10px;
  }
  .compact .shelf-grid.list .catalog-card {
    grid-template-columns: 48px minmax(0, 1fr);
    column-gap: 12px;
  }
  .list .card-bottom {
    grid-column: 2;
    grid-row: auto;
    justify-content: space-between;
    padding-top: 5px;
    gap: 8px;
  }
  .list .cover-button {
    grid-row: 1/6;
  }
  .list .card-meta {
    grid-column: 2;
  }
  .list .web-card-state {
    grid-column: 2;
  }
  dialog {
    width: calc(100vw - 16px);
    max-width: calc(100vw - 16px);
    max-height: calc(100dvh - 16px);
    padding: 24px 16px;
  }
  .detail-dialog {
    padding: 28px 16px 16px;
  }
  .detail-layout > div:first-child {
    display: none;
  }
  .detail-content h2 {
    font-size: 27px;
  }
  .detail-buttons .primary,
  .detail-buttons .secondary {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }
  .edition-picker select {
    font-size: 16px;
    min-height: 44px;
  }
  .metadata {
    gap: 15px 12px;
  }
  .metadata dd {
    font-size: 12px;
  }
  input,
  textarea,
  select,
  form input,
  form select,
  form textarea {
    font-size: 16px;
  }
  form input,
  form select {
    min-height: 44px;
  }
  .notebook-filters input,
  .notebook-filters select {
    font-size: 16px;
    min-width: 0;
    max-width: 100%;
    min-height: 44px;
  }
  .notebook-filters input {
    flex-basis: 100%;
  }
  .notebook-filters select {
    flex: 1 1 140px;
  }
  .reader-dialog,
  .pdf-compare-dialog {
    width: 100vw;
    height: 100dvh;
    max-width: 100vw;
    max-height: 100dvh;
    margin: 0;
    border: 0;
    border-radius: 0;
    padding: 0;
  }
  .reader-pane .reader-header {
    min-height: 48px;
    padding: 6px max(8px, env(safe-area-inset-right)) 6px max(10px, env(safe-area-inset-left));
    gap: 7px;
  }
  .reader-pane .reader-header h2 {
    font-size: 12px;
    line-height: 1.4;
    white-space: normal;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }
  .reader-pane .reader-header [data-close] {
    width: 40px;
    height: 40px;
    font-size: 27px;
    flex-shrink: 0;
  }
  .reader-pane .reader-controls {
    position: relative;
    padding: 5px 8px;
    gap: 5px;
    align-items: center;
  }
  .reader-mode-switch {
    flex-basis: calc(100% - 143px);
    margin: 0;
    order: 0;
  }
  .reader-mode-switch button {
    flex: 0 1 74px;
  }
  .reader-pane .reader-controls button,
  .reader-pane .reader-controls input,
  .reader-pane .reader-controls select {
    min-height: 36px;
    font-size: 12px;
    padding: 6px 8px;
  }
  .reader-pane [data-pdf='nav-toggle'] {
    order: 1;
    min-width: 82px;
  }
  .reader-more {
    display: block;
    order: 2;
    position: static;
    margin: 0;
  }
  .reader-more > summary {
    list-style: none;
    cursor: pointer;
    min-height: 36px;
    display: flex;
    align-items: center;
    padding: 6px 9px;
    border: 1px solid var(--line);
    border-radius: 4px;
    background: var(--white);
    font-size: 12px;
  }
  .reader-more > summary::-webkit-details-marker {
    display: none;
  }
  .reader-more[open] > summary {
    background: var(--lime);
  }
  .reader-pane [data-pdf='prev'] {
    order: 3;
    min-width: 40px;
  }
  .reader-pane .page-control {
    order: 4;
    flex: 1;
    justify-content: center;
    gap: 5px;
  }
  .reader-pane .page-control input {
    font-size: 16px;
    width: 56px;
  }
  .reader-pane [data-pdf='next'] {
    order: 5;
    min-width: 40px;
  }
  .reader-pane [data-pdf='zoom'] {
    order: 6;
    width: 100px;
    max-width: 100px;
  }
  .reader-pane [data-pdf='position'] {
    order: 7;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 10px;
    line-height: 14px;
    min-height: 14px;
    flex-basis: 100%;
  }
  .reader-more-panel {
    position: absolute;
    top: 100%;
    left: 5px;
    right: 5px;
    z-index: 14;
    background: var(--paper);
    border: 1px solid var(--line);
    box-shadow: 0 7px 24px #0005;
    border-radius: 4px;
    padding: 12px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    max-height: min(390px, 55dvh);
    overflow: auto;
  }
  .reader-more-panel .reader-edition-label {
    flex-basis: 100%;
    width: 100%;
  }
  .reader-pane .reader-more-panel .reader-edition-label select {
    font-size: 16px;
    min-height: 44px;
    max-width: 100%;
    width: 100%;
  }
  .reader-more-panel button,
  .reader-more-panel select,
  .reader-more-panel a {
    min-height: 40px !important;
    font-size: 12px !important;
  }
  .reader-more-panel a {
    display: inline-flex;
    align-items: center;
    font-size: 12px;
    border: 1px solid var(--line);
    padding: 8px;
    border-radius: 3px;
  }
  .reader-more-panel .reader-download {
    display: inline-flex;
  }
  .reader-pane .reader-workspace {
    min-height: 0;
  }
  .reader-pane .reader-stage {
    padding: 8px;
    touch-action: auto;
  }
  .reader-pane.catalog-mode.fit-page .reader-stage {
    touch-action: pan-y pinch-zoom;
  }
  .reader-pane .reader-navigation,
  .reader-pane .reader-notes {
    width: 100%;
    max-width: none;
    padding: 12px;
    box-shadow: none;
  }
  .reader-panel-heading button,
  .reader-notes-head > button {
    min-width: 40px;
    min-height: 40px;
  }
  .reader-navigation-tabs button {
    min-height: 40px;
    font-size: 12px;
  }
  .reader-pane .reader-composer input,
  .reader-pane .reader-composer select,
  .reader-pane .reader-composer textarea {
    font-size: 16px;
  }
  .reader-composer textarea {
    min-height: 120px;
  }
  .reader-composer .observation-actions {
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }
  .mobile-comparison-tabs {
    display: flex;
    gap: 8px;
    padding: 5px 10px;
    background: var(--reader-toolbar);
  }
  .mobile-comparison-tabs button {
    flex: 1;
    min-height: 36px;
    border: 1px solid var(--line);
    border-radius: 3px;
  }
  .mobile-comparison-tabs button[aria-pressed='true'] {
    background: var(--lime);
  }
  .comparison-panes {
    display: block;
    position: relative;
  }
  .comparison-panes .compare-reader-pane {
    height: 100%;
    border: 0;
  }
  .pdf-compare-dialog:not([data-mobile-side='right']) #pdf-compare-right,
  .pdf-compare-dialog[data-mobile-side='right'] #pdf-compare-left {
    display: none;
  }
  .compare-reader-pane .reader-controls {
    max-height: none;
    overflow: visible;
  }
  .comparison-header {
    padding: 8px 10px;
  }
  .comparison-header h2 {
    font-size: 16px;
  }
  .comparison-header button {
    min-width: 40px;
    min-height: 36px;
  }
  .website-header {
    padding-top: max(10px, env(safe-area-inset-top));
  }
  .website-header h2 {
    font-size: 14px;
  }
  .website-header .secondary {
    min-height: 40px;
  }
  .website-toolbar button {
    min-height: 40px;
  }
  .website-toolbar a {
    min-height: 36px;
    display: inline-flex;
    align-items: center;
  }
  .website-context {
    font-size: 11px;
  }
  .website-stage {
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    touch-action: auto;
  }
}
@media (max-width: 370px) {
  .compact .tabs {
    gap: 15px;
  }
  .compact .tabs > .tab {
    font-size: 11px;
  }
  .compact .card-bottom {
    align-items: flex-start;
    flex-wrap: wrap;
  }
  .card-actions {
    margin-left: auto;
  }
  .reader-pane .page-control {
    gap: 3px;
  }
  .reader-pane .page-control input {
    width: 46px;
  }
  .reader-pane [data-pdf='zoom'] {
    width: 91px;
    max-width: 91px;
  }
}
@media (max-height: 500px) and (max-width: 950px) {
  .reader-pane .reader-header {
    min-height: 36px;
    padding-block: 3px;
  }
  .reader-pane .reader-controls {
    gap: 4px;
    padding-block: 3px;
  }
  .reader-pane .reader-header h2 {
    font-size: 11px;
  }
  .reader-pane [data-pdf='position'] {
    display: none;
  }
}

@media (max-width: 700px), (max-width: 950px) and (max-height: 500px) {
  .reader-pane.catalog-mode:not(.fit-page) .reader-stage {
    touch-action: auto;
  }
  .reader-pane [data-pdf='retry'] {
    order: 8;
    min-height: 36px;
    background: var(--lime);
  }
}
@media (max-width: 700px), (max-width: 950px) and (max-height: 500px) {
  .reader-pane .reader-mode-switch {
    flex: 1 0 calc(100% - 158px);
    margin-right: 0;
  }
  .reader-pane .reader-stage {
    scrollbar-gutter: auto;
  }
  .reader-pane .reader-controls [data-pdf='zoom'] {
    font-size: 16px;
  }
}
