:root {
  --ink: #44374f;
  --muted: #88778d;
  --gold: #b58a48;
  --gold-deep: #a27c40;
  --gold-soft: #c5a065;
  --cream: #fcf7ef;
  --paper: #fffaf2;
  --bg: #f8f2ea;
  --purple: #635071;
  --purple-soft: #eee3e4;
  --line: #e4d8cc;
  --shadow: 0 18px 40px rgba(88, 64, 77, .16);
  --serif: Georgia, "Times New Roman", serif;
  --sans: Arial, Helvetica, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: var(--serif);
  -webkit-tap-highlight-color: transparent;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; }
button:disabled { opacity: .35; cursor: default; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }
img { max-width: 100%; display: block; }

.eyebrow {
  letter-spacing: 3px; color: var(--gold-deep);
  font-family: var(--sans); font-size: 11px; font-weight: 700; margin: 0 0 14px;
}

/* ================= ВХІД ================= */
.entrance { position: relative; min-height: 100svh; background: #f9f3ec; overflow: hidden; }
.scene { position: absolute; inset: 0; opacity: .55; background: url(media/scene.jpg) bottom / cover no-repeat; }
.mist { position: absolute; inset: 0; background: linear-gradient(90deg, #fdf6eb26, #fdf6ebe0 57%, #fcf7f0 94%); }
.brand {
  position: relative; display: flex; align-items: center; gap: 18px;
  padding: 28px 5vw; font-size: 11px; letter-spacing: 2.4px;
}
.brand-star { color: #a57c35; font-size: 30px; }
.brand-line { width: 1px; height: 20px; background: #bea981; }
.welcome {
  position: relative; display: grid; grid-template-columns: 1fr 1fr; align-items: center;
  gap: 60px; max-width: 1240px; margin: 0 auto; padding: 10px 60px 50px;
}
.book-display { position: relative; text-align: center; padding: 20px 30px; }
@media (max-width: 900px) { .book-display .halo { border: 0; } }
.halo { position: absolute; inset: 0; border: 1px solid #c6ab7555; border-radius: 50%; transform: scale(.95); }
.halo::before { content: "✧"; position: absolute; top: 0; right: 30px; color: var(--gold-soft); font-size: 44px; }
.cover {
  position: relative; z-index: 1; width: 90%; max-width: 340px; margin: 0 auto;
  border-radius: 3px 10px 10px 3px;
  transform: perspective(1200px) rotateY(-14deg) rotate(-4deg);
  box-shadow: -12px 7px 0 #665071, -16px 9px 0 #b79468, 22px 30px 48px #58404d55;
  animation: float 7s ease-in-out infinite;
}
@keyframes float {
  50% { transform: perspective(1200px) rotateY(-10deg) rotate(-3deg) translateY(-8px); }
}
.cover-caption { margin: 44px 0 0; color: #6b5471; font-size: 17px; font-style: italic; }
.gate { max-width: 470px; }
.gate h1 { margin: 0 0 22px; font-size: clamp(38px, 5vw, 58px); font-weight: 400; line-height: 1.08; color: var(--purple); }
.gate h1 em { color: #947257; }
.lead { color: #796778; font-size: 18px; line-height: 1.6; margin: 0 0 26px; }
.key-label { display: block; font-family: var(--sans); font-size: 13px; font-weight: 700; color: #61506c; margin-bottom: 9px; }
.key-field {
  display: flex; align-items: center; gap: 10px; padding: 0 14px;
  background: #fffaf0; border: 1px solid #d7c5a8; border-radius: 6px; height: 54px;
}
.key-icon { color: var(--gold); }
.key-field input { flex: 1; min-width: 0; border: 0; background: transparent; outline: 0; font-family: var(--sans); font-size: 15px; }
.key-toggle { font-family: var(--sans); font-size: 12px; color: #99899a; }
.key-error { min-height: 20px; margin: 8px 0 4px; color: #9d433d; font-family: var(--sans); font-size: 13px; }
.open-btn {
  display: flex; justify-content: space-between; align-items: center; width: 100%; height: 56px;
  padding: 0 22px; border-radius: 6px; background: var(--purple); color: #fff8ed;
  font-size: 17px; box-shadow: 0 10px 24px #63507144; transition: transform .2s, background .2s;
}
.open-btn:hover { background: #564563; transform: translateY(-1px); }
.hint { margin: 14px 0 26px; font-family: var(--sans); font-size: 12px; color: #9e8e92; }
.perks { list-style: none; display: flex; flex-wrap: wrap; gap: 8px 22px; padding: 18px 0 0; margin: 0; border-top: 1px solid #e0d6cf; font-family: var(--sans); font-size: 12px; color: #88748a; }
.perks li { color: #88748a; }
.buy-hint { margin: -2px 0 10px; font-family: var(--sans); font-size: 13px; color: #796778; }
.buy-hint a { color: var(--gold-deep); font-weight: 700; }
.buy-box {
  margin-top: 22px; padding: 18px 18px 16px;
  background: #fffaf0d9; border: 1px solid #e4c48e; border-radius: 10px;
}
.buy-title { margin: 0 0 4px; font-size: 18px; color: var(--purple); }
.buy-text { margin: 0 0 14px; font-family: var(--sans); font-size: 12.5px; line-height: 1.55; color: #88748a; }
.buy-actions { display: flex; gap: 10px; }
.buy-btn, .preview-btn {
  flex: 1; text-align: center; padding: 12px 12px; border-radius: 6px; text-decoration: none;
  font-family: var(--sans); font-size: 13px; font-weight: 700;
}
.buy-btn { background: linear-gradient(#c9a462, #a57c35); color: #fffaf0; box-shadow: 0 6px 16px #a57c3544; }
.preview-btn { background: #fff; color: var(--purple); border: 1px solid #cbb99e; }
.preview-btn:hover { background: #fcf4ea; }
@media (max-width: 480px) { .buy-box { text-align: center; } .buy-actions { flex-direction: column; } }

/* ================= ВЕРХНЯ ПАНЕЛЬ ================= */
.app { min-height: 100svh; display: flex; flex-direction: column; background: linear-gradient(#f9f3ec, #efe4e6); }
.topbar {
  position: sticky; top: 0; z-index: 20; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: 12px 32px; background: #fcf7f0f0; border-bottom: 1px solid var(--line); backdrop-filter: blur(6px);
}
.logo { display: flex; align-items: center; gap: 14px; }
.logo-star { color: var(--gold); font-size: 30px; }
.logo-title { letter-spacing: 2.6px; font-size: 16px; color: var(--purple); }
.logo-sub { letter-spacing: 2.6px; font-size: 9.5px; color: var(--muted); font-family: var(--sans); margin-top: 3px; }
.tabs { display: flex; gap: 6px; }
.tab { padding: 8px 12px; border-radius: 6px; font-family: var(--sans); font-size: 13px; color: #75607e; border: 1px solid transparent; }
.tab.active { background: #e8dfe6; border-color: #d3c3d3; color: var(--purple); }
.logout { justify-self: end; font-family: var(--sans); font-size: 14px; }

.view { flex: 1; }

/* ================= КНИГА ================= */
.view-book { display: flex; flex-direction: column; padding: 20px 20px 0; }
.mobile-title { display: none; }
.zoom-tool { white-space: nowrap; }
.reader { flex: 1; display: grid; grid-template-columns: 50px 1fr 50px 158px; align-items: center; gap: 12px; min-height: 0; }
.stage { position: relative; height: calc(100svh - 170px); min-height: 360px; display: flex; align-items: center; justify-content: center; touch-action: pan-y; }
.spread { position: relative; display: flex; height: 100%; max-width: 100%; align-items: center; justify-content: center; }
.page {
  position: relative; height: 100%; aspect-ratio: 516 / 728.6; max-width: 50%;
  background: #fff; box-shadow: var(--shadow); overflow: hidden;
}
.spread.single .page { max-width: 100%; border-radius: 4px; }
.spread:not(.single) .page.left { border-radius: 4px 0 0 4px; }
.spread:not(.single) .page.right { border-radius: 0 4px 4px 0; }
.spread:not(.single) .page.left::after {
  content: ""; position: absolute; inset: 0 0 0 auto; width: 26px;
  background: linear-gradient(90deg, transparent, rgba(68, 55, 79, .14));
}
.spread:not(.single) .page.right::after {
  content: ""; position: absolute; inset: 0 auto 0 0; width: 26px;
  background: linear-gradient(-90deg, transparent, rgba(68, 55, 79, .12));
}
.page img { width: 100%; height: 100%; object-fit: contain; user-select: none; -webkit-user-drag: none; }
.page.blank { background: transparent; box-shadow: none; }
.page .mark-ribbon {
  position: absolute; top: -4px; right: 18px; width: 18px; height: 42px; background: var(--gold);
  clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 78%, 0 100%);
}
.spread.turn-next { animation: turnNext .35s ease; }
.spread.turn-prev { animation: turnPrev .35s ease; }
@keyframes turnNext { from { opacity: .3; transform: translateX(26px); } }
@keyframes turnPrev { from { opacity: .3; transform: translateX(-26px); } }

.arrow {
  width: 46px; height: 46px; border-radius: 50%; background: var(--paper); border: 1px solid #d7c5ae;
  font-size: 26px; line-height: 1; color: #836c4e; box-shadow: 0 4px 12px #58404d22;
}
.tools { display: flex; flex-direction: column; gap: 12px; }
.tools > button, .zoom-tool {
  display: flex; align-items: center; gap: 6px; min-height: 48px; padding: 8px 12px; text-align: left;
  font-family: var(--sans); font-size: 13px; background: #fff9f1; border: 1px solid #e8e0dc; border-radius: 8px;
  box-shadow: 0 2px 8px #58404d10;
}
.tools > button { display: block; }
.zoom-tool button { padding: 2px 6px; font-weight: 700; }

.progress {
  display: grid; grid-template-columns: 110px 1fr 50px 180px; align-items: center; gap: 16px;
  padding: 12px 16px calc(14px + var(--safe-b)); font-family: var(--sans); font-size: 13px; color: #61506c;
}
.progress-hint { font-size: 10.5px; color: var(--muted); text-align: center; }
input[type=range] { width: 100%; accent-color: #a18e9e; }
#slider { -webkit-appearance: none; appearance: none; height: 3px; background: #e8dfe6; border-radius: 3px; }
#slider::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; border-radius: 50%; background: #c5a065; border: 3px solid #fff9f1; box-shadow: 0 0 0 1px #a57c35; }
#slider::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: #c5a065; border: 3px solid #fff9f1; }

/* ================= СПИСКИ ================= */
.view-list { padding: 40px 24px 120px; }
.list-head { text-align: center; max-width: 760px; margin: 0 auto 36px; }
.list-head h2 { font-size: clamp(30px, 4vw, 42px); font-weight: 400; color: var(--ink); margin: 0 0 14px; }
.back-link { color: #9c7b57; border-bottom: 1px solid #cbb68c; padding: 4px 2px; margin-bottom: 18px; font-size: 15px; }
.meta { font-family: var(--sans); font-size: 12px; color: var(--muted); margin: 18px 0 0; }
.grid { display: grid; gap: 24px; max-width: 1120px; margin: 0 auto; }
.coloring-grid { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.audio-grid { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }

.card { background: var(--paper); border: 1px solid #ece2da; border-radius: 14px; box-shadow: 0 10px 28px #58404d14; overflow: hidden; }
.col-img { background: #fff; padding: 16px; cursor: zoom-in; }
.col-img img { aspect-ratio: 3 / 4; object-fit: contain; width: 100%; }
.card-body { padding: 16px 18px 18px; }
.col-title { font-size: 18px; margin: 0 0 4px; }
.col-meta { font-family: var(--sans); font-size: 12px; color: var(--muted); margin: 0 0 14px; }
.dl {
  display: inline-flex; align-items: center; gap: 6px; padding: 9px 16px; border-radius: 6px;
  background: var(--purple); color: #fff8ed; text-decoration: none; font-family: var(--sans); font-size: 13px;
}

.audio-cards { display: flex; justify-content: center; gap: 12px; padding: 22px 18px 18px; background: linear-gradient(#fffaf2, #f6ede3); }
.audio-cards img { width: 44%; max-width: 190px; aspect-ratio: 360 / 549; object-fit: cover; border-radius: 16px; border: 4px solid #fff; box-shadow: 0 6px 16px #58404d30; }
.audio-cards img:first-child { transform: rotate(-3deg); }
.audio-cards img:last-child { transform: rotate(3deg); }
.audio-top { display: flex; justify-content: space-between; font-family: var(--sans); font-size: 12px; color: var(--muted); }
.audio-title { font-size: 22px; font-weight: 400; margin: 10px 0 14px; line-height: 1.25; }
.audio-links { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.audio-links button { font-family: var(--sans); font-size: 12px; padding: 7px 10px; border: 1px solid #e0d6cf; border-radius: 6px; background: #fff; }
.listen {
  width: 100%; display: flex; align-items: center; gap: 10px; padding: 13px 16px; border-radius: 8px;
  background: var(--purple); color: #fff8ed; font-size: 15px;
}
.listen.playing { background: #8f7994; }
.soon { text-align: center; margin: 56px auto 0; color: #796778; }
.soon-star { color: var(--gold-soft); font-size: 30px; }
.soon h3 { font-weight: 400; font-size: 22px; color: var(--ink); margin: 8px 0; }

/* ================= ПЛЕЄР ================= */
.player {
  position: fixed; left: 50%; bottom: calc(14px + var(--safe-b)); transform: translateX(-50%); z-index: 30;
  width: min(560px, calc(100% - 24px)); display: flex; align-items: center; gap: 12px; padding: 10px 14px;
  background: #fff9f1; border: 1px solid #e0d6cf; border-radius: 14px; box-shadow: 0 16px 36px #58404d33;
}
.player-btn { width: 42px; height: 42px; flex: none; border-radius: 50%; background: var(--purple); color: #fff; font-size: 13px; }
.player-info { flex: 1; min-width: 0; }
.player-title { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-bar { display: flex; align-items: center; gap: 8px; font-family: var(--sans); font-size: 11px; color: var(--muted); }
.player-close { font-size: 24px; color: var(--muted); padding: 0 4px; }
.app.has-player .view-book .progress { padding-bottom: calc(86px + var(--safe-b)); }

/* ================= ПАНЕЛЬ ================= */
.drawer-backdrop { position: fixed; inset: 0; z-index: 40; background: #44374f55; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 41; width: min(470px, 100%);
  background: var(--paper); box-shadow: -20px 0 50px #44374f33; display: flex; flex-direction: column;
  transform: translateX(105%); transition: transform .3s ease;
}
.drawer.open { transform: none; }
.drawer-head { display: flex; justify-content: space-between; align-items: center; padding: 26px 28px 8px; }
.drawer-head h3 { margin: 0; font-weight: 400; font-size: 27px; }
.drawer-close { font-size: 30px; color: var(--ink); }
.drawer-body { flex: 1; overflow-y: auto; padding: 8px 28px 40px; }
.drawer-note { font-family: var(--sans); font-size: 12px; color: var(--muted); margin: 0 0 14px; }
.search { width: 100%; padding: 12px 14px; border: 1px solid #d7c5ae; border-radius: 6px; background: #fff; font-family: var(--sans); font-size: 14px; margin-bottom: 14px; }
.toc-item {
  width: 100%; display: flex; justify-content: space-between; gap: 14px; text-align: left;
  padding: 13px 4px; border-bottom: 1px solid #eee3d6; font-size: 16px; line-height: 1.35;
}
.toc-item .num { color: var(--muted); flex: none; }
.toc-item.author { background: #f5ebe0; color: #9c7b57; padding-left: 12px; padding-right: 12px; margin-top: 10px; border-radius: 4px; }
.toc-item.sub { font-family: var(--sans); font-size: 12px; color: var(--muted); padding: 8px 4px 8px 22px; }
.toc-item.current { background: #efe4ec; }
.empty { color: var(--muted); font-style: italic; padding: 20px 0; }
.mark-row { display: flex; align-items: center; gap: 10px; border-bottom: 1px solid #eee3d6; }
.mark-row .toc-item { border: 0; flex: 1; }
.remove { color: #983c38; font-family: var(--sans); font-size: 12px; padding: 6px; }
.note-box textarea {
  width: 100%; min-height: 140px; padding: 12px; border: 1px solid #d7c5ae; border-radius: 6px; background: #fff;
  font-family: var(--serif); font-size: 16px; line-height: 1.5; resize: vertical;
}
.note-box h4 { margin: 0 0 8px; font-weight: 400; font-size: 17px; }
.note-saved { font-family: var(--sans); font-size: 11px; color: var(--muted); height: 16px; margin: 4px 0 18px; }
.note-item { padding: 12px 0; border-bottom: 1px solid #eee3d6; }
.note-item button { font-family: var(--sans); font-size: 12px; color: #9c7b57; padding: 0; margin-bottom: 4px; }
.note-item p { margin: 0; white-space: pre-wrap; font-size: 15px; color: #61506c; }
.goto-form { display: flex; gap: 10px; }
.goto-form input { flex: 1; padding: 12px; border: 1px solid #d7c5ae; border-radius: 6px; font-family: var(--sans); }
.goto-form button { padding: 0 18px; border-radius: 6px; background: var(--purple); color: #fff; }

/* ================= ЗБІЛЬШЕННЯ ================= */
.zoom-overlay { position: fixed; inset: 0; z-index: 50; background: #2e2535ee; display: flex; flex-direction: column; }
.zoom-scroll { flex: 1; overflow: auto; -webkit-overflow-scrolling: touch; }
.zoom-scroll img { margin: 20px auto; max-width: none; background: #fff; }
.zoom-scroll.fit { display: flex; align-items: center; justify-content: center; padding: 16px; }
.zoom-scroll.fit img { max-width: 100%; max-height: 100%; margin: 0; object-fit: contain; }
.zoom-bar { display: flex; justify-content: center; align-items: center; gap: 12px; padding: 12px 12px calc(12px + var(--safe-b)); background: #fff9f1; font-family: var(--sans); }
.zoom-bar button { padding: 9px 16px; border: 1px solid #e0d6cf; border-radius: 6px; background: #fff; }

.toast {
  position: fixed; left: 50%; bottom: 100px; z-index: 60; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  padding: 10px 18px; border-radius: 30px; background: var(--purple); color: #fff8ed; font-family: var(--sans); font-size: 13px;
  transition: .25s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ================= ТЕЛЕФОН ================= */
@media (max-width: 900px) {
  .welcome { grid-template-columns: 1fr; gap: 18px; padding: 0 22px 40px; }
  .brand { padding: 18px 22px; font-size: 10px; gap: 12px; }
  .book-display { padding: 10px 40px 0; }
  .cover { max-width: 230px; }
  .cover-caption { margin-top: 26px; font-size: 15px; }
  .gate { margin: 0 auto; }
  .lead { font-size: 16px; }
  .mist { background: linear-gradient(#fdf6eb40, #fdf6ebe8 45%, #fcf7f0 75%); }

  .topbar { grid-template-columns: 1fr auto; padding: 10px 14px 0; gap: 8px; }
  .logo-star { font-size: 22px; }
  .logo-title { font-size: 12px; letter-spacing: 1.8px; }
  .logo-sub { font-size: 7.5px; }
  .tabs { grid-column: 1 / -1; grid-row: 2; display: grid; grid-template-columns: repeat(3, 1fr); padding-bottom: 10px; }
  .tab { font-size: 12px; padding: 9px 4px; }

  .view-book { padding: 10px 10px 0; }
  .mobile-title { display: block; text-align: center; font-weight: 400; font-size: 21px; margin: 4px 0 10px; }
  .reader { grid-template-columns: 1fr; position: relative; }
  .tools { order: -1; flex-direction: row; flex-wrap: wrap; justify-content: center; gap: 6px; }
  .tools > button, .zoom-tool { min-height: 34px; padding: 6px 9px; font-size: 11.5px; }
  .stage { height: calc(100svh - 300px); min-height: 300px; }
  .arrow { position: absolute; top: 58%; z-index: 3; width: 34px; height: 34px; font-size: 20px; }
  .arrow.prev { left: -2px; }
  .arrow.next { right: -2px; }
  .progress { grid-template-columns: auto 1fr auto; gap: 10px; font-size: 11.5px; padding-top: 10px; }
  .progress-hint { grid-column: 1 / -1; font-size: 10px; margin-top: -4px; }

  .view-list { padding: 26px 14px 120px; }
  .coloring-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
  .col-img { padding: 8px; }
  .card-body { padding: 12px; }
  .col-title { font-size: 15px; }
  .dl { padding: 8px 10px; font-size: 12px; }
  .audio-grid { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
