/* Свиток о Туннеле
   По умолчанию вертикальная лента (телефон и режим без JS).
   Класс html.h включает горизонтальный свиток, его ставит app.js. */

:root {
  --paper: #dbe5e3;
  --ink: #1d3557;
  --night: #0e1b30;
  --red: #c8324b;
  --lamp: #ebc247;
  --white: #f8f6f0;

  --parade-h: 44px;
  --thread-b: 44px;

  --display: 'Dela Gothic One', 'Hiragino Sans', 'Yu Gothic', sans-serif;
  --hand: 'Kurale', 'Klee One', 'Yu Mincho', 'Hiragino Mincho ProN', serif;
}

*, *::before, *::after { box-sizing: border-box; }

html { background: var(--paper); }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--hand);
  font-size: 17px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* фактура старой бумаги васи (img/paper.webp, бесшовная плитка 1024) */
body { background: var(--paper) url("img/paper.webp") repeat 0 0 / 1024px auto; }

h1, h2 { font-family: var(--display); font-weight: 400; line-height: 1.1; margin: 0; }
p { margin: 0 0 .8em; }
a { color: var(--red); text-underline-offset: 3px; }
strong { font-weight: 400; color: var(--red); }

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

:focus-visible { outline: 3px solid var(--red); outline-offset: 3px; }

/* ---------- лента парада ---------- */
.parade {
  height: var(--parade-h);
  background: var(--night) url("img/parade.webp") repeat-x 0 0 / auto 100%;
  border-bottom: 3px solid var(--red);
  box-shadow: 0 1px 0 var(--ink);
}

/* ---------- дорожка и нить ---------- */
.track { position: relative; padding-left: 26px; }

.track::after {                 /* красная нить, на телефоне вертикальная */
  content: "";
  position: absolute;
  left: 12px; top: 0; bottom: 0;
  width: 3px;
  background: var(--red);
  z-index: 1;
}

.sheet {
  position: relative;
  padding: 48px 16px 56px 12px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.sheet + .sheet { border-top: 1px solid rgba(29, 53, 87, .14); }

.sheet::before {                /* узелок на нити у каждого листа */
  content: "";
  position: absolute;
  left: -20px; top: 52px;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--red);
  box-shadow: 0 0 0 3px var(--paper);
  z-index: 2;
}
.sheet-title::before { display: none; }

/* ---------- титульный лист ---------- */
.sheet-title {
  flex-direction: column;
  align-items: flex-start;
  gap: 20px;
  padding-top: 40px;
  min-height: calc(100svh - var(--parade-h));
}
.daisen {
  writing-mode: vertical-rl;
  flex: none;
  font-family: var(--display);
  font-size: 34px;
  letter-spacing: .18em;
  padding: 18px 10px;
  background: var(--white);
  border: 2px solid var(--ink);
  outline: 1px solid var(--red);
  outline-offset: 5px;
  margin: 6px;
}
.title-text { max-width: 34rem; min-width: 0; }
.kicker {
  font-weight: 400;
  color: var(--red);
  letter-spacing: .08em;
  font-size: 14px;
}
h1 { font-size: clamp(34px, 11vw, 92px); margin-bottom: .35em; }
.lede { font-size: 19px; }
.hint { margin-top: 1.6em; font-weight: 400; color: var(--red); }
.hint-wide { display: none; }
.hanko {
  position: absolute;
  right: 18px; bottom: 28px;
  width: 58px; height: 58px;
  display: grid; place-items: center;
  font-family: var(--display);
  font-size: 34px;
  color: var(--white);
  background: var(--red);
  border-radius: 6px;
  transform: rotate(-6deg);
}

/* ---------- лист главы ---------- */
.era {
  margin: 0;
  align-self: flex-start;
  font-family: var(--display);
  font-size: 15px;
  letter-spacing: .12em;
  color: var(--white);
  background: var(--red);
  padding: 4px 10px;
}

.print { margin: 0; }
.plate {
  position: relative;
  padding: 12px;
  background: var(--white);
  box-shadow: 0 1px 0 rgba(29,53,87,.25), 0 14px 30px -18px rgba(14,27,48,.55);
}
.plate img { display: block; width: 100%; height: auto; }
figcaption { margin-top: 10px; font-size: 14px; opacity: .78; }

