/* Phone reading layout: Books picker, one-row chapter heading, and the reader tools menu.
   The pieces are added by phone-reader.js; on wider screens they stay hidden. */

.lw-books-trigger,
.lw-heading-extra,
.lw-tools-extra {
  display: none;
}

/* The heading's shared button rule would otherwise show these two on wide screens. */
@media (min-width: 821px) {
  html .app-shell .reader-heading-navigation > .lw-heading-extra {
    display: none !important;
  }
}

/* ------------------------------------------------------------ Books picker */
.lw-books {
  position: fixed;
  inset: 0;
  z-index: 100000;
  display: flex;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
}

.lw-books[hidden] {
  display: none;
}

.lw-books-card {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 520px;
  height: 100%;
  color: var(--text, #1e2b24);
  background: var(--surface, #ffffff);
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.35);
}

.lw-books-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 12px 10px 16px;
  border-bottom: 1px solid var(--border, rgba(127, 127, 127, 0.3));
}

.lw-books-header h2 {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  overflow: hidden;
  font-size: 22px;
  font-weight: 800;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-strong, inherit);
}

.lw-books-back,
.lw-books-close,
.lw-books-footer button {
  min-height: 44px;
  padding: 0 14px;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  color: var(--text, inherit);
  background: var(--surface-raised, transparent);
  border: 1px solid var(--border, rgba(127, 127, 127, 0.3));
  border-radius: 10px;
  cursor: pointer;
}

.lw-books-back {
  display: grid;
  place-items: center;
  width: 44px;
  padding: 0;
  margin-left: -8px;
  border-color: transparent;
  background: transparent;
}

.lw-books-back[hidden] {
  display: none;
}

