:root {
  --soot: #070a0c;
  --paper: #f6efe4;
  --paper-dim: rgba(246, 239, 228, 0.68);
  --brass: #c4a056;
  --gold: #e8c36a;
  --accent: var(--gold);
  --accent-glow: rgba(201, 162, 74, 0.45);
  --blue: #7ea8d8;
  --blue-flash: rgba(90, 150, 230, 0.55);
  --red: #d46a5c;
  --red-flash: rgba(210, 80, 70, 0.55);
  --plaque: rgba(8, 11, 14, 0.78);
  --line: rgba(246, 239, 228, 0.14);
  --serif: "Cormorant Garamond", "Palatino Linotype", Palatino, "Times New Roman", serif;
  --text: "Literata", "Palatino Linotype", Georgia, serif;
  --head: 44dvh;
  --radius: 28px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}

/* Полки меняют дымку и тон неба; текст плашек не красим в полку */
html[data-shelf="a"] {
  --accent-glow: var(--blue-flash);
}

html[data-shelf="b"] {
  --accent-glow: rgba(210, 170, 110, 0.4);
}

.page-read {
  --head: 28dvh;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--soot);
}

html {
  color-scheme: dark;
}

body {
  font-family: var(--text);
  color: var(--paper);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

a {
  color: inherit;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

img {
  max-width: 100%;
}

/* ——— Sky + split universes ——— */

.sky {
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    url("../assets/city-phone.png") center 18% / cover no-repeat,
    var(--soot);
  transform-origin: 50% 30%;
  transition: filter 0.55s ease, transform 0.55s ease;
}

.sky::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 70% 50% at 50% 28%, transparent 0%, rgba(7, 10, 12, 0.28) 55%, rgba(7, 10, 12, 0.55) 100%),
    linear-gradient(180deg, rgba(7, 10, 12, 0.15) 0%, transparent 35%, rgba(7, 10, 12, 0.35) 100%);
  pointer-events: none;
  transition: background 0.55s ease, opacity 0.55s ease;
}

/* Мир грёз: ясное небо, тот же Кром теплее и без туч */
html[data-shelf="b"] .sky {
  background:
    url("../assets/city-phone-dream.png") center 18% / cover no-repeat,
    var(--soot);
  filter: brightness(1.04) saturate(0.95) contrast(0.97);
}

html[data-shelf="b"] .sky::after {
  background:
    radial-gradient(ellipse 75% 55% at 50% 30%, rgba(232, 210, 170, 0.1) 0%, transparent 55%),
    radial-gradient(ellipse 70% 50% at 50% 28%, transparent 0%, rgba(20, 18, 14, 0.08) 60%, rgba(18, 16, 12, 0.2) 100%),
    linear-gradient(180deg, rgba(40, 36, 28, 0.04) 0%, transparent 40%, rgba(18, 16, 12, 0.12) 100%);
}

.shelf-veil {
  position: fixed;
  inset: 0;
  z-index: 25;
  background: #050608;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
}

.shelf-veil.is-on {
  opacity: 1;
}

body.is-shelf-dim .sky {
  filter: brightness(0.35) saturate(0.7);
}

.worlds {
  position: fixed;
  inset: 0;
  z-index: 2;
  display: grid;
  grid-template-columns: 1fr 1fr;
  pointer-events: none;
}

.world {
  position: relative;
  overflow: hidden;
}

.world-a {
  background: linear-gradient(to right, rgba(90, 140, 210, 0.11) 0%, rgba(90, 140, 210, 0.04) 14%, transparent 25%);
}

.world-b {
  background: linear-gradient(to left, rgba(200, 160, 100, 0.1) 0%, rgba(200, 160, 100, 0.035) 14%, transparent 25%);
}

html[data-shelf="a"] .world-a {
  background: linear-gradient(to right, rgba(90, 140, 210, 0.16) 0%, rgba(90, 140, 210, 0.06) 16%, transparent 25%);
}

html[data-shelf="b"] .world-b {
  background: linear-gradient(to left, rgba(210, 175, 115, 0.14) 0%, rgba(210, 175, 115, 0.05) 16%, transparent 25%);
}

