/* ==========================================================================
   Opening — 「湯の流れが、TOJISMの世界をひらく。」
   Shown only while <html> has .opening-active (set by the inline script in
   index.html on a first visit). The overlay carries the `hidden` attribute,
   so without that class — or if this file fails to load — nothing is shown.
   The CSS animation alone hides the overlay at ~9.6s; opening.js only adds
   skip / cleanup.

   Timeline: light 0–0.7s → ripples / contours 0.45–1.9s → TOJISM 0.8–1.7s
   → message typed one character at a time 1.6–6.9s → hold
   → slow wipe to the main page 7.6–9.6s
   ========================================================================== */

.opening-active {
  overflow: hidden;
}

.opening-active .opening[hidden] {
  position: fixed;
  z-index: 1000;
  inset: 0;
  display: grid;
  place-items: center;
  color: #fff;
  background:
    radial-gradient(90% 70% at 50% 68%, rgba(30, 64, 54, 0.9) 0%, rgba(14, 24, 21, 0) 70%),
    #0c1110;
  /* 7.6s → 9.6s: the overlay is slowly wiped away left → right along the light line */
  animation: opening-wipe 2000ms cubic-bezier(0.55, 0, 0.35, 1) 7600ms forwards;
}

@keyframes opening-wipe {
  from {
    clip-path: inset(0 0 0 0);
  }
  to {
    clip-path: inset(0 0 0 100%);
    visibility: hidden;
  }
}

/* Decorative lines -------------------------------------------------------- */