.text { max-width: 30rem; }
.text h2 { font-size: clamp(28px, 7vw, 42px); margin-bottom: .45em; }
.year {
  font-weight: 400;
  color: var(--red);
  font-size: 14px;
  letter-spacing: .06em;
  margin-bottom: .4em;
}
.aside { font-size: 15px; opacity: .8; }

/* ---------- пузыри реплик ---------- */
.bubble {
  position: absolute;
  left: var(--x); top: var(--y);
  z-index: 4;
  max-width: min(46%, 230px);
  margin: 0;
  padding: .9em 1.3em;
  background: var(--white);
  color: var(--ink);
  border: 2.5px solid var(--ink);
  border-radius: 50%;
  font-weight: 400;
  font-size: 13px;
  line-height: 1.3;
  text-align: center;
}
.bubble.small { max-width: min(42%, 200px); }
.bubble::before, .bubble::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 26%;
  border-style: solid;
  border-color: transparent;
}
.bubble::before { border-width: 20px 8px 0 8px; border-top-color: var(--ink); }
.bubble::after  { border-width: 15px 5px 0 5px; border-top-color: var(--white); margin: -3px 0 0 3px; }
.bubble.tail-r::before, .bubble.tail-r::after { left: auto; right: 26%; }
.bubble.tail-r::after { margin: -3px 3px 0 0; }
.bubble.tail-up::before, .bubble.tail-up::after { top: auto; bottom: 100%; }
.bubble.tail-up::before { border-width: 0 8px 20px 8px; border-color: transparent transparent var(--ink); }
.bubble.tail-up::after  { border-width: 0 5px 15px 5px; border-color: transparent transparent var(--white); margin: 0 0 -3px 3px; }

/* ---------- ономатопея ---------- */
.sfx {
  position: absolute;
  left: var(--x); top: var(--y);
  z-index: 3;
  font-family: var(--display);
  font-size: clamp(28px, 8vw, 64px);
  line-height: 1;
  color: var(--red);
  -webkit-text-stroke: 5px var(--white);
  paint-order: stroke fill;
  text-shadow: 4px 4px 0 var(--ink);
  transform: rotate(var(--r));
  white-space: nowrap;
  user-select: none;
  cursor: default;
}
.sfx.v { writing-mode: vertical-rl; letter-spacing: -.04em; }

/* ---------- лисьи огни ---------- */
.orb {
  position: absolute;
  left: var(--x); top: var(--y);
  z-index: 3;
  width: 34px; height: 34px;
  margin: -17px 0 0 -17px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  background: radial-gradient(circle, var(--white) 0 14%, var(--lamp) 30%, rgba(200, 50, 75, .55) 58%, transparent 72%);
  filter: drop-shadow(0 0 6px var(--lamp));
}
.orb:hover { filter: drop-shadow(0 0 12px var(--lamp)); }
.orb.read { background: radial-gradient(circle, var(--white) 0 12%, rgba(235,194,71,.55) 34%, transparent 66%); }
.orb[aria-pressed="true"] { outline: 2px solid var(--white); outline-offset: 2px; }

.letter {
  margin-top: 1.2em;
  padding: 16px 18px;
  background: var(--white);
  border: 1.5px solid var(--ink);
  box-shadow: 5px 5px 0 var(--red);
}
.letter-head { font-weight: 400; font-size: 14px; color: var(--red); margin-bottom: .3em; }
.letter-body { margin: 0; min-height: 3.2em; overflow-wrap: anywhere; }

