/* ── 읽는 창 (story.css) ──────────────────────────────────────────────
   긴 이야기 글(본편 · 동료 장면 · 뒷이야기 · 축제 · 걸어온 길 · 함께한 이야기 · 회상록)을 읽는 창.
   core.js modal() 이 「넓은 창 + 바로 아래 .scene」 이면 .modal.reading, 뒤 가림막에 .rd-back 을 붙인다 (편지는 가림막만).
   · 뒤: 짙은 먹빛 가림막 + 살짝 흐리게 — 글 한 장만 떠 보이게
   · 종이: 기본은 먹빛 종이에 따뜻한 미색 글씨. 설정 「이야기 읽기 배경: 밝게」(html[data-readbg="light"])면 테마의 종이 그대로
   · 글: 한 줄 34em 안쪽 가운데 · 행간 1.9 · 문단 사이 띄움(들여쓰기 없음) · 대사는 이름표(인물 빛깔) 아래 한 줄, 왼쪽 가는 줄
   · 선택지: 번호 붙은 넓은 단추 (48px 이상), 글과 장식 줄로 갈라 둔다
   · 길면 창 안에서 스크롤, 아래 가장자리는 옅게 사라진다. ✕ 는 늘 위에 (style.css 겹창 공통) */

/* 뒤 가림막: 이야기 · 편지 */
.modal-back.rd-back { background: rgba(10, 6, 3, .8); }
@supports ((backdrop-filter: blur(2px)) or (-webkit-backdrop-filter: blur(2px))) {
  .modal-back.rd-back { background: rgba(10, 6, 3, .74); -webkit-backdrop-filter: blur(3px) saturate(.75); backdrop-filter: blur(3px) saturate(.75); }
}

/* ── 종이: 먹빛 (기본) ── 창 안의 색 낱말만 바꿔 단추 · 꼬리표 · 판이 저절로 따라온다 */
:root:not([data-readbg="light"]) .modal.reading {
  --page: #18120d; --surface: #261d16; --surface-2: #201812; --surface-3: #31261c;
  --line: #4a3b2b; --line-2: #6f593d;
  --ink: #f2e6cc; --ink-2: #e0d0af; --ink-3: #ad9776;
  --primary: #a24c37; --primary-2: #ba5f47; --primary-soft: #3f261d; --on-primary: #fcefd6;
  --gilt: #c7a159; --gilt-2: #e3c584;
  --rose: #d97a69; --rose-soft: #43261f; --mint: #8dbba1; --mint-soft: #22322a; --sky: #95b4d0; --sky-soft: #232d37;
  --butter: #e0bd69; --butter-soft: #3d321b; --peach: #e09b6c; --peach-soft: #43301f;
  --frame-gilt: url(/assets/ui/frame-night.svg);
  --shadow: 0 2px 8px rgba(0, 0, 0, .4);
  color-scheme: dark; color: var(--ink);
  background:
    radial-gradient(120% 70% at 50% 0%, rgba(199, 161, 89, .09), transparent 60%),
    radial-gradient(140% 90% at 50% 120%, rgba(0, 0, 0, .35), transparent 60%),
    var(--paper), var(--page);
  box-shadow: 0 24px 70px rgba(0, 0, 0, .65), 0 0 0 1px rgba(199, 161, 89, .12);
}
:root:not([data-readbg="light"]) .modal.reading .npcname { color: var(--ncd, inherit); text-decoration-color: color-mix(in srgb, var(--ncd, currentColor) 35%, transparent); }
:root:not([data-readbg="light"]) .modal.reading .scene { --rd-nc: var(--ncd, var(--gilt-2)); }
:root:not([data-readbg="light"]) .modal.reading .tag.gold { background: var(--butter-soft); }

