/* [Define404] */
/* Define404 전환·로더·숨은 404·비밀 장면·404 게임.
   토큰은 site.css 만 쓴다. 곡선은 --ease, --ease-in 두 개. */

/* ---------- 1. 페이지 전환: 문서 사이 View Transitions ---------- */
@media (prefers-reduced-motion: no-preference) {
  @view-transition { navigation: auto; }
}
.site-head .wordmark { view-transition-name: d404-wordmark; }

::view-transition-old(root) {
  animation: vt-old 560ms cubic-bezier(0.2, 0, 0, 1) both;
}
::view-transition-new(root) {
  animation: vt-new 560ms cubic-bezier(0.05, 0.7, 0.1, 1) both;
}
::view-transition-group(d404-wordmark) {
  animation-duration: 560ms;
  animation-timing-function: cubic-bezier(0.2, 0, 0, 1);
}
@keyframes vt-old {
  to { transform: translateX(-6%); opacity: 0.4; }
}
/* 새 페이지가 지그재그 가장자리로 왼쪽에서 오른쪽으로 덮는다 */
@keyframes vt-new {
  from { clip-path: polygon(calc(0% - 60px) 0, calc(0% - 40px + 0px) 0%, calc(0% - 40px + 28px) 8.3333%, calc(0% - 40px + 0px) 16.6667%, calc(0% - 40px + 28px) 25%, calc(0% - 40px + 0px) 33.3333%, calc(0% - 40px + 28px) 41.6667%, calc(0% - 40px + 0px) 50%, calc(0% - 40px + 28px) 58.3333%, calc(0% - 40px + 0px) 66.6667%, calc(0% - 40px + 28px) 75%, calc(0% - 40px + 0px) 83.3333%, calc(0% - 40px + 28px) 91.6667%, calc(0% - 40px + 0px) 100%, calc(0% - 60px) 100%); }
  to { clip-path: polygon(calc(0% - 60px) 0, calc(100% + 0px) 0%, calc(100% + 28px) 8.3333%, calc(100% + 0px) 16.6667%, calc(100% + 28px) 25%, calc(100% + 0px) 33.3333%, calc(100% + 28px) 41.6667%, calc(100% + 0px) 50%, calc(100% + 28px) 58.3333%, calc(100% + 0px) 66.6667%, calc(100% + 28px) 75%, calc(100% + 0px) 83.3333%, calc(100% + 28px) 91.6667%, calc(100% + 0px) 100%, calc(0% - 60px) 100%); }
}
@media (prefers-reduced-motion: reduce) {
  ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
}

/* 미지원 브라우저용 먹 덮개. JS가 clip-path 를 움직인다 */
.pt-wipe {
  position: fixed; inset: 0; z-index: 96;
  background: var(--ink-1);
  pointer-events: none;
}
/* 머리 스크립트가 html.pt-in 을 붙였으면 첫 페인트부터 덮어 둔다. 2초 뒤에는 무조건 걷힌다 */
html.pt-in body::after {
  content: ""; position: fixed; inset: 0; z-index: 96; background: var(--ink-1);
  animation: d404-failsafe 0s linear 2s forwards;
}
@keyframes d404-failsafe { to { visibility: hidden; opacity: 0; } }

/* ---------- 2. 로더 (홈, 세션 첫 방문) ---------- */
#loader { display: none; }
html.d404-loading #loader,
#loader.is-on {
  display: block; position: fixed; inset: 0; z-index: 90;
  background: var(--paper);
}
html.d404-loading #loader { animation: d404-failsafe 0s linear 2s forwards; }
#loader.is-on { animation: none; }
.loader-inner {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  padding: 0 16px;
}
.loader-mark { width: min(64vw, 360px); color: var(--ink-1); }
.loader-mark svg { width: 100%; height: auto; overflow: visible; }
.loader-line {
  position: fixed; left: 0; right: 0; z-index: 91;
  height: 2px; margin-top: -1px;
  background: var(--ink-1);
  transform: scaleX(0);
  pointer-events: none;
}

