/* Shared pieces: icons, type roles, the two buttons, the chrome (brand, bell, chapter rail),
   the toast and the petal canvas. (The colophon lives in the last chapter: css/sections/end.css.) */

/* ---------- Icons (assets/icons.svg) ---------- */
.icon {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  overflow: visible;
}

/* ---------- Type roles: one rule each, sizes from tokens.css ---------- */
.label {
  font: 500 var(--text-label) / 1.5 var(--font-ui);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
}
.muted {
  color: var(--muted);
}
.title {
  font: 800 var(--text-title) / 0.98 var(--font-display);
  letter-spacing: var(--tracking-title);
  text-transform: uppercase;
}
.accent {
  color: var(--shu); /* the one vermilion phrase in each title */
}
.story {
  font: 400 var(--text-story) / 1.14 var(--font-display);
  letter-spacing: -0.01em;
  text-wrap: balance;
}
.line {
  font: 400 var(--text-line) / 1.25 var(--font-display);
  text-wrap: balance;
}

/* Every chapter opens with the same mark: its kanji in vermilion, a short stroke, its name.
   The rail on the right uses the same kanji, so the two always agree. */
.chapter-mark {
  display: flex;
  align-items: center;
  gap: 14px;
  font: 500 var(--text-label) / 1 var(--font-ui);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
}
.chapter-kanji {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  font: 800 var(--text-line) / 1 var(--font-display);
  color: var(--shu);
}
.chapter-kanji::after {
  content: "";
  width: 30px;
  height: 1px;
  background: currentColor;
  opacity: 0.7;
}

/* ---------- Primary button: a carved lacquer plaque ----------
   A block of vermilion lacquer, built from two pseudo-elements cut by the same chamfer (so the button
   itself stays a plain box and its focus ring isn't clipped away):
     ::before  the block's edge: the same shape, 4 px deeper and darker, seen as the plaque's thickness
     ::after   the face: lacquer with a fine grain, a bevel (a light top edge, a dark bottom edge)
               and a sheen that sweeps across on hover
   The label and the icon are cut into the face: a dark line above each stroke, a light one below.
   Pressed, the face sinks into its thickness. */
