/* =====================================================================
   CHERRYPLAN MOTION STUDIES — site.css
   공통 디자인 시스템. 갤러리 / 작품 페이지 / Remix Lab이 함께 사용한다.
   작품(art.html) 내부에는 절대 영향을 주지 않는다 (iframe으로 격리).

   구조
   1. Tokens          5. Gallery
   2. Base            6. Artwork page (stage + lab panel)
   3. Layout/Header   7. Remix Lab components (sheet, code, fallback)
   4. Buttons         8. Record mode (?record=1)
   ===================================================================== */

/* 0. Fonts ----------------------------------------------------------- */
/* Bricolage Grotesque (SIL OFL 1.1, 셀프 호스팅 — decisions D-16). 라틴 서브셋 · wght 축 · 41KB.
   한글은 unicode-range 밖이라 자동으로 시스템 폰트(--font-sans)로 표시된다. */
@font-face {
  font-family: "Bricolage Grotesque";
  font-style: normal;
  font-display: swap;
  font-weight: 200 800;
  src: url("/assets/fonts/bricolage-grotesque-latin-wght.woff2") format("woff2-variations"),
       url("/assets/fonts/bricolage-grotesque-latin-wght.woff2") format("woff2");
  unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD;
}

/* 1. Tokens ---------------------------------------------------------- */
:root {
  /* Brand (PRD §2) */
  --cp-black: #111111;
  --cp-paper: #f8f7f4;
  --cp-cherry: #d91f45;

  /* Derived neutrals — 브랜드 3색에서 파생, 임의 색 추가 최소화 */
  --cp-ink: var(--cp-black);
  --cp-ink-2: #55534e;          /* 보조 텍스트 (paper 위 대비 7:1 이상) */
  --cp-ink-3: #8a877f;          /* 라벨/메타 (큰 글씨 전용) */
  --cp-line: #e3e0d8;
  --cp-line-strong: #cfcbc1;
  --cp-surface: #ffffff;
  --cp-surface-2: #efede7;
  --cp-cherry-ink: #b8173a;     /* 작은 텍스트용 체리 (대비 확보) */
  --cp-success: #1f7a4d;

  /* Type — 외부 폰트 없이 시스템 폰트 (라이선스/성능, decisions.md D-06) */
  --font-sans: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard",
    "Segoe UI", "Noto Sans KR", "Malgun Gothic", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: "Bricolage Grotesque", var(--font-sans);
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono",
    "D2Coding", monospace;

  --fs-xs: 0.75rem;
  --fs-sm: 0.875rem;
  --fs-md: 1rem;
  --fs-lg: 1.25rem;
  --fs-xl: clamp(1.75rem, 1.2rem + 2.4vw, 2.75rem);

  /* Space (4px grid) */
  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px;
  --sp-5: 24px; --sp-6: 32px; --sp-7: 48px; --sp-8: 64px;

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 16px;

  --header-h: 56px;
  --tap: 48px;                   /* 최소 터치 타깃 */
  --panel-w: 400px;
  --ease: cubic-bezier(0.2, 0.7, 0.1, 1);

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);

  /* Motion tokens (design-direction §3.1) — UI 전환에 공통 사용 */
  --dur-instant: 120ms;
  --dur-quick: 220ms;
  --dur-base: 360ms;
  --dur-slow: 640ms;
  --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out-quint: cubic-bezier(0.83, 0, 0.17, 1);
  --ease-overshoot: cubic-bezier(0.34, 1.56, 0.64, 1);

  color-scheme: light;
}

/* 2. Base ------------------------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--cp-paper);
  color: var(--cp-ink);
  font-family: var(--font-sans);
  font-size: var(--fs-md);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;            /* PRD §11: 본문 가로 스크롤 없음 */
  word-break: keep-all;          /* 한글 단어 단위 줄바꿈 */
  overflow-wrap: anywhere;
}

img, svg, iframe { display: block; max-width: 100%; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }

:focus-visible {
  outline: 2px solid var(--cp-cherry);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

.mono { font-family: var(--font-mono); letter-spacing: 0.02em; }

.eyebrow {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--cp-ink-2);
}

[hidden] { display: none !important; }

/* 3. Layout / Header ------------------------------------------------- */
.site {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  min-height: calc(var(--header-h) + var(--safe-top));
  padding: var(--safe-top) calc(var(--sp-4) + var(--safe-right)) 0 calc(var(--sp-4) + var(--safe-left));
  background: color-mix(in srgb, var(--cp-paper) 92%, transparent);
  -webkit-backdrop-filter: saturate(1.2) blur(10px);
  backdrop-filter: saturate(1.2) blur(10px);
  border-bottom: 1px solid var(--cp-line);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: var(--tap);
  text-decoration: none;
  font-weight: 700;
  letter-spacing: -0.01em;
}