/* ---------- тёмная сцена с фонарём ---------- */
.night {
  color: var(--paper);
  background: var(--night);
  margin-left: -26px;
  padding-left: 38px;
}
.night::before { left: 6px; box-shadow: 0 0 0 3px var(--night); }
.night .year { color: var(--lamp); }
.night .plate { background: #182845; box-shadow: none; }
.night figcaption { color: var(--paper); }

.lantern {
  --lx: 50%; --ly: 42%; --lr: 120px;
  cursor: crosshair;
}
.lantern .veil, .lantern .glow {
  position: absolute;
  inset: 12px;
  pointer-events: none;
  transition: opacity .6s;
}
.lantern .veil {
  z-index: 2;
  background: rgba(14, 27, 48, .97);
  -webkit-mask-image: radial-gradient(circle var(--lr) at var(--lx) var(--ly), transparent 0, transparent 40%, #000 100%);
          mask-image: radial-gradient(circle var(--lr) at var(--lx) var(--ly), transparent 0, transparent 40%, #000 100%);
}
.lantern .glow {
  z-index: 2;
  mix-blend-mode: soft-light;
  background: radial-gradient(circle calc(var(--lr) * 1.1) at var(--lx) var(--ly), rgba(235, 194, 71, .8), transparent 70%);
}
.lantern.lit .veil, .lantern.lit .glow { opacity: 0; }
.glow-sfx { color: var(--lamp); -webkit-text-stroke-color: var(--night); text-shadow: 3px 3px 0 var(--red); }
.bubble.dark { box-shadow: 0 0 22px rgba(235, 194, 71, .35); }

/* ---------- кнопки ---------- */
.btn {
  font: 400 17px/1.2 var(--hand);
  color: var(--white);
  background: var(--red);
  border: 2px solid var(--ink);
  padding: 11px 18px;
  cursor: pointer;
  box-shadow: 4px 4px 0 var(--ink);
}
.btn span { font-family: var(--display); font-weight: 400; margin-right: .4em; }
.btn:hover { background: #b12a41; }
.btn:active { transform: translate(2px, 2px); box-shadow: 2px 2px 0 var(--ink); }
.btn-light { background: var(--lamp); color: var(--night); border-color: var(--lamp); box-shadow: 4px 4px 0 var(--red); }
.btn-light:hover { background: #f2d06a; }
.btn-light[aria-pressed="true"] { background: transparent; color: var(--lamp); }

/* ---------- станция 01 ---------- */
.station-sign {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  line-height: .85;
}
.station-kanji {
  margin: 0;
  font-family: var(--display);
  font-size: 64px;
  color: var(--white);
  background: var(--ink);
  padding: 10px;
}
.station-no {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(110px, 32vw, 220px);
  color: var(--red);
  letter-spacing: -.04em;
}
.timetable {
  margin: 1.1em 0 1.4em;
  border-top: 2px solid var(--ink);
  border-bottom: 2px solid var(--ink);
}
.timetable div {
  display: grid;
  grid-template-columns: 8.5em 1fr;
  gap: 12px;
  padding: 6px 0;
}
.timetable div + div { border-top: 1px dashed rgba(29, 53, 87, .35); }
.timetable dt { font-weight: 400; color: var(--red); }
.timetable dd { margin: 0; }

.slip {
  display: flex;
  gap: 16px;
  margin-top: 18px;
  max-width: 26rem;
  padding: 16px 18px;
  background: var(--white);
  border: 1.5px solid var(--ink);
  border-top: 8px solid var(--red);
}
.slip[hidden] { display: none; }
.slip-rank {
  margin: 0;
  writing-mode: vertical-rl;
  font-family: var(--display);
  font-size: 40px;
  line-height: 1;
  color: var(--red);
}
.slip-name { font-weight: 400; margin-bottom: .2em; }
.slip-text { margin: 0; }

.torii { display: none; }

/* ---------- выходные данные ---------- */
.colophon .text.wide { max-width: 38rem; }
.credits { list-style: none; padding: 0; margin: 1em 0 1.2em; counter-reset: c; }
.credits li {
  counter-increment: c;
  padding: 7px 0 7px 2.2em;
  position: relative;
  border-top: 1px solid rgba(29, 53, 87, .18);
}
.credits li::before {
  content: counter(c);
  position: absolute; left: 0; top: 7px;
  font-family: var(--display);
  color: var(--red);
}
.credits li span { display: block; font-weight: 400; }
.endroll { display: none; }

/* ---------- лис: спрайт 7 кадров (6 бега + покой), ячейка 432×304 ---------- */
.fox { display: none; }
.fox-sprite {
  --f: 6;
  width: 100%;
  aspect-ratio: 432 / 304;
  background: url("img/fox-run.webp") no-repeat;
  background-size: 700% 100%;
  background-position-x: calc(var(--f) * 100% / 6);
}
.fox-inner { position: relative; }
.fox-inner::after {             /* лисий огонёк у головы */
  content: "";
  position: absolute;
  right: 1%; top: 6%;
  width: 11%; aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle, var(--white) 0 18%, var(--lamp) 42%, rgba(235, 194, 71, 0) 72%);
  filter: drop-shadow(0 0 5px var(--lamp));
}
.fox.back .fox-inner { scale: -1 1; }

/* ---------- эффект загрузки: свиток разворачивается ---------- */
.unroll { display: none; }

@media (prefers-reduced-motion: no-preference) {
  .unroll {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 100;
    pointer-events: none;
    background: var(--night);
    animation: unroll 1.5s cubic-bezier(.55, .05, .3, 1) .15s forwards;
  }
  .roller {
    position: absolute;
    top: 0; bottom: 0; left: -14px;
    width: 30px;
    background: linear-gradient(90deg, #3a2414, #8a5a32 40%, #c08a52 55%, #5a371d);
    box-shadow: 6px 0 14px rgba(0, 0, 0, .35);
  }
  .roller::before, .roller::after {
    content: "";
    position: absolute;
    left: -4px; right: -4px;
    height: 22px;
    background: var(--lamp);
    border-radius: 4px;
  }
  .roller::before { top: 0; }
  .roller::after { bottom: 0; }
  @keyframes unroll {
    0%   { clip-path: inset(0 0 0 0); }
    99%  { clip-path: inset(0 0 0 100%); }
    100% { clip-path: inset(0 0 0 100%); visibility: hidden; }
  }

  .sfx:hover { animation: shake .35s linear infinite; }
  @keyframes shake {
    0%, 100% { transform: rotate(var(--r)) translate(0, 0); }
    20% { transform: rotate(calc(var(--r) - 3deg)) translate(-3px, 2px); }
    40% { transform: rotate(calc(var(--r) + 2deg)) translate(3px, -2px); }
    60% { transform: rotate(calc(var(--r) - 2deg)) translate(-2px, -3px); }
    80% { transform: rotate(calc(var(--r) + 3deg)) translate(2px, 3px); }
  }

  .orb { animation: flicker 2.4s ease-in-out infinite; }
  .orb:nth-of-type(2n) { animation-delay: -1.1s; }
  .orb:nth-of-type(3n) { animation-delay: -.6s; }
  @keyframes flicker { 50% { transform: scale(.82); opacity: .8; } }

  .slip.drawn { animation: draw .45s cubic-bezier(.2, .8, .3, 1.2); }
  @keyframes draw { from { transform: translateY(-14px) scaleY(.6); opacity: 0; } }

  .fox-inner::after { animation: flicker 2s ease-in-out infinite; }
}

/* При отключённых анимациях дрожание заменяем подсветкой */
@media (prefers-reduced-motion: reduce) {
  .sfx:hover { color: var(--ink); }
}

/* ======================================================
   Горизонтальный свиток (широкий экран, включается из JS)
   ====================================================== */
@media (min-width: 821px) {
  .hint-wide { display: inline; }
  .hint-narrow { display: none; }
}

html.h .scroll { position: relative; }

html.h .stage {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100svh;
  overflow: hidden;
  overflow: clip;
}

html.h .parade {
  --parade-h: 58px;
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 5;
}

html.h .track {
  display: flex;
  height: 100%;
  width: max-content;
  padding-left: 0;
  will-change: transform;
}
html.h .track::after {
  left: 0; right: 0; top: auto;
  bottom: var(--thread-b);
  width: auto;
  height: 3px;
}

html.h .sheet {
  --ph: clamp(240px, calc(100svh - 330px), 700px);
  flex: none;
  flex-direction: row;
  align-items: center;
  gap: 44px;
  height: 100%;
  padding: 96px 72px calc(var(--thread-b) + 104px) 88px;
}
html.h .sheet + .sheet { border-top: 0; border-left: 1px solid rgba(29, 53, 87, .14); }
html.h .sheet::before { left: -7px; top: auto; bottom: calc(var(--thread-b) - 5px); }

html.h .era {
  position: absolute;
  top: 88px; left: 26px;
  writing-mode: vertical-rl;
  padding: 10px 4px;
  font-size: 16px;
}

html.h .plate img { height: var(--ph); width: calc(var(--ph) * var(--ar)); }
html.h .text { width: 330px; flex: none; }
html.h .bubble { font-size: 15px; }
html.h .sfx { font-size: clamp(40px, 7svh, 76px); }

html.h .sheet-title {
  flex-direction: row;
  width: 100vw;
  min-height: 0;
  align-items: center;
  justify-content: center;
  gap: 56px;
  padding-left: 72px;
}
html.h .daisen { font-size: 54px; padding: 28px 16px; }
html.h .title-text { max-width: 40rem; }
html.h .hanko { right: 56px; bottom: calc(var(--thread-b) + 30px); width: 72px; height: 72px; font-size: 42px; }

html.h .night {
  padding-left: 88px;
  background: linear-gradient(90deg, rgba(14,27,48,0) 0, var(--night) 90px, var(--night) calc(100% - 90px), rgba(14,27,48,0) 100%);
  padding-right: 120px;
  margin-right: -40px;
  margin-left: -40px;
  border-left: 0;
  z-index: 0;
}
html.h .night + .sheet { border-left: 0; }
html.h .night::before { left: 34px; box-shadow: 0 0 0 3px var(--night); }
html.h .night .era { left: 60px; }

html.h .station { gap: 56px; padding-right: 300px; }
html.h .station-no { font-size: clamp(140px, 30svh, 260px); }
html.h .station .text { width: 380px; }
html.h .torii {
  display: block;
  position: absolute;
  right: 60px;
  bottom: calc(var(--thread-b) - 2px);
  width: 190px;
  height: auto;
  z-index: 2;
}

html.h .colophon { padding-right: 160px; }



html.h .fox {
  display: block;
  position: absolute;
  left: 0;
  bottom: calc(var(--thread-b) - 1px);
  width: 120px;
  z-index: 6;
  pointer-events: none;
  will-change: transform;
}

html.h .print { width: min-content; }
html.h .colophon .text.wide { width: 860px; }
html.h .credits { display: grid; grid-template-columns: 1fr 1fr; column-gap: 36px; }

/* бумага едет вместе с листами */
html.h .track { background: url("img/paper.webp") repeat 0 0 / 1024px auto; }

/* потемневшие от времени верхний и нижний края свитка */
html.h .stage::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  mix-blend-mode: multiply;
  background: linear-gradient(to bottom,
    rgba(125, 104, 64, .18) 0, rgba(125, 104, 64, 0) 16%,
    rgba(125, 104, 64, 0) 82%, rgba(125, 104, 64, .24) 100%);
}

/* свёрнутый рулон в конце: та же бумага, в неё уходят лента парада и красная нить */
html.h .endroll {
  --w: 64px;
  display: block;
  position: absolute;
  top: 0; bottom: 0; left: 0;
  width: var(--w);
  z-index: 7;
  pointer-events: none;
  will-change: transform;
  background:
    linear-gradient(90deg,
      rgba(14, 27, 48, .42) 0%, rgba(14, 27, 48, .1) 16%,
      rgba(255, 255, 255, .42) 38%, rgba(255, 255, 255, .1) 56%,
      rgba(14, 27, 48, .16) 76%, rgba(14, 27, 48, .55) 100%),
    linear-gradient(to bottom, transparent 0 58px, var(--red) 58px 61px, transparent 61px),
    url("img/parade.webp") repeat-x 0 0 / auto 58px,
    linear-gradient(to top,
      transparent var(--thread-b), var(--red) var(--thread-b),
      var(--red) calc(var(--thread-b) + 3px), transparent calc(var(--thread-b) + 3px)),
    url("img/paper.webp") 0 0 / 1024px auto,
    var(--paper);
  box-shadow: -20px 0 26px -14px rgba(14, 27, 48, .5);
}
html.h .endroll::before {       /* край бумаги, заходящий на рулон */
  content: "";
  position: absolute;
  top: 0; bottom: 0; left: 0;
  width: 5px;
  background: linear-gradient(90deg, rgba(14, 27, 48, .35), rgba(248, 246, 240, .5));
}

/* вертикальная полоса прокрутки не нужна: свиток движется вбок */
html.h { scrollbar-width: none; }
html.h::-webkit-scrollbar { display: none; }