/* ── 창 모양 · 머리 ── */
.modal.reading { width: min(48rem, 100%); padding: 1rem clamp(1rem, 4vw, 2.4rem) 1.2rem; gap: 1.1rem; scroll-padding-block: 3.5rem 2rem; }
.modal.reading > .scene-head,
.modal.reading > .mx + div:not(.scene):not(.scene-foot),
.modal.reading > .mx + h3 { padding-inline: 2.8rem; }
.modal.reading > .scene-head, .modal.reading > .scene-head.tl-vhead { justify-content: center; }
.modal.reading > .scene-head .tl-vt { padding-right: 0; text-align: center; display: flex; flex-direction: column; align-items: center; gap: .15rem; }
.modal.reading > :is(.scene-head, .mx + div:not(.scene)) h3,
.modal.reading > .mx + h3 { font-size: 1.42rem; letter-spacing: .05em; color: var(--ink); line-height: 1.35; }
:root:not([data-readbg="light"]) .modal.reading > :is(.scene-head, .mx + div:not(.scene)) h3,
:root:not([data-readbg="light"]) .modal.reading > .mx + h3 { color: var(--gilt-2); text-shadow: 0 1px 0 rgba(0, 0, 0, .6); }
.modal.reading > .mx + div:not(.scene):not(.scene-head) { text-align: center; display: flex; flex-direction: column-reverse; align-items: center; gap: .1rem; } /* 본편: 「장」 작은 줄은 제목 아래로 */
.modal.reading > :is(.scene-head, .mx + div:not(.scene)) .faint { font-size: .8rem; letter-spacing: .08em; color: var(--ink-3); }
/* 머리 아래 장식 줄: 가는 금줄 + 가운데 마름모 */
.modal.reading > .scene,
.modal.reading > .mx + h3 + .scene { position: relative; padding-top: 1.35rem; }
.modal.reading > .scene::before {
  content: ''; position: absolute; top: 0; left: 50%; width: min(14rem, 60%); height: 9px; transform: translateX(-50%);
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='9' height='9'%3E%3Cpath d='M4.5 0 9 4.5 4.5 9 0 4.5z' fill='%23c7a159'/%3E%3C/svg%3E") center / 9px 9px no-repeat,
    linear-gradient(90deg, transparent, color-mix(in srgb, var(--gilt) 70%, transparent) 30%, transparent 46%, transparent 54%, color-mix(in srgb, var(--gilt) 70%, transparent) 70%, transparent) center / 100% 1px no-repeat;
  opacity: .8;
}
.modal.reading > .scene::after { content: none; }

/* ── 본문 ── */
.modal.reading > .scene {
  --rd-nc: var(--ncl, var(--primary)); --rd-measure: 34em;
  width: 100%; max-width: var(--rd-measure); margin-inline: auto;
  font-size: 1.1rem; line-height: 1.9; gap: 1em; letter-spacing: .012em; word-break: keep-all; overflow-wrap: break-word;
}
:root[data-tone="dark"] .modal.reading > .scene { --rd-nc: var(--ncd, var(--gilt-2)); }
.modal.reading > .scene p { text-indent: 0; color: var(--ink-2); }
/* 대사: 이름표(인물 빛깔) → 그 아래 한 줄. 왼쪽 가는 줄 · 아주 옅은 물든 바탕 */
.modal.reading > .scene p.q {
  color: var(--ink); padding: .35em .2em .35em 1em; margin-left: .1em;
  border-left: 2px solid color-mix(in srgb, var(--line-2) 80%, transparent);
}
.modal.reading > .scene p.sp {
  border-left-color: color-mix(in srgb, var(--rd-nc) 75%, transparent);
  background: linear-gradient(90deg, color-mix(in srgb, var(--rd-nc) 9%, transparent), transparent 70%);
}
.modal.reading > .scene p.sp > :first-child {
  display: block; margin: 0 0 .05em; font-family: var(--font-head); font-size: .78em; font-weight: 700; line-height: 1.5; letter-spacing: .08em;
  text-decoration: none;
}
.modal.reading > .scene p.sp > b:first-child:not(.npcname) { color: var(--gilt-2); }
:root[data-readbg="light"]:not([data-tone="dark"]) .modal.reading > .scene p.sp > b:first-child:not(.npcname) { color: var(--primary); }
.modal.reading > .scene p.sp > .sl { display: block; }
html[data-lh="wide"] .modal.reading > .scene p { line-height: 2.05; }