/* 심벌: 작은 붉은 원 두 개 + 연결선 (PRD §2) */
.brand-mark { width: 26px; height: 14px; flex: none; }
.brand-mark circle { fill: var(--cp-cherry); }
.brand-mark line { stroke: var(--cp-ink); stroke-width: 1.25; }

.site-header .collection {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  letter-spacing: 0.14em;
  color: var(--cp-ink-2);
  text-transform: uppercase;
}

.site-header .series-id {
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  color: var(--cp-ink);
}

.site-main { flex: 1; width: 100%; }

.container {
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 calc(var(--sp-4) + var(--safe-right)) 0 calc(var(--sp-4) + var(--safe-left));
}

.site-footer {
  border-top: 1px solid var(--cp-line);
  padding: var(--sp-5) 0 calc(var(--sp-5) + var(--safe-bottom));
  color: var(--cp-ink-2);
  font-size: var(--fs-sm);
}
.site-footer .container {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--sp-3);
}

@media (max-width: 560px) {
  .site-header .collection { display: none; }
}

/* 4. Buttons --------------------------------------------------------- */
.btn {
  -webkit-appearance: none;
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: var(--tap);
  padding: 0 var(--sp-5);
  border: 1px solid var(--cp-ink);
  border-radius: var(--radius);
  background: transparent;
  color: var(--cp-ink);
  font-weight: 600;
  font-size: var(--fs-md);
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;    /* iOS 더블탭 확대 지연 제거 */
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.18s var(--ease), color 0.18s var(--ease),
    border-color 0.18s var(--ease), transform 0.12s var(--ease);
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

@media (hover: hover) {
  .btn:hover { background: var(--cp-surface-2); }
  .btn--primary:hover { background: #2a2a2a; }
}

/* 최우선 CTA (내 버전 만들기) — 검정 바탕 + 체리 포인트 점 */
.btn--primary {
  background: var(--cp-ink);
  color: var(--cp-paper);
}
.btn--primary::before {
  content: "";
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--cp-cherry);
  flex: none;
}

.btn--ghost { border-color: var(--cp-line-strong); }
.btn--sm { min-height: 40px; padding: 0 var(--sp-4); font-size: var(--fs-sm); }
.btn--block { width: 100%; }

/* 복사 상태 피드백 (버튼 라벨이 바뀜 — 작품을 가리는 토스트 대신) */
.btn[data-state="success"] { border-color: var(--cp-success); color: var(--cp-success); background: transparent; }
.btn--primary[data-state="success"] { background: var(--cp-success); color: #fff; }
.btn--primary[data-state="success"]::before { background: #fff; }
.btn[data-state="error"] { border-color: var(--cp-cherry); color: var(--cp-cherry-ink); background: transparent; }
.btn--primary[data-state="error"] { background: var(--cp-cherry); color: #fff; }

.text-link {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
  color: var(--cp-ink);
  text-underline-offset: 3px;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  font-size: var(--fs-sm);
}

/* 5. Gallery --------------------------------------------------------- */
.works { padding-top: var(--sp-7); }
.works__head { margin-bottom: var(--sp-5); }
.works__head .eyebrow { margin: 0; }

.gallery-grid {
  list-style: none;
  margin: 0;
  padding: 0 0 var(--sp-8);
  display: grid;
  gap: var(--sp-6) var(--sp-5);
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr));
}

/* 카드 등장: 페이드가 아니라 아래에서 마스크로 올라오는 리빌 (design-direction 원칙 4) */
.gallery-grid.is-ready .art-card {
  animation: card-rise var(--dur-slow) var(--ease-out-expo) both;
  animation-delay: calc(var(--i, 0) * 120ms);
}
@keyframes card-rise { from { transform: translateY(32px); clip-path: inset(100% 0 0 0); } to { transform: none; clip-path: inset(0 0 0 0); } }

.art-card {
  display: block;
  text-decoration: none;
  color: inherit;
  border-radius: var(--radius);
}
.art-card__thumb {
  position: relative;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  background: var(--art-bg, var(--cp-black));
  border-radius: var(--radius);
  box-shadow: 0 0 0 1px var(--cp-line);
  transition: box-shadow var(--dur-base) var(--ease-out-expo);
}
.art-card__poster {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  object-fit: cover;
}
/* 반복 영상은 재생이 시작되면 중앙에서 원형으로 열리며 포스터 위에 겹쳐진다 (Iris) */
.art-card__video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
  clip-path: circle(0% at 50% 50%);
  transition: clip-path var(--dur-slow) var(--ease-out-expo);
}
.art-card__thumb.is-playing .art-card__video { clip-path: circle(75% at 50% 50%); }
.gallery-toolbar { display: flex; justify-content: flex-end; margin: 0 0 var(--sp-4); min-height: 0; }
.art-card__placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  letter-spacing: 0.14em;
  color: var(--cp-ink-3);
}
.art-card__meta {
  display: flex;
  align-items: baseline;
  gap: var(--sp-3);
  padding-top: var(--sp-3);
}
.art-card__title {
  margin: 0;
  font-size: clamp(1.5rem, 1.1rem + 1.4vw, 2.25rem);
  line-height: 1.05;
  letter-spacing: -0.03em;
  font-weight: 700;
  transition: transform var(--dur-base) var(--ease-out-expo);
}
.art-card__code { font-family: var(--font-mono); font-size: var(--fs-xs); color: var(--cp-ink-2); }
.art-card__code::before {
  content: "";
  display: inline-block;
  width: 7px; height: 7px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--cp-cherry);
  transform: scale(0);
  transition: transform var(--dur-quick) var(--ease-overshoot);
  vertical-align: 1px;
}
.art-card__summary { margin: var(--sp-1) 0 0; font-size: var(--fs-sm); color: var(--cp-ink-2); max-width: 40em; }
.art-card:focus-visible .art-card__code::before { transform: scale(1); }
.art-card:focus-visible .art-card__thumb { box-shadow: 0 0 0 2px var(--cp-ink); }
@media (hover: hover) {
  .art-card:hover .art-card__thumb { box-shadow: 0 0 0 2px var(--cp-ink); }
  .art-card:hover .art-card__code::before { transform: scale(1); }
  .art-card:hover .art-card__title { transform: translateX(4px); }
}
.review-banner {
  margin: 0 0 var(--sp-5);
  padding: var(--sp-2) var(--sp-3);
  border-left: 3px solid var(--cp-cherry);
  background: var(--cp-surface);
  font-size: var(--fs-sm);
  color: var(--cp-cherry-ink);
}