/* ---------- 3. 숨은 404 ---------- */
:where([data-404-slot]) { position: relative; }
.f404 {
  -webkit-appearance: none; appearance: none;
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 1px;
  min-width: 24px; min-height: 24px; padding: 3px 4px;
  margin: 0; border: 0; border-radius: var(--r-sm);
  background: transparent;
  color: var(--ink-3);
  font: 700 9px/1 var(--font-sans);
  letter-spacing: 0.04em;
  font-feature-settings: "tnum" 1;
  opacity: 0.55;
  cursor: help;
  vertical-align: middle;
  transition: opacity var(--t-quick) var(--ease), color var(--t-quick) var(--ease);
}
.f404:hover, .f404:focus-visible { opacity: 1; color: var(--ink-1); }
.f404-glyph { display: block; }
.f404-wave { display: block; width: 18px; height: 5px; overflow: visible; }
.f404-zig, .f404-flat { fill: none; stroke-width: 1.2; }
.f404-zig { stroke: var(--sky); stroke-dasharray: 40; stroke-dashoffset: 0; transition: stroke-dashoffset var(--t-std) var(--ease); }
.f404-flat { stroke: currentColor; transform: scaleX(0); transform-origin: 0 50%; transform-box: fill-box; transition: transform var(--t-std) var(--ease-in) 120ms; }
.f404:hover .f404-zig { animation: f404-wiggle 600ms var(--ease); }
@keyframes f404-wiggle { 30% { transform: translateY(-1px); } 60% { transform: translateY(1px); } }
.f404.is-found { opacity: 1; color: var(--ink-1); cursor: default; }
.f404.is-found .f404-zig { stroke-dashoffset: 40; }
.f404.is-found .f404-flat { transform: scaleX(1); }
.f404.is-nudge { animation: f404-nudge 360ms var(--ease); }
@keyframes f404-nudge { 25% { transform: translateX(-2px); } 75% { transform: translateX(2px); } }

/* 어두운 바탕 */
.chapter-ink .f404, .site-foot .f404 { color: var(--line-2); }
.chapter-ink .f404:hover, .site-foot .f404:hover,
.chapter-ink .f404:focus-visible, .site-foot .f404:focus-visible,
.chapter-ink .f404.is-found, .site-foot .f404.is-found { color: var(--paper); }

/* 자리별 배치 */
.f404-inline { margin-left: 6px; }
.f404-li { position: absolute; left: var(--gutter); bottom: -36px; list-style: none; }
.f404-abs-tree { position: absolute; right: var(--gutter); bottom: -32px; }
.f404-abs-corner { position: absolute; top: 6px; right: 6px; }

/* 선 조각 터짐 */
.f404-burst { position: fixed; left: 0; top: 0; width: 0; height: 0; z-index: 85; pointer-events: none; }
.f404-burst i { position: absolute; left: 0; top: -0.75px; width: 12px; height: 1.5px; transform-origin: 0 50%; }

/* 모두 찾았을 때 */
.f404-done {
  position: fixed; left: 16px; bottom: 16px; z-index: 75;
  max-width: calc(100vw - 32px);
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px;
  padding: 14px 16px;
  background: var(--paper-raised); color: var(--ink-1);
  border: var(--bw) solid var(--ink-1); border-radius: var(--r-sm);
  font-size: var(--fs-small);
  transform: translateY(calc(100% + 24px));
  transition: transform var(--t-std) var(--ease-in);
}
.f404-done.is-in { transform: none; }
.f404-done p { margin: 0; font-weight: 650; }
.f404-done a { font-weight: 700; color: var(--sky-ink); border-bottom: 1px solid currentColor; }
.f404-done button {
  -webkit-appearance: none; appearance: none; border: 0; background: transparent; padding: 4px 0;
  font: inherit; color: var(--ink-3); cursor: pointer;
}
.f404-done button:hover { color: var(--ink-1); }
.f404-footlink { margin-left: 10px; color: var(--sky); border-bottom: 1px solid currentColor; font-weight: 650; }

