:root {
  --ink: #0b1626;
  --card: rgba(12, 20, 34, 0.92);
  --line: rgba(255, 255, 255, 0.1);
  --text: #f2eee6;
  --dim: #a9b1bf;
  --amber: #f2a541;
  --amber-ink: #1d1406;
  --red: #c0453b;
  --paper: #f1e5c8;
  --paper-ink: #3d2b1a;
  --radius: 22px;
  --ui: "Manrope", -apple-system, "Segoe UI", Roboto, sans-serif;
  --serif: "Lora", Georgia, serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--ink);
  color: var(--text);
  font-family: var(--ui);
  -webkit-font-smoothing: antialiased;
}

#app {
  position: relative;
  max-width: 560px;
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
  background: var(--ink);
}

.view { position: absolute; inset: 0; display: flex; flex-direction: column; }

/* ---------- кнопки ---------- */
.btn {
  min-height: 54px;
  padding: 0 20px;
  border-radius: 18px;
  border: 0;
  font: 800 17px/1 var(--ui);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  text-decoration: none;
  transition: transform .1s ease, opacity .2s;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; }
.btn-primary { background: var(--amber); color: var(--amber-ink); }
.btn-ghost { background: rgba(255,255,255,.08); color: var(--text); border: 1px solid var(--line); font-weight: 600; }
.btn-square { width: 54px; flex: 0 0 54px; padding: 0; font-size: 22px; }
.row { display: flex; gap: 12px; }
.row.small .btn { min-height: 44px; font-size: 14px; }

.icon-btn {
  width: 44px; height: 44px;
  border-radius: 14px;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 24px;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  flex: 0 0 auto;
}
.icon-btn.glass { background: rgba(8, 14, 24, .55); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); border: 1px solid var(--line); }
.text-btn { background: none; border: 0; color: #9cc3ff; font: 600 15px var(--ui); cursor: pointer; padding: 8px 0; }

.pill {
  background: rgba(8, 14, 24, .65);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  font: 600 13px var(--ui);
  padding: 7px 12px;
}

/* ---------- старт ---------- */
.home-bg { position: absolute; inset: 0; background: url("scenes/hero.svg") center/cover no-repeat; }
.home-bg::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(11,22,38,.1) 30%, rgba(11,22,38,.92) 78%); }
.home-content {
  position: relative;
  margin-top: auto;
  padding: 24px 22px max(28px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 12px;
}
.eyebrow { font-size: 13px; letter-spacing: .08em; text-transform: uppercase; color: var(--amber); font-weight: 800; }
h1 { font: 500 48px/1.02 var(--serif); margin: 0 0 4px; letter-spacing: -.01em; }
.lead { color: #d8dbe2; font-size: 17px; line-height: 1.5; margin: 0 0 10px; }

/* ---------- главы ---------- */
.topbar {
  position: relative; z-index: 3;
  display: flex; align-items: center; gap: 10px;
  padding: max(10px, env(safe-area-inset-top)) 12px 10px;
}
.topbar.solid { background: var(--ink); border-bottom: 1px solid var(--line); }
.topbar-title { font-weight: 800; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-center { flex: 1; min-width: 0; background: rgba(8,14,24,.55); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); border: 1px solid var(--line); border-radius: 14px; padding: 7px 12px 9px; }
.progress { height: 4px; border-radius: 2px; background: rgba(255,255,255,.15); margin-top: 6px; overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: var(--amber); transition: width .4s ease; }

.chapter-list { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.chapter {
  position: relative;
  min-height: 190px;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line);
  cursor: pointer;
  display: flex; flex-direction: column; justify-content: flex-end;
  background: #1a2233 center/cover no-repeat;
  text-align: left; color: var(--text); padding: 0; font: inherit;
}
.chapter::before { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(0,0,0,0) 20%, rgba(8,12,20,.9) 100%); }
.chapter-body { position: relative; padding: 16px 18px 18px; }
.chapter-num { font-size: 12px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--amber); }
.chapter-title { font: 500 23px/1.2 var(--serif); margin: 4px 0 6px; }
.chapter-meta { font-size: 14px; color: var(--dim); }
.chapter-badge { position: absolute; top: 12px; right: 12px; z-index: 1; }