@media (prefers-reduced-motion: reduce) {
  .gallery-grid.is-ready .art-card { animation: none; }
  .art-card__video { transition: none; }
  .art-card__title, .art-card__code::before { transition: none; }
}

/* 빈 상태 — 가짜 작품 대신 정직한 준비 중 화면 */
.empty-state {
  display: grid;
  justify-items: start;
  gap: var(--sp-4);
  padding: var(--sp-7) var(--sp-5);
  margin-bottom: var(--sp-8);
  border: 1px dashed var(--cp-line-strong);
  border-radius: var(--radius-lg);
  background: var(--cp-surface);
}
.empty-state__mark { width: 64px; height: 24px; }
.empty-state__mark circle { fill: var(--cp-cherry); }
.empty-state__mark line { stroke: var(--cp-line-strong); stroke-width: 1.5; stroke-dasharray: 3 4; }
.empty-state h2 { margin: 0; font-size: var(--fs-lg); letter-spacing: -0.01em; }
.empty-state p { margin: 0; color: var(--cp-ink-2); max-width: 32em; }

/* 6. Artwork page ---------------------------------------------------- */
/* 전시실형 레이아웃 (design-direction §7)
   모바일: 작품 전폭(여백 0) → 컨트롤 → 정보/Remix Lab
   데스크톱(≥960): 작품 영역 약 70% (작품 배경색의 "방") + 정보 패널 약 30% */
.art-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  width: 100%;
  max-width: 1920px;
  margin: 0 auto;
}
.art-figure {
  margin: 0;
  background: var(--art-bg, var(--cp-black));
  border-bottom: 1px solid var(--cp-line);
}
.lab {
  padding: var(--sp-5) calc(var(--sp-4) + var(--safe-right)) var(--sp-7) calc(var(--sp-4) + var(--safe-left));
}

/* 1:1 스테이지. iframe 안의 art.html이 이 정사각형을 꽉 채운다. */
.art-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  background: var(--art-bg, var(--cp-black));
  overflow: hidden;
  isolation: isolate;
}
.art-stage iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: transparent;
}
/* 작품 미등록/로드 실패 시 보여주는 상태 (가짜 애니메이션 아님) */
.art-stage__placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: var(--sp-2);
  padding: var(--sp-5);
  text-align: center;
  color: #bdbab2;
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  background:
    linear-gradient(var(--cp-black), var(--cp-black)) padding-box,
    repeating-linear-gradient(45deg, #1d1d1d 0 10px, #161616 10px 20px);
}
.art-stage__placeholder strong { color: var(--cp-paper); font-weight: 600; letter-spacing: 0.08em; }

.art-caption {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-3);
  margin-top: var(--sp-3);
  font-size: var(--fs-sm);
  color: var(--cp-ink-2);
}

/* Remix Lab 패널 */
.lab {
  display: grid;
  min-width: 0;
  gap: var(--sp-5);
  align-content: start;
}
.lab__head h1 {
  margin: var(--sp-1) 0 var(--sp-2);
  font-size: var(--fs-xl);
  line-height: 1.1;
  letter-spacing: -0.03em;
}
.lab__head p { margin: 0; color: var(--cp-ink-2); }

.lab__actions {
  display: grid;
  gap: var(--sp-3);
}
.lab__hint {
  margin: calc(var(--sp-1) * -1) 0 0;
  font-size: var(--fs-sm);
  color: var(--cp-ink-2);
}
.lab__secondary {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
}
.lab__secondary .btn { flex: 1 1 140px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  padding: 2px var(--sp-2);
  border-radius: 999px;
  border: 1px solid var(--cp-line-strong);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--cp-ink-2);
  background: var(--cp-surface);
}
.badge--warn { border-color: var(--cp-cherry); color: var(--cp-cherry-ink); }