:root {
  /* a fine grain for lacquer: SVG noise, kept close to mid-grey so it only textures (overlay blend) */
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3CfeComponentTransfer%3E%3CfeFuncR type='linear' slope='.4' intercept='.3'/%3E%3CfeFuncG type='linear' slope='.4' intercept='.3'/%3E%3CfeFuncB type='linear' slope='.4' intercept='.3'/%3E%3C/feComponentTransfer%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23g)'/%3E%3C/svg%3E");
  --lacquer: linear-gradient(180deg, #ef7056 0%, var(--shu) 36%, #b9371f 72%, #93291a 100%);
  --carved: 0 -1px 0 #5c130aa6, 0 1px 0 #ffc6a852; /* a stroke cut into lacquer */
}
.btn {
  --cut: 9px;
  --chamfer: polygon(
    var(--cut) 0,
    calc(100% - var(--cut)) 0,
    100% var(--cut),
    100% calc(100% - var(--cut)),
    calc(100% - var(--cut)) 100%,
    var(--cut) 100%,
    0 calc(100% - var(--cut)),
    0 var(--cut)
  );
  position: relative;
  isolation: isolate;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 54px;
  margin-bottom: 4px; /* room for the plaque's thickness */
  padding: 0 30px 0 24px;
  font: 700 var(--text-label) / 1 var(--font-ui);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: #ffeedd;
  text-shadow: var(--carved);
  filter: drop-shadow(0 8px 12px #0000005c); /* it sits above the page */
  transition:
    transform 0.2s,
    filter 0.25s;
}
.btn::before {
  content: "";
  position: absolute;
  inset: 0 0 -4px;
  z-index: -2;
  clip-path: var(--chamfer);
  background: linear-gradient(#8f2818, #4e1009);
  transition: inset 0.2s;
}
.btn::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  clip-path: var(--chamfer);
  background:
    linear-gradient(105deg, transparent 42%, #fff3e22e 50%, transparent 58%) 160% 0 / 260% 100% no-repeat,
    var(--grain) 0 0 / 200px 200px,
    var(--lacquer);
  background-blend-mode: normal, overlay, normal;
  box-shadow:
    inset 0 1px 0 #ffc8b080,
    inset 0 -1px 0 #5c130a8c,
    inset 1px 0 0 #ffc8b02e,
    inset -1px 0 0 #5c130a4d;
  transition:
    background-position 0.9s cubic-bezier(0.2, 0.7, 0.2, 1),
    filter 0.25s;
}
.btn:hover {
  transform: translateY(-1px);
}
.btn:hover::after {
  background-position:
    -60% 0,
    0 0,
    0 0; /* the lacquer catches the light */
  filter: brightness(1.06);
}
.btn:active {
  transform: translateY(2px); /* the face sinks... */
}
.btn:active::before {
  inset: 0 0 -2px; /* ...into its own thickness, whose bottom stays put */
}
.btn .icon {
  width: 20px;
  height: 20px;
  filter: drop-shadow(0 -1px 0 #5c130aa6) drop-shadow(0 1px 0 #ffc6a852);
}
.btn:disabled {
  opacity: 0.7;
}

/* ---------- Secondary button: an ink link ----------
   A short brush stroke waits under the label and sweeps across on hover. */
.link {
  --brush: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 200 8' preserveAspectRatio='none'%3E%3Cpath d='M1 4.4C42 2.1 118 1.6 199 3.2l-1 2.4C126 6.9 62 7.1 2 6.4Z'/%3E%3C/svg%3E");
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  font: 500 var(--text-label) / 1 var(--font-ui);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: inherit;
  transition: color 0.25s;
}
.link .icon {
  width: 20px;
  height: 20px;
  color: var(--shu);
}
.link::after {
  content: "";
  position: absolute;
  left: 30px;
  right: -4px;
  bottom: 6px;
  height: 5px;
  background: var(--shu);
  -webkit-mask: var(--brush) 0 0 / 100% 100% no-repeat;
  mask: var(--brush) 0 0 / 100% 100% no-repeat;
  transform: scaleX(0.22);
  transform-origin: left;
  opacity: 0.75;
  transition: transform 0.6s cubic-bezier(0.2, 0.7, 0.2, 1);
}
.link:not(:has(.icon))::after {
  left: 0;
}
.link:is(:hover, :focus-visible)::after {
  transform: scaleX(1);
}

/* ---------- Icon button: the bell, close ---------- */
.icon-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  color: inherit;
  transition: color 0.25s;
}
.icon-btn:hover {
  color: var(--shu-light);
}
.icon-btn .icon {
  width: 24px;
  height: 24px;
}

/* The bell: it swings and its ripples show while the sound is on. */
@property --icon-sway {
  syntax: "<angle>";
  inherits: true;
  initial-value: 0deg;
}
[data-audio] {
  --icon-waves: 0;
}
[data-audio][aria-pressed="true"] {
  --icon-waves: 1;
  animation: bell-sway 2.4s ease-in-out infinite alternate;
}
@keyframes bell-sway {
  from {
    --icon-sway: -9deg;
  }
  to {
    --icon-sway: 9deg;
  }
}

.skip {
  position: fixed;
  top: -100px;
  left: 20px;
  z-index: 100;
  background: var(--paper);
  color: var(--ink);
  padding: 12px 20px;
}
.skip:focus {
  top: 20px;
}

/* ---------- The chrome: brand top left, bell top right ----------
   No header bar. The pieces float on the chapters, and switch to ink on the ivory arts sheet
   (js/ui/chapter-rail.js writes the current chapter to <html data-chapter>). */
:root {
  --chrome-ink: var(--paper);
  --chrome-bg: #0b0f0a88;
}
:root[data-chapter="arts"] {
  --chrome-ink: var(--ink);
  --chrome-bg: transparent;
  --chrome-shadow: transparent;
}
.chrome {
  position: fixed;
  top: var(--chrome-top);
  left: var(--pad);
  right: var(--pad);
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
  color: var(--chrome-ink);
  transition:
    opacity 0.3s,
    color 0.4s;
}
.chrome > * {
  pointer-events: auto;
}
.chrome::before {
  /* a soft shade so the brand reads over any chapter, without drawing a bar */
  content: "";
  position: fixed;
  inset: 0 0 auto;
  height: 120px;
  z-index: -1;
  background: linear-gradient(var(--chrome-bg), transparent);
  pointer-events: none;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font: 800 var(--text-lead) / 1 var(--font-display);
  letter-spacing: 0.12em;
}
.brand .icon {
  width: 34px;
  height: 34px;
  stroke-width: 1.4;
}
.chrome-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}
/* Phone only: the current chapter's kanji in a seal, which opens the chapter sheet */
.chapter-button {
  display: none;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 6px;
  color: #ffeedd;
  font: 800 var(--text-lead) / 1 var(--font-display);
  text-shadow: var(--carved);
  /* the same carved lacquer as the buttons, with a solid shadow below for its thickness */
  background: var(--grain) 0 0 / 200px 200px, var(--lacquer);
  background-blend-mode: overlay, normal;
  box-shadow:
    inset 0 1px 0 #ffc8b080,
    inset 0 -1px 0 #5c130a8c,
    0 3px 0 #6a1a0e,
    0 6px 12px #0000005c;
}

/* While the 3D passage is on screen, the chrome and the rail wait. */
.threshold-active :is(.chrome, .rail) {
  opacity: 0;
  pointer-events: none;
}
.threshold-active .chrome > * {
  pointer-events: none;
}

/* ---------- The chapter rail: one kanji per chapter, the red sun travelling down it ---------- */
.rail {
  --step: 46px; /* space between two kanji: js/ui/chapter-rail.js moves the sun by this much */
  position: fixed;
  right: 12px;
  top: 50%;
  z-index: 20;
  transform: translateY(-50%);
  color: var(--chrome-ink);
  transition:
    opacity 0.3s,
    color 0.4s;
}
.rail ol {
  position: relative;
  margin: 0;
  padding: 0 14px 0 0;
  list-style: none;
}
.rail ol::before,
.rail ol::after {
  /* the track, and the part of it the sun has already travelled */
  content: "";
  position: absolute;
  right: 0;
  top: calc(var(--step) / 2);
  width: 1px;
  height: calc(var(--step) * 5);
  background: currentColor;
  opacity: 0.32;
}
.rail ol::after {
  height: var(--rail-y, 0px);
  background: var(--shu);
  opacity: 0.85;
}
.rail-sun {
  position: absolute;
  right: -4px;
  top: calc(var(--step) / 2 - 4.5px);
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--shu);
  box-shadow: 0 0 12px 2px #d9442f88;
  transform: translateY(var(--rail-y, 0px));
}
.rail a {
  position: relative;
  display: grid;
  place-items: center;
  width: 36px;
  height: var(--step);
  font: 800 var(--text-lead) / 1 var(--font-display);
  text-shadow: 0 0 12px var(--chrome-shadow, #0b0f0a);
  opacity: 0.5;
  transition: opacity 0.3s;
}
.rail a:hover,
.rail a[aria-current] {
  opacity: 1;
}
.rail-name {
  position: absolute;
  right: calc(100% + 6px);
  top: 50%;
  padding: 6px 10px;
  white-space: nowrap;
  font: 500 var(--text-label) / 1 var(--font-ui);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--paper);
  background: #0b0f0ad9;
  opacity: 0;
  transform: translate(6px, -50%);
  transition:
    opacity 0.25s,
    transform 0.25s;
  pointer-events: none;
}
.rail a:is(:hover, :focus-visible) .rail-name {
  opacity: 1;
  transform: translate(0, -50%);
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: calc(100% - 40px);
  padding: 13px 20px;
  font-size: var(--text-small);
  color: var(--paper);
  background: #141a12f2;
  border: 1px solid var(--line);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 15px);
  transition: 0.25s;
}
.toast::before {
  content: "";
  flex-shrink: 0;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--shu);
}
.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}
.threshold-active .toast {
  opacity: 0;
}