/* 고른 길: 「내가 한 말」 + 이어진 대사 */
.modal.reading > .scene .path { margin: .6em 0 0; gap: .6em; }
.modal.reading > .scene .said { font-size: .95em; line-height: 1.75; padding: .3em .4em .3em 1em; border-left-width: 2px; background: color-mix(in srgb, var(--gilt) 8%, transparent); }
.modal.reading > .scene .said-who { font-size: .76em; color: var(--gilt-2); }
:root[data-readbg="light"]:not([data-tone="dark"]) .modal.reading > .scene .said-who { color: color-mix(in srgb, var(--gilt) 60%, var(--ink)); }
.modal.reading > .scene .said-t { color: var(--ink); }
.modal.reading > .scene .reply-blk { gap: 1em; padding: .8em 1em .8em 1.1em; margin-left: 0; background: color-mix(in srgb, var(--gilt) 5%, transparent); }
.modal.reading > .scene .reply-fx p { font-size: .8em; color: var(--ink-3); }
.modal.reading > .scene .rt-endmark { text-align: center; font-size: .82em; letter-spacing: .1em; color: var(--gilt-2); margin-top: .4em; }
:root[data-readbg="light"]:not([data-tone="dark"]) .modal.reading > .scene .rt-endmark { color: color-mix(in srgb, var(--gilt) 60%, var(--ink)); }

/* ── 아래: 선택지 · 받은 것 · 닫기 ── 글과 같은 폭 */
.modal.reading > .scene-foot,
.modal.reading > .row.end,
.modal.reading > .rt-wickline { width: 100%; max-width: calc(34 * 1.1rem); margin-inline: auto; }
.modal.reading > .scene-foot { gap: .8rem; }
.modal.reading > .scene-foot:empty { display: none; }
.modal.reading .scene-foot .row.end,
.modal.reading > .row.end:last-child { margin-top: .1rem; padding-top: .8rem; border-top: 1px solid color-mix(in srgb, var(--line-2) 55%, transparent); gap: .6rem; align-items: center; }
.modal.reading .scene-foot .row.end .tag.gold { margin-right: auto; font-size: .78rem; padding: .2rem .55rem; }
.modal.reading .scene-foot .plate.flat { background: var(--surface-2); border-color: var(--line); }

/* 선택지: 번호 붙은 넓은 단추 */
.modal.reading .choices { counter-reset: rdch; gap: .55rem; margin-top: .2rem; padding-top: 1.5rem; position: relative; }
.modal.reading .choices::before { /* 글과 선택지 사이: 가는 줄 + 「어떻게 할까」 대신 작은 점 셋 */
  content: '· · ·'; position: absolute; top: 0; left: 0; right: 0; text-align: center; font-family: var(--font-num); font-size: .8rem; letter-spacing: .3em; line-height: 1; color: var(--gilt);
}
.modal.reading .choices button {
  counter-increment: rdch; position: relative; width: 100%; min-height: 48px; display: flex; align-items: center; gap: .8rem;
  justify-content: flex-start; text-align: left; white-space: normal; word-break: keep-all; overflow-wrap: break-word;
  padding: .65rem 1rem .65rem .75rem; font-size: 1.02rem; line-height: 1.6; font-weight: 500; color: var(--ink);
  background: linear-gradient(180deg, color-mix(in srgb, var(--surface) 92%, transparent), color-mix(in srgb, var(--surface-2) 92%, transparent));
  border: 1px solid color-mix(in srgb, var(--gilt) 38%, var(--line)); border-radius: var(--r);
  box-shadow: 0 1px 0 rgba(255, 240, 200, .04) inset, 0 2px 6px rgba(0, 0, 0, .18);
  transition: border-color .15s, background-color .15s, transform .12s, box-shadow .15s;
}
.modal.reading .choices button::before {
  content: counter(rdch); flex: none; width: 1.75rem; height: 1.75rem; margin: 0; display: grid; place-items: center;
  font-family: var(--font-body); font-size: .82rem; font-weight: 700; line-height: 1; color: var(--gilt-2); font-variant-numeric: lining-nums;
  border: 1px solid color-mix(in srgb, var(--gilt) 55%, transparent); border-radius: var(--r-s);
  background: color-mix(in srgb, var(--gilt) 10%, transparent);
}
:root[data-readbg="light"]:not([data-tone="dark"]) .modal.reading .choices button::before { color: color-mix(in srgb, var(--gilt) 55%, var(--ink)); }
.modal.reading .choices button:hover:not(:disabled) {
  border-color: var(--gilt); transform: translateX(2px);
  background: linear-gradient(180deg, color-mix(in srgb, var(--gilt) 14%, var(--surface)), color-mix(in srgb, var(--gilt) 8%, var(--surface-2)));
}
.modal.reading .choices button:hover:not(:disabled)::before { background: var(--gilt); color: var(--page); border-color: var(--gilt); }
.modal.reading .choices button:active:not(:disabled) { transform: translateY(1px); box-shadow: inset 0 1px 4px rgba(0, 0, 0, .3); }
.modal.reading .choices button:focus-visible { outline: 2px solid var(--gilt-2); outline-offset: 2px; }
.modal.reading .choices .rm.pathic { margin: 0; }
@media (prefers-reduced-motion: reduce) { .modal.reading .choices button { transition: none; } .modal.reading .choices button:hover:not(:disabled) { transform: none; } }
:root[data-motion="reduce"] .modal.reading .choices button:hover:not(:disabled) { transform: none; }

