/* Читка. Тема задаётся на <html data-theme>, всё остальное живёт на переменных. */

:root {
  --ruby: #A81E37;
  --ruby-soft: rgba(168, 30, 55, 0.12);
  --ui: 'Golos Text', system-ui, -apple-system, sans-serif;
  --read: 'Literata', Georgia, serif;
  --mono: 'IBM Plex Mono', ui-monospace, monospace;
  --radius: 14px;
  --pad: clamp(16px, 4vw, 32px);
  --reading-size: 1;
}

[data-theme='day'] {
  --bg: #F6F5F2;
  --surface: #FFFFFF;
  --fg: #1A1917;
  --dim: #6E6B65;
  --line: rgba(26, 25, 23, 0.12);
  --shadow: 0 8px 30px rgba(26, 25, 23, 0.09);
}

[data-theme='sepia'] {
  --bg: #EFE3CB;
  --surface: #F6EDDB;
  --fg: #3B2E20;
  --dim: #7A6852;
  --line: rgba(59, 46, 32, 0.16);
  --shadow: 0 8px 30px rgba(59, 46, 32, 0.12);
}

[data-theme='night'] {
  --ruby: #E4536D;
  --ruby-soft: rgba(228, 83, 109, 0.16);
  --bg: #14161A;
  --surface: #1C1F25;
  --fg: #E8E6E1;
  --dim: #8C8A85;
  --line: rgba(232, 230, 225, 0.13);
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--ui);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  transition: background .35s, color .35s;
}

button, input { font: inherit; color: inherit; }
button { background: none; border: none; cursor: pointer; }
:focus-visible { outline: 2px solid var(--ruby); outline-offset: 3px; border-radius: 6px; }

.screen { display: none; height: 100dvh; flex-direction: column; }
.screen.on { display: flex; }

/* ---------------------------------------------------------------- знак */

.mark { display: flex; align-items: center; gap: 9px; }
.mark svg { width: 26px; height: 26px; display: block; flex: none; }
.mark b { font-size: 18px; font-weight: 600; letter-spacing: -.02em; }

/* ---------------------------------------------------------------- шапка */

.top {
  display: flex; align-items: center; gap: 12px;
  padding: 14px var(--pad); border-bottom: 1px solid var(--line); flex: none;
}
.top .grow { flex: 1; }

