/* Темы: paper (по умолчанию), light, dark */
:root {
  --bg: #f5efe3; --bg2: #ece4d4; --card: #fbf7ef; --text: #2b2620; --muted: #837868;
  --line: #ddd2bf; --accent: #9a5b2e; --accent-soft: #efe0cf; --ok: #4f7a4a; --ok-soft: #e1ead9;
  --orig: #e9e0cf; --shadow: 0 8px 30px rgba(60,40,20,.18);
  --hl-yellow: #f3dc84; --hl-green: #c7dfa8; --hl-blue: #b9d4ea; --hl-pink: #efc2c8;
  --font-size: 19px;
}
:root[data-theme="light"] {
  --bg: #ffffff; --bg2: #f2f2f0; --card: #ffffff; --text: #1f1f1f; --muted: #7a7a7a;
  --line: #e4e4e0; --accent-soft: #f4e8dc; --orig: #f1efea;
}
:root[data-theme="dark"] {
  --bg: #1c1a17; --bg2: #262320; --card: #2a2723; --text: #e7e0d4; --muted: #9a9082;
  --line: #3a3530; --accent: #d59a64; --accent-soft: #3b2f24; --ok: #95c08c; --ok-soft: #2c3829;
  --orig: #2e2a25; --shadow: 0 8px 30px rgba(0,0,0,.5);
  --hl-yellow: #6b5a1c; --hl-green: #3f5a2a; --hl-blue: #2c4a63; --hl-pink: #633640;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body { background: #d9d2c4; font-family: Inter, system-ui, sans-serif; color: var(--text); font-size: 15px; }
:root[data-theme="dark"] body { background: #0e0d0c; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
input, textarea { font: inherit; color: inherit; }

/* Приложение: колонка телефона, на ПК по центру */
.app { position: relative; max-width: 430px; height: 100dvh; margin: 0 auto; background: var(--bg); overflow: hidden; }
@media (min-width: 600px) { .app { height: min(900px, 100dvh); margin-top: max(0px, calc((100dvh - 900px) / 2)); border-radius: 28px; box-shadow: 0 20px 60px rgba(0,0,0,.25); } }
.screen { position: absolute; inset: 0; display: none; flex-direction: column; }
.screen.on { display: flex; }
.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.icon { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* Шапка экранов */
.bar { display: flex; align-items: center; gap: 8px; padding: calc(10px + env(safe-area-inset-top)) 12px 10px; }
.bar h1 { font-size: 20px; margin: 0; flex: 1; font-weight: 600; }
.iconbtn { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; color: var(--text); }
.iconbtn:active { background: var(--bg2); }

/* Вход */
#login { justify-content: center; padding: 32px; gap: 14px; }
.logo { font-family: Literata, serif; font-size: 34px; text-align: center; margin-bottom: 4px; }
.logo small { display: block; font-family: Inter, sans-serif; font-size: 14px; color: var(--muted); margin-top: 6px; }
.field { width: 100%; padding: 14px 16px; border-radius: 14px; border: 1px solid var(--line); background: var(--card); outline: none; }
.field:focus { border-color: var(--accent); }
.btn { padding: 14px 18px; border-radius: 14px; background: var(--accent); color: #fff; font-weight: 600; text-align: center; }
:root[data-theme="dark"] .btn { color: #1c1a17; }
.btn.ghost { background: var(--accent-soft); color: var(--accent); }
.btn.small { padding: 9px 14px; border-radius: 11px; font-size: 14px; }
.btn:disabled { opacity: .5; }

/* Библиотека */
.sync { font-size: 12px; color: var(--ok); display: flex; align-items: center; gap: 4px; }
.sync::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.books { padding: 6px 16px 24px; display: flex; flex-direction: column; gap: 14px; }
.book { position: relative; cursor: pointer; display: flex; gap: 14px; padding: 12px; border-radius: 18px; background: var(--card); border: 1px solid var(--line); text-align: left; width: 100%; }
.cover { width: 74px; height: 108px; border-radius: 8px; flex: none; padding: 9px 8px; color: #fff; font-family: Literata, serif; font-size: 12.5px; line-height: 1.2; display: flex; flex-direction: column; justify-content: space-between; box-shadow: 2px 3px 8px rgba(0,0,0,.18); overflow: hidden; }
.cover small { font-family: Inter, sans-serif; font-size: 9px; opacity: .85; }
.book-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 5px; }
.book-title { font-family: Literata, serif; font-size: 17px; font-weight: 600; }
.book-author { color: var(--muted); font-size: 13px; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px; border-radius: 99px; font-size: 12px; font-weight: 500; background: var(--bg2); color: var(--muted); white-space: nowrap; }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.accent { background: var(--accent-soft); color: var(--accent); }
.meter { height: 4px; border-radius: 4px; background: var(--bg2); overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--accent); border-radius: 4px; transition: width .3s; }
.book-meta { font-size: 12.5px; color: var(--muted); margin-top: auto; }
.upload { margin: 0 16px 20px; border: 1.5px dashed var(--line); border-radius: 18px; padding: 16px; color: var(--muted); display: flex; gap: 10px; align-items: center; justify-content: center; }

/* Читалка */
#reader .bar { padding-bottom: 6px; gap: 4px; }
.rtitle { flex: 1; min-width: 0; text-align: center; }
.rtitle b { display: block; font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rtitle span { display: block; font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rsub { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 0 16px 8px; }
.seg { display: inline-flex; background: var(--bg2); border-radius: 10px; padding: 2px; }
.seg button { padding: 5px 11px; border-radius: 8px; font-size: 12.5px; color: var(--muted); font-weight: 500; }
.seg button.on { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.1); }
.topmeter { height: 2px; background: var(--bg2); }
.topmeter i { display: block; height: 100%; background: var(--accent); transition: width .3s; }
#text { padding: 18px 22px 120px; font-family: Literata, Georgia, serif; font-size: var(--font-size); line-height: 1.62; }
#text h2 { font-size: 1.35em; line-height: 1.25; margin: 6px 0 22px; font-weight: 600; }
.chap-num { font-family: Inter, sans-serif; font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.blk { position: relative; margin: 0 0 1em; border-radius: 6px; transition: background .6s; }
.blk.flash { background: var(--accent-soft); }
.blk.note-lost::before { content: ""; position: absolute; left: -12px; top: 4px; bottom: 4px; width: 3px; border-radius: 3px; background: var(--hl-yellow); }
.blk.swapped { animation: swap .6s; }
@keyframes swap { from { background: var(--ok-soft); } to { background: transparent; } }
.orig { font-size: .86em; line-height: 1.55; color: var(--muted); background: var(--orig); border-radius: 10px; padding: 10px 12px; margin-top: 8px; font-style: italic; }
.orig-h { display: flex; justify-content: space-between; align-items: center; font-family: Inter, sans-serif; font-style: normal; font-size: 10.5px; letter-spacing: .1em; text-transform: uppercase; margin-bottom: 3px; }
.orig-x { font-size: 12px; letter-spacing: 0; text-transform: none; color: var(--accent); font-weight: 500; padding: 4px 0 4px 12px; }
mark.hl { color: inherit; border-radius: 3px; padding: 0 1px; cursor: pointer; }
.c-yellow { background: var(--hl-yellow); } .c-green { background: var(--hl-green); } .c-blue { background: var(--hl-blue); } .c-pink { background: var(--hl-pink); }
.banner { font-family: Inter, sans-serif; font-size: 13.5px; line-height: 1.45; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; margin-bottom: 22px; display: flex; gap: 12px; align-items: center; }
.banner p { margin: 0; flex: 1; color: var(--muted); }
/* Карточка следующей главы в конце текста */
.next { font-family: Inter, sans-serif; background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 16px; margin-top: 36px; }
.next-k { font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.next-t { font-family: Literata, serif; font-size: 19px; font-weight: 600; margin: 4px 0 8px; line-height: 1.3; }
.next .row { margin-top: 14px; }
.prev { display: block; margin: 16px auto 0; font-family: Inter, sans-serif; font-size: 13.5px; color: var(--muted); padding: 8px; }
.adapting { display: flex; flex-direction: column; gap: 7px; flex: 1; }
.adapting .meter i { background: var(--ok); }

/* Нижняя панель */
.tabbar { position: absolute; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-around; padding: 8px 6px calc(8px + env(safe-area-inset-bottom)); background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(10px); border-top: 1px solid var(--line); }
.tabbar button { display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 11px; color: var(--muted); padding: 4px 8px; border-radius: 10px; min-width: 58px; }
.tabbar button:active { background: var(--bg2); }
.tabbar button.hot { color: var(--accent); }

/* Панель действий с выделением */
#selbar { position: absolute; left: 12px; right: 12px; bottom: calc(76px + env(safe-area-inset-bottom)); display: none; background: var(--text); color: var(--bg); border-radius: 16px; padding: 6px; box-shadow: var(--shadow); z-index: 20; }
#selbar.on { display: flex; }
#selbar button { flex: 1; min-width: 0; padding: 9px 2px; border-radius: 11px; font-size: 12px; white-space: nowrap; font-weight: 500; display: flex; flex-direction: column; align-items: center; gap: 3px; }
#selbar button:active { background: rgba(255,255,255,.12); }
#selbar .icon { width: 20px; height: 20px; }

/* Нижний лист */
#backdrop { position: absolute; inset: 0; background: rgba(20,15,10,.35); opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 30; }
#backdrop.on { opacity: 1; pointer-events: auto; }
#sheet { position: absolute; left: 0; right: 0; bottom: 0; max-height: 82%; background: var(--card); border-radius: 22px 22px 0 0; transform: translateY(105%); transition: transform .25s ease; z-index: 31; display: flex; flex-direction: column; box-shadow: var(--shadow); }
#sheet.on { transform: none; }
.grab { width: 38px; height: 5px; border-radius: 5px; background: var(--line); margin: 8px auto 2px; flex: none; }
.sheet-body { overflow-y: auto; padding: 8px 20px calc(22px + env(safe-area-inset-bottom)); }
.sheet-body h3 { margin: 6px 0 14px; font-size: 17px; }

/* Карточка слова */
.word { font-family: Literata, serif; font-size: 28px; font-weight: 600; }
.ipa { color: var(--muted); font-size: 15px; margin: 2px 0 10px; display: flex; gap: 8px; align-items: center; }
.meaning { font-family: Literata, serif; font-size: 17px; line-height: 1.5; margin: 12px 0; }
.label { font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); margin: 16px 0 6px; }
.ex { font-family: Literata, serif; font-size: 15.5px; line-height: 1.5; margin: 0 0 6px; padding-left: 12px; border-left: 3px solid var(--line); }
.ctx { font-family: Literata, serif; font-size: 15px; line-height: 1.5; color: var(--muted); background: var(--bg2); padding: 10px 12px; border-radius: 12px; }
.ctx b { color: var(--text); font-weight: 600; }
.row { display: flex; gap: 10px; margin-top: 18px; }
.row .btn { flex: 1; white-space: nowrap; padding: 12px 10px; font-size: 14.5px; }
.skel { height: 14px; border-radius: 7px; background: linear-gradient(90deg, var(--bg2), var(--line), var(--bg2)); background-size: 200% 100%; animation: sk 1.1s infinite; margin: 10px 0; }
@keyframes sk { to { background-position: -200% 0; } }
.variant { font-family: Literata, serif; font-size: 17px; line-height: 1.5; background: var(--bg2); border-radius: 14px; padding: 12px 14px; margin-bottom: 10px; }
.quote { font-family: Literata, serif; font-style: italic; color: var(--muted); font-size: 15px; line-height: 1.5; border-left: 3px solid var(--accent); padding-left: 12px; margin: 0 0 6px; }
.colors { display: flex; gap: 12px; margin: 8px 0 14px; }
.colors button { width: 36px; height: 36px; border-radius: 50%; border: 3px solid transparent; }
.colors button.on { border-color: var(--text); }
textarea.field { min-height: 90px; resize: none; }

/* Оглавление */
.toc-item { display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 4px; border-bottom: 1px solid var(--line); text-align: left; }
.toc-item.cur .toc-t { color: var(--accent); font-weight: 600; }
.toc-n { width: 22px; color: var(--muted); font-size: 13px; }
.toc-t { flex: 1; font-family: Literata, serif; font-size: 16px; }
.off { color: var(--muted); display: inline-flex; }
.off .icon { width: 16px; height: 16px; }

/* Настройки */
.levels { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.levels button, .themes button { padding: 10px 0; border-radius: 11px; background: var(--bg2); font-weight: 600; font-size: 14px; }
.levels button.on, .themes button.on { background: var(--accent); color: #fff; }
:root[data-theme="dark"] .levels button.on, :root[data-theme="dark"] .themes button.on { color: #1c1a17; }
.hint { font-size: 12.5px; color: var(--muted); line-height: 1.45; margin: 8px 0 0; }
.fontrow { display: flex; align-items: center; gap: 12px; }
.fontrow button { width: 48px; height: 42px; border-radius: 11px; background: var(--bg2); font-family: Literata, serif; }
.fontrow span { flex: 1; text-align: center; color: var(--muted); }
.themes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }

/* Чат */
.chat-ctx { font-size: 12px; color: var(--muted); }
#msgs { padding: 12px 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 86%; padding: 10px 13px; border-radius: 17px; line-height: 1.5; font-size: 15px; }
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 5px; }
:root[data-theme="dark"] .msg.user { color: #1c1a17; }
.msg.ai { align-self: flex-start; background: var(--card); border: 1px solid var(--line); border-bottom-left-radius: 5px; font-family: Literata, serif; font-size: 16px; }
.steps { align-self: flex-start; display: flex; flex-direction: column; gap: 4px; }
.step { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; font-family: ui-monospace, Menlo, monospace; }
.step::before { content: "✓"; color: var(--ok); }
.step.run::before { content: ""; width: 10px; height: 10px; border: 2px solid var(--muted); border-top-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.sugg { display: flex; gap: 8px; overflow-x: auto; padding: 0 14px 8px; scrollbar-width: none; }
.sugg button { flex: none; padding: 8px 12px; border-radius: 99px; border: 1px solid var(--line); font-size: 13px; background: var(--card); }
.composer { display: flex; gap: 8px; padding: 8px 12px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.composer input { flex: 1; padding: 12px 14px; border-radius: 22px; border: 1px solid var(--line); background: var(--card); outline: none; }
.send { width: 44px; height: 44px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; flex: none; }
.empty { text-align: center; color: var(--muted); padding: 40px 24px; line-height: 1.5; }

/* Заметки */
.tabs { display: flex; gap: 6px; padding: 0 16px 10px; }
.tabs button { flex: 1; padding: 9px; border-radius: 11px; background: var(--bg2); font-weight: 500; color: var(--muted); }
.tabs button.on { background: var(--text); color: var(--bg); }
.list { padding: 4px 16px 30px; display: flex; flex-direction: column; gap: 10px; }
.note { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px; text-align: left; width: 100%; display: flex; gap: 12px; }
.note .dot { width: 4px; border-radius: 4px; flex: none; }
.note-q { font-family: Literata, serif; font-size: 15.5px; line-height: 1.45; }
.note-c { font-size: 13.5px; margin-top: 6px; line-height: 1.4; }
.note-m { font-size: 12px; color: var(--muted); margin-top: 6px; }
.w-top { display: flex; align-items: baseline; gap: 8px; }
.w-top b { font-family: Literata, serif; font-size: 18px; }
.w-top span { color: var(--muted); font-size: 13px; }

/* Главный экран: вкладки Books, Words, Notes, Settings */
.tabbar button.on { color: var(--accent); }
#homeScroll { padding-bottom: 84px; }
.filters { display: flex; gap: 6px; overflow-x: auto; padding: 0 16px 12px; scrollbar-width: none; }
.filters button { flex: none; padding: 7px 12px; border-radius: 99px; background: var(--bg2); color: var(--muted); font-size: 13px; font-weight: 500; }
.filters button.on { background: var(--text); color: var(--bg); }
.count { padding: 0 16px 8px; font-size: 13px; color: var(--muted); }
.form { padding: 0 16px 24px; display: flex; flex-direction: column; gap: 10px; }
.form .label { margin: 14px 0 0; }
.form .field { padding: 12px 14px; }
.saved { font-size: 12.5px; color: var(--ok); }
.acc { display: flex; align-items: center; justify-content: space-between; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }

/* Уведомление */
#toast { position: absolute; left: 50%; top: calc(14px + env(safe-area-inset-top)); transform: translate(-50%, -80px); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 14px; font-size: 13.5px; z-index: 50; transition: transform .25s; max-width: 88%; text-align: center; box-shadow: var(--shadow); }
#toast.on { transform: translate(-50%, 0); }

/* Ошибки, загрузка */
.banner.err { border-color: var(--hl-pink); }
.banner.err p { color: var(--text); }
.loading { text-align: center; color: var(--muted); padding: 60px 20px; font-family: Inter, sans-serif; }
.btn.danger { background: transparent; color: #b4483c; border: 1px solid var(--line); }
.login-err { color: #b4483c; font-size: 14px; text-align: center; min-height: 20px; }

/* Типы блоков из EPUB */
.chap-num { margin-bottom: 14px; }
.t-h { font-weight: 600; font-size: 1.2em; line-height: 1.3; margin-top: .4em; }
.t-li { padding-left: 1.1em; }
.t-li::after { content: "•"; position: absolute; left: .2em; top: 0; color: var(--muted); }
.t-quote { padding-left: 1em; border-left: 3px solid var(--line); font-style: italic; }

/* Меню книги */
.book-title { padding-right: 28px; }
.book-more { position: absolute; top: 6px; right: 6px; width: 36px; height: 36px; border-radius: 10px; font-size: 20px; line-height: 1; color: var(--muted); }
.book-more:active { background: var(--bg2); }
.menu-item { display: block; width: 100%; text-align: left; padding: 14px 4px; border-top: 1px solid var(--line); font-size: 16px; }
.menu-item.danger { color: #b4483c; }
.btn.danger-fill { background: #b4483c; color: #fff; }