/* 접이식 섹션 (원본 프롬프트, 원본 HTML, 기술 정보) — 네이티브 <details> */
.lab-section {
  border-top: 1px solid var(--cp-line);
}
.lab-section > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  min-height: var(--tap);
  padding: var(--sp-2) 0;
  cursor: pointer;
  list-style: none;
  font-weight: 600;
}
.lab-section > summary::-webkit-details-marker { display: none; }
.lab-section > summary::after {
  content: "";
  width: 9px; height: 9px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: translateY(-3px) rotate(45deg);
  transition: transform 0.2s var(--ease);
  flex: none;
}
.lab-section[open] > summary::after { transform: translateY(2px) rotate(-135deg); }
.lab-section__body { padding: 0 0 var(--sp-4); display: grid; gap: var(--sp-3); }
.lab-section__desc { margin: 0; font-size: var(--fs-sm); color: var(--cp-ink-2); }

.meta-list {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: var(--sp-1) var(--sp-4);
  margin: 0;
  font-size: var(--fs-sm);
}
.meta-list dt { color: var(--cp-ink-2); }
.meta-list dd { margin: 0; }

.lab-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--sp-3);
  border-top: 1px solid var(--cp-line);
  padding-top: var(--sp-2);
}

/* 스테이지 컨트롤 바 — 작품 위에 겹치지 않고 작품 아래에 둔다 */
.stage-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-2) calc(var(--sp-4) + var(--safe-right)) var(--sp-2) calc(var(--sp-4) + var(--safe-left));
  font-size: var(--fs-sm);
  color: var(--cp-ink-2);
}
.stage-bar__id { flex: none; }
.stage-bar__controls { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--sp-2); }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 var(--sp-3);
  border: 1px solid color-mix(in srgb, var(--cp-ink) 18%, transparent);
  border-radius: 999px;
  background: color-mix(in srgb, var(--cp-paper) 70%, transparent);
  color: var(--cp-ink);
  font-size: var(--fs-sm);
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: background-color var(--dur-quick, 0.22s) var(--ease), border-color var(--dur-quick, 0.22s) var(--ease), transform 0.12s var(--ease);
}
.chip:active { transform: scale(0.97); }
@media (hover: hover) { .chip:hover { border-color: var(--cp-ink); background: var(--cp-paper); } }
@media (max-width: 420px) {
  .stage-bar__id { display: none; }
  .stage-bar__controls { width: 100%; justify-content: space-between; }
  .chip { flex: 1 1 0; justify-content: center; padding: 0 var(--sp-2); }
}

/* 데스크톱: 작품 70 / 패널 30. 작품 영역은 화면 높이에 고정(sticky)되고 패널만 길어진다 */
@media (min-width: 960px) {
  .art-layout {
    grid-template-columns: minmax(0, 7fr) minmax(340px, 3fr);
    align-items: start;
  }
  .art-figure {
    position: sticky;
    top: var(--header-h);
    height: calc(100vh - var(--header-h));
    height: calc(100dvh - var(--header-h));
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-5) var(--sp-6);
    border-bottom: 0;
    border-right: 1px solid var(--cp-line);
  }
  .art-stage {
    /* 작품 영역 안에 들어가는 가장 큰 정사각형 (컨트롤 바 높이 + 여백 제외) */
    width: min(100%, calc(100vh - var(--header-h) - 140px));
    width: min(100%, calc(100dvh - var(--header-h) - 140px));
    flex: none;
    box-shadow: 0 0 0 1px color-mix(in srgb, var(--cp-ink) 8%, transparent);
  }
  .stage-bar {
    width: min(100%, calc(100vh - var(--header-h) - 140px));
    width: min(100%, calc(100dvh - var(--header-h) - 140px));
    padding: 0;
  }
  .lab { padding: var(--sp-6) var(--sp-6) var(--sp-7); }
  .lab__head h1 { font-size: clamp(2.5rem, 1rem + 2.6vw, 4.25rem); }
}

/* 전체화면 (Fullscreen API) */
.art-stage:fullscreen { width: 100vw; height: 100vh; aspect-ratio: auto; border-radius: 0; box-shadow: none; }
.art-stage:-webkit-full-screen { width: 100vw; height: 100vh; }