html[data-shelf="b"] .deck {
  visibility: hidden;
  pointer-events: none;
}

.world::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
}

.world-a::after {
  background: linear-gradient(to right, rgba(90, 150, 230, 0.22), transparent 25%);
}

.world-b::after {
  background: linear-gradient(to left, rgba(220, 185, 120, 0.2), transparent 25%);
}

.world.is-flash::after {
  animation: bang 0.62s ease-out;
}

@keyframes bang {
  0% { opacity: 1; }
  100% { opacity: 0; }
}

/* ——— Deck / plaques ——— */

.deck {
  position: relative;
  z-index: 3;
  width: 100%;
  max-width: 430px;
  margin: 0 auto;
  padding: calc(var(--head) - 2.2rem) 14px calc(1.4rem + var(--safe-bot));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.page-gate {
  min-height: 100dvh;
  overflow: hidden;
}

.page-gate .deck {
  min-height: 100dvh;
  justify-content: flex-end;
  padding-top: calc(var(--head) - 1rem);
}

.plaque {
  position: relative;
  border-radius: var(--radius);
  background: var(--plaque);
  -webkit-backdrop-filter: blur(18px) saturate(1.15);
  backdrop-filter: blur(18px) saturate(1.15);
  border: 1px solid var(--line);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
  color: var(--paper);
}

.plaque-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.85rem 1.15rem;
  font-family: var(--serif);
  font-size: 0.78rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: #c9a24a;
  background: linear-gradient(180deg, rgba(22, 18, 14, 0.92), rgba(8, 7, 6, 0.9));
  border-color: rgba(201, 162, 74, 0.35);
}

.plaque-nav a {
  text-decoration: none;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}

.gate-card,
.sheet {
  padding: 1.35rem 1.2rem 1.45rem;
}

.gate-card.is-wrinkle,
.card-sign.is-wrinkle {
  animation: wrinkle 0.55s ease-in-out;
}

@keyframes wrinkle {
  0%, 100% { transform: rotate(-0.35deg); }
  20% { transform: rotate(0.7deg) skewX(-0.6deg); }
  45% { transform: rotate(-0.55deg) skewX(0.4deg); }
  70% { transform: rotate(0.35deg); }
}

.place-label {
  margin: 0 0 0.75rem;
  text-align: center;
  font-family: var(--serif);
  font-size: 0.72rem;
  letter-spacing: 0.38em;
  text-transform: uppercase;
  color: var(--gold);
}

.title-slot {
  margin: 0 auto 0.35rem;
  min-height: 3.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 0.55rem 0.4rem;
  font-family: var(--serif);
  font-weight: 600;
  font-size: 2.1rem;
  font-style: italic;
  letter-spacing: 0.04em;
  color: #fffaf3;
}

.title-empty {
  display: block;
  width: 42%;
  height: 1px;
  background: rgba(246, 239, 228, 0.35);
}

.title-whisper {
  margin: 0.55rem 0 1.25rem;
  text-align: center;
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.08rem;
  color: var(--paper);
}

.gate-form label {
  display: block;
  font-family: var(--serif);
  font-size: 0.68rem;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.35rem;
}

.gate-row {
  display: flex;
  gap: 0.55rem;
  align-items: stretch;
}

#gate-pass {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  border-bottom: 1px solid rgba(246, 239, 228, 0.35);
  padding: 0.7rem 0.15rem;
  color: var(--paper);
  font-size: 17px;
  letter-spacing: 0.16em;
  outline: none;
  border-radius: 0;
}

#gate-pass:focus {
  border-bottom-color: var(--accent);
}

