/* Suffler PWA — тёмный flat, mobile-first */
:root {
  --bg: #121216;
  --surface: #1c1c21;
  --surface-2: #26262d;
  --border: #2e2e36;
  --text: #ececf0;
  --muted: #8b8b95;
  --accent: #ff4b4b;
  --accent-press: #d63c3c;
  --guide: #55555f;
  --radius: 14px;
  --font-scale: 1;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

/* атрибут hidden должен побеждать любые display-правила ниже */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  overscroll-behavior: none;
}

.view {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}

button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible,
textarea:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

svg { width: 24px; height: 24px; display: block; }

/* ---------- Библиотека ---------- */

.lib-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  padding: 28px 20px 12px;
}
.lib-header h1 { font-size: 28px; font-weight: 700; letter-spacing: -0.5px; }
.tagline { color: var(--muted); font-size: 14px; margin-top: 2px; }

#book-list { list-style: none; padding: 8px 16px; flex: 1; overflow-y: auto; }

.book-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: background 180ms ease;
}
.book-item:hover, .book-item:active { background: var(--surface-2); }
.book-item .info { flex: 1; min-width: 0; }
.book-item .name {
  font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.book-item .meta { color: var(--muted); font-size: 13px; margin-top: 2px; }
.book-item .pct { color: var(--accent); font-weight: 600; font-size: 14px; }
.book-item .del {
  min-width: 44px; min-height: 44px;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); border-radius: 10px;
  transition: color 180ms ease, background 180ms ease;
}
.book-item .del:hover { color: var(--accent); background: var(--surface-2); }

.empty { color: var(--muted); text-align: center; padding: 48px 32px; flex: 1; }

.install-banner {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  margin: 0 16px 12px;
  min-height: 48px;
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  color: var(--accent);
  font-weight: 600; font-size: 15px;
  cursor: pointer;
  transition: background 180ms ease;
}
.install-banner:hover { background: var(--surface-2); }
.install-banner svg { width: 20px; height: 20px; }

.install-hint {
  display: flex; align-items: center; gap: 8px;
  margin: 0 16px 12px;
  padding: 10px 4px 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 14px;
}
.install-hint p { margin: 0; flex: 1; }
.install-hint strong { color: var(--text); }
.install-hint .inline-ico { width: 16px; height: 16px; vertical-align: -3px; }

.lib-actions {
  display: flex; gap: 10px; padding: 12px 16px 20px;
}

.btn {
  flex: 1;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 50px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-weight: 600; font-size: 15px;
  transition: background 180ms ease;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-press); }
.btn svg { width: 20px; height: 20px; }

/* ---------- Читалка ---------- */

.reader-top {
  display: flex; align-items: center; gap: 4px;
  padding: 8px 8px 0;
}
.icon-btn {
  min-width: 44px; min-height: 44px;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); border-radius: 12px;
  transition: color 180ms ease, background 180ms ease;
}
.icon-btn:hover { color: var(--text); background: var(--surface); }
.book-title {
  flex: 1; text-align: center; color: var(--muted); font-size: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

#stage {
  flex: 1;
  position: relative;
  display: flex; align-items: center;
  overflow: hidden;
  cursor: pointer;
  user-select: none;
  touch-action: pan-y;
}

.guide {
  position: absolute; left: 50%; transform: translateX(-50%);
  width: 2px; height: 14px; background: var(--guide);
}
.guide-top { top: calc(50% - 3.2em * var(--font-scale)); }
.guide-bottom { bottom: calc(50% - 3.2em * var(--font-scale)); }

#word {
  display: flex; width: 100%;
  font-size: calc(min(16vw, 92px) * var(--font-scale));
  font-weight: 650;
  letter-spacing: 0.01em;
  white-space: nowrap;
  line-height: 1.1;
}
#w-before { flex: 1 0 0; text-align: right; overflow: visible; }
#w-orp { flex: 0 0 auto; color: var(--accent); }
#w-after { flex: 1 0 0; text-align: left; overflow: visible; }

/* индикатор «рядом с этим абзацем есть картинка», виден и в погружении */
.img-hint {
  position: absolute; top: 10px; right: 12px; z-index: 5;
  display: flex; align-items: center; justify-content: center;
  min-width: 44px; min-height: 44px;
  border-radius: 12px;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--accent);
  cursor: pointer;
  animation: img-hint-in 300ms ease;
}
.img-hint svg { width: 22px; height: 22px; }
.img-hint:hover { background: var(--surface-2); }
@keyframes img-hint-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

#message {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px;
  background: var(--bg);
  text-align: center; padding: 24px;
  font-size: 20px; font-weight: 600;
}
#message small { color: var(--muted); font-size: 14px; font-weight: 400; }

#stage-hint {
  position: absolute; left: 0; right: 0; bottom: 18px;
  text-align: center; color: var(--muted); font-size: 14px;
  pointer-events: none;
  transition: opacity 300ms ease;
}
#stage-hint.gone { opacity: 0; }

