/* ==========================================================================
   Apocrypha — 흑백 판화 테마
   원칙 1. 흑과 백, 그 사이의 회색만 쓴다. 붉은색·노란색(난색)은 쓰지 않는다.
   원칙 2. 빛은 귀하다. 가장 밝은 흰색은 '지금 손댈 곳'(포커스·눌린 버튼)과
          카메오 속 창에만 허락한다. 나머지는 모두 회색.
   명암비(바탕 #0E0E0E 기준): 본문 #A8A8A8 8.1:1, 보조 #8C8C8C 5.7:1, 입력 테두리 #7C7C7C 4.6:1
   전체 규칙은 docs/design-guide.md 를 따른다.
   ========================================================================== */

:root {
  --void: #0E0E0E;        /* 바탕 */
  --pit: #070707;         /* 입력칸, 카메오 바탕 */
  --slab: #161616;        /* 상자 */
  --bar: #262626;         /* 상자 머리 띠 */
  --line: #7C7C7C;        /* 입력 테두리, 선 */
  --line-soft: #3A3A3A;   /* 구분선 */
  --ash: #8C8C8C;         /* 보조 글자 */
  --text: #A8A8A8;        /* 본문 */
  --bone: #D6D6D6;        /* 강조 글자, 라벨 */
  --light: #F4F4F4;       /* 빛 — 아껴 쓴다 */

  --font-black: "UnifrakturMaguntia", "IM Fell English", serif;   /* 게임명 로고 전용 */
  --font-woven: "Jacquard 24", "UnifrakturMaguntia", serif;        /* 메뉴·입구 이름 (첫 글자만 대문자) */
  --font-fell: "IM Fell English", "Noto Serif KR", serif;
  --font-fell-sc: "IM Fell English SC", "IM Fell English", serif;
  --font-ko-title: "Song Myung", "Noto Serif KR", serif;
  --font-body: "Noto Serif KR", "Nanum Myeongjo", "AppleMyungjo", "Batang", serif;
}

*, *::before, *::after { box-sizing: border-box; }
html { color-scheme: dark; background: var(--void); }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.75;
  word-break: keep-all;
  overflow-wrap: anywhere;
  background: var(--void);
}

/* 복사본 같은 입자감 */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10;
  opacity: .55;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1  0 0 0 0 1  0 0 0 0 1  0 0 0 .07 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

a { color: var(--bone); text-underline-offset: .22em; text-decoration-thickness: 1px; }
a:hover { color: var(--light); }
:focus-visible { outline: 2px solid var(--light); outline-offset: 3px; }

.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;
}

/* ─── 지면(폴리오): 흰 실선 이중 테두리 + 네 모서리 장식 ─────────── */
.folio {
  position: relative;
  width: min(100% - 2rem, 68rem);
  margin: 2.5rem auto;
  padding: clamp(2rem, 5vw, 4rem) clamp(1.25rem, 5vw, 4.5rem);
  border: 1px solid #5A5A5A;
  outline: 1px solid #2E2E2E;
  outline-offset: 7px;
}
.corner {
  position: absolute;
  width: 128px;
  height: 128px;
  pointer-events: none;
}
.corner.tl { top: -14px; left: -14px; }
.corner.tr { top: -14px; right: -14px; transform: scaleX(-1); }
.corner.bl { bottom: -14px; left: -14px; transform: scaleY(-1); }
.corner.br { bottom: -14px; right: -14px; transform: scale(-1, -1); }

.spread {
  display: grid;
  grid-template-columns: minmax(0, 23rem) minmax(0, 28rem);
  justify-content: center;
  align-items: start;
  gap: clamp(2rem, 6vw, 5.5rem);
}

/* ─── 왼쪽: 카메오 ───────────────────────────────────────── */
.plate {
  position: sticky;
  top: 2.5rem;
  margin: 0;
  text-align: center;
}
.cameo {
  display: block;
  width: min(100%, 19rem);
  height: auto;
  margin: 0 auto;
  transition: filter 1.4s ease;
}
.plate figcaption { margin-top: 1.25rem; }
.plate .caption-sc {
  display: block;
  font-family: var(--font-fell-sc);
  font-size: .82rem;
  letter-spacing: .32em;
  text-indent: .32em;
  color: var(--ash);
}
.plate .motto {
  display: block;
  margin-top: 1.1rem;
  font-family: var(--font-fell);
  font-style: italic;
  font-size: 1.15rem;
  line-height: 1.45;
  color: var(--bone);
}
.plate .motto-ko {
  display: block;
  margin-top: .35rem;
  font-size: .8rem;
  color: var(--ash);
  letter-spacing: .04em;
}