.btn-brass {
  appearance: none;
  border: 1px solid #c9a24a;
  border-radius: 999px;
  background: linear-gradient(180deg, #1c1812 0%, #0a0908 100%);
  color: #e8c36a;
  padding: 0.7rem 1.15rem;
  min-height: 44px;
  font-family: var(--serif);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  box-shadow:
    0 0 16px rgba(201, 162, 74, 0.22),
    inset 0 1px 0 rgba(232, 195, 106, 0.12);
}

.btn-brass:active {
  transform: translateY(1px);
  filter: brightness(1.08);
}

a.btn-brass {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  color: #e8c36a;
}

.gate-err {
  margin: 0.7rem 0 0;
  font-size: 0.95rem;
  font-style: italic;
  color: #f0b4a8;
}

.gate-skip {
  display: block;
  margin-top: 0.35rem;
  text-align: center;
  font-family: var(--serif);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 0.78rem;
  color: var(--accent);
  text-decoration: none;
  min-height: 44px;
  line-height: 44px;
}

.gate-foot {
  margin: 0.9rem 0 0;
  text-align: center;
  font-size: 0.82rem;
  color: var(--paper-dim);
  font-style: italic;
}

.chapter-card {
  display: block;
  text-decoration: none;
  padding: 1.15rem 1.2rem 1.2rem;
  background: linear-gradient(180deg, rgba(22, 18, 14, 0.92), rgba(8, 7, 6, 0.9));
  border-color: rgba(201, 162, 74, 0.35);
}

.chapter-card .n {
  display: block;
  font-family: var(--serif);
  letter-spacing: 0.28em;
  text-transform: uppercase;
  font-size: 0.68rem;
  color: #c9a24a;
  margin-bottom: 0.3rem;
}

.chapter-card h2 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.7rem;
  line-height: 1.15;
  color: #f0e2c0;
}

.chapter-card p {
  margin: 0.4rem 0 0;
  font-size: 0.98rem;
  color: rgba(240, 226, 192, 0.62);
}

.chapter-card.is-sealed {
  pointer-events: none;
  user-select: none;
}

.chapter-card.is-sealed h2 {
  font-style: italic;
  letter-spacing: 0.12em;
  font-weight: 500;
  font-size: 1.35rem;
  color: rgba(246, 239, 228, 0.72);
}

.chapter-card.is-d1 { opacity: 0.42; }
.chapter-card.is-d2 { opacity: 0.24; }
.chapter-card.is-d3 {
  opacity: 0.12;
  filter: blur(0.4px);
}

.prose {
  font-size: 1.08rem;
  line-height: 1.7;
  color: var(--paper);
}

.prose h1 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.85rem;
  line-height: 1.15;
  margin: 0 0 1.2rem;
  font-style: italic;
  color: #fffaf3;
}

.prose .kicker {
  font-family: var(--serif);
  font-style: normal;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  font-size: 0.7rem;
  color: var(--gold);
  display: block;
  margin-bottom: 0.4rem;
}

.prose p {
  margin: 0 0 0.95em;
}

.prose strong {
  font-weight: 600;
  color: #fffaf3;
}

.prose .pov {
  margin: 1.4em 0 0.7em;
  font-family: var(--serif);
  font-size: 0.78rem;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--gold);
}

.prose .pov:first-of-type {
  margin-top: 0.2em;
}

.prose hr.scene {
  border: 0;
  height: 1px;
  margin: 1.6em 0;
  background: linear-gradient(to right, transparent, var(--line), transparent);
}

.prose .ill {
  display: block;
  width: 100%;
  margin: 1.1rem 0 1.35rem;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid rgba(201, 162, 74, 0.28);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
  background: #0a0908;
}

.prose .ill img {
  display: block;
  width: 100%;
  height: auto;
  vertical-align: middle;
}

.touch {
  margin: 1.8rem 0 0;
  padding-top: 1.2rem;
  border-top: 1px solid var(--line);
}

.touch h2,
.coauthor > h2 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.12rem;
  margin: 0 0 0.75rem;
  letter-spacing: 0.08em;
  color: var(--gold);
}

.pillar-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.7rem;
  min-height: 11rem;
  justify-content: flex-end;
  position: relative;
}

