:root {
  --bg: #f6f1e7;
  --paper: #fffdf8;
  --ink: #2a2622;
  --ink2: #6d655b;
  --line: #e6dccb;
  --acc: #b4542e;
  --acc-ink: #fff;
  --acc-soft: #f3dfd3;
  --mark: #fde9a8;
  --saved: #3f7d5c;
  --saved-soft: #dcefe3;
  --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 6px 24px rgba(60, 40, 20, .08);
  --serif: 'Literata', Georgia, 'Times New Roman', serif;
  --sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --fs: 19px;
  --r: 14px;
  color-scheme: light;
}
:root[data-theme="sepia"] {
  --bg: #efe2c8; --paper: #f7ecd5; --ink: #3b2f22; --ink2: #7a6a55; --line: #dcc9a6;
  --acc-soft: #ecd3bd; --mark: #f5d989;
}
:root[data-theme="dark"] {
  --bg: #15130f; --paper: #1d1a16; --ink: #e8e1d5; --ink2: #9d9486; --line: #332e27;
  --acc: #e07a50; --acc-soft: #3a2a21; --mark: #5a4a17; --saved: #7cc49b; --saved-soft: #1f3528;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 28px rgba(0, 0, 0, .35);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #15130f; --paper: #1d1a16; --ink: #e8e1d5; --ink2: #9d9486; --line: #332e27;
    --acc: #e07a50; --acc-soft: #3a2a21; --mark: #5a4a17; --saved: #7cc49b; --saved-soft: #1f3528;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 28px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font: 15px/1.5 var(--sans); min-height: 100vh; }
button, input, select { font: inherit; color: inherit; }
a { color: inherit; }
[hidden] { display: none !important; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

#app { max-width: 760px; margin: 0 auto; padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
body.reading #app { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }

/* ---------- felso sav */
#bar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 6px;
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid transparent;
  transition: border-color .2s;
}
#bar.sh { border-bottom-color: var(--line); }
#bar h1 { font: 600 22px/1.2 var(--serif); margin: 0 0 0 4px; flex: 1; letter-spacing: -.01em; }
#bar .ttl { flex: 1; min-width: 0; text-align: center; }
#bar .ttl b { display: block; font: 600 14px/1.25 var(--sans); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#bar .ttl small { display: block; color: var(--ink2); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ib {
  display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 12px;
  border: 0; background: transparent; cursor: pointer; color: var(--ink);
}
.ib:hover { background: var(--acc-soft); }
.ib.on { background: var(--acc); color: var(--acc-ink); }
.ib .aa { font: 600 17px var(--serif); }

