/* Бібліотека історій (режим core). Специфікація: docs/design/screens/library.md. Лише тема «Містечко». */
.lib-res { display: inline-flex; flex: none; align-items: flex-end; justify-content: center; }
.lib-res > svg, .lib-res .lib-fox { width: 100%; height: 100%; }
.lib-av { display: grid; place-items: center; width: 100%; height: auto; aspect-ratio: 1; align-self: flex-end; font-size: 0; border-radius: 50%; background: color-mix(in srgb, var(--rc) 22%, #fff); box-shadow: inset 0 0 0 2px var(--rc); }
.lib-av { font-size: 1.6em; }
.lib-res[style*="width:56px"] .lib-av { font-size: 30px; } .lib-res[style*="width:64px"] .lib-av { font-size: 34px; }
.lib-res[style*="width:36px"] .lib-av { font-size: 20px; } .lib-res[style*="width:48px"] .lib-av { font-size: 26px; } .lib-res[style*="width:96px"] .lib-av { font-size: 50px; }

/* Зірка та репліка */
.lib-host { display: flex; align-items: center; gap: 12px; padding: 12px 16px; margin: 0 0 18px; border-radius: 22px; background: var(--glass-bg); box-shadow: var(--glass-edge), var(--glass-shadow); }
.lib-say p { margin: 0; font-size: 16px; font-weight: 600; line-height: 1.35; }
.lib-say .btn { margin-top: 10px; min-height: 48px; }

/* Полиці */
.lib-shelf { margin: 0 0 22px; }
.lib-h { display: flex; align-items: center; gap: 10px; margin: 0 0 10px; font-size: 20px; }
.lib-hi { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--accent-tint); color: var(--accent); }
.lib-hi svg { width: 18px; height: 18px; }
.lib-shelf.locked .lib-hi { background: var(--fill); color: var(--label2); }
.lib-shelf-note { margin: -2px 0 10px; font-size: 14px; color: var(--label2); }
.lib-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.lib-plank { height: 8px; margin-top: 8px; border-radius: 4px; background: #c98a55; box-shadow: 0 0 0 2px #3b2f2a; }

.lib-book { position: relative; display: flex; flex-direction: column; min-height: 228px; padding: 0; overflow: hidden; border-radius: 16px; text-align: left; color: var(--label);
  background: var(--glass-bg); box-shadow: var(--glass-edge), var(--glass-shadow); transition: transform .15s var(--ease); }
.lib-book:hover { transform: translateY(-2px); }
.lib-book:active { transform: scale(.97); }
.lib-book:focus-visible, .lib-w:focus-visible, .lib-tip-say:focus-visible { outline: 3px solid var(--label); outline-offset: 3px; }
.lib-spine { position: absolute; left: 0; top: 0; bottom: 0; width: 10px; background: var(--c); z-index: 1; }
.lib-cover { position: relative; display: block; height: 120px; background: #cfe8f2; }
.lib-castrow { position: absolute; inset: 0 0 0 10px; gap: 2px; display: flex; align-items: flex-end; justify-content: space-between; padding: 0 6px 6px; }
.lib-castrow > i { width: 36px; }
.lib-bld { display: block; width: 76px; height: 76px; flex: none; }
.lib-bld svg { width: 100%; height: 100%; display: block; }
.lib-ribbon { display: inline-flex; align-items: center; gap: 4px; height: 28px; padding: 0 10px; border-radius: 99px; font-size: 13px; font-weight: 800; }
.lib-ribbon svg { width: 14px; height: 14px; }
.lib-ribbon.new { position: absolute; right: 8px; top: 8px; background: #f2b632; color: #3b2a1e; box-shadow: 0 0 0 2px #3b2f2a; }
.lib-ribbon.read { background: #dcefe0; color: #2d6b46; align-self: flex-start; }
.lib-book-t { display: flex; flex-direction: column; gap: 4px; padding: 10px 12px 12px 18px; }
.lib-book-t b { font-size: 17px; font-weight: 800; line-height: 1.25; }
.lib-book-t small { font-size: 14px; color: var(--label2); }
.lib-again { font-size: 13px; font-weight: 700; color: var(--accent); }
.lib-need { display: flex; align-items: flex-start; gap: 6px; margin-top: 4px; font-size: 13px; font-weight: 700; color: var(--label); }
.lib-need svg { width: 14px; height: 14px; flex: none; margin-top: 2px; color: var(--label2); }
.lib-book.locked { background: #f6efe2; box-shadow: none; border: 2px dashed var(--fill2); }
.lib-book.locked .lib-spine { background: var(--fill2); }
.lib-book.locked .lib-cover > * { filter: grayscale(.8); opacity: .5; }

/* Лист умови */
.lib-need-sheet .sheet-head small { display: block; font-size: 15px; color: var(--label2); }
.lib-need-say { display: flex; align-items: center; gap: 10px; }
.lib-need-say p { margin: 0; font-size: 16px; }
.lib-need-list { list-style: none; margin: 8px 0; padding: 0; }
.lib-need-row { display: flex; align-items: center; gap: 10px; min-height: 48px; }
.lib-need-ic { width: 20px; height: 20px; color: var(--label2); } .lib-need-ic svg { width: 20px; height: 20px; }
.lib-need-row b { font-size: 16px; flex: 1; } .lib-need-row small { font-size: 13px; color: var(--label2); }
.lib-need-later { font-size: 14px; color: var(--label2); margin: 4px 0 12px; }
.lib-need-sheet .btn.wide svg, .lib-need-sheet .btn svg { width: 18px; height: 18px; margin-right: 6px; }
.lib-close { width: 48px; height: 48px; }

/* Помилка даних */
.lib-error { display: flex; gap: 12px; align-items: center; padding: 16px; border-radius: 22px; background: var(--glass-bg); box-shadow: var(--glass-edge), var(--glass-shadow); }
.lib-error p { margin: 4px 0 12px; color: var(--label2); }

/* Читання */
.lib-read { background: var(--bg2); }
.lib-top { gap: 12px; }
.lib-dots { flex: 1; display: flex; gap: 6px; justify-content: center; }
.lib-dots i { width: 10px; height: 10px; border-radius: 99px; background: var(--fill2); }
.lib-dots i.on { background: var(--accent); }
.lib-count, .lib-qcount { font-size: 15px; font-weight: 800; color: var(--label2); }
.lib-qcount { flex: 1; text-align: center; margin-right: 48px; }
.lib-body { max-width: 640px; padding: 12px 16px 210px; }
.lib-scene { position: relative; display: flex; align-items: flex-end; justify-content: space-between; height: 140px; padding: 0 12px 16px; border-radius: 20px; overflow: hidden; background: #cfe8f2; animation: libIn .25s var(--ease) backwards; }
.lib-scene::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 16px; background: #9cc98a; z-index: 0; }
.lib-scene > * { position: relative; z-index: 1; }
.lib-scene > i { width: 64px; }
.lib-scene .lib-bld { width: 120px; height: 120px; margin-bottom: -10px; }
.lib-talk { animation: libBob 2.4s ease-in-out infinite; }
@keyframes libBob { 50% { transform: translateY(-3px); } }
@keyframes libIn { from { opacity: 0; transform: translateX(16px); } }
.lib-tools { display: flex; gap: 8px; justify-content: center; margin: 14px 0 0; }
.lib-tools .btn { min-height: 48px; height: 48px; padding: 0 16px; font-size: 15px; font-weight: 700; min-width: 0; gap: 6px; }
.lib-tools .btn svg { width: 18px; height: 18px; }
.lib-ua { font-size: 12px; font-weight: 800; padding: 1px 5px; border-radius: 6px; background: var(--fill2); margin-right: 6px; }
.lib-tr[aria-pressed="true"] { background: var(--accent-tint); box-shadow: inset 0 0 0 2px var(--accent); color: var(--accent); }
.lib-text { max-width: 34ch; margin: 16px auto 0; font-family: var(--font-round); font-size: 28px; line-height: 1.75; color: #3b2a1e; text-align: left; outline: none; animation: libIn .25s var(--ease) backwards; overflow-wrap: break-word; }
.lib-w { position: relative; display: inline; font: inherit; color: inherit; padding: 0 1px; margin: 0; border-radius: 8px; background: none; text-align: inherit;
  text-decoration: underline; text-decoration-color: var(--fill2); text-decoration-thickness: 3px; text-underline-offset: 6px; cursor: pointer; }
.lib-w::after { content: ""; position: absolute; inset: -10px -3px; }
.lib-w.new { text-decoration-style: dashed; text-decoration-color: var(--accent); }
.lib-w.name { text-decoration-style: wavy; text-decoration-color: color-mix(in srgb, var(--rc) 70%, transparent); }
.lib-w.on { background: var(--accent-tint); text-decoration-style: solid; text-decoration-color: var(--accent); }
.lib-uk { max-width: 40ch; margin: 12px auto 0; font-size: 17px; line-height: 1.45; color: var(--label2); }
.lib-legend { max-width: 40ch; margin: 18px auto 0; font-size: 14px; color: var(--label2); }
.lib-ln { display: inline-block; width: 22px; vertical-align: middle; border-top: 3px solid var(--fill2); margin-right: 4px; }
.lib-ln.dashed { border-top: 3px dashed var(--accent); }
.lib-live { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.lib-read .footer .btn { height: 56px; }
.lib-read .footer-inner { gap: 12px; }

/* Підказка слова */
.lib-tip { position: fixed; z-index: 400; padding: 14px 16px; border-radius: 20px; background: #fff; color: var(--label); box-shadow: var(--shadow-lg), inset 0 0 0 1.5px var(--glass-border, rgba(0,0,0,.08)); animation: libTip .15s var(--ease); display: flex; flex-direction: column; gap: 8px; }
.lib-tip > .lib-res { align-self: flex-start; }
.lib-tip-top { display: flex; align-items: center; gap: 10px; }
.lib-tip-e { font-size: 36px; line-height: 1; }
.lib-tip-b { flex: 1; display: flex; flex-direction: column; }
.lib-tip-w { font-size: 26px; font-weight: 800; line-height: 1.15; }
.lib-tip-b span { font-size: 18px; }
.lib-tip-say { width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; background: var(--fill); color: var(--accent); }
.lib-tip-say svg { width: 22px; height: 22px; }
.lib-tip-st { display: flex; align-items: center; gap: 8px; padding-top: 8px; border-top: 1px solid var(--fill); font-size: 15px; font-weight: 700; color: var(--label2); }
.lib-tip-st svg { width: 18px; height: 18px; }
.lib-tip-st.added { color: #2d6b46; }
.lib-chk { display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--green); color: #fff; }
.lib-chk svg { width: 14px; height: 14px; }
.lib-tip-tail { position: absolute; left: var(--tx, 50%); top: -6px; width: 12px; height: 12px; background: #fff; transform: translateX(-50%) rotate(45deg); }
.lib-tip.up .lib-tip-tail { top: auto; bottom: -6px; }
@keyframes libTip { from { opacity: 0; transform: scale(.96); } }

/* Запитання */
.lib-ask { display: flex; align-items: center; gap: 12px; margin: 8px 0 18px; }
.lib-bubble { flex: 1; padding: 14px 16px; border-radius: 20px; background: var(--glass-bg); box-shadow: var(--glass-edge), var(--glass-shadow); font-size: 22px; font-weight: 800; line-height: 1.3; outline: none; }
.lib-opts { display: grid; grid-template-columns: 1fr; gap: 10px; }
.lib-opts .opt { min-height: 56px; font-size: 18px; font-weight: 600; }
.lib-opts .opt svg { width: 18px; height: 18px; margin-left: auto; }
.lib-opts .opt.try { background: #fdf1d2; box-shadow: inset 0 0 0 2px #7a4f0a; color: #7a4f0a; animation: none; }
.lib-opts .opt.try .key { background: #7a4f0a; color: #fff; }
.lib-opts .opt[disabled]:not(.ok):not(.try) { opacity: .6; }
.lib-qok { margin: 14px 0 0; font-size: 16px; color: var(--label); font-weight: 700; }
.lib-hint { margin-top: 14px; padding: 12px 14px; border-radius: 16px; background: #fdf1d2; color: #3b2a1e; }
.lib-hint p { margin: 0 0 8px; font-size: 16px; }
.lib-hint .btn { min-height: 48px; height: 48px; min-width: 0; gap: 6px; } .lib-hint .btn svg { width: 18px; height: 18px; }
.lib-peek .lib-text { font-size: 28px; }
.lib-peek .btn.wide { margin-top: 14px; }

/* Кінець */
.lib-done-hero { display: flex; align-items: flex-end; justify-content: center; gap: 8px; }
.lib-done-hero .mascot, .lib-done-hero svg:not(.lib-res svg) { width: 96px; }
.lib-done .mascot { width: 96px; animation: none; }
.lib-new-words { max-width: 480px; margin-top: 18px; }
.lib-new-words > div { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 8px; }
.lib-pill { padding: 6px 12px; border-radius: 99px; background: var(--fill); font-weight: 700; font-size: 15px; }

@media (min-width: 701px) {
  .lib-castrow .lib-bld { width: 88px; height: 88px; }
  .lib-grid { grid-template-columns: repeat(4, 1fr); }
  .lib-book { min-height: 236px; }
  .lib-scene { height: 180px; }
  .lib-text { font-size: 32px; }
  .lib-done .mascot { width: 120px; }
}
@media (max-width: 700px) {
  .lib-read .footer-inner { flex-direction: row; align-items: center; }
  .lib-read .footer-inner > span:empty { display: none; }
  .lib-read .footer .btn { flex: 1; min-width: 0; min-height: 56px; }
  .lib-read .footer .lib-prev { flex: 0 0 48%; }
}
@media (min-width: 1100px) { .lib-body { max-width: 720px; } }
@media (prefers-reduced-motion: reduce) {
  .lib-scene, .lib-text, .lib-tip, .lib-talk, .lib-book { animation: none; transition: none; }
}
html.no-motion .lib-scene, html.no-motion .lib-text, html.no-motion .lib-tip, html.no-motion .lib-talk { animation: none; }