/* 몰입 모드 — 요소 전체화면을 지원하지 않는 iPhone Safari 폴백. 사용자가 직접 열었을 때만 표시 */
html.is-immersive, html.is-immersive body { overflow: hidden; }
html.is-immersive .art-stage {
  position: fixed;
  inset: 0;
  z-index: 100;
  width: 100%;
  height: 100%;
  aspect-ratio: auto;
  border-radius: 0;
  box-shadow: none;
}
.stage-exit {
  position: absolute;
  top: calc(var(--sp-3) + var(--safe-top));
  right: calc(var(--sp-3) + var(--safe-right));
  z-index: 2;
  width: var(--tap); height: var(--tap);
  border: 1px solid color-mix(in srgb, var(--cp-ink) 20%, transparent);
  border-radius: 50%;
  background: color-mix(in srgb, var(--cp-paper) 85%, transparent);
  color: var(--cp-ink);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

/* 7. Remix Lab components ------------------------------------------- */
.code-view {
  margin: 0;
  max-height: 360px;
  overflow: auto;
  padding: var(--sp-4);
  border-radius: var(--radius-sm);
  background: var(--cp-black);
  color: #ecebe6;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  -webkit-overflow-scrolling: touch;
  tab-size: 2;
}
.code-view--source { white-space: pre; word-break: normal; overflow-wrap: normal; }

.placeholder-banner {
  margin: 0;
  padding: var(--sp-2) var(--sp-3);
  border-left: 3px solid var(--cp-cherry);
  background: color-mix(in srgb, var(--cp-cherry) 7%, var(--cp-surface));
  font-size: var(--fs-sm);
  color: var(--cp-cherry-ink);
}

/* 복사 실패 시 수동 복사 박스 (PRD §8, §11) */
.manual-copy {
  display: grid;
  gap: var(--sp-2);
  padding: var(--sp-3);
  border: 1px solid var(--cp-cherry);
  border-radius: var(--radius-sm);
  background: var(--cp-surface);
}
.manual-copy p { margin: 0; font-size: var(--fs-sm); color: var(--cp-cherry-ink); }
.manual-copy textarea {
  width: 100%;
  min-height: 160px;
  padding: var(--sp-3);
  border: 1px solid var(--cp-line-strong);
  border-radius: var(--radius-sm);
  background: var(--cp-paper);
  font-family: var(--font-mono);
  font-size: 16px;               /* iOS: 16px 미만이면 포커스 시 자동 확대 */
  line-height: 1.5;
  resize: vertical;
}

/* 바텀시트 / 모달 — 네이티브 <dialog>. 사용자가 열 때만 표시 */
.sheet {
  width: 100%;
  max-width: 640px;
  max-height: min(92vh, 900px);
  max-height: min(92dvh, 900px);
  margin: auto auto 0;
  padding: 0;
  border: 0;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  background: var(--cp-paper);
  color: var(--cp-ink);
  box-shadow: 0 -10px 40px rgba(17, 17, 17, 0.18);
  overflow: hidden;
}
.sheet[open] { display: flex; flex-direction: column; animation: sheet-up 0.28s var(--ease); }
.sheet::backdrop { background: rgba(17, 17, 17, 0.45); }
@keyframes sheet-up { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }

@media (min-width: 720px) {
  .sheet { margin: auto; border-radius: var(--radius-lg); }
}

.sheet__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-5) var(--sp-5) var(--sp-3);
}
.sheet__head h2 { margin: var(--sp-1) 0 0; font-size: var(--fs-lg); letter-spacing: -0.01em; }
.sheet__close {
  flex: none;
  width: var(--tap); height: var(--tap);
  margin: calc(var(--sp-3) * -1) calc(var(--sp-3) * -1) 0 0;
  border: 0;
  background: none;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.5rem;
  line-height: 1;
}
.sheet__body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 0 var(--sp-5) var(--sp-4);
  display: grid;
  gap: var(--sp-4);
  align-content: start;
}
.sheet__foot {
  display: grid;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-5) calc(var(--sp-4) + var(--safe-bottom));
  border-top: 1px solid var(--cp-line);
  background: var(--cp-paper);
}

.steps {
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: step;
  display: grid;
  gap: var(--sp-1);
  font-size: var(--fs-sm);
  color: var(--cp-ink-2);
}
.steps li { counter-increment: step; display: flex; gap: var(--sp-2); }
.steps li::before {
  content: counter(step);
  flex: none;
  width: 20px; height: 20px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--cp-ink);
  color: var(--cp-paper);
  font-family: var(--font-mono);
  font-size: 11px;
  margin-top: 2px;
}

/* 내 버전 만들기 입력 폼 */
.remix-form { display: grid; gap: var(--sp-3); }
.field { display: grid; gap: var(--sp-1); }
.field label { font-size: var(--fs-sm); font-weight: 600; }
.field small { font-size: var(--fs-xs); color: var(--cp-ink-2); }
.field input[type="text"], .field select {
  width: 100%;
  min-height: var(--tap);
  padding: 0 var(--sp-3);
  border: 1px solid var(--cp-line-strong);
  border-radius: var(--radius-sm);
  background: var(--cp-surface);
  font-size: 16px;               /* iOS 자동 확대 방지 */
}
.field input[type="text"]:focus, .field select:focus { border-color: var(--cp-ink); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--cp-cherry) 25%, transparent); }
.field-color { display: flex; gap: var(--sp-2); }
.field-color input[type="color"] {
  flex: none;
  width: var(--tap); height: var(--tap);
  padding: 4px;
  border: 1px solid var(--cp-line-strong);
  border-radius: var(--radius-sm);
  background: var(--cp-surface);
  cursor: pointer;
}
.remix-preview-label { display: flex; justify-content: space-between; align-items: baseline; gap: var(--sp-2); }