/* ---------- also fulek */
#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: center; gap: 4px;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
body.reading #tabs { display: none; }
#tabs a, #tabs button {
  position: relative; flex: 0 1 140px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 4px; border-radius: 12px; text-decoration: none; color: var(--ink2); font-size: 12px; font-weight: 500;
  border: 0; background: none; cursor: pointer;
}
#tabs a.on { color: var(--acc); }
#tabs b { position: absolute; top: 2px; left: calc(50% + 8px); background: var(--acc); color: var(--acc-ink); font-size: 10px; line-height: 16px; min-width: 16px; padding: 0 4px; border-radius: 8px; }
#tabs b:empty { display: none; }
#syncBtn[data-s="ok"] { color: var(--saved); }
#syncBtn[data-s="busy"] svg { animation: spin 1s linear infinite; }
#syncBtn[data-s="off"], #syncBtn[data-s="auth"] { color: var(--acc); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- altalanos */
.wrap { padding: 4px 16px 24px; }
.muted { color: var(--ink2); }
.small { font-size: 13px; }
.sec { font: 600 12px/1 var(--sans); text-transform: uppercase; letter-spacing: .08em; color: var(--ink2); margin: 26px 0 12px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 42px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--paper); cursor: pointer; font-weight: 600; font-size: 14px; text-decoration: none;
}
.btn:hover { border-color: var(--ink2); }
.btn.pri { background: var(--acc); border-color: var(--acc); color: var(--acc-ink); }
.btn.ok { background: var(--saved); border-color: var(--saved); color: #fff; }
.btn.wide { width: 100%; }
.btn svg { width: 18px; height: 18px; }
.inp {
  width: 100%; min-height: 44px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--paper); outline: none;
}
.inp:focus { border-color: var(--acc); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 7px 14px; border-radius: 99px; border: 1px solid var(--line); background: var(--paper);
  font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.chip.on { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.empty { text-align: center; padding: 48px 16px; color: var(--ink2); }
.empty svg { width: 40px; height: 40px; opacity: .5; margin-bottom: 8px; }

/* ---------- konyvtar */
.cont {
  display: flex; gap: 14px; align-items: center; padding: 14px; border-radius: var(--r);
  background: var(--paper); box-shadow: var(--shadow); text-decoration: none; margin-top: 8px;
}
.cont .cv { width: 62px; flex: none; }
.cont .ci { flex: 1; min-width: 0; }
.cont .ci small { color: var(--acc); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
.cont .ci b { display: block; font: 600 17px/1.3 var(--serif); margin: 2px 0; }
.cont .ci span { color: var(--ink2); font-size: 13px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.prog { height: 4px; border-radius: 4px; background: var(--line); overflow: hidden; margin-top: 8px; }
.prog i { display: block; height: 100%; background: var(--acc); border-radius: 4px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 18px 14px; }
.bk { text-decoration: none; display: block; }
.cv {
  position: relative; aspect-ratio: 2 / 3; border-radius: 6px 10px 10px 6px; overflow: hidden;
  padding: 12% 10% 10% 16%; display: flex; flex-direction: column; justify-content: space-between;
  color: #fff; box-shadow: var(--shadow), inset 4px 0 0 rgba(0,0,0,.18), inset 7px 0 0 rgba(255,255,255,.08);
}
.cv::after { content: ''; position: absolute; inset: 0; background: linear-gradient(160deg, rgba(255,255,255,.14), transparent 45%, rgba(0,0,0,.18)); pointer-events: none; }
.cv .ct { font: 600 15px/1.18 var(--serif); letter-spacing: -.005em; text-wrap: balance; }
.cv .ca { font-size: 10.5px; opacity: .85; letter-spacing: .04em; text-transform: uppercase; }
.cv .rule { width: 26px; height: 2px; background: currentColor; opacity: .6; margin: 10px 0; }
.cont .cv { padding: 10% 8% 8% 14%; }
.cont .cv .ct { font-size: 8px; }
.cont .cv .ca, .cont .cv .rule { display: none; }
.bk .meta { padding: 8px 2px 0; }
.bk .meta b { display: block; font: 600 14px/1.3 var(--sans); }
.bk .meta span { display: block; font-size: 12.5px; color: var(--ink2); line-height: 1.35; margin-top: 2px; }
.lv { display: inline-block; font: 700 10px/1 var(--sans); letter-spacing: .05em; padding: 4px 6px; border-radius: 6px; background: var(--acc-soft); color: var(--acc); margin-right: 6px; vertical-align: 1px; }
.bk .prog { margin-top: 6px; }
.lvh { display: flex; align-items: baseline; gap: 10px; margin: 30px 0 14px; }
.lvh h2 { font: 600 20px var(--serif); margin: 0; }
.lvh span { color: var(--ink2); font-size: 13px; }
.res { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.res > div { flex: 1; min-width: 0; }
.res b { display: block; font-weight: 600; }
.res span { color: var(--ink2); font-size: 13px; }
.res select { min-height: 38px; border-radius: 10px; border: 1px solid var(--line); background: var(--paper); padding: 0 6px; }

/* ---------- olvaso */
#reader { padding: 8px 22px 40px; font: 400 var(--fs)/1.7 var(--serif); background: var(--bg); }
#reader h2 { font: 600 calc(var(--fs) * 1.15)/1.3 var(--serif); margin: 26px 0 26px; text-align: center; letter-spacing: .01em; }
#reader p { margin: 0 0 .95em; text-align: left; hyphens: auto; -webkit-hyphens: auto; }
#reader w { cursor: pointer; border-radius: 3px; transition: background .12s; }
#reader w.k { text-decoration: underline; text-decoration-color: var(--saved); text-decoration-thickness: 2px; text-underline-offset: 4px; text-decoration-style: dotted; }
#reader w.sel { background: var(--mark); box-shadow: 0 0 0 2px var(--mark); }
#reader .s.cur { background: color-mix(in srgb, var(--mark) 45%, transparent); border-radius: 3px; }
#reader .s.spk { background: color-mix(in srgb, var(--saved-soft) 90%, transparent); border-radius: 3px; box-shadow: 0 0 0 2px color-mix(in srgb, var(--saved-soft) 90%, transparent); }
.chnav { display: flex; gap: 10px; justify-content: space-between; margin: 30px 0 8px; font-family: var(--sans); }
.chnav .btn { flex: 1; }
.loading { padding: 80px 20px; text-align: center; color: var(--ink2); }
.spinner { width: 28px; height: 28px; margin: 0 auto 14px; border: 3px solid var(--line); border-top-color: var(--acc); border-radius: 50%; animation: spin .8s linear infinite; }

#rfoot {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  padding: 8px 16px calc(8px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--ink2);
}
#rfoot .prog { flex: 1; margin: 0; }
#rfoot .ib { width: 36px; height: 36px; }

/* ---------- fejezetlista */
.chl { list-style: none; margin: 0; padding: 0; }
.chl li a { display: flex; justify-content: space-between; gap: 12px; padding: 12px 4px; border-bottom: 1px solid var(--line); text-decoration: none; font-size: 14px; }
.chl li a.on { color: var(--acc); font-weight: 600; }
.chl li a span { color: var(--ink2); font-size: 12px; flex: none; }

/* ---------- szokartya (also lap) */
#sheetBg { position: fixed; inset: 0; z-index: 40; background: rgba(20, 14, 8, .18); }
#sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; max-width: 760px; margin: 0 auto;
  max-height: 72vh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--paper); border-radius: 20px 20px 0 0; box-shadow: 0 -10px 40px rgba(0,0,0,.18);
  padding: 8px 20px calc(20px + env(safe-area-inset-bottom));
  animation: up .2s ease-out;
}
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
#sheet .grab { width: 40px; height: 4px; border-radius: 4px; background: var(--line); margin: 4px auto 12px; }
.wh { display: flex; align-items: center; gap: 10px; }
.wh h3 { font: 600 26px/1.15 var(--serif); margin: 0; }
.wh .ipa { color: var(--ink2); font-size: 15px; }
.wh .sp { margin-left: auto; display: flex; gap: 6px; }
.wh .ib { background: var(--acc-soft); color: var(--acc); }
.trm { font: 600 19px/1.35 var(--sans); margin: 10px 0 4px; }
.base { font-size: 13px; color: var(--ink2); margin: 2px 0 6px; }
.base b { color: var(--ink); }
.dl { margin: 10px 0 0; padding: 0; list-style: none; }
.dl li { padding: 6px 0; font-size: 14px; line-height: 1.45; border-top: 1px dashed var(--line); }
.dl li i { font-style: normal; color: var(--ink2); font-size: 12px; margin-right: 6px; }
details.def { margin-top: 10px; font-size: 14px; }
details.def summary { cursor: pointer; color: var(--ink2); font-size: 13px; font-weight: 600; padding: 4px 0; }
details.def p { margin: 6px 0; }
details.def p em { display: block; color: var(--ink2); font-size: 13px; }
.ctx { margin-top: 14px; padding: 12px 14px; border-radius: 12px; background: var(--bg); font: 15px/1.55 var(--serif); }
.ctx b { background: var(--mark); font-weight: 600; border-radius: 3px; padding: 0 2px; }
.ctx .ctr { font: 14px/1.5 var(--sans); color: var(--ink2); margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); }
.ctx .row { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.ctx .row .btn { min-height: 34px; padding: 0 12px; font-size: 13px; }
.sact { display: flex; gap: 10px; margin-top: 16px; }
.sact .btn { flex: 1; }
.skel { height: 14px; border-radius: 6px; background: linear-gradient(90deg, var(--line), var(--bg), var(--line)); background-size: 200% 100%; animation: sk 1.2s infinite; margin: 10px 0; }
@keyframes sk { to { background-position: -200% 0; } }

/* ---------- szotar */
.wl { list-style: none; margin: 0; padding: 0; }
.wl li { display: flex; gap: 10px; padding: 14px 0; border-bottom: 1px solid var(--line); align-items: flex-start; }
.wl li > div { flex: 1; min-width: 0; }
.wl .w1 { font: 600 18px/1.3 var(--serif); }
.wl .w1 span { font: 400 13px var(--sans); color: var(--ink2); margin-left: 6px; }
.wl .w2 { font-size: 14.5px; margin-top: 1px; }
.wl .w3 { font: italic 13.5px/1.45 var(--serif); color: var(--ink2); margin-top: 5px; }
.wl .w3 b { font-style: normal; color: var(--ink); }
.wl .w4 { font-size: 11.5px; color: var(--ink2); margin-top: 3px; }
.wl li.kn { opacity: .55; }
.wl .acts { display: flex; flex-direction: column; gap: 2px; }
.wl .acts .ib { width: 36px; height: 36px; }
.wl .acts .ib.ck.on { background: var(--saved-soft); color: var(--saved); }
.tools { display: flex; gap: 10px; align-items: center; margin: 12px 0 4px; }
.tools .inp { flex: 1; }

/* ---------- modal */
#modal { position: fixed; inset: 0; z-index: 60; background: rgba(20, 14, 8, .4); display: grid; place-items: center; padding: 16px; }
#modal .card { width: 100%; max-width: 420px; max-height: 90vh; overflow-y: auto; background: var(--paper); border-radius: 18px; padding: 22px; box-shadow: var(--shadow); }
#modal h2 { font: 600 21px var(--serif); margin: 0 0 6px; }
.stack > * + * { margin-top: 12px; }
.fb.bad { color: #b3261e; font-size: 13px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.field select { width: 100%; min-height: 42px; border-radius: 12px; border: 1px solid var(--line); background: var(--paper); padding: 0 10px; }
.field input[type=range] { width: 100%; accent-color: var(--acc); }
.seg { display: flex; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.seg button { flex: 1; border: 0; background: var(--paper); padding: 10px 4px; cursor: pointer; font-size: 13px; font-weight: 600; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--ink); color: var(--paper); }
.mfoot { display: flex; gap: 10px; margin-top: 18px; }
.mfoot .btn { flex: 1; }

#toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 70;
  background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 12px; font-size: 14px; box-shadow: var(--shadow);
  max-width: calc(100vw - 32px);
}

@media (min-width: 700px) {
  #reader { padding: 8px 48px 40px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
}