.opening-lines {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.opening-lines path,
.opening-lines ellipse {
  fill: none;
  vector-effect: non-scaling-stroke;
}

/* Contour / spring-vein lines grow outward from the light (0.5s → ~1.5s) */
.opening-contour {
  stroke: #dcb684;
  stroke-width: 1;
  stroke-dasharray: 0 2;
  stroke-dashoffset: -0.5;
  animation:
    opening-grow 950ms cubic-bezier(0.22, 1, 0.36, 1) var(--d, 500ms) forwards,
    opening-drift 2000ms cubic-bezier(0.55, 0, 0.35, 1) 7600ms forwards;
}

.opening-contour:nth-of-type(1) { --d: 500ms; opacity: 0.55; }
.opening-contour:nth-of-type(2) { --d: 560ms; opacity: 0.5; }
.opening-contour:nth-of-type(3) { --d: 640ms; opacity: 0.38; }
.opening-contour:nth-of-type(4) { --d: 700ms; opacity: 0.32; }
.opening-contour:nth-of-type(5) { --d: 780ms; opacity: 0.24; }
.opening-contour:nth-of-type(6) { --d: 840ms; opacity: 0.2; }
.opening-contour:nth-of-type(7) { --d: 920ms; opacity: 0.14; }

@keyframes opening-grow {
  to {
    stroke-dasharray: 1 2;
    stroke-dashoffset: 0;
  }
}

/* Lines stream to the right as the page is revealed */
@keyframes opening-drift {
  to {
    transform: translateX(6%);
  }
}

/* Pulses of heat travelling outward through two of the lines (like flow in a pipe).
   Three slow pulses keep the background quietly alive while the message is typed. */
.opening-flow {
  stroke: #f6dfb8;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-dasharray: 0.05 2;
  stroke-dashoffset: -0.48;
  opacity: 0;
  animation: opening-flow 2200ms cubic-bezier(0.45, 0, 0.2, 1) 1100ms 3 forwards;
}

.opening-flow-back {
  animation-name: opening-flow-back;
}

@keyframes opening-flow {
  0% { opacity: 0; stroke-dashoffset: -0.48; }
  8% { opacity: 0.9; }
  50% { opacity: 0.9; }
  60%, 100% { opacity: 0; stroke-dashoffset: -1; }
}

@keyframes opening-flow-back {
  0% { opacity: 0; stroke-dashoffset: -0.48; }
  8% { opacity: 0.9; }
  50% { opacity: 0.9; }
  60%, 100% { opacity: 0; stroke-dashoffset: 0.05; }
}

/* Ripples on the water surface (0.45s →) */
.opening-ripple {
  stroke: #dcb684;
  stroke-width: 1;
  opacity: 0;
  transform: scale(0.04);
  transform-box: fill-box;
  transform-origin: center;
  animation: opening-ripple 1700ms cubic-bezier(0.22, 1, 0.36, 1) var(--d, 450ms) forwards;
}

.opening-ripple:nth-of-type(2) { --d: 700ms; }
.opening-ripple:nth-of-type(3) { --d: 950ms; }

@keyframes opening-ripple {
  0% { opacity: 0; transform: scale(0.04); }
  20% { opacity: 0.7; }
  100% { opacity: 0; transform: scale(1); }
}

/* The amber light (0.0s → 0.5s) */
.opening-glow,
.opening-light {
  opacity: 0;
  transform-box: fill-box;
  transform-origin: center;
  animation: opening-light 600ms ease-out 100ms forwards;
}

.opening-glow {
  fill: url(#opening-glow);
}

.opening-light {
  fill: #f6dfb8;
}

@keyframes opening-light {
  from { opacity: 0; transform: scale(0.3); }
  to { opacity: 1; transform: scale(1); }
}

/* The leading edge of the wipe: a thin line of light crossing the screen */
.opening-sweep {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 200px;
  background: linear-gradient(90deg, #f6dfb8 0, rgba(220, 182, 132, 0.5) 2px, rgba(220, 182, 132, 0) 100%);
  opacity: 0;
  transform: translateX(0);
  animation: opening-sweep 2000ms cubic-bezier(0.55, 0, 0.35, 1) 7600ms forwards;
  pointer-events: none;
}

@keyframes opening-sweep {
  0% { opacity: 1; transform: translateX(0); }
  100% { opacity: 1; transform: translateX(100vw); }
}

/* Logo and message ------------------------------------------------------- */

.opening-inner {
  position: relative;
  display: grid;
  justify-items: center;
  gap: clamp(14px, 2.4vw, 22px);
  padding: 0 20px;
  text-align: center;
  /* sit slightly above the light source */
  transform: translateY(-6vh);
}

.opening-logo {
  margin: 0;
  font-family: "Montserrat", "Helvetica Neue", Arial, sans-serif;
  font-size: clamp(44px, 9vw, 112px);
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0.4em;
  /* text-indent balances the trailing letter-spacing so the word stays centred */
  text-indent: 0.4em;
  opacity: 0;
  filter: blur(10px);
  animation: opening-logo 900ms cubic-bezier(0.22, 1, 0.36, 1) 800ms forwards;
}

@keyframes opening-logo {
  to {
    letter-spacing: 0.06em;
    text-indent: 0.06em;
    opacity: 1;
    filter: blur(0);
  }
}

/* The message is typed one character at a time (180ms apart).
   Each line sets --base (its start time) inline; each character sets --i. */
.opening-message {
  display: grid;
  justify-items: center;
  gap: 0.5em;
  margin: 0;
  font-family: "Noto Serif JP", "Yu Mincho", "Hiragino Mincho ProN", serif;
  font-size: clamp(17px, 2.6vw, 32px);
  font-weight: 500;
  line-height: 1.5;
  letter-spacing: 0.12em;
}

.opening-line {
  display: block;
  color: rgba(255, 255, 255, 0.92);
  white-space: nowrap;
  /* balance the trailing letter-spacing so each line stays centred */
  text-indent: 0.12em;
}

.opening-line-accent {
  color: #dcb684;
}

/* Half-width figures for 「150」, set close together */
.opening-num {
  letter-spacing: 0.02em;
}

.opening-char {
  display: inline-block;
  opacity: 0;
  filter: blur(6px);
  transform: translateY(0.35em);
  animation: opening-char 650ms cubic-bezier(0.22, 1, 0.36, 1) calc(var(--base) + var(--i) * 180ms) forwards;
}

@keyframes opening-char {
  to {
    opacity: 1;
    filter: blur(0);
    transform: none;
  }
}

/* Skip — usable from the first frame -------------------------------------- */

.opening-skip {
  position: absolute;
  z-index: 2;
  top: max(16px, env(safe-area-inset-top));
  right: max(16px, env(safe-area-inset-right));
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 44px;
  min-height: 44px;
  padding: 8px 18px;
  color: rgba(255, 255, 255, 0.9);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 999px;
  font-family: "Montserrat", "Helvetica Neue", Arial, sans-serif;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.16em;
  cursor: pointer;
  transition: background 160ms ease, border-color 160ms ease;
}

.opening-skip:hover,
.opening-skip:focus-visible {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.7);
}

.opening-skip:focus-visible {
  outline: 2px solid #dcb684;
  outline-offset: 3px;
}

/* Reduced motion: no lines moving, no typing, no wipe — the whole message is
   shown at once, held long enough to read, then fades out (~3.6s).
   !important is needed to win over the site-wide reduced-motion rule in styles.css. */
@media (prefers-reduced-motion: reduce) {
  .opening-active .opening[hidden] {
    animation: opening-fade-out 600ms ease 3000ms forwards !important;
  }

  .opening-inner {
    animation: opening-fade-in 400ms ease both !important;
  }

  .opening-logo {
    letter-spacing: 0.06em;
    text-indent: 0.06em;
    opacity: 1;
    filter: none;
    animation: none !important;
  }

  .opening-char {
    opacity: 1;
    filter: none;
    transform: none;
    animation: none !important;
  }

  .opening-contour {
    stroke-dasharray: none;
    animation: none !important;
  }

  .opening-glow,
  .opening-light {
    opacity: 1;
    transform: none;
    animation: none !important;
  }

  .opening-ripple,
  .opening-flow,
  .opening-sweep {
    display: none;
  }
}

@keyframes opening-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes opening-fade-out {
  to {
    opacity: 0;
    visibility: hidden;
  }
}