/* ---------- The page-wide petal canvas ---------- */
.landing-petals {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 12;
  opacity: 0; /* js/three/page-petals.js fades it in around chapter openings */
  transition: opacity 0.2s;
}
html.threshold-active .landing-petals,
body.modal-open .landing-petals {
  visibility: hidden;
}

/* ---------- Tablet and phone: the chapter seal and sheet take over from the rail ---------- */
@media (max-width: 1100px) {
  .chapter-button {
    display: grid;
  }
  .rail {
    display: none;
  }
}

/* ---------- Phone ---------- */
@media (max-width: 760px) {
  /* Phones scroll text right under the brand, so the shade becomes nearly solid at the top */
  :root {
    --chrome-bg: #0b0f0ae8;
  }
  :root[data-chapter="arts"] {
    --chrome-bg: #ebe5d3eb;
  }
  .chrome::before {
    height: 92px;
    background: linear-gradient(var(--chrome-bg) 62%, transparent);
  }
  .threshold-active .chrome::before {
    display: none;
  }
  .brand {
    gap: 10px;
  }
  .brand .icon {
    width: 30px;
    height: 30px;
  }
}

/* ---------- Reduced motion (OS setting or the Motion button) ---------- */
html.reduced *,
html.reduced *::before,
html.reduced *::after {
  animation: none !important;
  transition: none !important;
}
html:is(.reduced, .compact-layout) .landing-petals {
  display: none;
}
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}

/* ---------- V3: living characters (js/ui/living.js) ----------
   A .living-frame takes the old picture's class and box. Its video is larger than the picture (wind
   carries the scarf past its edges), absolutely placed by the script so the picture's part lands where
   the picture was. Nothing clips it: the frame lets it spill. */
.living-frame {
  overflow: visible;
}
.living-frame > .living-video {
  position: absolute;
  max-width: none;
  object-fit: fill;
  pointer-events: none;
}
