/* 글꼴(HN·PRT)은 frame.css 가 선언한다 */
:root {
  --ink: #05060a;
  --paper: #fff;
  --live: #ffd629;
  --tint: #7fd4c8;
  --face: "HN", "Pretendard", Arial, sans-serif; /* Helvetica Neue — @font-face 는 frame.css */
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #05060a;
    --paper: #fff;
  }
}

:root[data-theme="dark"] {
  --ink: #05060a;
  --paper: #fff;
}

html {
  scroll-padding-top: env(safe-area-inset-top, 0px);
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  background: var(--ink);
  color: var(--paper);
  font-family: var(--face);
}

canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 0;
  touch-action: none;
}

/* ── words: fixed at the centre; a stage fades out where it is and the next fades in where it is ── */
#words {
  font-family: var(--face);
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  font-weight: 700;
  /* 선명하게: 검은 바탕 위 밝은 글자가 번지지 않게(Mac). 커닝은 늘 켠다 */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-kerning: normal;
}

#words .st {
  position: absolute;
  inset: 0;
  /* 높이를 짝수 px 로 내림 → 가운데 정렬이 0.5px 에 걸리지 않는다 */
  bottom: auto;
  height: 100%;
  height: round(down, 100%, 2px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.6s ease;
}

#words .st.on {
  opacity: 1;
  transition: opacity 0.8s ease 0.4s;
}

#words .q {
  margin: 0;
  /* 큰 제목 1장 "WE WORK WITH AI": 선언이라 대문자. 65 Medium 48px
     (검은 바탕에서 75 Bold 는 한 단계 더 굵어 보여 Medium) */
  font-weight: 500; /* Helvetica Neue 65 Medium */
  font-size: min(48px, 6vw);
  font-size: round(down, min(48px, 6vw), 2px); /* 정수(짝수) px */
  line-height: 56px; /* 정수 px */
  letter-spacing: 0.02em;
  word-spacing: 0.04em; /* 0.16em 은 일부러 벌린 티가 나 0.04em */
  white-space: nowrap;
}

#words .ls {
  text-align: center;
  padding: 0 clamp(24px, 9vw, 170px); /* Helvetica 대문자는 폭이 넓어 긴 문장 한 줄이 들어가도록 13vw·230 → 9vw·170 */
  max-width: 1100px;
  text-wrap: balance;
}

#words i {
  display: block;
  font-style: normal;
  /* 작은 대문자를 넓은 자간으로: 65 Medium 20px — 24px Roman 과 무게는 비슷하고 더 단단하다 */
  font-weight: 500; /* Helvetica Neue 65 Medium */
  font-size: 20px;
  letter-spacing: 0.04em;
  word-spacing: 0.12em;
  line-height: 36px; /* 1.8배, 정수·짝수 px: 줄마다 픽셀에 딱 맞아 흐려지지 않는다 */
  opacity: 0;
  transition: opacity 0.5s ease 0s;
}

#words .st.on i {
  opacity: 1;
  transition: opacity 0.8s ease var(--d);
}

#words .tint {
  transition: color 0.4s ease 0s;
}

#words .st.on .tint {
  color: var(--tint);
  transition: color 1.8s ease 2.2s;
}

#hint {
  position: fixed;
  left: 50%;
  bottom: calc(54px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 3;
  font-weight: 400; /* 55 Roman — 하단 한 줄과 같다 */
  font-size: 12px;
  line-height: 1;
  font-family: var(--face);
  letter-spacing: 0.01em; /* 대소문자 Scroll — 하단 한 줄(Colophon 등)과 같은 간격 */
  color: #5a5955; /* 하단 한 줄과 같은 색(사이트 공통 회색) */
  opacity: 0;
  transition: opacity 0.8s;
  pointer-events: none;
}

#hint.on {
  opacity: 1;
}

/* 넓은 화면: SCROLL 을 하단 한 줄(카피라이트·새 숫자)과 같은 바닥선에. 정수 px 로 재서 맞춘 값 */
@media (min-width: 621px) {
  #hint {
    bottom: calc(30px + env(safe-area-inset-bottom, 0px));
  }
}

/* 바닥 오른쪽(#ctx, 틀이 옮겨 놓는다): 지금 화면의 새 수 — 노랑 점은 살아 있는 표시 */
#ctx .live {
  display: flex;
  align-items: center;
  gap: 9px;
  color: #5a5955;
  font-variant-numeric: tabular-nums;
}