/* 빛의 상태 — 카메오 속 창만 밝아지거나 꺼진다 */
body[data-light="cold"] .cameo { filter: brightness(.4) contrast(.9); }
body[data-light="bright"] .cameo { filter: brightness(1.12) contrast(1.05); }

/* ─── 오른쪽: 본문 ───────────────────────────────────────── */
.leaf { min-width: 0; }

.masthead { margin: 0 0 2.25rem; }
.masthead a { text-decoration: none; display: inline-block; }
.masthead .blackletter {
  display: block;
  font-family: var(--font-black);
  font-weight: 400;
  font-size: clamp(3rem, 7vw, 4.4rem);
  line-height: .95;
  color: var(--light);
  letter-spacing: .01em;
}
.masthead .strap {
  display: flex;
  align-items: center;
  gap: .8rem;
  margin-top: .65rem;
  font-family: var(--font-fell-sc);
  font-size: .78rem;
  letter-spacing: .28em;
  color: var(--ash);
}
.masthead .strap::after { content: ""; flex: 1; height: 1px; background: var(--line-soft); }

h1, .title {
  margin: 0;
  font-family: var(--font-ko-title);
  font-weight: 400;
  font-size: clamp(1.55rem, 4.2vw, 1.95rem);
  line-height: 1.35;
  color: var(--bone);
  letter-spacing: .02em;
}

.lede {
  margin: .6rem 0 0;
  color: var(--ash);
  font-size: .95rem;
}
.lede-plain { margin: .75rem 0 0; font-size: .95rem; color: var(--text); }

.divider {
  display: flex;
  align-items: center;
  gap: .9rem;
  margin: 2rem 0;
  color: #5E5E5E;
}
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line-soft); }
.divider svg { width: .8rem; height: 1.1rem; flex: none; }

/* ─── 폼 ─────────────────────────────────────────────────── */
form { margin: 0; }
.field { margin-bottom: 1.4rem; }

.field > label {
  display: block;
  margin-bottom: .45rem;
  font-weight: 700;
  font-size: .86rem;
  letter-spacing: .12em;
  color: var(--bone);
}

.help { margin: .45rem 0 0; font-size: .82rem; color: var(--ash); line-height: 1.6; }

input[type="text"], input[type="email"], input[type="password"], input[type="number"], textarea {
  width: 100%;
  min-height: 48px;
  padding: .7rem .9rem;
  font: inherit;
  font-size: 1rem;
  color: var(--bone);
  background: var(--pit);
  border: 1px solid var(--line);
  border-radius: 0;
  transition: border-color .2s;
}
input:hover { border-color: #9A9A9A; }
input:focus-visible {
  outline: 2px solid var(--light);
  outline-offset: 2px;
  border-color: var(--light);
}
/* 오류: 색 대신 점선 테두리 + † 표시 + 글자 */
.field.has-error input { border-style: dashed; border-color: var(--bone); }

.password-wrap { position: relative; }
.password-wrap input { padding-right: 5rem; }
.toggle-password {
  position: absolute;
  top: 50%;
  right: .45rem;
  transform: translateY(-50%);
  min-height: 34px;
  padding: .2rem .75rem;
  font: inherit;
  font-size: .78rem;
  letter-spacing: .08em;
  color: var(--bone);
  background: transparent;
  border: 1px solid #555;
  cursor: pointer;
}
.toggle-password:hover { border-color: var(--bone); }

.errors { margin: .5rem 0 0; padding: 0; list-style: none; color: var(--bone); font-size: .88rem; line-height: 1.55; }
.errors li { display: flex; gap: .5rem; align-items: baseline; }
.errors li::before { content: "†"; font-family: var(--font-fell); font-size: 1.05rem; color: var(--light); }
.errors svg { display: none; }
.form-errors {
  margin-bottom: 1.5rem;
  padding: .85rem 1rem;
  border: 1px dashed var(--line);
}

/* 동의 상자 — 흰 테두리 + 회색 머리 띠 (서약 연출 밖, 평문) */
.consent {
  margin: 2.1rem 0 0;
  padding: 0;
  border: 1px solid #BDBDBD;
  background: var(--pit);
  min-width: 0;
}
.consent legend {
  float: left;
  width: 100%;
  margin: 0;
  padding: .5rem 1rem;
  background: var(--bar);
  border-bottom: 1px solid #BDBDBD;
  font-weight: 700;
  font-size: .86rem;
  letter-spacing: .06em;
  color: var(--bone);
}
.consent-body { clear: both; padding: 1rem 1rem 1.1rem; }
.consent .check-row + .check-row { margin-top: .6rem; }
.check { display: flex; gap: .65rem; align-items: flex-start; font-size: .9rem; color: var(--text); cursor: pointer; }
.check input {
  appearance: none;
  flex: none;
  width: 1.15rem;
  height: 1.15rem;
  margin: .3rem 0 0;
  border: 1px solid var(--line);
  background: var(--void);
  cursor: pointer;
  display: grid;
  place-content: center;
}
.check input::before {
  content: "";
  width: .62rem;
  height: .62rem;
  transform: scale(0);
  transition: transform .12s;
  background: var(--light);
  clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);
}
.check input:checked { border-color: var(--light); }
.check input:checked::before { transform: scale(1); }
.check input:checked + span { color: var(--bone); }
.check-all { padding-bottom: .75rem; margin-bottom: .75rem; border-bottom: 1px solid var(--line-soft); }
.check-all .check { font-weight: 700; }
.consent details { margin: .15rem 0 0 1.8rem; font-size: .8rem; color: var(--ash); }
.consent summary { cursor: pointer; width: fit-content; color: var(--ash); text-decoration: underline; text-underline-offset: .2em; }
.consent summary:hover { color: var(--bone); }
.consent details p { margin: .45rem 0 0; line-height: 1.65; }