/* Remix Lab — 스테이션 / 토큰 / 줄번호 코드 / 공유 */
.lab__summary { font-size: var(--fs-md); }
.lab__status { display: grid; gap: var(--sp-2); justify-items: start; margin-top: var(--sp-3); }
.station {
  display: inline-grid;
  place-items: center;
  min-width: 2.1em;
  height: 1.6em;
  margin-right: var(--sp-2);
  padding: 0 0.4em;
  border-radius: 999px;
  background: var(--cp-ink);
  color: var(--cp-paper);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  font-weight: 500;
  letter-spacing: 0.04em;
}
.lab-section > summary { justify-content: flex-start; }
.lab-section > summary::after { margin-left: auto; }
.lab-section[open] .station { background: var(--cp-cherry); }
.lab-section__actions { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.lab-section__actions .btn { flex: 1 1 150px; }

.token, .token-sample {
  color: #ff8aa3;
  background: color-mix(in srgb, var(--cp-cherry) 22%, transparent);
  border-radius: 3px;
  padding: 0 2px;
}
.token-sample { color: var(--cp-cherry-ink); background: color-mix(in srgb, var(--cp-cherry) 10%, transparent); font-family: var(--font-mono); font-size: 0.92em; }

/* 줄 번호: CSS counter — 각 줄은 JS가 textContent 로 만든 span */
.code-view.has-lines { counter-reset: line; padding-left: 0; }
.code-view.has-lines .line { display: block; padding-left: 3.6em; text-indent: -3.6em; }
.code-view.has-lines .line::before {
  counter-increment: line;
  content: counter(line);
  display: inline-block;
  width: 2.6em;
  margin-right: 1em;
  padding-right: 0.2em;
  text-align: right;
  color: #6f6c66;
  text-indent: 0;
  user-select: none;
  -webkit-user-select: none;
}
.code-view--source.has-lines .line { padding-left: 0; text-indent: 0; }
.code-view--source { max-height: min(60vh, 520px); }

.source-integrity { margin: 0; font-size: var(--fs-sm); color: var(--cp-ink-2); }

.lab-share { display: grid; gap: var(--sp-2); border-top: 1px solid var(--cp-line); padding-top: var(--sp-4); }
.lab-share .eyebrow { margin: 0; }
.share-row { display: flex; align-items: center; gap: var(--sp-2); min-width: 0; }
.share-url {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--cp-line);
  border-radius: var(--radius-sm);
  background: var(--cp-surface);
  user-select: all;
  -webkit-user-select: all;
}
.lab-nav__pager { display: inline-flex; gap: var(--sp-4); }

/* 디스플레이 타이포 — 영문 제목에만 Bricolage, 한글은 시스템 폰트 */
.brand,
.lab__head h1,
.art-card__title,
.empty-state h2,
.sheet__head h2 {
  font-family: var(--font-display);
  font-optical-sizing: auto;
}
.lab__head h1 { font-weight: 750; letter-spacing: -0.045em; }

/* 재생/정지 오버레이 — 작품이 멈춰 있을 때만 (사용자가 정지했거나, 동작 줄이기 설정으로 자동재생하지 않은 경우) */
.stage-play {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: none;
  place-content: center;
  justify-items: center;
  gap: var(--sp-3);
  padding: var(--sp-5);
  border: 0;
  background: var(--art-bg, var(--cp-black));
  color: var(--cp-ink);
  font: inherit;
  cursor: pointer;
}
html.is-art-stopped .stage-play { display: grid; }
.stage-play__poster { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0.55; }
.stage-play__btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: var(--tap);
  padding: 0 var(--sp-5);
  border-radius: 999px;
  background: var(--cp-ink);
  color: var(--cp-paper);
  font-weight: 600;
}
.stage-play__btn span { color: var(--cp-cherry); }
.stage-play__note {
  position: relative;
  display: none;
  max-width: 26em;
  padding: var(--sp-1) var(--sp-3);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--cp-paper) 85%, transparent);
  font-size: var(--fs-sm);
  color: var(--cp-ink-2);
  text-align: center;
}
html.is-reduced-motion .stage-play__note { display: block; }
html.is-record .stage-play { display: none !important; }

.prompt-note {
  margin: 0;
  padding: var(--sp-2) var(--sp-3);
  border-left: 3px solid var(--cp-line-strong);
  background: var(--cp-surface);
  font-size: var(--fs-sm);
  color: var(--cp-ink-2);
}
.source-integrity.meta-list { grid-template-columns: max-content 1fr; }
.source-integrity dd { overflow-wrap: anywhere; }

