:root {
  --white: #ffffff;
  --ink: #111111;
  --ink-soft: #555555;
  --orange: #ff6a13;
  --red: #e8322b;
  --blue: #2f5bff;
  --sans: "Noto Sans KR", system-ui, sans-serif;
  --pen: "Nanum Pen Script", "Noto Sans KR", cursive;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --hand: 255px 18px 225px 18px / 18px 225px 18px 255px; /* 손으로 그린 듯한 테두리 */
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { background: var(--white); }
body { color: var(--ink); font-family: var(--sans); -webkit-font-smoothing: antialiased; overflow-x: hidden; }
body.loading { overflow: hidden; }
img, svg, canvas { display: block; }
#track { height: 100vh; }
button { font: inherit; color: inherit; cursor: pointer; }

/* ---------- 로더: 펜 선 ---------- */
#loader { position: fixed; inset: 0; z-index: 100; display: grid; place-content: center; justify-items: center; gap: 6px; background: var(--white); transition: opacity .6s .3s, visibility 0s .9s; }
#loader.done { opacity: 0; visibility: hidden; }
.ld-line { width: min(720px, 86vw); height: auto; overflow: visible; }
.ld-line path { fill: none; stroke: var(--ink); stroke-width: 5; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 1; stroke-dashoffset: 1; transition: stroke-dashoffset .4s ease-out; }
.ld-name { font-family: var(--pen); font-size: clamp(40px, 6vw, 72px); line-height: 1; }
.ld-name span { font-size: .5em; color: var(--orange); margin-left: .3em; }
.ld-pct { font-family: var(--mono); font-size: 12px; letter-spacing: .14em; color: #888; }

/* ---------- 무대: WebGL 캔버스 + 같은 카메라를 따라가는 HTML 층 ---------- */
#gl { position: fixed; inset: 0; width: 100%; height: 100%; touch-action: pan-y; }
#view { position: fixed; inset: 0; z-index: 5; overflow: hidden; pointer-events: none; } /* 낙서 캔버스(3) 위 — S9 링크가 눌리게 */
.world { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.world > div { position: absolute; left: 0; top: 0; }
.page { width: 1600px; height: 9800px; }
#grain { position: fixed; inset: 0; z-index: 6; pointer-events: none; opacity: .5; mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .07  0 0 0 0 .06  0 0 0 0 .05  0 0 0 .11 0'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)'/%3E%3C/svg%3E"); }

/* ---------- 원고 위 글 (그림과 겹치지 않는 여백에만) ---------- */
.txt { position: absolute; z-index: 5; }
.txt .w { display: block; }
.label { font-family: var(--mono); font-size: 15px; letter-spacing: .14em; text-transform: uppercase; color: #777; margin-bottom: 18px; }
.h1 { font-weight: 900; font-size: 64px; line-height: 1.12; letter-spacing: -.045em; }
.h2 { font-weight: 900; font-size: 54px; line-height: 1.16; letter-spacing: -.04em; }
.h3 { font-weight: 700; font-size: 40px; line-height: 1.3; letter-spacing: -.035em; }
.big .line, .h1, .h2 { white-space: nowrap; }
.u { background: linear-gradient(rgba(255, 106, 19, .42), rgba(255, 106, 19, .42)) no-repeat 0 88% / 0% 38%; padding: 0 .04em; }
.pen { display: inline-block; font-family: var(--pen); font-size: 40px; line-height: 1.05; transform: rotate(-3deg); transform-origin: left center; white-space: nowrap; }
.pen.o { color: var(--orange); } .pen.r { color: var(--red); } .pen.b { color: var(--blue); }
.txt .pen { margin-top: 22px; }
.cap-dark { background: #0b0b0c; color: #f3f3f3; padding: 34px 40px 38px; border: 4px solid #0b0b0c; }
.cap-dark .label { color: #9a9a9a; }
.spark { font-weight: 900; font-size: 150px; line-height: 1; letter-spacing: -.06em; color: var(--orange); margin: 6px 0 14px; }
.ruler { position: absolute; border-left: 4px solid var(--ink); }
.ruler span { position: absolute; left: 14px; font: 500 20px var(--mono); transform: translateY(-50%); white-space: nowrap; }
.ruler span::before { content: ""; position: absolute; left: -18px; top: 50%; width: 16px; border-top: 4px solid var(--ink); }
.ruler span.deep { color: var(--blue); }
.ruler span.deep::before { border-top-style: dotted; }
.ruler i { position: absolute; left: -16px; top: -14px; width: 28px; height: 28px; border-radius: 50%; background: var(--blue); }

/* 그림 위 핫스팟: 펜으로 그린 동그라미 + 누르면 손글씨 메모 */
.hot { position: absolute; z-index: 6; pointer-events: auto; width: 64px; height: 64px; margin: -32px 0 0 -32px; border: 0; background: none; padding: 0; }
.hot::before { content: ""; position: absolute; inset: 10px; border: 4px solid var(--orange); border-radius: 48% 52% 45% 55% / 55% 45% 52% 48%; animation: ping 1.8s ease-in-out infinite; }
.hot span { position: absolute; left: 70px; top: 6px; font-family: var(--pen); font-size: 40px; color: var(--orange); white-space: nowrap; background: rgba(255, 255, 255, .92); padding: 2px 12px 4px; border-radius: var(--hand); opacity: 0; transform: translateY(8px) rotate(-3deg); transition: opacity .25s, transform .25s; pointer-events: none; }
.hot.on span { opacity: 1; transform: translateY(0) rotate(-3deg); }
.hot.on::before { animation: none; border-color: var(--ink); }
.hot:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; border-radius: 50%; }
@keyframes ping { 50% { transform: scale(1.18); opacity: .55; } }

/* 손그림 테두리 링크 */
.links { list-style: none; display: flex; flex-wrap: wrap; gap: 14px 16px; margin-top: 34px; }
.links a, .links button {
  display: inline-block; padding: 14px 24px; font: 500 20px var(--mono); letter-spacing: .06em; text-transform: uppercase;
  color: var(--ink); text-decoration: none; background: var(--white); pointer-events: auto;
  border: 3px solid var(--ink); border-radius: var(--hand);
  transition: background .15s, color .15s, transform .15s;
}
.links a:hover, .links button:hover { background: var(--orange); border-color: var(--orange); color: #fff; transform: rotate(-1.5deg); }
.links a:focus-visible, .links button:focus-visible { outline: 4px solid var(--blue); outline-offset: 4px; }
.links button { background: var(--ink); color: #fff; }

/* ---------- 인터랙션 자리(하단 가운데) ---------- */
#dock { position: fixed; left: 50%; bottom: 46px; z-index: 32; transform: translateX(-50%); display: flex; align-items: center; gap: 14px; pointer-events: none; transition: opacity .3s, transform .3s; }
#dock.off { opacity: 0; transform: translate(-50%, 10px); }
#dock .hint { font-family: var(--pen); font-size: 28px; color: var(--orange); white-space: nowrap; text-shadow: 0 0 6px #fff, 0 0 2px #fff; }
#dock.dark .hint { color: #ffb37c; text-shadow: none; }
#dock button {
  flex: none; white-space: nowrap; pointer-events: auto; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  font: 700 17px var(--sans); letter-spacing: -.02em; padding: 14px 26px; color: var(--ink); background: var(--white);
  border: 3px solid var(--ink); border-radius: var(--hand); box-shadow: 4px 4px 0 var(--ink); transition: transform .1s, box-shadow .1s, background .15s;
}
#dock button.held, #dock button:active { transform: translate(3px, 3px); box-shadow: 1px 1px 0 var(--ink); background: #fff3e8; }
#dock button:focus-visible { outline: 4px solid var(--blue); outline-offset: 4px; }
#dock .rec { font: 500 13px var(--mono); letter-spacing: .08em; color: #fff; mix-blend-mode: difference; white-space: nowrap; }

#doodle { position: fixed; inset: 0; z-index: 3; width: 100%; height: 100%; pointer-events: none; touch-action: none; }
body.doodling #doodle { pointer-events: auto; cursor: crosshair; }

#sound {
  position: fixed; left: 24px; bottom: 36px; z-index: 41; padding: 6px 12px 7px; font: 400 22px var(--pen); color: #fff; background: none;
  border: 2px solid #fff; border-radius: var(--hand); mix-blend-mode: difference;
}
#sound[aria-pressed="true"] { background: #fff; color: #000; }
#sound:focus-visible { outline: 3px solid var(--blue); outline-offset: 3px; }

/* ---------- 진행 표시: 하단 펜 선 ---------- */
#progress { position: fixed; left: 24px; right: 24px; bottom: 14px; width: calc(100% - 48px); height: 18px; z-index: 40; overflow: visible; pointer-events: none; mix-blend-mode: difference; }
#progress path { fill: none; stroke: #fff; stroke-width: 2.4; stroke-linecap: round; stroke-dasharray: 1; stroke-dashoffset: 1; }

/* ---------- 세로 화면: 원고 위 글은 숨기고 하단 캡션으로 ---------- */
#mcap { display: none; }
body.portrait .txt, body.portrait .ruler { display: none; }
body.portrait #mcap { display: block; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; min-height: 33vh; padding: 22px 22px 46px; background: var(--white); box-shadow: 0 -1px 0 var(--ink); }
body.portrait #dock { bottom: calc(33vh + 62px); width: calc(100vw - 32px); flex-wrap: wrap; justify-content: center; gap: 8px 12px; } /* 소리 버튼(왼쪽 아래)과 겹치지 않게 한 줄 위로, 좁으면 힌트가 윗줄로 */
body.portrait #dock .hint { flex: 1 0 100%; text-align: center; font-size: 24px; }
body.portrait #sound { bottom: calc(33vh + 18px); }
body.portrait .hot span { font-size: 54px; }
#mcap.dark { background: #0b0b0c; color: #f3f3f3; box-shadow: none; }
#mcap .label { font-size: 11px; margin-bottom: 10px; }
#mcap .h1 { font-size: 34px; } #mcap .h2 { font-size: 27px; } #mcap .h3 { font-size: 22px; }
#mcap .spark { font-size: 60px; margin: 4px 0 6px; }
#mcap .pen { font-size: 26px; margin: 10px 0 0; }
#mcap p.w:not(.h1):not(.h2):not(.h3):not(.pen):not(.label):not(.spark) { font-size: 14px; color: #666; }
#mcap .w { animation: write .55s both; animation-delay: calc(var(--i, 0) * .1s); }
#mcap .u { background-size: 100% 38%; }
#mcap .links { margin-top: 16px; gap: 10px; }
#mcap .links a, #mcap .links button { font-size: 13px; padding: 10px 16px; }
@keyframes write { from { clip-path: inset(-10% 100% -10% -4%); } to { clip-path: inset(-10% -4% -10% -4%); } }

@media (prefers-reduced-motion: reduce) {
  .hot::before { animation: none; }
}
