/* ───────────── 색 · 테마 ───────────── */
:root {
  --bg: #fbf8f3;
  --surface: #ffffff;
  --text: #2a2521;
  --muted: #85796c;
  --faint: #b3a899;
  --accent: #8a6440;
  --accent-soft: rgba(138, 100, 64, .1);
  --line: #ebe3d7;
  --hl: rgba(226, 186, 116, .24);
  --shadow: 0 10px 30px rgba(60, 40, 20, .08), 0 2px 6px rgba(60, 40, 20, .05);
  --art-filter: none;

  --serif: "Gowun Batang", "Nanum Myeongjo", "AppleMyungjo", "Noto Serif KR", serif;
  --sans: "Gowun Dodum", -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  --ui: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR", "Malgun Gothic", sans-serif;

  --fs: 19px;
  --lh: 1.95;
  --read-font: var(--serif);
  --measure: 34em;
  --topbar-h: 56px;
  --player-h: 0px;
  color-scheme: light;
}
:root[data-theme="paper"] {
  --bg: #f2e9d8;
  --surface: #f8f1e4;
  --text: #3a3026;
  --muted: #8b7b67;
  --faint: #b5a68f;
  --accent: #8a5f35;
  --accent-soft: rgba(138, 95, 53, .1);
  --line: #e2d5bd;
  --hl: rgba(205, 150, 80, .22);
}
:root[data-theme="dark"] {
  --bg: #1b1a18;
  --surface: #242220;
  --text: #e6dfd3;
  --muted: #a0968a;
  --faint: #6f675e;
  --accent: #d4b083;
  --accent-soft: rgba(212, 176, 131, .12);
  --line: #34312c;
  --hl: rgba(212, 176, 131, .16);
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --art-filter: brightness(.82) saturate(.9);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --bg: #1b1a18;
    --surface: #242220;
    --text: #e6dfd3;
    --muted: #a0968a;
    --faint: #6f675e;
    --accent: #d4b083;
    --accent-soft: rgba(212, 176, 131, .12);
    --line: #34312c;
    --hl: rgba(212, 176, 131, .16);
    --shadow: 0 10px 30px rgba(0, 0, 0, .35);
    --art-filter: brightness(.82) saturate(.9);
    color-scheme: dark;
  }
}
:root[data-font="sans"] { --read-font: var(--sans); }
:root[data-leading="tight"] { --lh: 1.7; }
:root[data-leading="loose"] { --lh: 2.25; }