/* ---------- Низ читалки ---------- */

.reader-bottom { padding: 0 16px 16px; }

.progress-row { display: flex; align-items: center; gap: 10px; padding: 6px 0 10px; }
#progress-bar {
  flex: 1; height: 4px; border-radius: 2px; background: var(--surface-2);
  overflow: hidden;
}
#progress-fill { height: 100%; width: 0; background: var(--accent); }
#progress-label { color: var(--muted); font-size: 12px; min-width: 96px; text-align: right; }

.controls {
  display: flex; align-items: center; justify-content: center; gap: 18px;
  padding-bottom: 10px;
}
.ctl {
  min-width: 56px; min-height: 56px;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text);
  transition: background 180ms ease;
}
.ctl:hover { background: var(--surface-2); }
.ctl.play {
  min-width: 72px; min-height: 72px;
  background: var(--accent); border-color: var(--accent); color: #fff;
}
.ctl.play:hover { background: var(--accent-press); }
.ctl.play svg { width: 32px; height: 32px; }

.wpm-row { display: flex; align-items: center; gap: 8px; }
.wpm-row label { color: var(--muted); font-size: 14px; margin-right: 4px; }
.wpm-row input[type="range"] { flex: 1; min-width: 0; }
#wpm-val { min-width: 44px; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.wpm-btn {
  min-width: 44px; min-height: 44px;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 24px; font-weight: 600; line-height: 1;
  border-radius: 10px;
  transition: color 180ms ease, background 180ms ease;
}
.wpm-btn:hover { color: var(--text); background: var(--surface); }

/* погружение: во время чтения панели скрыты, остаётся слово и прогресс */
.reader-top, .controls, .wpm-row { transition: opacity 250ms ease; }
#reader.immersive .reader-top,
#reader.immersive .controls,
#reader.immersive .wpm-row { opacity: 0; pointer-events: none; }

/* ---------- Ползунки и переключатели ---------- */

input[type="range"] {
  -webkit-appearance: none; appearance: none;
  height: 28px; background: transparent; cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 4px; border-radius: 2px; background: var(--surface-2);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px; height: 22px; margin-top: -9px;
  border-radius: 50%; background: var(--accent); border: none;
}
input[type="range"]::-moz-range-track {
  height: 4px; border-radius: 2px; background: var(--surface-2);
}
input[type="range"]::-moz-range-thumb {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent); border: none;
}

.switch {
  -webkit-appearance: none; appearance: none;
  width: 48px; height: 28px; border-radius: 14px;
  background: var(--surface-2); position: relative; cursor: pointer;
  transition: background 180ms ease;
  flex-shrink: 0;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 22px; height: 22px; border-radius: 50%; background: var(--muted);
  transition: transform 180ms ease, background 180ms ease;
}
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(20px); background: #fff; }

/* ---------- Оригинал страниц ---------- */

.orig-hint {
  color: var(--muted); font-size: 13px; text-align: center;
  padding: 0 20px 8px;
}
#orig-content {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 4px 20px 48px;
}
#orig-content p, #orig-content h3 {
  cursor: pointer; border-radius: 8px;
  transition: background 180ms ease;
}
#orig-content p {
  font-size: 17px; line-height: 1.65; margin-bottom: 14px;
}
#orig-content h3 {
  font-size: 20px; line-height: 1.4; margin: 22px 0 12px;
}
#orig-content p:hover, #orig-content h3:hover { background: var(--surface); }
#orig-content .current {
  background: rgba(255, 75, 75, 0.14);
  box-shadow: 0 0 0 8px rgba(255, 75, 75, 0.14);
}
#orig-content img {
  max-width: 100%; height: auto; display: block;
  margin: 14px auto; border-radius: 10px;
}
.pdf-page {
  min-height: 200px; margin-bottom: 12px;
  background: var(--surface); border-radius: 6px;
  cursor: pointer; overflow: hidden;
}
.pdf-page canvas { width: 100%; display: block; }
.pdf-page.current { outline: 3px solid var(--accent); }

/* ---------- Индикатор занятости ---------- */

#busy-bar {
  position: fixed; top: 0; left: 0; right: 0; height: 3px;
  z-index: 70; overflow: hidden; pointer-events: none;
}
#busy-bar::before {
  content: ""; position: absolute; top: 0; bottom: 0; width: 40%;
  background: var(--accent); border-radius: 3px;
  animation: busy-run 1.1s linear infinite;
}
@keyframes busy-run { from { left: -40%; } to { left: 100%; } }
@media (prefers-reduced-motion: reduce) {
  #busy-bar::before { animation: busy-pulse 1.4s ease-in-out infinite; left: 0; width: 100%; }
}
@keyframes busy-pulse { 0%, 100% { opacity: 0.25; } 50% { opacity: 0.8; } }

/* ---------- Тост ---------- */