/* ─── 버튼: 검은 판에 흰 이중선. 손을 올린 순간에만 빛(반전) ─── */
.actions { margin-top: 2.25rem; }

.btn-seal,
.leaf button[type="submit"]:not([class]) {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .1rem;
  width: 100%;
  min-height: 64px;
  padding: .8rem 1.5rem;
  font-family: var(--font-ko-title);
  font-size: 1.2rem;
  letter-spacing: .45em;
  text-indent: .45em;
  color: var(--light);
  text-decoration: none;
  background: var(--void);
  border: 1px solid var(--bone);
  outline: 1px solid #4A4A4A;
  outline-offset: -6px;
  cursor: pointer;
  transition: background-color .25s, color .25s, outline-color .25s;
}
.btn-seal small {
  font-family: var(--font-body);
  font-size: .7rem;
  letter-spacing: .18em;
  text-indent: .18em;
  color: var(--ash);
  transition: color .25s;
}
.btn-seal:hover, .leaf button[type="submit"]:not([class]):hover {
  background: var(--light);
  color: var(--void);
  outline-color: var(--void);
}
.btn-seal:hover small { color: #333; }
.btn-seal:focus-visible { outline: 2px solid var(--light); outline-offset: 4px; }
.btn-seal:active { transform: translateY(1px); }

.btn-plain {
  min-height: 44px;
  padding: .55rem 1.4rem;
  font: inherit;
  font-size: .92rem;
  letter-spacing: .1em;
  color: var(--bone);
  background: transparent;
  border: 1px solid var(--line);
  cursor: pointer;
}
.btn-plain:hover { border-color: var(--light); color: var(--light); }

.after-links { margin: 1.5rem 0 0; font-size: .88rem; color: var(--ash); }

/* ─── 알림 ───────────────────────────────────────────────── */
.messages { margin: 0 0 1.75rem; padding: 0; list-style: none; }
.messages li {
  padding: .7rem 1rem;
  border: 1px solid var(--line-soft);
  border-left: 2px solid var(--bone);
  background: var(--slab);
  font-size: .9rem;
  color: var(--bone);
}

.notice {
  margin: 1.5rem 0 0;
  padding: 1.1rem 1.2rem;
  background: var(--pit);
  border: 1px solid #BDBDBD;
  font-size: .9rem;
}
.notice dt { color: var(--ash); font-size: .8rem; letter-spacing: .06em; }
.notice dd { margin: 0 0 .85rem; color: var(--text); }
.notice dd:last-child { margin-bottom: 0; }
.sent-to { font-weight: 700; color: var(--light); word-break: break-all; }

.site-footer {
  padding: 0 1rem 2.5rem;
  text-align: center;
  font-family: var(--font-fell-sc);
  font-size: .75rem;
  letter-spacing: .3em;
  color: var(--ash);
}

/* ─── 좁은 화면: 한 단으로 ──────────────────────────────────── */
@media (max-width: 860px) {
  .folio { margin: 1.25rem auto; }
  .spread { grid-template-columns: minmax(0, 28rem); gap: 2rem; }
  .plate { position: static; }
  .cameo { width: min(56%, 12rem); }
  .plate .motto { font-size: 1rem; }
  .masthead { text-align: center; }
  .masthead .strap { justify-content: center; }
  .masthead .strap::before { content: ""; flex: 1; height: 1px; background: var(--line-soft); }
  .corner { width: 84px; height: 84px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

@media (forced-colors: active) {
  input, .btn-plain, .toggle-password, .check input, .btn-seal { border: 1px solid CanvasText; }
}

/* ─── 캐릭터 ─────────────────────────────────────────────── */
textarea {
  min-height: 13rem;
  resize: vertical;
  line-height: 1.75;
}
textarea:focus-visible { outline: 2px solid var(--light); outline-offset: 2px; border-color: var(--light); }
.field.has-error textarea { border-style: dashed; border-color: var(--bone); }

.field-foot { display: flex; justify-content: space-between; gap: 1rem; align-items: baseline; }
.field-foot .help { flex: 1; }
.counter {
  margin: .45rem 0 0;
  flex: none;
  font-family: var(--font-fell);
  font-size: .85rem;
  color: var(--ash);
  font-variant-numeric: tabular-nums;
}
.counter.is-near { color: var(--bone); }
.counter.is-full { color: var(--light); }

/* 명부에 새겨질 모습 — 흰 테두리 상자 + 회색 머리띠 */
.preview {
  margin: 0 0 2rem;
  border: 1px solid #BDBDBD;
  background: var(--pit);
  text-align: center;
  padding: 0 1rem 1.4rem;
}
.preview-label {
  display: block;
  margin: 0 -1rem 1.2rem;
  padding: .45rem 1rem;
  background: var(--bar);
  border-bottom: 1px solid #BDBDBD;
  font-size: .8rem;
  font-weight: 700;
  letter-spacing: .08em;
  color: var(--bone);
  text-align: left;
}

.persona-epithet {
  display: block;
  margin: 0 0 .35rem;
  min-height: 1.2em;
  font-size: .92rem;
  letter-spacing: .32em;
  text-indent: .32em;
  color: var(--ash);
}
.persona-name {
  display: block;
  margin: 0;
  font-family: var(--font-ko-title);
  font-weight: 400;
  font-size: clamp(1.9rem, 5vw, 2.5rem);
  line-height: 1.25;
  letter-spacing: .06em;
  color: var(--bone);
}
.persona-name.is-empty { color: #5A5A5A; }

.persona { text-align: center; }
.persona .persona-name { font-size: clamp(2.2rem, 6vw, 3rem); }
.persona-text {
  text-align: left;
  color: var(--text);
  white-space: normal;
}
.persona-text p { margin: 0 0 1em; }
.persona-text p:first-child::first-letter {
  float: left;
  margin: .08em .45rem 0 0;
  font-family: var(--font-ko-title);
  font-size: 3.1em;
  line-height: .9;
  color: var(--light);
}
.persona-text.is-empty { color: var(--ash); text-align: center; }

.account-strip {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin-top: 2.5rem;
  color: var(--ash);
}
.account-strip strong { color: var(--bone); }

/* ─── 초상 (사용자 이미지) — 언제나 흑백·고대비·입자감으로 ───────── */
[hidden] { display: none !important; }

.portrait-frame {
  position: relative;
  width: min(100%, 19rem);
  aspect-ratio: 300 / 420;
  margin: 0 auto;
  padding: 9px;
  border: 1.4px solid #EDEDED;
  border-radius: 50%;
}
.portrait-frame::before {          /* 바깥 가는 고리 */
  content: "";
  position: absolute;
  inset: -8px;
  border: 1px solid rgba(237, 237, 237, .55);
  border-radius: 50%;
  pointer-events: none;
}
.portrait-frame::after {           /* 입자감 + 가장자리 어둠 */
  content: "";
  position: absolute;
  inset: 9px;
  border-radius: 50%;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 50% 42%, transparent 52%, rgba(0, 0, 0, .7) 100%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='1.1' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1  0 0 0 0 1  0 0 0 0 1  0 0 0 .28 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
.portrait {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  object-position: 50% 28%;
  background: var(--pit);
  filter: grayscale(1) contrast(1.18) brightness(.9);
  transition: filter 1.4s ease;
}
body[data-light="cold"] .portrait { filter: grayscale(1) contrast(1) brightness(.4); }
body[data-light="bright"] .portrait { filter: grayscale(1) contrast(1.2) brightness(.98); }

.preview-portrait {
  width: 4.5rem;
  aspect-ratio: 300 / 420;
  margin: 0 auto .9rem;
  padding: 3px;
  border: 1px solid #BDBDBD;
  border-radius: 50%;
}
.preview-portrait img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  object-position: 50% 28%;
  filter: grayscale(1) contrast(1.18) brightness(.9);
}

/* 파일 고르기 — 버튼은 .btn-plain 문법 */
.file-row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
input[type="file"] {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: .88rem;
  color: var(--ash);
}
input[type="file"]::file-selector-button {
  min-height: 44px;
  margin-right: .9rem;
  padding: .5rem 1.2rem;
  font: inherit;
  font-size: .9rem;
  letter-spacing: .08em;
  color: var(--bone);
  background: var(--pit);
  border: 1px solid var(--line);
  border-radius: 0;
  cursor: pointer;
}
input[type="file"]::file-selector-button:hover { border-color: var(--light); color: var(--light); }
input[type="file"]:focus-visible { outline: 2px solid var(--light); outline-offset: 3px; }

/* ─── 정사각형 초상: 직각 이중선 액자 ───────────────────────── */
.portrait-frame.is-square { aspect-ratio: 1; }
.portrait-frame.is-square,
.portrait-frame.is-square::before,
.portrait-frame.is-square::after,
.portrait-frame.is-square .portrait { border-radius: 0; }
.portrait-frame.is-square .portrait { object-position: 50% 50%; }
.preview-portrait.is-square { aspect-ratio: 1; border-radius: 0; }
.preview-portrait.is-square img { border-radius: 0; object-position: 50% 50%; }

/* ─── 초상 모양 고르기 ──────────────────────────────────────── */
.shape-choice {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem 1.6rem;
  margin: 1rem 0 0;
  padding: 0;
  border: 0;
  min-width: 0;
}
.shape-choice legend {
  float: left;
  width: 100%;
  margin-bottom: .35rem;
  padding: 0;
  font-size: .82rem;
  font-weight: 700;
  letter-spacing: .08em;
  color: var(--bone);
}
.check input[type="radio"]::before { clip-path: none; width: .5rem; height: .5rem; }

/* ─── 자르기 ────────────────────────────────────────────────── */
.cropper { margin-top: 1rem; }
.crop-stage {
  position: relative;
  width: fit-content;
  max-width: 100%;
  margin: 0 auto;
  overflow: hidden;
  background: var(--pit);
  outline: 1px solid var(--line);
  outline-offset: 4px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.crop-stage img {
  display: block;
  max-width: 100%;
  max-height: 26rem;
  width: auto;
  height: auto;
  filter: grayscale(1) contrast(1.1);
  pointer-events: none;
}
.crop-box {
  position: absolute;
  top: 0;
  left: 0;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, .66);
  outline: 1px solid var(--light);
  cursor: move;
}
.crop-box::before {                 /* 안쪽 이중선 */
  content: "";
  position: absolute;
  inset: 5px;
  border: 1px solid rgba(244, 244, 244, .35);
  pointer-events: none;
}
.crop-box:focus-visible { outline: 2px solid var(--light); outline-offset: 3px; }
.crop-handle {
  position: absolute;
  right: -8px;
  bottom: -8px;
  width: 16px;
  height: 16px;
  background: var(--light);
  border: 1px solid var(--void);
  cursor: nwse-resize;
}
.crop-handle::before { content: ""; position: absolute; inset: -10px; }  /* 손가락으로도 잡히게 */
.crop-size {
  display: flex;
  align-items: center;
  gap: .9rem;
  margin-top: 1rem;
  font-size: .85rem;
  color: var(--bone);
}
.crop-size input[type="range"] { flex: 1; accent-color: #D6D6D6; min-height: 32px; }

/* 되돌릴 수 없음을 알리는 문장 — 색 대신 † 와 굵기로 */
.permanence {
  display: flex;
  gap: .6rem;
  align-items: baseline;
  margin: 2rem 0 0;
  padding: .8rem 1rem;
  border: 1px dashed var(--line);
  font-size: .88rem;
  color: var(--text);
}
.permanence strong { color: var(--light); font-weight: 700; }
.permanence-mark { font-family: var(--font-fell); font-size: 1.1rem; color: var(--light); }