.lw-books-body {
  flex: 1 1 auto;
  min-height: 0;
  padding: 12px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.lw-books-continue {
  display: block;
  width: 100%;
  margin: 0 0 14px;
  padding: 12px 14px;
  font: inherit;
  text-align: left;
  color: var(--text, inherit);
  background: var(--surface-raised, transparent);
  border: 1px solid var(--accent-border, var(--border, rgba(127, 127, 127, 0.4)));
  border-left: 4px solid var(--accent, #285c45);
  border-radius: 10px;
  cursor: pointer;
}

.lw-books-continue strong {
  display: block;
  font-size: 16px;
  color: var(--text-strong, inherit);
}

.lw-books-continue small,
.lw-books-sub {
  font-size: 13px;
  color: var(--text-muted, inherit);
}

.lw-books-sub {
  margin: 0 4px 12px;
}

.lw-books-search-label {
  display: block;
  margin: 0 2px 6px;
  font-size: 14px;
  font-weight: 700;
}

#lw-books-search {
  width: 100%;
  min-height: 46px;
  margin-bottom: 12px;
  padding: 0 14px;
  box-sizing: border-box;
  font: inherit;
  font-size: 16px;
  color: var(--text, inherit);
  background: var(--surface-raised, #ffffff);
  border: 1px solid var(--border-strong, rgba(127, 127, 127, 0.5));
  border-radius: 10px;
}

.lw-books-source > summary {
  min-height: 44px;
  padding: 0 6px;
  display: flex;
  align-items: center;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  list-style: none;
  color: var(--text-strong, inherit);
}

.lw-books-source > summary::-webkit-details-marker {
  display: none;
}

.lw-books-source > summary::before {
  content: "▸";
  width: 18px;
  flex: 0 0 auto;
  color: var(--text-muted, inherit);
}

.lw-books-source[open] > summary::before {
  content: "▾";
}

.lw-books-book {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 46px;
  padding: 4px 12px;
  font: inherit;
  font-size: 16px;
  text-align: left;
  color: var(--text, inherit);
  background: transparent;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

.lw-books-book:active,
.lw-books-book:hover {
  background: var(--surface-hover, rgba(127, 127, 127, 0.14));
}

.lw-books-book small {
  display: block;
  font-size: 12px;
  color: var(--text-muted, inherit);
}

.lw-books-book em {
  flex: 0 0 auto;
  font-size: 12px;
  font-style: normal;
  color: var(--text-muted, inherit);
}

.lw-books-source-only {
  font-weight: 800;
  font-size: 15px;
}

.lw-books-empty {
  margin: 12px 6px;
  font-size: 15px;
  color: var(--text-muted, inherit);
}

.lw-books-chapters {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(52px, 1fr));
  gap: 8px;
}

.lw-books-chapters.is-named {
  grid-template-columns: 1fr;
}

.lw-books-chapters button {
  min-height: 48px;
  padding: 4px 8px;
  font: inherit;
  font-size: 16px;
  font-weight: 600;
  color: var(--text, inherit);
  background: var(--surface-raised, transparent);
  border: 1px solid var(--border, rgba(127, 127, 127, 0.3));
  border-radius: 10px;
  cursor: pointer;
}

.lw-books-chapters.is-named button {
  text-align: left;
  padding: 4px 14px;
}

.lw-books-chapters button.is-current {
  color: var(--surface, #ffffff);
  background: var(--accent, #285c45);
  border-color: var(--accent, #285c45);
}

.lw-books-footer {
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border, rgba(127, 127, 127, 0.3));
}

.lw-books-footer button {
  width: 100%;
}

@media (max-width: 820px) {
  /* ---------------------------------------------------------------- top bar */
  html.lw-phone-chrome .topbar .quick-search {
    display: none !important;
  }

  html.lw-phone-chrome .topbar .lw-books-trigger {
    display: flex;
    flex: 1 1 auto;
    align-items: center;
    gap: 8px;
    min-width: 0;
    height: 38px;
    padding: 0 12px;
    font: inherit;
    font-size: 16px;
    font-weight: 800;
    color: var(--nav-active-text, #ffffff);
    background: var(--nav-control, rgba(255, 255, 255, 0.1));
    border: 1px solid var(--nav-border, transparent);
    border-radius: 8px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  html.lw-phone-chrome .topbar .lw-books-trigger svg {
    flex: 0 0 auto;
  }

  /* ------------------------------------------------------- one-row heading */
  html.lw-phone-chrome .app-shell:not(.presentation-mode) .passage-selectors {
    display: none !important;
  }

  html.lw-phone-chrome {
    --lw-sticky-heading-top: 0px !important;
  }

  html.lw-phone-chrome .app-shell:not(.presentation-mode) .chapter-heading {
    top: 0 !important;
    padding: 4px 4px 4px 12px !important;
  }

  html.lw-phone-chrome .app-shell:not(.presentation-mode) .chapter-heading .reader-heading-copy {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) auto !important;
    grid-template-rows: auto auto !important;
    align-items: center !important;
    gap: 0 4px !important;
  }

  html.lw-phone-chrome .app-shell:not(.presentation-mode) .chapter-heading h1 {
    grid-column: 1 !important;
    grid-row: 1 !important;
    font-size: 17px !important;
    font-weight: 800 !important;
    line-height: 1.2 !important;
    text-align: left !important;
  }

  html.lw-phone-chrome .app-shell:not(.presentation-mode) .chapter-heading .reader-heading-identity {
    display: block !important;
    grid-column: 1 !important;
    grid-row: 2 !important;
    overflow: hidden !important;
    font-size: 11px !important;
    line-height: 1.3 !important;
    letter-spacing: 0 !important;
    text-transform: none !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
    color: var(--text-muted, inherit) !important;
    text-align: left !important;
    cursor: pointer !important;
  }

  html.lw-phone-chrome .app-shell:not(.presentation-mode) .chapter-heading .reader-heading-footer {
    grid-column: 2 !important;
    grid-row: 1 / 3 !important;
  }

  html.lw-phone-chrome .app-shell:not(.presentation-mode) .reader-heading-navigation {
    gap: 0 !important;
  }

  /* Previous / next become plain arrows; bookmarks and find move into the tools menu. */
  html.lw-phone-chrome .app-shell:not(.presentation-mode) .reader-heading-navigation > button,
  html.lw-phone-chrome .app-shell:not(.presentation-mode) .reader-heading-navigation > .lw-heading-extra {
    display: inline-flex !important;
    width: 40px !important;
    min-width: 40px !important;
    height: 40px !important;
    min-height: 40px !important;
    padding: 0 !important;
    border-radius: 999px !important;
  }

  html.lw-phone-chrome .app-shell:not(.presentation-mode) .reader-heading-navigation > button > span {
    display: none !important;
  }

  html.lw-phone-chrome .app-shell:not(.presentation-mode) .reader-heading-navigation > :is(#lw-bookmarks-open, #lw-st-find-open, .chapter-contents-trigger) {
    display: none !important;
  }

  html.lw-phone-chrome.lw-tools-open #lw-tools-open {
    background: var(--surface-active, rgba(127, 127, 127, 0.25)) !important;
  }

  /* ------------------------------------------------------------ tools menu */
  html.lw-phone-chrome .app-shell:not(.presentation-mode) .reader-tools {
    display: none !important;
  }

  html.lw-phone-chrome.lw-tools-open .app-shell:not(.presentation-mode) .reader-tools {
    position: fixed !important;
    top: var(--lw-tools-top, 100px) !important;
    right: 8px !important;
    left: 8px !important;
    z-index: 44 !important;
    display: flex !important;
    flex-wrap: wrap !important;
    align-items: center !important;
    gap: 4px !important;
    width: auto !important;
    max-width: none !important;
    max-height: calc(100vh - var(--lw-tools-top, 100px) - 80px) !important;
    padding: 10px !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    background: var(--surface-raised, #ffffff) !important;
    border: 1px solid var(--border-strong, rgba(127, 127, 127, 0.4)) !important;
    border-radius: 12px !important;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35) !important;
  }

  html.lw-phone-chrome .app-shell:not(.presentation-mode) .reader-tools > button {
    flex: 0 0 auto !important;
    align-items: center !important;
    justify-content: flex-start !important;
    gap: 8px !important;
    width: auto !important;
    min-width: 0 !important;
    height: 42px !important;
    min-height: 42px !important;
    padding: 0 12px !important;
    font-size: 14px !important;
    white-space: nowrap !important;
    color: var(--text, inherit) !important;
    background: transparent !important;
    border: 1px solid transparent !important;
    border-radius: 8px !important;
  }

  html.lw-phone-chrome .app-shell:not(.presentation-mode) .reader-tools > button:is(.active, [aria-pressed="true"]) {
    background: var(--accent-soft, rgba(127, 127, 127, 0.2)) !important;
    border-color: var(--accent-border, transparent) !important;
  }

  /* Icon-only tools get their name spelled out. */
  html.lw-phone-chrome .app-shell:not(.presentation-mode) .reader-tools > button.icon-button[title]::after {
    content: attr(title);
  }

  html.lw-phone-chrome .reader-tools > button.icon-button .sr-only {
    display: none !important;
  }

  html.lw-phone-chrome .reader-tools .lw-tools-extra {
    display: block;
    flex: 0 0 100%;
    margin-bottom: 6px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border, rgba(127, 127, 127, 0.3));
  }

  /* Nothing else to separate from when every optional tool is off. */
  html.lw-phone-chrome .reader-tools .lw-tools-extra:last-child {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: 0;
  }

  .lw-tools-font {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: var(--text, inherit);
  }

  .lw-tools-font span {
    margin-right: auto;
    font-weight: 700;
  }

  .lw-tools-font output {
    min-width: 48px;
    text-align: center;
    color: var(--text-muted, inherit);
  }

  .lw-tools-links {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 8px;
  }

  /* The older phone rules turn every button in the tool bar into a bare 36px icon;
     these put the size, label and colour back for the buttons in this menu. */
  html.lw-phone-chrome .app-shell .reader-tools .lw-tools-extra button {
    flex: 0 0 auto !important;
    font: inherit !important;
    font-size: 14px !important;
    color: var(--text, inherit) !important;
    cursor: pointer;
  }

  html.lw-phone-chrome .app-shell .reader-tools .lw-tools-font button {
    width: 44px !important;
    min-width: 44px !important;
    height: 40px !important;
    font-weight: 700 !important;
    background: var(--surface, transparent) !important;
    border: 1px solid var(--border-strong, rgba(127, 127, 127, 0.4)) !important;
    border-radius: 8px !important;
  }

  html.lw-phone-chrome .app-shell .reader-tools .lw-tools-links button {
    justify-content: flex-start !important;
    gap: 8px !important;
    width: auto !important;
    min-width: 0 !important;
    height: 42px !important;
    padding: 0 12px !important;
    background: transparent !important;
    border: 0 !important;
    border-radius: 8px !important;
  }

  html.lw-phone-chrome .app-shell .reader-tools .lw-tools-extra button svg,
  html.lw-phone-chrome .app-shell .reader-tools > button svg {
    flex: 0 0 auto !important;
    margin: 0 !important;
  }

  /* ------------------------------------------- study panels on a phone */
  /* The panels already switch with tabs; this trims the space above them. */
  html.lw-phone-chrome .comparison-page .comparison-toolbar {
    display: block !important;
    padding: 4px 8px !important;
    min-height: 0 !important;
  }

  html.lw-phone-chrome .comparison-page .comparison-toolbar > div:first-child {
    display: none !important;
  }

  html.lw-phone-chrome .comparison-page .comparison-toolbar-actions {
    display: flex !important;
    flex-wrap: nowrap !important;
    gap: 6px !important;
    width: 100% !important;
    overflow-x: auto !important;
    scrollbar-width: none !important;
  }

  html.lw-phone-chrome .comparison-page .comparison-toolbar-actions::-webkit-scrollbar {
    display: none !important;
  }

  html.lw-phone-chrome .comparison-page .comparison-toolbar-actions > button {
    flex: 0 0 auto !important;
    height: 36px !important;
    min-height: 36px !important;
    white-space: nowrap !important;
  }

  html.lw-phone-chrome .comparison-page .comparison-mobile-tabs {
    gap: 6px !important;
    padding: 6px 8px !important;
    overflow-x: auto !important;
    scrollbar-width: none !important;
  }

  html.lw-phone-chrome .comparison-page .comparison-mobile-tabs > button {
    flex: 1 0 auto !important;
    justify-content: center !important;
    min-height: 40px !important;
    padding: 0 14px !important;
    font-size: 14px !important;
    border-radius: 999px !important;
  }
}
