/* Reading utilities share the reader's theme and remain available offline. */
.shelf-update-check { margin-bottom: 24px; }
.chapter-update-badge { display: inline-flex; align-self: start; padding: 5px 10px; border-radius: 999px; background: var(--ink); color: var(--on-ink); font-size: var(--text-xs); font-weight: 600; }
.series-updates { margin-top: 18px; padding: 14px 18px; border: 1px solid var(--line-strong); border-radius: 12px; display: flex; flex-wrap: wrap; align-items: center; gap: 12px; font-size: var(--text-base); }
/* Chapter tools: one quiet row of icon links under the title, so the text
   starts close to the top of the screen. */
.chapter-tools { display: flex; justify-content: center; flex-wrap: wrap; gap: 4px; margin-top: 14px; }
.chapter-tools > button, .chapter-tools-more > summary { display: inline-flex; align-items: center; gap: 7px; min-height: 40px; padding: 8px 12px; border: 1px solid transparent; border-radius: 999px; color: var(--text-muted); background: transparent; font: 500 var(--text-xs)/1.4 var(--font-ui); cursor: pointer; transition: background-color 0.2s var(--steps-3), color 0.2s var(--steps-3); }
.chapter-tools > button:hover, .chapter-tools-more > summary:hover { background: var(--surface-2); color: var(--text); }
.chapter-tools-more { position: relative; text-align: left; }
.chapter-tools-more > summary { list-style: none; }
.chapter-tools-more > summary::-webkit-details-marker { display: none; }
.chapter-tools-more[open] > summary { border-color: var(--line); background: var(--surface-2); color: var(--text); }
.chapter-tools-menu { position: absolute; z-index: var(--z-dropdown); right: 0; top: calc(100% + 8px); width: 230px; max-width: calc(100vw - 36px); display: grid; gap: 4px; padding: 6px; border: 1px solid var(--line-strong); border-radius: 14px; background: var(--raised); box-shadow: var(--shadow-pop); }
.chapter-tools-menu button { min-height: 44px; padding: 10px 12px; text-align: left; border: 0; border-radius: 8px; color: var(--text); background: transparent; font: 500 var(--text-sm)/1.5 var(--font-ui); }
.chapter-tools-menu button:hover { background: var(--surface-2); }
.chapter-tools-more:not([open]) > .chapter-tools-menu { display: none; }
.chapter-tools :is(button, summary):focus-visible, .character-guide > summary:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }
.reader-content .character-link { padding: 0; border: 0; border-bottom: 1px dotted currentColor; background: transparent; color: inherit; font: inherit; line-height: inherit; text-align: inherit; vertical-align: baseline; }
.character-link:hover { background: var(--surface-2); }
.illustration-open { position: relative; overflow: hidden; }
.illustration-reveal { display: none; }
body[data-spoilers="hidden"] .illustration-open:not(.is-revealed) .illustration-img { filter: blur(28px) brightness(0.65) !important; user-select: none; }
body[data-spoilers="hidden"] .illustration-open:not(.is-revealed) .illustration-reveal { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); display: block; width: max-content; max-width: calc(100% - 28px); padding: 12px 18px; border-radius: 999px; color: var(--on-ink); background: var(--ink); font: var(--text-base) var(--font-ui); }
#spoiler-switch button[aria-pressed="true"] { background: var(--ink); color: var(--on-ink); }
.tools-dialog { width: min(760px, calc(100% - 32px)); max-height: min(88dvh, 900px); margin: auto; padding: 0; border: 1px solid var(--line-strong); border-radius: 22px; background: var(--surface); color: var(--text); box-shadow: var(--shadow-pop); overflow: hidden; }
.tools-dialog::backdrop { background: rgba(0, 0, 0, 0.48); }
.tools-dialog[open] { display: flex; flex-direction: column; }
.tools-heading { display: flex; align-items: start; justify-content: space-between; gap: 16px; padding: 24px 28px 18px; }
.tools-heading h2 { margin-top: 7px; font-family: var(--font-serif); font-size: 26px; }
.tools-heading .eyebrow { max-width: 560px; font-size: var(--text-2xs); line-height: 1.7; }
.tools-close { width: 44px; height: 44px; flex-shrink: 0; border: 1px solid var(--line); border-radius: 50%; background: transparent; color: var(--text); font-size: 26px; line-height: 1; }
.tools-tabs { display: flex; flex-shrink: 0; gap: 6px; padding: 0 24px 14px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tools-tabs button { min-height: 44px; white-space: nowrap; padding: 8px 14px; border: 0; border-radius: 999px; background: transparent; color: var(--text-soft); font: 500 var(--text-sm) var(--font-ui); }
.tools-tabs button[aria-selected="true"] { background: var(--ink); color: var(--on-ink); }
.tools-feedback { margin: 14px 28px 0; padding: 10px 14px; border-radius: 9px; background: var(--surface-2); color: var(--text); font: var(--text-sm)/1.6 var(--font-ui); }
.tools-panel { padding: 24px 28px 28px; overflow-y: auto; min-height: 240px; overscroll-behavior: contain; }
.tools-hint { color: var(--text-muted); font: var(--text-sm)/1.8 var(--font-ui); margin-bottom: 16px; }
.tools-empty { margin: 16px 0; color: var(--text-muted); font-size: var(--text-base); line-height: 1.8; }
.tool-card { border: 1px solid var(--line); border-radius: 14px; background: var(--paper); padding: 16px 18px; margin-bottom: 12px; font-size: var(--text-base); line-height: 1.8; }
.tool-card p { white-space: pre-wrap; }
.tool-card .tools-hint { margin-top: 8px; margin-bottom: 0; }
.tool-card h3 { font-size: 16px; font-weight: 600; }
.character-controls { margin-bottom: 14px; }
.character-overview { display: flex; align-items: start; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.character-count { padding-top: 9px; color: var(--text-muted); font: var(--text-xs)/1.6 var(--font-ui); }
.character-count strong { color: var(--text-soft); font-weight: 600; }
.character-guide { flex: 0 0 auto; max-width: 58%; }
.character-guide > summary { min-height: 36px; padding: 8px 10px; border-radius: 9px; color: var(--text-muted); cursor: pointer; font: 500 var(--text-sm)/1.5 var(--font-ui); text-align: right; }
.character-guide > summary:hover { color: var(--text); background: var(--surface-2); }
.character-guide[open] { flex: 1 1 0; }
.character-guide .tools-hint { margin: 10px 0 0; font-size: var(--text-xs); }
.tools-panel .character-search { margin-bottom: 10px; }
.character-search-label { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.tools-panel .character-search input { min-height: 44px; padding: 10px 12px; }
.tools-panel .character-show-all { flex-direction: row; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; margin-bottom: 0; font-weight: 400; color: var(--text-soft); }
.character-switch-title { display: block; font-size: var(--text-xs); }
.character-show-all small { display: block; color: var(--text-muted); font: var(--text-2xs)/1.5 var(--font-ui); }
.tools-panel .character-show-all { padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius-md); }
.character-switch-title { color: var(--text); font-weight: 600; }
.tool-card .tool-card-heading { align-items: start; }
.tool-card-heading h3 { min-width: 0; overflow-wrap: anywhere; }
.tool-action { flex: 0 0 auto; min-height: 44px; padding: 8px 14px; font: 500 var(--text-xs)/1.5 var(--font-ui); }
.tool-card-heading, .tool-rule { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.tool-rule > span { min-width: 0; overflow-wrap: anywhere; }
.tool-rule strong { flex-shrink: 0; }
.tools-editor { margin-top: 20px; padding: 18px; border: 1px solid var(--line); border-radius: 14px; background: var(--raised); }
.tools-editor summary { cursor: pointer; font-size: var(--text-base); font-weight: 600; }
.tools-editor[open] form { margin-top: 18px; }
.tools-panel label { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; font: 500 var(--text-sm)/1.6 var(--font-ui); }
.tools-panel input, .tools-panel textarea, .tools-panel select { width: 100%; min-width: 0; padding: 11px 12px; border: 1px solid var(--line-strong); border-radius: 9px; background: var(--paper); color: var(--text); font: var(--text-base)/1.7 var(--font-ui); }
.tools-panel textarea { resize: vertical; }
.tools-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.tools-actions .btn-primary, .tools-actions .btn-secondary, .tools-editor .btn-primary { min-height: 44px; padding: 10px 18px; font-size: var(--text-sm); }
.pronunciation-list { margin-top: 20px; }
.pronunciation-preview { min-height: 44px; margin-top: 8px; padding: 12px 16px; background: var(--surface-2); border-radius: 10px; font-size: var(--text-md); line-height: 1.8; }
.tools-stat-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin: 22px 0 28px; }
.tools-stat-grid > div { padding: 18px 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--paper); display: flex; flex-direction: column; gap: 8px; }
.tools-stat-grid strong { font: 600 22px/1.4 var(--font-serif); }
.tools-stat-grid span { color: var(--text-muted); font-size: var(--text-xs); line-height: 1.6; }
.tools-subtitle { margin: 24px 0 14px; font: 600 16px var(--font-ui); }
.reading-chart { height: 200px; display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 14px; margin-top: 22px; }
.reading-day { display: flex; flex-direction: column; align-items: center; gap: 8px; color: var(--text-muted); font: var(--text-xs) var(--font-ui); }
.reading-bar { width: min(100%, 36px); height: 142px; display: flex; flex-direction: column-reverse; border-radius: 5px; overflow: hidden; background: var(--surface-2); }
.reading-bar i { background: var(--ink); }
.reading-bar b { background: var(--text-muted); opacity: 0.45; }
.chart-legend { display: flex; justify-content: center; gap: 20px; color: var(--text-soft); font-size: var(--text-xs); }
.chart-legend span + span { opacity: 0.5; }
.goal-summary { display: flex; flex-direction: column; gap: 12px; padding: 22px; border: 1px solid var(--line-strong); border-radius: 14px; background: var(--paper); }
.goal-summary progress { width: 100%; height: 10px; accent-color: var(--ink); }
.goal-summary p { color: var(--text-soft); }
.goal-summary .tool-action { align-self: start; }
.quote-preview { display: block; width: min(100%, 330px); max-height: 440px; object-fit: contain; object-position: top; margin: 24px auto; border-radius: 8px; }
.saved-quotes blockquote { margin: 0; font: 16px/1.9 var(--font-serif); white-space: pre-wrap; }
/* Selection bar: a quiet row of icon + word buttons on the raised surface.
   Docked at the bottom on touch screens; .is-floating (mouse) sits by the
   selection with a small pointer towards it. */
.selection-tools { position: fixed; z-index: var(--z-popover); left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%); display: flex; align-items: stretch; gap: 2px; width: max-content; max-width: calc(100% - 24px); padding: 4px; border: 1px solid var(--line-strong); border-radius: 14px; background: var(--raised); color: var(--text); box-shadow: var(--shadow-pop); font: 500 var(--text-sm) var(--font-ui); }
.selection-tools button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 38px; padding: 6px 12px; border: 0; border-radius: 10px; background: transparent; color: inherit; font: inherit; white-space: nowrap; cursor: pointer; }
.selection-tools button svg { flex-shrink: 0; color: var(--text-muted); }
.selection-tools button:hover, .selection-tools button:focus-visible { background: var(--surface-2); }
.selection-tools button:hover svg, .selection-tools button:focus-visible svg { color: var(--text); }
.selection-tools button:focus-visible { outline: 2px solid var(--ink); outline-offset: -2px; }
.selection-tools button + button { position: relative; }
.selection-tools button + button::before { content: ""; position: absolute; left: -2px; top: 9px; bottom: 9px; width: 1px; background: var(--line); }
.selection-tools .selection-note { align-self: center; padding: 0 10px 0 8px; color: var(--text-muted); font-size: var(--text-2xs); white-space: nowrap; }
.selection-tools.is-floating { bottom: auto; transform: none; animation: selection-pop 0.12s ease-out; }
.selection-tools.is-floating::after { content: ""; position: absolute; left: var(--arrow-x, 50%); bottom: -6px; width: 10px; height: 10px; margin-left: -5px; background: var(--raised); border: solid var(--line-strong); border-width: 0 1px 1px 0; transform: rotate(45deg); }
.selection-tools.is-floating.is-below::after { top: -6px; bottom: auto; border-width: 1px 0 0 1px; }
@keyframes selection-pop { from { opacity: 0; transform: translateY(3px); } }
body.is-listening .selection-tools:not(.is-floating) { bottom: calc(150px + env(safe-area-inset-bottom)); }
@media (max-width: 640px) {
  .chapter-tools { gap: 2px; margin-top: 10px; }
  .chapter-tools > button, .chapter-tools-more > summary { min-height: 44px; padding: 8px 10px; }
  .tools-dialog { width: calc(100% - 16px); max-height: 92dvh; border-radius: 18px; }
  .tools-heading { padding: 20px 18px 14px; }
  .tools-tabs { padding: 0 14px 12px; }
  .tools-feedback { margin: 12px 18px 0; }
  .tools-panel { padding: 20px 18px calc(24px + env(safe-area-inset-bottom)); }
  .tools-heading h2 { font-size: 23px; }
  .tools-stat-grid { gap: 7px; }
  .tools-stat-grid > div { padding: 14px 10px; }
  .tools-stat-grid strong { font-size: var(--text-lg); }
  .reading-chart { gap: 8px; }
  .tool-rule { align-items: start; }
  .tool-rule strong { font-size: var(--text-sm); }
  /* Touch: equal-width buttons, icon above the word. */
  .selection-tools { width: calc(100% - 24px); }
  .selection-tools button { flex: 1 1 0; flex-direction: column; gap: 3px; min-width: 0; min-height: 52px; padding: 6px 4px; font-size: var(--text-xs); }
  .selection-tools .selection-note { display: none; }
  .tools-panel input, .tools-panel textarea, .tools-panel select { font-size: 16px; }
}

/* A tab with nothing in it yet: an icon, a line and what to do next. */
.tools-empty-state { display: grid; justify-items: center; gap: 8px; max-width: 420px; margin: 32px auto; text-align: center; color: var(--text-muted); }
.tools-empty-state svg { margin-bottom: 6px; opacity: 0.7; }
.tools-empty-state strong { color: var(--text); font: 600 var(--text-lg)/1.4 var(--font-serif); }
.tools-empty-state p { font-size: var(--text-sm); line-height: 1.7; }
.reader-aa-dialog > .tools-heading { display: flex; align-items: center; gap: 8px; }
.reader-aa-dialog > .tools-heading h2 { flex: 1 1 auto; min-width: 0; margin-top: 0; font-size: 22px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reader-aa-dialog > .tools-heading .reader-aa-all { flex: none; width: auto; margin: 0; }
.reader-aa-all { min-height: 44px; padding-inline: 4px; white-space: nowrap; font-size: var(--text-xs); }