.chip {
  padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line);
  font-size: 13px; color: var(--dim); white-space: nowrap;
  transition: border-color .2s, color .2s;
}
.chip:hover { border-color: var(--fg); color: var(--fg); }
.chip.solid { background: var(--ruby); border-color: var(--ruby); color: #fff; }
.chip.solid:hover { opacity: .9; color: #fff; }

/* ---------------------------------------------------------------- каталог */

.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.wrap { max-width: 940px; margin: 0 auto; padding: var(--pad); }

.hero { padding: clamp(20px, 5vw, 44px) 0 clamp(16px, 3vw, 28px); }
.hero h1 {
  font-family: var(--read); font-weight: 600;
  font-size: clamp(28px, 5.2vw, 46px); line-height: 1.08; letter-spacing: -.02em;
}
.hero p { color: var(--dim); margin-top: 12px; max-width: 46ch; }

.resume {
  display: flex; align-items: center; gap: 14px; margin: 22px 0 8px;
  padding: 16px 18px; border-radius: var(--radius);
  background: var(--ruby-soft); border: 1px solid transparent;
  cursor: pointer; text-align: left; width: 100%;
}
.resume:hover { border-color: var(--ruby); }
.resume .bar { flex: 1; }
.resume b { display: block; font-size: 15px; }
.resume span { font-size: 13px; color: var(--dim); }
.resume .pc { font-family: var(--mono); font-size: 13px; color: var(--ruby); }

.sect { display: flex; align-items: baseline; gap: 12px; margin: 30px 0 14px; }
.sect h2 { font-size: 15px; font-weight: 600; }
.sect i { flex: 1; height: 1px; background: var(--line); }
.sect em { font-style: normal; font-family: var(--mono); font-size: 12px; color: var(--dim); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; }

.book {
  display: flex; flex-direction: column; text-align: left;
  padding: 18px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line);
  transition: transform .25s cubic-bezier(.2,.8,.2,1), border-color .25s;
  min-height: 132px; cursor: pointer;
}
.book:hover { transform: translateY(-3px); border-color: var(--ruby); }
.book .author { font-size: 12px; color: var(--dim); letter-spacing: .02em; }
.book .title {
  font-family: var(--read); font-size: 19px; line-height: 1.2;
  margin: 6px 0 auto; letter-spacing: -.01em;
}
.book .meta { font-family: var(--mono); font-size: 11px; color: var(--dim); margin-top: 14px; }
.book.locked .title::after { content: ' 🔒'; font-size: 13px; }

.book.upload { border-style: dashed; justify-content: center; align-items: center; text-align: center; }
.book.upload .title { margin: 0; }
.book.upload .author { margin-top: 6px; }

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

.reader-top {
  display: flex; align-items: center; gap: 10px;
  padding: 10px var(--pad); border-bottom: 1px solid var(--line); flex: none;
}
.reader-top .who { flex: 1; min-width: 0; }
.reader-top .who b { display: block; font-size: 14px; font-weight: 500; }
.reader-top .who span {
  display: block; font-size: 12px; color: var(--dim);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.icon { padding: 8px 10px; border-radius: 10px; font-size: 13px; color: var(--dim); }
.icon:hover { background: var(--ruby-soft); color: var(--fg); }
.icon.on { color: var(--ruby); }

.stage { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.view { flex: 1; position: relative; overflow: hidden; min-height: 0; }
.view.split { flex: none; height: 46%; }

.pane { position: absolute; inset: 0; display: none; }
.pane.on { display: flex; }

/* режим слов */
#pane-word { flex-direction: column; align-items: center; justify-content: center; padding: 0 16px; }
.rail { width: min(700px, 100%); height: 1px; background: var(--line); position: relative; }
.rail::before, .rail::after {
  content: ''; position: absolute; left: 50%; transform: translateX(-50%);
  border-left: 5px solid transparent; border-right: 5px solid transparent;
}
.rail::before { top: -9px; border-top: 7px solid var(--ruby); }
.rail::after { bottom: -9px; border-bottom: 7px solid var(--ruby); }
.word {
  display: flex; white-space: pre; padding: 16px 0;
  font-family: var(--read);
  font-size: calc(clamp(30px, 6.4vw, 58px) * var(--reading-size));
  line-height: 1.25;
}
.word .l { flex: 1 1 0; text-align: right; }
.word .r { flex: 1 1 0; text-align: left; }
.word .pivot { color: var(--ruby); }
.echo {
  font-family: var(--read); font-size: 14px; color: var(--dim);
  margin-top: 22px; max-width: 620px; text-align: center; line-height: 1.7; opacity: .8;
}

/* режим фраз */
#pane-phrase { flex-direction: column; align-items: center; justify-content: center; padding: 0 22px; }
.phrase {
  font-family: var(--read);
  font-size: calc(clamp(20px, 3.2vw, 32px) * var(--reading-size));
  line-height: 1.45; max-width: 24em;
  border-left: 3px solid var(--ruby); padding: 8px 0 8px 20px;
}
.phrase.empty { color: var(--dim); border-color: var(--line); }

/* бегущая строка */
#pane-line { align-items: center; overflow: hidden; }
.strip {
  white-space: nowrap; font-family: var(--read);
  font-size: calc(clamp(24px, 4.6vw, 46px) * var(--reading-size));
  padding-left: 100%; will-change: transform;
}
.veil {
  position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(90deg, var(--bg), transparent 12%, transparent 88%, var(--bg));
}

/* прокрутка */
#pane-scroll { display: none; }
#pane-scroll.on { display: block; }
.column {
  font-family: var(--read);
  font-size: calc(clamp(17px, 2.1vw, 20px) * var(--reading-size));
  line-height: 1.9; max-width: 640px; margin: 0 auto; padding: 0 20px; will-change: transform;
}
.column p { margin-bottom: 1.15em; }
.focus-band {
  position: absolute; left: 0; right: 0; top: 38%; height: 3em;
  background: var(--ruby-soft); border-top: 1px solid var(--ruby); border-bottom: 1px solid var(--ruby);
  opacity: .5; pointer-events: none;
}
.column-fade {
  position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(180deg, var(--bg), transparent 20%, transparent 80%, var(--bg));
}

/* фоновая заставка */
.loop { flex: 1; position: relative; display: none; border-top: 1px solid var(--line); background: #0A0B0D; min-height: 0; }
.loop.on { display: block; }
.loop canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.loop .picker { position: absolute; left: 10px; bottom: 10px; display: flex; gap: 4px; z-index: 2; }
.loop .picker button {
  font-family: var(--mono); font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em;
  padding: 6px 10px; border-radius: 8px;
  background: rgba(0,0,0,.55); color: rgba(255,255,255,.65); backdrop-filter: blur(6px);
}
.loop .picker button.on { background: var(--ruby); color: #fff; }

/* панель управления */
.controls {
  flex: none; border-top: 1px solid var(--line);
  padding: 12px var(--pad) calc(12px + env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: 16px;
}
.play {
  width: 48px; height: 48px; border-radius: 50%; flex: none;
  background: var(--ruby); color: #fff; display: grid; place-items: center; font-size: 15px;
  transition: transform .18s;
}
.play:active { transform: scale(.94); }
.meter { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.meter .row {
  display: flex; justify-content: space-between; gap: 10px;
  font-family: var(--mono); font-size: 11px; color: var(--dim);
}
.meter .row b { color: var(--fg); font-weight: 500; }

input[type=range] {
  -webkit-appearance: none; appearance: none; width: 100%;
  height: 3px; border-radius: 2px; background: var(--line);
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 18px; height: 18px; border-radius: 50%;
  background: var(--ruby); border: 3px solid var(--bg); cursor: pointer;
}
input[type=range]::-moz-range-thumb {
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--ruby); border: 3px solid var(--bg); cursor: pointer;
}

.progress { position: absolute; left: 0; right: 0; bottom: 0; height: 2px; background: var(--line); z-index: 3; }
.progress i { display: block; height: 100%; background: var(--ruby); width: 0; transition: width .2s linear; }

/* ---------------------------------------------------------------- шторка */

.sheet-bg {
  position: fixed; inset: 0; z-index: 60; background: rgba(0, 0, 0, .45);
  display: none; align-items: flex-end; justify-content: center;
  backdrop-filter: blur(3px);
}
.sheet-bg.on { display: flex; }
.sheet {
  background: var(--surface); width: min(560px, 100%);
  border-radius: 20px 20px 0 0; padding: 22px var(--pad) calc(28px + env(safe-area-inset-bottom));
  max-height: 88dvh; overflow-y: auto; box-shadow: var(--shadow);
}
.sheet h3 { font-size: 17px; margin-bottom: 4px; }
.sheet .lead { font-size: 13.5px; color: var(--dim); margin-bottom: 20px; }

.field { margin-bottom: 18px; }
.field label {
  display: flex; justify-content: space-between;
  font-size: 12.5px; color: var(--dim); margin-bottom: 8px;
}
.field label b { color: var(--fg); font-family: var(--mono); font-weight: 500; }

.segment { display: flex; gap: 3px; padding: 3px; background: var(--bg); border-radius: 11px; }
.segment button {
  flex: 1; padding: 9px 6px; border-radius: 8px; font-size: 13px; color: var(--dim);
  transition: background .2s, color .2s;
}
.segment button.on { background: var(--surface); color: var(--fg); font-weight: 500; box-shadow: var(--shadow); }

input[type=email], input[type=password], input[type=text] {
  width: 100%; padding: 13px 14px; border-radius: 11px;
  background: var(--bg); border: 1px solid var(--line); color: var(--fg);
}
input::placeholder { color: var(--dim); }

.btn {
  width: 100%; padding: 14px; border-radius: 12px; font-size: 15px; font-weight: 500;
  background: var(--ruby); color: #fff; margin-top: 6px;
}
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--fg); }
.note { font-size: 12.5px; color: var(--dim); margin-top: 14px; text-align: center; }
.note a { color: var(--ruby); text-decoration: none; cursor: pointer; }
.msg { font-size: 13px; margin-top: 12px; padding: 11px 13px; border-radius: 10px; background: var(--ruby-soft); }

/* ---------------------------------------------------------------- знакомство */

#screen-intro { align-items: center; justify-content: center; text-align: center; padding: var(--pad); }
.intro-box { max-width: 460px; width: 100%; }
.intro-demo {
  height: 140px; display: flex; align-items: center; justify-content: center;
  margin: 28px 0; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line);
}
.intro-box h2 { font-family: var(--read); font-size: clamp(24px, 5vw, 34px); line-height: 1.15; letter-spacing: -.02em; }
.intro-box p { color: var(--dim); margin-top: 12px; }
.dots { display: flex; gap: 6px; justify-content: center; margin: 22px 0 18px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--line); }
.dots i.on { background: var(--ruby); width: 18px; border-radius: 3px; }

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

.book .cover {
  width: 100%; height: 116px; object-fit: cover;
  border-radius: 8px; margin-bottom: 12px; display: block;
}

.plan {
  width: 100%; display: flex; justify-content: space-between; align-items: center;
  padding: 15px 16px; margin-bottom: 8px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg);
  transition: border-color .2s;
}
.plan:hover { border-color: var(--ruby); }
.plan b { font-size: 15px; }
.plan span { font-family: var(--mono); font-size: 14px; color: var(--ruby); }
#userPlan a, #authMessage a { color: var(--ruby); cursor: pointer; text-decoration: none; }

/* премиум-шторка */
.perks { display: flex; flex-direction: column; gap: 12px; margin-bottom: 16px; }
.perk { padding: 13px 15px; border-radius: 11px; background: var(--bg); border: 1px solid var(--line); }
.perk b { display: block; font-size: 14px; margin-bottom: 2px; }
.perk span { font-size: 13px; color: var(--dim); }
.free-note { font-size: 13px; color: var(--dim); padding: 12px 14px; border-left: 3px solid var(--ruby); margin-bottom: 18px; }
.plangrid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.planbtn { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); transition: border-color .2s; }
.planbtn:hover { border-color: var(--ruby); }
.planbtn b { font-size: 14px; }
.planbtn .rub { font-family: var(--mono); font-size: 16px; color: var(--ruby); }
.planbtn .mo { font-size: 11.5px; color: var(--dim); }