.pillar {
  appearance: none;
  border: 0;
  background: linear-gradient(90deg, #6e5a32, #c4a56a 45%, #8a6a38);
  width: 1.25rem;
  height: 9.2rem;
  border-radius: 0.5rem;
  box-shadow: inset 2px 0 0 rgba(255, 240, 200, 0.35), 0 0 0 3px rgba(246, 239, 228, 0.2);
  cursor: pointer;
  touch-action: none;
}

.pillar.is-held {
  filter: brightness(1.15);
  box-shadow:
    inset 2px 0 0 rgba(255, 240, 200, 0.5),
    0 0 0 3px rgba(246, 239, 228, 0.25),
    0 0 28px var(--accent-glow);
}

.pillar-hint,
.card-note {
  font-size: 0.9rem;
  font-style: italic;
  color: var(--paper-dim);
  text-align: center;
  margin: 0;
}

.swarm {
  position: absolute;
  inset: 8% 10% 30%;
  opacity: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 30% 40%, rgba(200, 210, 220, 0.28), transparent 42%),
    radial-gradient(circle at 62% 55%, rgba(180, 190, 200, 0.22), transparent 38%);
  filter: blur(6px);
  transition: opacity 0.4s ease;
}

.swarm.is-on {
  opacity: 1;
}

.card-sign {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 1rem 1rem 1.1rem;
}

.card-sign.is-blot input,
.card-sign.is-wrinkle input {
  color: transparent;
}

.card-sign.is-blot {
  background-image: radial-gradient(circle at 38% 62%, rgba(0, 0, 0, 0.72) 0 18px, transparent 42px);
}

.card-sign.is-wrinkle {
  background-image: repeating-linear-gradient(-12deg, transparent, transparent 6px, rgba(246, 239, 228, 0.08) 7px);
}

.card-sign label {
  display: block;
  font-family: var(--serif);
  font-size: 0.68rem;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.4rem;
}

.card-sign input {
  width: 100%;
  border: none;
  border-bottom: 1px solid rgba(246, 239, 228, 0.3);
  background: transparent;
  padding: 0.45rem 0;
  font-family: var(--serif);
  font-size: 1.35rem;
  outline: none;
  color: var(--paper);
  border-radius: 0;
}

.card-note {
  margin: 0.55rem 0 0;
  text-align: left;
}

.coauthor {
  margin-top: 1.6rem;
}

.coauthor > h2 {
  border: 0;
  padding: 0;
}

.coauthor label {
  display: block;
  margin: 0.85rem 0 0.3rem;
  font-size: 0.98rem;
  color: var(--paper);
}

.coauthor textarea {
  width: 100%;
  min-height: 4.8rem;
  resize: vertical;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.28);
  color: var(--paper);
  padding: 0.7rem 0.75rem;
  outline: none;
  border-radius: 16px;
  font-size: 16px;
}

.coauthor textarea:focus {
  border-color: var(--accent);
}

.coauthor .btn-brass {
  margin-top: 1rem;
  width: 100%;
}

.coauthor .thanks {
  margin: 0.7rem 0 0;
  font-style: italic;
  color: var(--accent);
}

.btn-dive {
  width: 100%;
  margin-top: 1.5rem;
}

.chapter-next {
  margin-top: 1.4rem;
}

.chapter-next .btn-brass {
  width: 100%;
}

.undivided {
  position: fixed;
  inset: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 1.5rem;
  text-align: center;
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.25rem;
  color: var(--paper);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  text-shadow: 0 2px 18px rgba(0, 0, 0, 0.7);
}

html[data-shelf="b"] .undivided {
  opacity: 1;
  visibility: visible;
}

.dive-veil,
.arrive-veil {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: #050608;
  opacity: 0;
  pointer-events: none;
}

body.is-diving .deck {
  opacity: 0;
  transition: opacity 0.7s ease;
}

body.is-diving .sky {
  transform: scale(2.15);
  filter: brightness(0.32) saturate(0.75) contrast(1.12);
  transition: transform 2.5s cubic-bezier(0.42, 0, 0.18, 1), filter 2.5s ease;
}

body.is-diving .dive-veil {
  opacity: 1;
  transition: opacity 1.05s ease 1.55s;
}

.page-arrive .arrive-veil {
  animation: unveil 1.15s ease forwards;
}

@keyframes unveil {
  from { opacity: 1; }
  to { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .world.is-flash::after,
  .gate-card.is-wrinkle,
  .card-sign.is-wrinkle,
  .page-arrive .arrive-veil {
    animation: none;
  }

  body.is-diving .sky,
  body.is-diving .deck,
  body.is-diving .dive-veil,
  .sky,
  .sky::after,
  .shelf-veil {
    transition: none;
  }
}