/* ───────────── 기본 ───────────── */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--topbar-h) + 16px); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--ui);
  word-break: keep-all;
  overflow-wrap: break-word;
  -webkit-font-smoothing: antialiased;
  transition: background-color .3s, color .3s;
  padding-bottom: calc(var(--player-h) + env(safe-area-inset-bottom));
}
button { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
img { display: block; max-width: 100%; }
main:focus { outline: none; }
[hidden] { display: none !important; }

/* ───────────── 상단 바 ───────────── */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  height: calc(var(--topbar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid transparent;
  transition: border-color .2s;
}
.topbar.scrolled { border-bottom-color: var(--line); }
.topbar-title {
  flex: 1; min-width: 0; text-align: center;
  font-family: var(--serif); font-size: 15px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  opacity: 0; transition: opacity .25s;
}
.topbar.show-title .topbar-title { opacity: 1; }
.topbar-actions { display: flex; gap: 4px; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-width: 44px; height: 44px; padding: 0 10px;
  border: 0; border-radius: 22px; background: transparent; color: var(--text);
}
.icon-btn:hover { background: var(--accent-soft); }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn svg .fill, .play-btn svg .fill { fill: currentColor; stroke: none; }
.btn-label { font-size: 15px; }
.text-btn { font-family: var(--serif); font-size: 20px; letter-spacing: -2px; }
.text-btn small { font-size: 14px; }
.read-progress { position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; }
.read-progress span { display: block; height: 100%; width: 0; background: var(--accent); opacity: .7; transition: width .1s linear; }

/* ───────────── 목차 ───────────── */
.home { max-width: 1040px; margin: 0 auto; padding: 8px max(16px, env(safe-area-inset-left)) 64px; }
.hero { text-align: center; padding: 36px 0 32px; }
.hero .eyebrow { max-width: none; font-family: var(--ui); font-size: 11.5px; letter-spacing: .22em; color: var(--muted); text-transform: uppercase; margin: 0 0 14px; }
.hero h1 { font-family: var(--serif); font-weight: 700; font-size: clamp(30px, 7vw, 44px); letter-spacing: -.01em; margin: 0 0 14px; }
.hero p { font-family: var(--serif); color: var(--muted); font-size: 17px; line-height: 1.7; margin: 0 auto; max-width: 26em; text-wrap: balance; }
@media (max-width: 480px) { .hero p br { display: none; } .hero .eyebrow { letter-spacing: .14em; font-size: 10.5px; } }
.hero .credit { margin-top: 16px; font-family: var(--ui); font-size: 13px; letter-spacing: .04em; color: var(--muted); }
.ornament { display: block; width: 64px; height: 12px; margin: 22px auto 0; color: var(--faint); }

.continue {
  display: flex; align-items: center; gap: 14px; width: 100%;
  max-width: 640px; margin: 0 auto 32px; padding: 14px 18px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  text-align: left; box-shadow: var(--shadow);
}
.continue-icon { flex: none; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.continue-icon svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.continue-text { flex: 1; min-width: 0; }
.continue-text small { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 2px; }
.continue-text strong { display: block; font-family: var(--serif); font-weight: 400; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.continue-pct { font-size: 13px; color: var(--accent); }

.cards { display: grid; gap: 22px; grid-template-columns: 1fr; }
@media (min-width: 720px) { .cards { grid-template-columns: repeat(2, 1fr); gap: 26px; } }
@media (min-width: 1000px) { .cards { grid-template-columns: repeat(3, 1fr); } }
.card {
  display: flex; flex-direction: column; text-align: left; padding: 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: 18px; overflow: hidden;
  box-shadow: var(--shadow); transition: transform .2s ease, box-shadow .2s ease;
  text-decoration: none; color: inherit;
}
.card:hover { transform: translateY(-2px); }
.card:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.card-art { aspect-ratio: 15 / 8; overflow: hidden; background: var(--line); }
.card-art img { width: 100%; height: 100%; object-fit: cover; filter: var(--art-filter); }
.card-body { padding: 18px 20px 22px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.card-meta { font-size: 12.5px; color: var(--muted); letter-spacing: .02em; display: flex; gap: 6px; flex-wrap: wrap; }
.card-meta .num { white-space: pre-wrap; color: var(--accent); font-weight: 600; letter-spacing: .04em; }
.card h2 { font-family: var(--serif); font-weight: 700; font-size: 18px; line-height: 1.5; margin: 0; }
.card h2 .sub { display: block; font-weight: 400; font-size: 16px; color: var(--muted); margin-top: 2px; }
.card h2, .card p { text-wrap: balance; }
.card p { margin: 0; font-size: 13.5px; line-height: 1.6; color: var(--muted); }

.home-foot { text-align: center; margin-top: 48px; font-size: 13px; color: var(--faint); line-height: 1.8; }

/* ───────────── 편지 읽기 ───────────── */
.letter { padding-bottom: 40px; }
.letter-art { max-width: 1040px; margin: 0 auto; padding: 0 max(0px, env(safe-area-inset-left)); }
figure.letter-art { margin-block: 0; }
.letter-art img { width: 100%; aspect-ratio: 15 / 8; max-height: 46vh; object-fit: cover; filter: var(--art-filter); }
@media (min-width: 760px) {
  .letter-art { padding: 8px 24px 0; }
  .letter-art img { border-radius: 20px; }
}
.letter-inner { max-width: var(--measure); margin: 0 auto; padding: 0 22px; font-size: var(--fs); }
.letter-head { text-align: center; padding: 34px 0 10px; }
.letter-num { white-space: pre-wrap; font-family: var(--ui); font-size: 12.5px; letter-spacing: .12em; color: var(--accent); margin: 0 0 14px; }
.letter-head h1 { font-family: var(--serif); font-weight: 700; text-wrap: balance; font-size: calc(var(--fs) * 1.3); line-height: 1.45; margin: 0; letter-spacing: -.01em; }
.letter-head h1 .sub { display: block; font-weight: 400; font-size: .78em; color: var(--muted); margin-top: 6px; }
.summary { margin: 16px 0 0; font-family: var(--serif); font-size: 15px; color: var(--muted); line-height: 1.75; text-wrap: balance; }
.letter-date { margin-top: 8px; font-size: 13px; color: var(--faint); }

.listen-row { display: flex; justify-content: center; margin: 26px 0 8px; }
.listen-btn {
  display: inline-flex; align-items: center; gap: 10px;
  padding: 11px 22px 11px 16px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow);
  font-size: 15px;
}
.listen-btn:hover { border-color: var(--accent); }
.listen-btn .dot { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: var(--bg); }
.listen-btn .dot svg { width: 14px; height: 14px; fill: currentColor; margin-left: 2px; }
.listen-btn small { color: var(--muted); font-size: 13px; }

.rule { display: block; width: 72px; height: 14px; margin: 26px auto; color: var(--faint); }

.letter-body { font-family: var(--read-font); line-height: var(--lh); letter-spacing: -.003em; }
.letter-body p { margin: 0 0 1.15em; padding: .1em .45em; margin-inline: -.45em; border-radius: 8px; transition: background-color .4s ease; }
.letter-body p.salutation { margin-bottom: .9em; }
.letter-body .ref { font-size: .8em; color: var(--muted); white-space: nowrap; }
.letter-body .q { color: inherit; }
.letter-body [data-seg].speaking { background: var(--hl); }
.letter-body.seekable [data-seg] { cursor: pointer; }
.closing { text-align: right; margin-top: 2em; }
.closing p { margin: 0 0 .2em !important; }
.closing .sig { font-size: 1.15em; letter-spacing: .1em; margin: .4em 0 .3em !important; }
/* 좋아요(하트) */
.like-row { display: flex; justify-content: center; margin: 2.4em 0 0; }
.like-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-width: 48px; height: 48px; padding: 0 18px 0 15px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface);
  font-family: var(--ui); font-size: 15px; color: var(--muted);
  transition: color .2s, border-color .2s, background-color .2s;
}
.like-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linejoin: round; transition: fill .2s; }
.like-btn:hover { border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.like-btn[aria-pressed="true"] { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, transparent); background: var(--accent-soft); }
.like-btn[aria-pressed="true"] svg { fill: currentColor; }
.like-btn.pop svg { animation: heart-pop .45s ease-out; }
@keyframes heart-pop { 30% { transform: scale(1.35); } 60% { transform: scale(.92); } }
.like-n { font-variant-numeric: tabular-nums; }
.like-n:empty { display: none; }
.like-btn:has(.like-n:empty) { padding: 0 14px; }
.card-like .heart { color: var(--accent); }
.letter-body p.letter-credit { margin: 2em 0 0; padding: 1.2em 0 0; border-top: 1px solid var(--line); border-radius: 0; text-align: center; font-family: var(--ui); font-size: 13px; color: var(--muted); letter-spacing: .04em; }
.closing .place { font-size: .85em; color: var(--muted); }


/* 이전/다음 */
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 44px 0 0; }
.pager button {
  padding: 14px 16px; border-radius: 14px; border: 1px solid var(--line); background: transparent;
  text-align: left; min-height: 72px;
}
.pager button:hover { background: var(--accent-soft); }
.pager button.next { text-align: right; grid-column: 2; }
.pager small { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.pager span { font-family: var(--serif); font-size: 15px; line-height: 1.5; }

/* ───────────── 설정 시트 ───────────── */
.sheet-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(20, 15, 10, .25); }
.sheet {
  position: fixed; z-index: 41; left: 50%; bottom: 0; transform: translateX(-50%);
  width: min(100%, 460px);
  padding: 10px 20px calc(20px + env(safe-area-inset-bottom));
  background: var(--surface); color: var(--text);
  border-radius: 20px 20px 0 0; box-shadow: 0 -10px 40px rgba(0,0,0,.18);
  animation: sheet-up .22s ease-out;
}
@media (min-width: 760px) {
  .sheet { left: auto; right: 20px; top: calc(var(--topbar-h) + 8px); bottom: auto; transform: none; width: 360px; border-radius: 18px; border: 1px solid var(--line); animation: fade-in .15s ease-out; }
  .sheet-handle { display: none; }
}
@keyframes sheet-up { from { transform: translate(-50%, 30px); opacity: 0; } }
@keyframes fade-in { from { opacity: 0; transform: translateY(-4px); } }
.sheet-handle { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 0 auto 14px; }
.setting { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.setting:last-child { border-bottom: 0; }
.setting-label { font-size: 14px; color: var(--muted); flex: none; }
.stepper { display: flex; align-items: center; gap: 4px; }
.stepper button { width: 48px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); font-family: var(--serif); }
.stepper output { min-width: 44px; text-align: center; font-variant-numeric: tabular-nums; font-size: 15px; }
.seg { display: flex; padding: 3px; gap: 2px; border-radius: 12px; background: var(--bg); border: 1px solid var(--line); }
.seg button { border: 0; background: transparent; padding: 7px 12px; border-radius: 9px; font-size: 14px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,.1); }
.seg .f-serif { font-family: var(--serif); }
.seg .f-sans { font-family: var(--sans); }
.swatches button { padding: 7px 9px; font-size: 13px; }
.sw { width: 12px; height: 12px; border-radius: 50%; border: 1px solid rgba(0,0,0,.15); display: inline-block; }
.sw-auto { background: linear-gradient(135deg, #fbf8f3 50%, #1b1a18 50%); }
.sw-light { background: #fbf8f3; }
.sw-paper { background: #f2e9d8; }
.sw-dark { background: #1b1a18; }

/* ───────────── 플레이어 ───────────── */
.player {
  position: fixed; z-index: 30; left: 50%; transform: translateX(-50%);
  bottom: calc(10px + env(safe-area-inset-bottom));
  width: min(calc(100% - 20px), 560px);
  padding: 10px 14px 8px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow);
  animation: player-up .25s ease-out;
}
@keyframes player-up { from { transform: translate(-50%, 20px); opacity: 0; } }
.player-track { display: flex; align-items: center; gap: 10px; }
.time { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 34px; }
.time:last-child { text-align: right; }
#seek { flex: 1; accent-color: var(--accent); height: 20px; margin: 0; }
.player-controls { display: flex; align-items: center; justify-content: space-between; gap: 2px; margin-top: 4px; }
.pill {
  min-width: 56px; height: 34px; padding: 0 10px; border-radius: 17px; border: 1px solid var(--line);
  background: transparent; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums;
}
.pill[aria-pressed="true"] { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, transparent); background: var(--accent-soft); }
.play-btn { width: 52px; height: 52px; border-radius: 50%; border: 0; background: var(--accent); color: var(--bg); display: grid; place-items: center; }
.play-btn svg { width: 24px; height: 24px; }
.play-btn .i-pause, .player.playing .play-btn .i-play { display: none; }
.player.playing .play-btn .i-pause { display: block; }
.player.loading .play-btn { opacity: .55; }
.player.loading.want-play .play-btn { animation: pulse 1.1s ease-in-out infinite; }
.player.loading.want-play .play-btn .i-play { display: none; }
.player.loading.want-play .play-btn .i-pause { display: block; }
@keyframes pulse { 50% { opacity: .9; transform: scale(.94); } }
.close-btn { min-width: 36px; padding: 0 6px; color: var(--muted); }
.close-btn svg { width: 18px; height: 18px; }
@media (max-width: 380px) { .pill { min-width: 46px; padding: 0 6px; font-size: 12px; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