#toast {
  position: fixed; left: 50%; bottom: calc(28px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(8px);
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 999px;
  padding: 10px 18px; font-size: 14px;
  width: max-content; max-width: 90vw; text-align: center;
  opacity: 0; pointer-events: none; z-index: 60;
  transition: opacity 200ms ease, transform 200ms ease;
}
#toast.show { opacity: 1; transform: translateX(-50%); }

/* ---------- Шторки ---------- */

#overlay {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55); z-index: 40;
}

.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  border-top: 1px solid var(--border);
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
  max-height: 75dvh; overflow-y: auto;
  animation: sheet-in 220ms ease;
}
@keyframes sheet-in { from { transform: translateY(30%); opacity: 0.5; } to { transform: none; opacity: 1; } }

.sheet h2 { font-size: 17px; margin-bottom: 14px; }

#chapter-list { list-style: none; }
#chapter-list button {
  display: flex; align-items: center; gap: 10px;
  width: 100%; min-height: 48px; padding: 0 8px;
  border-radius: 10px; text-align: left;
  transition: background 180ms ease;
}
#chapter-list button:hover { background: var(--surface-2); }
#chapter-list button.active { color: var(--accent); font-weight: 600; }
#chapter-list .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex-shrink: 0; }

.set-row {
  display: flex; align-items: center; gap: 12px;
  min-height: 48px;
  border-bottom: 1px solid var(--border);
}
.set-row:last-child { border-bottom: none; }
.set-row label { flex: 1; font-size: 15px; }
.set-row select {
  max-width: 55%;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; font-size: 14px;
}
.set-row input[type="range"] { width: 120px; }
.set-row span { min-width: 44px; text-align: right; color: var(--muted); font-size: 14px; }

.sheet.help h3 { font-size: 15px; margin: 16px 0 8px; }
.sheet.help p, .sheet.help li { color: var(--text); font-size: 14px; line-height: 1.55; }
.sheet.help ol { padding-left: 20px; }
.sheet.help ol li { margin-bottom: 6px; }
.sheet.help a { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
.voice-links { list-style: none; padding: 6px 0 2px; }
.voice-links li { margin-bottom: 2px; }
.voice-links a {
  display: inline-flex; align-items: center; min-height: 40px;
}
.help-note { color: var(--muted); margin-top: 12px; }

/* аккаунт и синхронизация */
#btn-account { position: relative; }
.account-dot {
  position: absolute; top: 8px; right: 8px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent);
}
#sheet-account .btn { width: 100%; justify-content: center; margin-top: 10px; }
#sheet-account .btn.small { width: auto; margin-top: 0; min-height: 36px; padding: 6px 14px; font-size: 14px; }
.acc-note { color: var(--muted); font-size: 14px; line-height: 1.5; }
.acc-warn { color: var(--accent); margin-top: 12px; }
.acc-or { text-align: center; margin-top: 16px; }
.acc-phrase {
  margin-top: 8px; padding: 12px;
  background: var(--surface-2); border: 1px dashed var(--border); border-radius: 10px;
  font-size: 17px; line-height: 1.5; text-align: center;
  user-select: all; -webkit-user-select: all;
}
.acc-error { color: var(--accent); font-size: 14px; margin-top: 10px; }
#acc-phrase-input {
  width: 100%; margin-top: 10px;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 12px; font: inherit; font-size: 15px;
}

#sheet-paste input[type="text"], #sheet-paste textarea, #yt-url {
  width: 100%;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 12px; font: inherit; font-size: 15px;
  margin-bottom: 12px;
  resize: vertical;
}
#yt-url { margin-top: 12px; }
#sheet-yt .btn { width: 100%; justify-content: center; margin-top: 10px; }
#sheet-yt .btn:disabled { opacity: 0.55; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* планшет/десктоп: ограничить ширину контента */
@media (min-width: 768px) {
  .lib-header, #book-list, .lib-actions, .reader-bottom,
  #original .reader-top, .orig-hint, #orig-content {
    width: 100%; max-width: 720px; margin-left: auto; margin-right: auto;
  }
  #word { font-size: calc(min(8vw, 84px) * var(--font-scale)); }
}

/* телефон в ландшафте: компактная панель одной строкой, слово крупнее */
@media (orientation: landscape) and (max-height: 520px) {
  #word { font-size: calc(min(11vw, 26vh) * var(--font-scale)); }
  /* прицел чуть левее центра: на широком экране фокусной точке комфортнее у трети строки */
  .guide { left: 44%; }
  #w-before { flex-grow: 44; }
  #w-after { flex-grow: 56; }
  .reader-bottom {
    display: flex; flex-wrap: wrap; align-items: center;
    column-gap: 16px; padding: 0 16px 8px; max-width: none;
  }
  .progress-row { width: 100%; padding: 2px 0 4px; }
  .controls { padding-bottom: 0; gap: 12px; }
  .ctl { min-width: 46px; min-height: 46px; }
  .ctl.play { min-width: 56px; min-height: 56px; }
  .ctl.play svg { width: 26px; height: 26px; }
  .wpm-row { flex: 1; min-width: 220px; }
  .wpm-row label { display: none; }
}