/* статистика в кабинете */
.statbox { margin: 16px 0; padding: 16px; border-radius: 12px; background: var(--bg); border: 1px solid var(--line); }
.statrow { display: flex; align-items: baseline; gap: 10px; margin-bottom: 8px; }
.statrow b { font-family: var(--read); font-size: 22px; }
.statrow span { font-size: 13px; color: var(--dim); }
.chart { display: flex; align-items: flex-end; gap: 3px; height: 44px; margin-top: 12px; }
.chart i { flex: 1; background: var(--ruby); border-radius: 2px 2px 0 0; min-height: 3px; opacity: .8; }

.promo {
  width: 100%; display: flex; align-items: center; gap: 18px; text-align: left;
  padding: 20px 22px; margin: 24px 0 4px; border-radius: var(--radius);
  background: var(--ruby); color: #fff; border: none;
  transition: transform .2s cubic-bezier(.2,.8,.2,1);
}
.promo:hover { transform: translateY(-2px); }
.promo b { display: block; font-size: 16px; margin-bottom: 4px; }
.promo span { font-size: 13.5px; opacity: .85; line-height: 1.5; display: block; }
.promo .arrow { font-size: 13px; white-space: nowrap; opacity: .9; font-family: var(--mono); }
@media (max-width: 600px) { .promo { flex-direction: column; align-items: flex-start; gap: 12px; } }