#ctx .live i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--live);
  animation: pulse 2.4s ease-in-out infinite;
}

@keyframes pulse {
  50% {
    opacity: 0.35;
  }
}

/* 오른쪽 인디케이터 — Work Index 와 같은 점. 올리면 이름 */
#dots {
  position: fixed;
  right: 22px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

#dots button {
  position: relative;
  width: 7px;
  height: 7px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.5);
  background: none;
  cursor: pointer;
  transition:
    background 0.3s,
    border-color 0.3s;
}

#dots button::after {
  content: "";
  position: absolute;
  inset: -9px;
}

#dots button:hover {
  border-color: #fff;
}

#dots button.on {
  background: #fff;
  border-color: #fff;
}

#dots button span {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  white-space: nowrap;
  pointer-events: none;
  font-weight: 700; /* 인디케이터 이름표: Work Index 기준 — 10px · 75 Bold · 자간 0.1em · 회색 / 지금 장은 흰색 */
  font-size: 10px;
  line-height: 1;
  font-family: var(--face);
  letter-spacing: 0;
  color: #5a5955;
  opacity: 0;
  transition: opacity 0.2s;
}

#dots button.on span {
  color: #fff;
  opacity: 1; /* 지금 장의 이름은 항상 보인다. 다른 장은 마우스를 올릴 때만 */
}

#dots button:hover span,
#dots button:focus-visible span {
  opacity: 1;
}

#dots button:focus-visible {
  outline: 1px solid var(--tint);
  outline-offset: 3px;
}

body.menuOpen #dots,
body.menuOpen #hint,
body.menuOpen #words {
  visibility: hidden;
}

@media (max-width: 620px) {
  #dots {
    right: 10px;
    gap: 17px;
  }
}

/* MODEL~LIBRARY 장(sys): 첫 줄(이름) 아래 가운데 짧은 세로선 하나로 제목과 본문을 잇는다.
   선 1×20px, 위아래 12px → 44px(정수, 짝수). 본문은 제목과 같은 흰색 */
#words .st.sys i:first-child::after {
  content: "";
  display: block;
  width: 1px;
  height: 20px;
  margin: 12px auto;
  background: #5a5955;
}

/* 마지막 장: "IN 2100……" 다음 한 줄(행간과 같은 44px) 비움 */
#words .st[data-s="9"] i:first-child {
  margin-bottom: 36px; /* 빈 줄 = 행간 */
}

.fail {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: none;
  place-items: center;
  padding: 24px;
  text-align: center;
  color: #5a5955;
  font-weight: 500;
  font-size: 14px;
  line-height: 1.6;
  font-family: var(--face);
}

/* 태블릿·모바일 문장: 16px 은 잘 안 읽혀 20px. 행간도 크기에 맞춰 줄인다(정수 px) */
@media (max-width: 900px) {
  #words i {
    font-size: 20px;
    line-height: 32px;
  }
  #words .st.sys i:first-child::after {
    margin: 8px auto; /* 세로선 구간 36px(8 + 20 + 8) */
  }
  #words .st[data-s="9"] i:first-child {
    margin-bottom: 32px; /* 빈 줄 = 행간 */
  }
}

/* 큰 제목 4-1장 "AMOEBA AI SYSTEMS": 1장과 같은 대문자 선언(여기만 대소문자면 튄다) — 따로 두는 값 없이 #words .q 규칙 그대로 */

/* 5–8장 본문: 제목(첫 줄)은 대문자 흰색, 본문은 대소문자 회색, 핵심 단어만 민트.
   대소문자는 기본 간격이 넉넉해 자간·어간을 더하지 않는다. 회색은 반투명 대신 불투명(가장자리가 또렷) */
#words .st.sys i + i {
  color: #5a5955;
  letter-spacing: 0;
  word-spacing: 0;
}

/* 큰 제목의 줄바꿈 자리(<br class="m">): 데스크톱에서는 한 줄 */
#words .q br.m {
  display: none;
}

/* 모바일(620px 이하)
   · 큰 제목(1장, 4-1장): 24px / 행간 34px, 가운데 — 메인 시작 제목과 같은 값(저절로 넘어가는 제목의 모바일 규칙)
   · 그 밖의 글: 모두 왼쪽 정렬, 18px / 32px — 장 이름 줄(5–8장, IN 2100)도 본문과 같은 크기(메인 · Work Index 모바일과 같은 값)
   · 세로선도 왼쪽 */