/* View Transitions (D-19) — 갤러리 카드 ↔ 작품 스테이지. 미지원 브라우저는 일반 페이지 이동 */
@media (prefers-reduced-motion: no-preference) {
  @view-transition { navigation: auto; }
  ::view-transition-group(*) {
    animation-duration: 0.62s;
    animation-timing-function: var(--ease-in-out-quint);
  }
  ::view-transition-old(root), ::view-transition-new(root) { animation-duration: 0.36s; }
}

/* 동작 줄이기 (D-17) — UI 모션을 최소화. 작품 iframe 은 별도 문서라 영향 없음(자동재생은 위 스크립트가 막음) */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}


/* 9. Home hero + opening ---------------------------------------------- */
/* "Two Points Become a Line. A Line Becomes Art." (design-direction §4, decisions D-27)
   기본 스타일 = 오프닝의 최종 화면. html.cp-opening 동안만 home.js 가 초기 상태를 만들고 재생한다. */
.page-home .site-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  transition: background-color var(--dur-base) var(--ease-out-expo), border-color var(--dur-base) var(--ease-out-expo), color var(--dur-base) var(--ease-out-expo);
}
/* 검은 히어로 위에 있을 때 (home.js 가 IntersectionObserver 로 토글) */
.site-header.is-on-dark {
  background: transparent;
  border-color: transparent;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
  color: var(--cp-paper);
}
.site-header.is-on-dark .brand-mark line { stroke: var(--cp-paper); }
.site-header.is-on-dark .collection { color: color-mix(in srgb, var(--cp-paper) 62%, transparent); }

.hero {
  --gutter: clamp(16px, 4vw, 56px);
  position: relative;
  display: flex;
  min-height: 100vh;
  min-height: 100svh;          /* 모바일 주소창이 펼쳐진 상태에서도 잘리지 않는 높이 */
  background: var(--cp-black);
  color: var(--cp-paper);
  overflow: hidden;
  container-type: inline-size; /* 타이포 크기를 히어로 폭(cqi)에 맞춘다 */
}
.hero__inner {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: clamp(20px, 4vh, 48px);
  width: 100%;
  padding:
    calc(var(--header-h) + var(--safe-top) + clamp(16px, 4vh, 48px))
    calc(var(--gutter) + var(--safe-right))
    calc(clamp(20px, 4vh, 44px) + var(--safe-bottom))
    calc(var(--gutter) + var(--safe-left));
}
.hero__eyebrow {
  margin: 0;
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: color-mix(in srgb, var(--cp-paper) 58%, transparent);
}
.hero__title {
  align-self: center;
  margin: 0;
  font-family: var(--font-display);
  font-weight: 760;
  line-height: 0.84;
  letter-spacing: -0.045em;
}
/* 브랜드: 데스크톱 한 줄 "CHERRYPLAN" — 히어로 폭에 꽉 차게 (계수는 Bricolage 실측) */
.hero__brand {
  display: block;
  white-space: nowrap;
  font-size: calc((100cqi - 2 * var(--gutter)) / 6.68);
}
.hero__word { display: inline-block; }
.hero__mask {
  display: inline-block;
  overflow: hidden;
  vertical-align: top;
  white-space: nowrap;          /* 글자 단위 span 이 줄바꿈되지 않게 */
  padding-top: 0.08em;          /* 글자 윗부분이 마스크에 잘리지 않게 */
  margin-top: -0.08em;
}
.ch { display: inline-block; will-change: transform; }
/* MOTION 은 왼쪽, STUDIES 는 오른쪽 — 편집 디자인식 양끝 정렬 */
.hero__sub {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.4em;
  margin-top: 0.42em;
  font-size: calc((100cqi - 2 * var(--gutter)) / 16.5);
  letter-spacing: -0.02em;
  line-height: 0.92;
}
.hero__motion, .hero__studies { display: inline-block; }
.hero__period {
  display: inline-block;
  width: 0.2em;
  height: 0.2em;
  margin-left: 0.07em;
  border-radius: 50%;
  background: var(--cp-cherry);
}
.hero__foot {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: var(--sp-5);
}
/* 스크롤 인디케이터는 왼쪽 — 오프닝에서 연결선을 거둬들인 왼쪽 점이 그 자리로 곧장 떨어진다 */
.hero__lead {
  margin: 0;
  max-width: 24em;
  text-align: right;
  font-size: clamp(0.9375rem, 0.85rem + 0.35vw, 1.125rem);
  color: color-mix(in srgb, var(--cp-paper) 72%, transparent);
}
/* 스크롤 인디케이터 — 오프닝의 연결선이 변형된 결과. 작은 점이 선을 따라 천천히 내려간다 */
.hero__scroll {
  flex: none;
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--sp-2);
  min-width: var(--tap);
  padding: var(--sp-2) 0 0;
  color: var(--cp-paper);
  text-decoration: none;
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  letter-spacing: 0.12em;
}
.hero__scroll-track { position: relative; width: 9px; height: clamp(48px, 9vh, 72px); margin-left: -4px; } /* 선의 중심을 브랜드 왼쪽 끝(C 의 시작)에 맞춘다 */
.hero__scroll-line {
  position: absolute;
  left: 4px; top: 0; bottom: 0;
  width: 1px;
  background: color-mix(in srgb, var(--cp-paper) 45%, transparent);
  transform-origin: 50% 0;
}
.hero__scroll-dot {
  position: absolute;
  left: 1px; top: -3.5px;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--cp-cherry);
  animation: scroll-dot 2.6s var(--ease-in-out-quint) 0.6s infinite;
}
@keyframes scroll-dot {
  0%, 12% { transform: translateY(0); }
  62%, 100% { transform: translateY(calc(clamp(48px, 9vh, 72px) - 0px)); }
}
.hero.is-offscreen .hero__scroll-dot { animation-play-state: paused; }
@media (hover: hover) { .hero__scroll:hover .hero__scroll-label { text-decoration: underline; text-underline-offset: 4px; } }