/* ---------- 4. 비밀 장면 /found ---------- */
.scene { min-height: 100svh; padding: calc(var(--head-h) + var(--s8)) 0 var(--s9); display: flex; align-items: center; }
.scene-inner { position: relative; width: 100%; }
.scene-inner > :not(.scene-rain) { position: relative; z-index: 1; }
.scene-title {
  position: relative;
  display: flex; flex-wrap: wrap;
  margin: var(--s5) 0 var(--s6);
  font-size: clamp(64px, 16vw, 220px); line-height: 1; font-weight: 820; letter-spacing: var(--tr-display);
}
.scene-ch { position: relative; display: inline-block; }
.scene-ch .ch { display: inline-block; }
.scene-ch .q { position: absolute; left: 0; right: 0; top: 0; text-align: center; color: var(--ink-3); font-style: normal; font-weight: 500; opacity: 0; }
.scene-js .scene-ch .ch { opacity: 0; }
.scene-rule { position: relative; display: block; height: 10px; margin-top: -4px; margin-bottom: var(--s6); max-width: 100%; }
.scene-rule svg { width: 100%; height: 10px; overflow: visible; }
.scene-rule .zig { fill: none; stroke: var(--sky); stroke-width: 2; vector-effect: non-scaling-stroke; transition: opacity var(--t-std) var(--ease); }
.scene-rule .flat { position: absolute; left: 0; right: 0; top: 4px; height: 2px; background: var(--ink-1); transform: scaleX(0); transform-origin: 0 50%; transition: transform var(--t-slow) var(--ease-in); }
.scene-rule.is-defined .zig { opacity: 0; }
.scene-rule.is-defined .flat { transform: scaleX(1); }
.scene-lead { font-size: clamp(20px, 2.6vw, 32px); font-weight: 700; letter-spacing: -0.02em; line-height: 1.35; max-width: 28ch; }
.scene-en { margin-top: var(--s3); color: var(--ink-3); font-size: var(--fs-small); }
.scene-note { margin-top: var(--s5); color: var(--ink-2); }
.scene-actions { margin-top: var(--s6); }
.scene-rain { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.scene-rain i {
  position: absolute; top: 0; font-style: normal; font-weight: 600;
  color: var(--ink-3); font-size: 14px; line-height: 1;
}
.scene-rain i.is-sky { color: var(--sky-ink); }
.scene-floor { position: absolute; left: 0; right: 0; bottom: 0; height: 1px; background: var(--line-1); }

/* ---------- 5. 404 게임 ---------- */
.nf { padding: calc(var(--head-h) + var(--s7)) 0 var(--s9); }
.nf-title {
  font-size: clamp(28px, 4.6vw, 60px); font-weight: 780; letter-spacing: -0.03em; line-height: 1.18;
  margin: var(--s4) 0 var(--s3);
  word-break: keep-all;
}
.nf-mark { position: relative; display: inline-block; padding-bottom: 6px; }
.nf-mark::before, .nf-mark::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; pointer-events: none; }
.nf-mark::before {
  height: 8px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='8' viewBox='0 0 16 8'%3E%3Cpath d='M0 7 L4 1 L8 7 L12 1 L16 7' fill='none' stroke='%236CC4F2' stroke-width='2' stroke-linecap='square'/%3E%3C/svg%3E") repeat-x left bottom / 16px 8px;
  transition: clip-path var(--t-std) var(--ease);
  clip-path: inset(0 0 0 0);
}
.nf-mark::after { height: 3px; background: var(--ink-1); transform: scaleX(0); transform-origin: 0 50%; transition: transform var(--t-slow) var(--ease-in) 120ms; }
.is-won .nf-mark::before { clip-path: inset(0 0 0 100%); }
.is-won .nf-mark::after { transform: scaleX(1); }
.nf-en { color: var(--ink-3); font-size: var(--fs-small); }
.nf-lead { margin-top: var(--s5); color: var(--ink-2); max-width: 44ch; }
.nf-game { margin-top: var(--s6); }
.nf-lane {
  position: relative; display: block; width: 100%; height: 240px;
  background: var(--paper-raised);
  border: var(--bw) solid var(--line-1); border-radius: var(--r-sm);
  touch-action: none; cursor: crosshair;
}
.nf-lane:focus-visible { outline: 2px solid var(--sky-ink); outline-offset: 3px; }
.nf-lane canvas { display: block; width: 100%; height: 100%; }
.nf-bar { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px var(--s5); margin-top: var(--s3); font-size: var(--fs-small); color: var(--ink-3); }
.nf-status { color: var(--ink-2); font-weight: 600; }
.nf-done { margin-top: var(--s6); display: none; }
.is-won .nf-done { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s4) var(--s5); }
.nf-done p { font-weight: 650; }
@media (max-width: 600px) {
  .nf-lane { height: 220px; }
}