/* ---------- сцена ---------- */
.stage { position: absolute; inset: 0; z-index: 0; }
/* Иллюстрация занимает зону над карточкой, чтобы главное (письмо, башня) не пряталось под текстом. */
.stage-bg { position: absolute; left: 0; right: 0; top: 0; bottom: calc(var(--card-h, 30%) - 40px); background: #0b1626 center bottom/cover no-repeat; }
.stage-scrim { position: absolute; inset: 0; pointer-events: none; background: linear-gradient(180deg, rgba(11,22,38,.35) 0%, rgba(11,22,38,0) 18%, rgba(11,22,38,0) 40%, rgba(11,22,38,.85) 70%); }

.gallery { position: absolute; left: 0; right: 0; top: 0; bottom: calc(var(--card-h, 38%) + 14px); z-index: 1; background: #090f1a; }
.gallery-track { display: flex; height: 100%; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; }
.gallery-track::-webkit-scrollbar { display: none; }
.gallery-slide { flex: 0 0 100%; height: 100%; scroll-snap-align: center; position: relative; overflow: hidden; cursor: zoom-in; }
.gallery-slide .blur { position: absolute; inset: -20px; background: center/cover no-repeat; filter: blur(22px) brightness(.45); }
.gallery-slide img { position: relative; width: 100%; height: 100%; object-fit: contain; padding: 76px 10px 88px; }
.gallery-count { position: absolute; left: 14px; bottom: 16px; }
.zoom-btn { position: absolute; right: 14px; bottom: 16px; cursor: pointer; }
.gallery-caption { position: absolute; left: 14px; right: 130px; bottom: 54px; font-size: 13px; color: #e6e1d6; text-shadow: 0 1px 3px #000; }

/* ---------- карточка ---------- */
.card {
  position: absolute; left: 10px; right: 10px; bottom: 10px; z-index: 2;
  max-height: 62%;
  display: flex; flex-direction: column;
  background: var(--card);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 18px max(16px, env(safe-area-inset-bottom));
  box-shadow: 0 -10px 40px rgba(0,0,0,.35);
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 22px; }
.card-label { font-size: 12px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--amber); }
.listen { background: rgba(255,255,255,.08); border: 1px solid var(--line); color: var(--text); border-radius: 999px; padding: 6px 12px; font: 600 13px var(--ui); cursor: pointer; display: inline-flex; align-items: center; gap: 7px; }
.listen.playing { background: var(--amber); color: var(--amber-ink); }

/* Эквалайзер — визуальный индикатор голоса, пока идёт озвучка блока */
.eq { display: inline-flex; align-items: flex-end; gap: 2px; height: 13px; }
.eq i { width: 3px; background: currentColor; border-radius: 1px; animation: eq-bounce .9s ease-in-out infinite; }
.eq i:nth-child(1) { animation-delay: 0s; }
.eq i:nth-child(2) { animation-delay: .15s; }
.eq i:nth-child(3) { animation-delay: .3s; }
.eq i:nth-child(4) { animation-delay: .45s; }
@keyframes eq-bounce {
  0%, 100% { height: 3px; }
  50% { height: 13px; }
}

.card-text {
  overflow-y: auto;
  margin: 10px 0 4px;
  font-size: 18px; line-height: 1.55;
  white-space: pre-line;
  animation: rise .22s ease-out;
}
.card-text.quote {
  font-family: var(--serif); font-style: italic; font-size: 19px;
  background: var(--paper); color: var(--paper-ink);
  border-radius: 12px; padding: 14px 16px;
  box-shadow: inset 0 0 30px rgba(120,80,30,.18);
}
.card-text.feedback { color: #d9f1dc; }
.card-text.wrong { color: #ffd0c7; }
.card-link { color: #9cc3ff; font-weight: 600; font-size: 15px; margin: 4px 0; text-decoration: none; }

@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.card-foot { display: flex; align-items: center; justify-content: space-between; margin: 6px 0 12px; }
.card-foot:has(.dots:empty):has(.text-btn[hidden]) { margin: 0 0 8px; }
.dots { display: flex; gap: 6px; font-size: 13px; color: var(--dim); font-weight: 600; }
.dots span { width: 7px; height: 7px; border-radius: 50%; background: rgba(255,255,255,.22); transition: all .2s; }
.dots span.on { background: var(--amber); width: 18px; border-radius: 4px; }

.actions { display: flex; flex-direction: column; gap: 12px; }
.answer { display: flex; gap: 10px; }
.answer input {
  flex: 1; min-width: 0; min-height: 54px;
  border-radius: 18px; border: 1px solid rgba(255,255,255,.2);
  background: rgba(255,255,255,.07); color: var(--text);
  padding: 0 16px; font: 600 18px var(--ui); outline: none;
}
.answer input:focus { border-color: var(--amber); }
.answer.shake { animation: shake .35s; }
@keyframes shake { 20%,60% { transform: translateX(-6px); } 40%,80% { transform: translateX(6px); } }

/* ---------- журнал ---------- */
.sheet {
  position: absolute; inset: 0; z-index: 10;
  background: #070c16;
  display: flex; flex-direction: column;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: max(12px, env(safe-area-inset-top)) 16px 12px; border-bottom: 1px solid var(--line); }
.sheet-title { font: 500 22px var(--serif); }
.sheet-body { flex: 1; overflow-y: auto; padding: 16px 18px 40px; display: flex; flex-direction: column; gap: 14px; }
.j-item { font-size: 16px; line-height: 1.55; white-space: pre-line; color: #dfe2e8; }
.j-item.quote { font-family: var(--serif); font-style: italic; background: var(--paper); color: var(--paper-ink); padding: 12px 14px; border-radius: 12px; }
.j-item.user { align-self: flex-end; background: var(--amber); color: var(--amber-ink); padding: 8px 14px; border-radius: 14px; font-weight: 600; }
.j-item.hint { color: #ffe0a8; }
.j-photos { display: flex; gap: 8px; overflow-x: auto; }
.j-photos img { height: 110px; border-radius: 10px; cursor: zoom-in; }

/* ---------- лайтбокс ---------- */
.lightbox { position: absolute; inset: 0; z-index: 20; background: #000; }
.lightbox-scroll { position: absolute; inset: 0; overflow: auto; display: flex; align-items: center; justify-content: center; touch-action: pan-x pan-y pinch-zoom; }
.lightbox-scroll img { max-width: 100%; max-height: 100%; }
.lightbox-scroll.zoomed { display: block; }
.lightbox-scroll.zoomed img { max-width: none; max-height: none; width: 220%; }
.lightbox-close { position: absolute; top: max(12px, env(safe-area-inset-top)); right: 12px; z-index: 1; }

.toast {
  position: absolute; left: 50%; top: 80px; transform: translateX(-50%); z-index: 30;
  background: #1c2536; border: 1px solid var(--line); color: var(--text);
  padding: 10px 16px; border-radius: 14px; font-size: 14px; max-width: 90%;
}

@media (min-height: 800px) {
  .card-text { font-size: 19px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