@media (max-width: 620px) {
  #words .ls {
    padding: 0 40px 0 24px;
    text-align: left;
  }
  #words i {
    font-size: 18px;
    line-height: 32px;
  }
  #words .st.sys i:first-child,
  #words .st[data-s="9"] i:first-child {
    font-size: 18px;
    line-height: 32px;
  }
  #words .st.sys i:first-child::after {
    margin: 8px 0;
  }
  #words .q {
    font-size: 24px;
    line-height: 34px;
    letter-spacing: 0.06em;
    word-spacing: 0;
    white-space: normal;
    text-wrap: balance; /* 한 줄에 들어가면 한 줄, 좁은 폰에서는 고르게 두 줄 */
    padding: 0 24px;
    text-align: center;
  }
  /* 시작 제목(WE WORK WITH AI)은 한 줄. 중간 제목은 세 줄: AMOEBA / AI / SYSTEMS (<br class="m"> 을 이 장에서만 켠다) */
  #words .st[data-s="3"] .q br.m {
    display: inline;
  }
}

@media (prefers-reduced-motion: reduce) {
  #words .st,
  #words .st.on,
  #words i,
  #words .st.on i,
  #words .tint,
  #words .st.on .tint {
    transition-duration: 0.01s !important;
    transition-delay: 0s !important;
  }

  #ctx .live i {
    animation: none;
  }
}

/* ── 글꼴 규칙 시험: Work Index 규칙을 About 에 적용 ─────────────────────────────
   about.html 만 해당한다(<body data-type="wi">). 다른 about-*.html 은 그대로.
   A·B·C 블록은 따로 지울 수 있다 — 지우면 그 부분이 원래 About 값으로 돌아간다.
   1200px 미만(작은 노트북·태블릿·모바일)은 원래 About 값 그대로 — 24px 선언의 가장 긴 줄이 약 1,040px 라 그보다 좁으면 넘친다 */
@media (min-width: 1200px) {
  /* A. 큰 제목(1장 "WE WORK WITH AI" · 4-1장 "AMOEBA AI SYSTEMS") — Work Index 장 제목 규칙: 48px · 65 Medium · 자간 0.06em · 행간 72px */
  body[data-type="wi"] #words .q {
    font-weight: 500;
    font-size: 48px;
    line-height: 72px;
    letter-spacing: 0.06em;
    word-spacing: 0;
  }
  /* B. 본문 선언(1·2·4·9) — Work Index 세 문장 규칙: 24px · 65 Medium · 자간 0.012em · 어간 0.2em · 행간 48px */
  body[data-type="wi"] #words .st:not(.sys) i {
    font-weight: 500;
    font-size: 24px;
    line-height: 48px;
    letter-spacing: 0.012em;
    word-spacing: 0.2em;
  }
  /* C. 5~8장 — 제목 줄도 65 Medium(24px · 행간 48px). 제목과 본문은 대문자·넓은 자간 / 대소문자, 그리고 사이의 세로선으로 가른다. 본문은 24px · 65 Medium · 자간 -0.01em · 어간 0 · 행간 32px */
  body[data-type="wi"] #words .st.sys i {
    font-weight: 500;
    font-size: 24px;
    line-height: 48px;
    letter-spacing: 0.012em;
    word-spacing: 0.2em;
  }
  body[data-type="wi"] #words .st.sys i:not(:first-child) {
    font-weight: 500;
    line-height: 32px;
    letter-spacing: -0.01em; /* 대소문자 본문은 어간·자간을 좁게(대문자 선언과 다르게) */
    word-spacing: 0;
  }
}

/* ── 본문은 읽는 속도로 차오른다 (모든 화면 폭) ──
   글은 회색(#5a5955)으로 함께 나타나고, 한 줄씩 왼쪽에서 오른쪽으로 흰색이 된다. 다 차면 아래에 Scroll(저절로 넘어가지 않는다).
   .rd = 줄 안쪽의 글(about.html 의 스크립트가 감싸고, 차는 시간 --dur 과 시작 --del 을 글자 수로 정한다).
   5~8장은 제목 줄은 처음부터 흰색이고 본문만 찬다 — 다 찬 뒤의 구분은 대문자 / 대소문자와 가운데 세로선(굵기는 둘 다 65).
   민트 낱말은 처음부터 민트. 장을 떠날 때(.on 이 빠질 때)는 흰색인 채로 사라진다 */