/* ── 스크롤: 위 장식(왕관 무늬)은 위에 붙어 남고, 그 아래로 글이 옅게 사라진다 ── */
.modal.reading::before {
  position: sticky; top: -1rem; z-index: 5; pointer-events: none; align-self: stretch;
  width: auto; height: 2.3rem; margin: -1rem calc(-1 * clamp(1rem, 4vw, 2.4rem)) calc(-1.1rem - .4rem);
  background: url(/assets/ui/crown-orn.svg) center .45rem / 150px 22px no-repeat, linear-gradient(180deg, var(--page) 55%, transparent);
}
@supports (animation-timeline: scroll()) { /* 맨 위에서는 장식만, 내리기 시작하면 옅은 띠가 깔린다 */
  .modal.reading::before { background: url(/assets/ui/crown-orn.svg) center .45rem / 150px 22px no-repeat; animation: rdTop linear both; animation-timeline: scroll(nearest block); animation-range: 0 3rem; }
  @keyframes rdTop { 0%, 30% { background: url(/assets/ui/crown-orn.svg) center .45rem / 150px 22px no-repeat; } 31%, 100% { background: url(/assets/ui/crown-orn.svg) center .45rem / 150px 22px no-repeat, linear-gradient(180deg, var(--page) 55%, transparent); } }
}
/* ── 스크롤: 아래 가장자리가 옅게 사라진다 (끝까지 내리면 걷힌다 · 지원하는 브라우저만) ── */
.modal.reading::after {
  content: ''; position: sticky; bottom: -1.2rem; z-index: 5; flex: none; order: 99; pointer-events: none;
  height: 2.6rem; margin: calc(-1.1rem - 2.6rem) calc(-1 * clamp(1rem, 4vw, 2.4rem)) -1.2rem; /* 흐름에 자리를 차지하지 않게 */
  background: linear-gradient(180deg, transparent, var(--page) 85%);
}
@supports (animation-timeline: scroll()) {
  .modal.reading::after { animation: rdFade linear both; animation-timeline: scroll(nearest block); }
  @keyframes rdFade { 0%, 90% { opacity: 1; } 100% { opacity: 0; } }
}

/* ── 휴대폰 ── */
@media (max-width: 640px) {
  .modal.reading { padding: .8rem 1rem 1rem; gap: .9rem; }
  .modal.reading > .scene { font-size: 1.1rem; line-height: 1.88; gap: .95em; }
  .modal.reading > .scene p.q { padding-left: .85em; }
  .modal.reading > :is(.scene-head, .mx + div:not(.scene)) h3, .modal.reading > .mx + h3 { font-size: 1.24rem; }
  .modal.reading > .scene-head, .modal.reading > .mx + div:not(.scene):not(.scene-foot), .modal.reading > .mx + h3 { padding-inline: 2.6rem; }
  .modal.reading .choices button { padding: .6rem .8rem .6rem .6rem; font-size: 1rem; }
  .modal.reading::after { margin-inline: -1rem; }
}

/* 편지: 종이 모양은 그대로, 가림막만 짙게 (위 .rd-back) */

/* ── 텍스트 피드백 (public/js/textfb.js): 이야기 창 맨 아래 작은 단추 · 고르는 낱장 · 운영자 목록 ── */
.tfb-foot { display: flex; justify-content: center; margin-top: .55rem; }
.tfb-btn { display: inline-flex; align-items: center; gap: .3rem; min-height: 1.6rem; padding: .1rem .55rem; font-size: var(--t-micro); font-weight: 400; white-space: nowrap;
  background: transparent; border: 0; box-shadow: none; color: var(--ink-3); opacity: .8; }