/* 작은 화면: 데스크톱 한 줄 구성을 축소하지 않고 "CHERRY / PLAN" 두 줄로 재구성 (D-27) */
@container (max-width: 639px) {
  .hero__brand { white-space: normal; font-size: calc((100cqi - 2 * var(--gutter)) / 4.02); }
  .hero__word { display: block; }
  .hero__sub { font-size: calc((100cqi - 2 * var(--gutter)) / 10.2); margin-top: 0.55em; }
}
@media (max-width: 639px) {
  .hero__foot { align-items: flex-end; }
  .hero__lead { max-width: 18em; }
}

/* 홈의 갤러리·푸터를 히어로와 같은 좌우 기준선에 맞춘다 (CHERRYPLAN 의 C 와 작품 카드의 왼쪽 끝이 일치) */
.page-home .works,
.page-home .site-footer .container {
  max-width: none;
  padding-left: calc(clamp(16px, 4vw, 56px) + var(--safe-left));
  padding-right: calc(clamp(16px, 4vw, 56px) + var(--safe-right));
}

/* 오프닝 오버레이 (점 두 개 + 연결선) — 오프닝 중에만 존재 */
.hero__fx { position: absolute; inset: 0; z-index: 2; pointer-events: none; display: none; }
html.cp-opening .hero__fx { display: block; }
.fx-dot, .fx-line { position: absolute; left: 0; top: 0; will-change: transform; }
.fx-dot { border-radius: 50%; background: var(--cp-cherry); }
.fx-line { height: 2px; width: 100px; margin-top: -1px; background: var(--cp-paper); transform-origin: 0 50%; transform: scaleX(0); }

/* JS 가 초기 상태를 잡기 전 첫 페인트에서 최종 화면이 번쩍 보이지 않게 */
html.cp-opening .hero__title,
html.cp-opening .hero [data-hero],
html.cp-opening .page-home .site-header { visibility: hidden; }
html.cp-opening .hero__scroll-dot { animation: none; }
html.cp-opening.cp-opening-ready .hero__title,
html.cp-opening.cp-opening-ready .hero [data-hero],
html.cp-opening.cp-opening-ready .page-home .site-header { visibility: visible; }

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

/* 8. Record mode (?record=1) ---------------------------------------- */
/* html.is-record 는 <head>의 인라인 스크립트가 첫 페인트 전에 붙인다 (깜빡임 방지) */
html.is-record,
html.is-record body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;      /* iOS 고무줄 스크롤 / Android 당겨서 새로고침 방지 */
  background: var(--record-bg, var(--cp-black));
}
html.is-record body { touch-action: none; }  /* 녹화 중 실수로 확대·스크롤되지 않게 */
html.is-record .site-header,
html.is-record .site-footer,
html.is-record .lab,
html.is-record .art-caption,
html.is-record .sheet,
html.is-record [data-ui] {
  display: none !important;
}
html.is-record .site-main,
html.is-record .container,
html.is-record .art-layout {
  display: block;
  height: 100%;
  max-width: none;
  padding: 0;
  margin: 0;
}
html.is-record .art-figure {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  height: auto;
  margin: 0;
  padding: 0;
  border: 0;
  background: var(--record-bg, var(--cp-black));
}
/* 화면에 들어오는 가장 큰 정사각형 − 크롭 여백(PRD §9-5) */
html.is-record .art-stage {
  --record-gap: 24px;
  width: min(
    100vw - var(--safe-left) - var(--safe-right) - var(--record-gap) * 2,
    100vh - var(--safe-top) - var(--safe-bottom) - var(--record-gap) * 2
  );
  width: min(
    100vw - var(--safe-left) - var(--safe-right) - var(--record-gap) * 2,
    100dvh - var(--safe-top) - var(--safe-bottom) - var(--record-gap) * 2
  );
  min-width: 0;
  border-radius: 0;
  box-shadow: none;
}