#words .st.on i {
  transition: opacity 0.5s ease 0s; /* 줄들이 차례로 뜨지 않고 함께 나타난다(차오르는 것이 순서를 알린다) */
}
#words .st.sys i + i {
  color: #fff; /* 다 읽힌 뒤의 색. 차오르는 동안의 회색은 .rd 가 칠한다 */
}
#words .tint,
#words .st.on .tint {
  color: var(--tint);
  transition: none;
}
@supports ((-webkit-background-clip: text) or (background-clip: text)) {
  #words .st.on .rd {
    /* 그림 폭 206%: 왼쪽 100%는 흰색, 오른쪽 100%는 회색, 그 사이 6%가 좁은 경계 */
    background: linear-gradient(90deg, #fff 48.54%, var(--unread, #363532) 51.46%) 100% 0 / 206% 100% no-repeat;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    -webkit-box-decoration-break: slice;
    box-decoration-break: slice;
    padding: 0.3em 0; /* 색은 글자 상자 안에만 칠해진다 — 글자 윗부분이 잘리지 않게 상자를 위아래로 넓힌다(줄 간격은 그대로) */
    animation: aboutRead var(--dur, 1.2s) linear var(--del, 1s) both;
  }
  #words .st.on .rd .tint {
    -webkit-text-fill-color: var(--tint);
  }
}
@keyframes aboutRead {
  from {
    background-position: 100% 0;
  }
  to {
    background-position: 0 0;
  }
}
@media (prefers-reduced-motion: reduce) {
  #words .st.on .rd {
    animation: none;
    background: none;
    -webkit-text-fill-color: currentColor;
  }
  #words .st.on .rd .tint {
    -webkit-text-fill-color: var(--tint);
  }
}

/* 모바일: 지금 장의 이름표(CELLS 등)가 왼쪽 정렬 본문의 줄 끝과 겹친다 — Work Index 모바일과 같이 이름은 숨기고 점만 남긴다 */
@media (max-width: 620px) {
  #dots button.on span,
  #dots button:hover span {
    opacity: 0;
  }
}

/* ── 한글(html.ko — 주소의 ?lang=ko) ──
   Pretendard Bold(frame.css 의 "Pretendard KR Bold"), 자간·낱말 간격 0, 낱말 단위로만 줄이 바뀐다. 5~8장의 제목 줄은 영어 그대로(Helvetica).
   넓은 화면(1200px 이상): 24px / 48px — 5~8장 본문도 48px(Work Index 세 문장과 같은 행간).
   그리는 방식은 영어와 같다 — 차오르는 동안과 다 찬 뒤를 같은 방식으로 그려 글자가 흔들리지 않는다. 세로 자리는 스크립트가 기기 화소에 맞춘다 */
html.ko body[data-type] #words .st i.k,
html.ko body[data-type] #words .st i.k * {
  font-family: "Pretendard KR Bold", "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  font-weight: 700;
  letter-spacing: 0;
  word-spacing: 0;
  word-break: keep-all;
}
@media (min-width: 1200px) {
  html.ko body[data-type] #words .st i.k {
    font-size: 24px;
    line-height: 48px;
  }
}

/* 본문 줄 안의 <br class="m"> = 모바일에서만 줄을 바꾸는 자리(뜻 단위로 끊기게) */
#words .ls br.m {
  display: none;
}

/* ── 모바일(620px 이하): 본문은 왼쪽 정렬, 왼쪽 끝 24px 에 고정 ──
   글 상자를 화면 폭으로 넓혀 둔다 — 줄이 짧은 장에서도 글이 가운데로 떠 있지 않고 왼쪽 끝이 늘 같다.
   큰 제목(1장 · 4-1장)은 저절로 넘어가는 제목이라 가운데 그대로 */
@media (max-width: 620px) {
  #words .ls {
    width: 100%;
    box-sizing: border-box;
  }
  html.ko #words .ls {
    text-wrap: wrap; /* 줄 자리는 <br class="m"> 이 정한다 */
  }
  #words .ls br.m {
    display: inline;
  }
}