.tfb-btn:hover, .tfb-btn:focus-visible { opacity: 1; color: var(--ink-2); background: color-mix(in srgb, var(--surface-3) 50%, transparent); }
.tfb-btn .tfb-ic { width: .9rem; height: .9rem; }
.modal.tfb-sheet { max-width: min(var(--modal), calc(100vw - 16px)); text-align: center; }
.tfb-sheet h3 { margin-bottom: .2rem; }
.tfb-sub, .tfb-note { font-size: var(--t-small); margin: 0 0 .45rem; }
.tfb-note { margin: .4rem 0 .5rem; }
.tfb-lines { display: flex; flex-direction: column; gap: .25rem; max-height: min(34vh, 300px); overflow-y: auto; overscroll-behavior: contain; text-align: left;
  padding: .3rem; border: 1px solid color-mix(in srgb, var(--line-2) 55%, transparent); border-radius: var(--r-s); background: color-mix(in srgb, var(--surface-2) 70%, transparent); }
.tfb-row { flex: none; display: flex; align-items: flex-start; gap: .45rem; padding: .35rem .45rem; border-radius: var(--r-s); cursor: pointer; font-size: var(--t-small); line-height: 1.45; min-height: var(--tap); }
.tfb-row:hover { background: color-mix(in srgb, var(--surface-3) 55%, transparent); }
.tfb-row:has(input:checked) { background: color-mix(in srgb, var(--gilt) 20%, transparent); box-shadow: inset 2px 0 0 var(--gilt); }
.tfb-row input { margin-top: .2rem; flex: none; }
.tfb-row .tfb-t { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.tfb-row .tfb-k { flex: none; font-size: var(--t-micro); color: var(--ink-3); border: 1px solid color-mix(in srgb, var(--line-2) 60%, transparent); border-radius: var(--r-s); padding: 0 .3rem; margin-top: .1rem; }
.tfb-row.sel-part { margin-bottom: .35rem; text-align: left; border: 1px dashed color-mix(in srgb, var(--gilt) 60%, transparent); }
.tfb-row.ttl .tfb-t { font-weight: 600; }
.tfb-f { margin-top: .55rem; display: flex; flex-direction: column; align-items: center; gap: .3rem; }
.tfb-fl { font-size: var(--t-micro); color: var(--ink-3); }
.tfb-chips { display: flex; flex-wrap: wrap; justify-content: center; gap: .3rem; }
.tfb-chip { white-space: nowrap; }
.tfb-cmrow { width: 100%; gap: .4rem; align-items: center; }
.tfb-cm { flex: 1; min-width: 0; font-size: var(--t-small); }
.tfb-cnt { flex: none; font-size: var(--t-micro); }
.tfb-sheet .row.end { justify-content: center; }
.tfb-sheet .row.end button { white-space: nowrap; min-width: 5.5rem; }
/* 동료 · 마을 사람 목록 위의 한 줄 안내 */
.npc-hint { margin: 0 auto .5rem; max-width: 34rem; text-align: center; font-size: var(--t-micro); line-height: 1.5; color: var(--ink-3); opacity: .9; text-wrap: balance; }
/* 운영자 목록 */
.tfa-bar { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; justify-content: center; margin-bottom: .5rem; }
.tfa-bar select, .tfa-bar .tfa-q { min-width: 0; max-width: 12rem; }
.tfa-list { display: flex; flex-direction: column; gap: .5rem; }
.tfa-item { padding: .5rem .6rem; border: 1px solid color-mix(in srgb, var(--line-2) 60%, transparent); border-radius: var(--r-s); background: color-mix(in srgb, var(--surface) 70%, transparent); text-align: left; }
.tfa-item.done { opacity: .6; }
.tfa-h { display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; font-size: var(--t-small); }
.tfa-src { font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.tfa-t { margin-left: auto; font-size: var(--t-micro); }
.tfa-q1 { margin: .35rem 0; padding: .3rem .55rem; border-left: 3px solid var(--gilt); background: color-mix(in srgb, var(--surface-2) 80%, transparent); white-space: pre-wrap; font-size: var(--t-small); user-select: text; }
.tfa-cm { margin: 0 0 .3rem; font-size: var(--t-small); color: var(--ink-2); }
.tfa-pre { margin: 0 0 .3rem; padding: .25rem .45rem; font: var(--t-micro)/1.4 ui-monospace, monospace; white-space: pre-wrap; overflow-wrap: anywhere; color: var(--ink-3); background: color-mix(in srgb, var(--surface-3) 45%, transparent); border-radius: var(--r-s); user-select: all; }
.tfa-acts { gap: .35rem; align-items: center; }
.tfa-acts button, .tfa-done { white-space: nowrap; }
.tfa-done { font-size: var(--t-small); }
