/* 시담 — 여백과 활자 중심. 외부 폰트 없이 시스템 명조 계열을 쓴다. */
@font-face {
  font-family: "SidamSerif"; src: url("/static/fonts/NanumMyeongjo-Regular.woff2") format("woff2");
  font-weight: 400; font-style: normal; font-display: swap;
}
:root {
  --paper: #f6f3ec;
  --ink: #1d1c1a;
  --ink-2: #5c5850;
  --mute: #9a958a;
  --line: #dcd6ca;
  --seal: #a23b2a;
  --serif: "SidamSerif", "Nanum Myeongjo", "AppleMyungjo", "Noto Serif KR", "Noto Serif CJK KR", "Batang", "바탕", serif;
  --sans: "Pretendard", -apple-system, "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif;
  --latin: "Bellefair", "Cormorant Garamond", Georgia, "Times New Roman", serif;
  --header-h: 64px;
}
@media (prefers-color-scheme: dark) {
  :root { --paper: #171614; --ink: #ece7dc; --ink-2: #b4aea1; --mute: #7d786d; --line: #35322d; --seal: #d46a57; }
}
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--paper); color: var(--ink); font-family: var(--serif);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
:focus-visible { outline: 1px solid currentColor; outline-offset: 4px; }
[hidden] { display: none !important; }

/* ── 헤더 ── */
.top {
  position: fixed; inset: 0 0 auto 0; z-index: 20; height: var(--header-h);
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; column-gap: clamp(20px, 2.5vw, 36px);
  padding: 0 clamp(20px, 4vw, 48px); transition: color .6s;
}
body[data-tone="light"] .top, body[data-tone="light"] .chips, body[data-tone="light"] .side, body[data-tone="light"] .hint { color: #1d1c1a; }
body[data-tone="dark"] .top, body[data-tone="dark"] .chips, body[data-tone="dark"] .side, body[data-tone="dark"] .hint { color: #f1ece1; }
.logo { display: flex; align-items: baseline; gap: 10px; }
.top .logo { justify-self: start; }
.logo-mark { font-size: 1.15rem; letter-spacing: .44em; margin-right: -.44em; }
.logo-sub { font-family: var(--latin); font-size: .8rem; letter-spacing: .3em; opacity: .55; }
.lang-control { position: relative; display: inline-flex; align-items: center; justify-content: space-between; gap: 9px; padding: 7px 0 8px; border-bottom: 1px solid color-mix(in srgb, currentColor 50%, transparent); font-family: var(--sans); font-size: .78rem; line-height: 1.2; white-space: nowrap; }
.lang-control:hover, .lang-control:focus-within { border-color: currentColor; }
.lang-control:focus-within { outline: 1px solid currentColor; outline-offset: 4px; }
.lang-chevron { width: 7px; height: 7px; border-right: 1px solid currentColor; border-bottom: 1px solid currentColor; transform: translateY(-2px) rotate(45deg); flex: none; }
.lang-native { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; font: inherit; }
.lang-native option { color: #1d1c1a; background: #f6f3ec; }
.end-link { display: block; margin: 1.2rem auto 0; font-size: .85rem; letter-spacing: .1em; border-bottom: 1px solid currentColor; padding-bottom: 3px; opacity: .8; }
.nav { justify-self: center; font-family: var(--sans); display: flex; align-items: center; gap: clamp(18px, 2.1vw, 30px); font-size: .86rem; letter-spacing: .12em; white-space: nowrap; }
.nav a { padding: 6px 0; border-bottom: 1px solid transparent; opacity: .68; transition: opacity .3s, border-color .3s; }
.nav a:hover, .nav a[aria-current] { opacity: 1; border-color: currentColor; }

/* ── 장르 칩 ── */
.chips {
  position: fixed; z-index: 19; top: var(--header-h); left: 0; right: 0;
  display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; justify-content: safe center;
  padding: 4px clamp(20px, 4vw, 48px) 10px; transition: color .6s;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  font-family: var(--sans); flex: none; font-size: .8rem; letter-spacing: .1em; padding: 7px 14px; border: 1px solid currentColor;
  border-color: color-mix(in srgb, currentColor 24%, transparent); border-radius: 999px; opacity: .76;
  transition: opacity .25s, background .25s, color .25s, border-color .25s;
}
.chip:hover { opacity: 1; }
.chip[aria-pressed="true"], .chip[aria-current="true"] { opacity: 1; border-color: currentColor; background: color-mix(in srgb, currentColor 6%, transparent); }
.static-chips { position: static; justify-content: flex-start; flex-wrap: wrap; padding: 0; margin: 0 0 40px; overflow: visible; }
.author-chips { align-items: center; gap: 22px; }
.author-back { font-family: var(--sans); font-size: .76rem; opacity: .7; white-space: nowrap; }
.author-back:hover { opacity: 1; }
.author-heading { font-size: .9rem; letter-spacing: .13em; white-space: nowrap; }

/* ── 피드 ── */
.feed {
  height: 100vh; height: 100dvh; overflow-y: auto; scroll-snap-type: y mandatory; scrollbar-width: none;
  overscroll-behavior-y: contain; outline: none;
}
.feed::-webkit-scrollbar { display: none; }
.poem {
  position: relative; height: 100vh; height: 100dvh; scroll-snap-align: start; scroll-snap-stop: always;
  display: grid; grid-template-rows: minmax(0, 1fr); place-items: center; padding: calc(var(--header-h) + 72px) 28px calc(var(--header-h) + 72px); overflow: hidden;
  -webkit-user-select: none; user-select: none; touch-action: pan-y;
}
.poem-viewport { position: relative; width: 100%; height: 100%; min-height: 0; display: grid; place-items: center; overflow: hidden; }
.poem-inner { position: relative; width: 100%; max-width: 30rem; text-align: center; }
.poem.long .poem-viewport { display: block; -webkit-mask-image: linear-gradient(to bottom, transparent 0 40px, #000 96px); mask-image: linear-gradient(to bottom, transparent 0 40px, #000 96px); }
.poem.long .poem-inner { position: absolute; top: var(--long-start); left: 0; right: 0; margin: 0 auto; }
.poem.long.active .poem-inner { animation: long-poem-scroll var(--scroll-duration) linear var(--scroll-delay) forwards; }
@keyframes long-poem-scroll { to { transform: translateY(var(--travel)); } }
.poem-meta { position: absolute; top: calc(var(--header-h) + 62px); left: 0; right: 0; display: flex; justify-content: center; gap: 12px; align-items: baseline; font-size: .78rem; letter-spacing: .24em; opacity: .82; }
.poem-meta .genre { font-family: var(--sans); letter-spacing: .12em; font-size: .72rem; padding-left: 12px; border-left: 1px solid currentColor; }
.poem-meta .seal { font-family: var(--serif); font-size: .68rem; letter-spacing: .2em; padding: 2px 6px 1px; border: 1px solid var(--seal); color: var(--seal); border-radius: 2px; }
.poem-title { margin: 0; font-size: .95rem; letter-spacing: .3em; }
.poem-body { letter-spacing: .035em; font-size: var(--fs, 1.2rem); line-height: var(--lh, 2.05); word-break: keep-all; overflow-wrap: anywhere; }
.poem-body .ln { display: block; min-height: calc(var(--lh, 2.05) * 1em); }
.poem-body .ln.gap { min-height: 1.1em; }
/* 지은이는 시 바로 아래에 붙되, 본문만 화면 중앙에 오도록 흐름 밖에 둔다 */
.poem-author { position: absolute; top: 100%; left: 0; right: 0; margin: 2.1rem 0 0; text-align: center; font-size: .85rem; letter-spacing: .2em; opacity: .72; }
.poem button.poem-author:hover { opacity: 1; }
.poem-author::before { content: ""; display: block; width: 28px; height: 1px; background: currentColor; opacity: .5; margin: 0 auto 1rem; }
.poem .ln, .poem .poem-meta, .poem .poem-author { opacity: 0; transform: translateY(6px); transition: opacity .65s ease, transform .65s ease; transition-delay: calc(var(--i, 0) * 85ms); }
.poem.active .ln { opacity: 1; transform: none; }
.poem.active .poem-meta { opacity: .82; transform: none; }
.poem.active .poem-author { opacity: .72; transform: none; transition-delay: calc(var(--i, 0) * 85ms + 100ms); }
.dwell { position: absolute; left: 0; bottom: 0; height: 2px; width: 0; background: currentColor; opacity: .35; }
.poem.active .dwell { width: 100%; transition: width var(--read, 8s) linear; }

/* 오른쪽 액션 (쇼츠 스타일: 동그란 아이콘 + 아래 숫자) */
.actions { position: absolute; right: clamp(10px, 2.5vw, 36px); bottom: calc(22px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; align-items: center; gap: 12px; }
.act { display: flex; flex-direction: column; align-items: center; gap: 3px; font-family: var(--sans); font-size: .64rem; }
.act-ico { display: grid; place-items: center; width: 40px; height: 40px; border: 1px solid color-mix(in srgb, currentColor 27%, transparent); border-radius: 50%;
  background: color-mix(in srgb, currentColor 4%, transparent); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  transition: background .25s, border-color .25s, transform .2s; }
.act:hover .act-ico { background: color-mix(in srgb, currentColor 13%, transparent); border-color: color-mix(in srgb, currentColor 55%, transparent); }
.act:active .act-ico { transform: scale(.92); }
.act-text { opacity: .78; min-height: 1em; }
.act svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.4; stroke-linecap: round; stroke-linejoin: round; transition: fill .25s, stroke .25s; }
.act svg circle { fill: currentColor; stroke: none; }
.act[data-role="like"][aria-pressed="true"] svg { fill: var(--seal); stroke: var(--seal); animation: pop .4s ease; }
@keyframes pop { 40% { transform: scale(1.3); } }
.burst { position: absolute; width: 90px; height: 90px; margin: -45px 0 0 -45px; pointer-events: none; fill: var(--seal); animation: burst .8s ease-out forwards; }
@keyframes burst { 0% { opacity: 0; transform: scale(.4); } 25% { opacity: .9; transform: scale(1.1); } 100% { opacity: 0; transform: scale(1.3) translateY(-30px); } }

.side { position: fixed; z-index: 15; right: clamp(14px, 3vw, 40px); top: 50%; transform: translateY(-50%); display: none; flex-direction: column; gap: 10px; }
.ghost-btn { width: 36px; height: 36px; border: 1px solid currentColor; border-color: color-mix(in srgb, currentColor 30%, transparent); border-radius: 50%; opacity: .6; transition: opacity .25s; }
.ghost-btn:hover { opacity: 1; }
@media (hover: hover) and (min-width: 900px) { .side { display: flex; } .actions { right: clamp(80px, 9vw, 130px); bottom: 7vh; } }

.act[data-role="sound"][aria-pressed="true"] .act-ico { background: color-mix(in srgb, currentColor 13%, transparent); }
.hint { position: fixed; z-index: 15; left: 50%; bottom: calc(26px + env(safe-area-inset-bottom)); transform: translateX(-50%); font-size: .75rem; letter-spacing: .25em; opacity: .68; transition: opacity .6s; pointer-events: none; }
.hint span { display: inline-block; animation: bob 1.8s ease-in-out infinite; }
.hint.gone { opacity: 0; }
@keyframes bob { 50% { transform: translateY(5px); } }
.end { text-align: center; }
.end p { line-height: 2; opacity: .7; }
.end a { display: inline-block; margin-top: 1.4rem; border-bottom: 1px solid currentColor; padding-bottom: 3px; letter-spacing: .15em; }

/* ── 배경 테마 (글자색은 data-tone으로 짝지어짐) ── */
.bg-paper  { background: #f6f3ec; color: #1d1c1a; }
.bg-dawn   { background: linear-gradient(180deg, #f8e9dc 0%, #f4d9d0 55%, #eed3da 100%); color: #3a2a2a; }
.bg-rose   { background: linear-gradient(160deg, #f6e6e6 0%, #ecd0d4 100%); color: #3b2a2e; }
.bg-night  { background: linear-gradient(180deg, #0d1226 0%, #1a2142 100%); color: #ece9f5; }
.bg-dusk   { background: linear-gradient(180deg, #2b2147 0%, #6b3f5e 60%, #c0795f 100%); color: #f7ebe3; }
.bg-sea    { background: linear-gradient(180deg, #0f2a33 0%, #1f5663 100%); color: #e5f1f1; }
.bg-forest { background: linear-gradient(180deg, #14231a 0%, #2c4a36 100%); color: #e8efe3; }
.bg-ink    { background: #0c0b0a; color: #e9e4d8; }
.bg-night, .bg-dusk, .bg-sea, .bg-forest, .bg-ink { --seal: #e7a694; }

/* ── 온보딩 시트 ── */
.sheet-backdrop { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 20px; background: rgba(20,18,15,.5); backdrop-filter: blur(6px); }
.sheet { width: 100%; max-width: 30rem; background: var(--paper); color: var(--ink); padding: clamp(28px, 6vw, 48px); border: 1px solid var(--line); }
.sheet h2 { margin: 6px 0 10px; font-weight: 400; font-size: 1.5rem; letter-spacing: .08em; }
.sheet-sub { margin: 0 0 28px; color: var(--ink-2); font-size: .9rem; line-height: 1.8; }
.sheet-actions { display: flex; gap: 12px; justify-content: flex-end; margin-top: 32px; }
.chip-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-grid .chip { color: var(--ink); }
.chip-grid .chip[aria-pressed="true"] { background: var(--ink); color: var(--paper); }

/* ── 일반 페이지 (쓰기·인기) ── */
.page { max-width: 36rem; margin: 0 auto; padding: calc(var(--header-h) + 64px) 24px 120px; }
.eyebrow { margin: 0; font-family: var(--latin); font-size: .8rem; letter-spacing: .4em; color: var(--mute); }
.page h1 { margin: 14px 0 12px; font-weight: 400; font-size: clamp(1.8rem, 5vw, 2.4rem); letter-spacing: .1em; }
.lead { margin: 0 0 56px; color: var(--ink-2); line-height: 1.9; }
.lead a { border-bottom: 1px solid currentColor; }
.field { display: block; margin: 0 0 36px; padding: 0; border: 0; position: relative; }
.field > span, .field > legend { display: block; padding: 0; margin-bottom: 10px; font-size: .8rem; letter-spacing: .2em; color: var(--ink-2); }
.field em { font-style: normal; color: var(--mute); letter-spacing: .05em; margin-left: 6px; }
.field input, .field textarea {
  width: 100%; font: inherit; font-size: 1.05rem; color: var(--ink); background: transparent; border: 0; border-bottom: 1px solid var(--line);
  padding: 10px 0; border-radius: 0; outline: none; transition: border-color .3s; resize: vertical; line-height: 1.9;
}
.field textarea { font-size: 1.15rem; border: 1px solid var(--line); padding: 16px; }
.field input:focus, .field textarea:focus { border-color: var(--ink); }
.field ::placeholder { color: var(--mute); }
.count { position: absolute; right: 0; bottom: -22px; font-family: var(--sans); font-size: .72rem; color: var(--mute); }
.trap { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }
.swatches { display: flex; flex-wrap: wrap; gap: 12px; }
.swatch { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line); position: relative; }
.swatch[aria-pressed="true"]::after { content: ""; position: absolute; inset: -6px; border: 1px solid var(--ink); border-radius: 50%; }
.preview-label { font-size: .8rem; letter-spacing: .2em; color: var(--ink-2); margin: 0 0 10px; }
.preview { position: relative; min-height: 300px; display: grid; place-items: center; padding: 40px 24px; margin-bottom: 36px; transition: background .5s, color .5s; }
.preview .poem-body { font-size: 1.1rem; }
.preview .poem-author { position: static; margin-top: 2rem; }
.preview .ln, .preview .poem-author { opacity: 1; transform: none; }
.error { min-height: 1.4em; margin: 0 0 16px; color: var(--seal); font-size: .9rem; }
.line-btn { padding: 12px 26px; border: 1px solid var(--ink); font-size: .9rem; letter-spacing: .2em; color: var(--ink); transition: background .25s, color .25s, opacity .25s; }
.line-btn:hover:not(:disabled) { background: var(--ink); color: var(--paper); }
.line-btn.solid { background: var(--ink); color: var(--paper); }
.line-btn.solid:hover:not(:disabled) { opacity: .85; }
.line-btn:disabled { opacity: .35; cursor: not-allowed; }
.wide { width: 100%; padding: 16px; }

.rank { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.rank li { display: flex; gap: 28px; padding: 28px 0; border-bottom: 1px solid var(--line); }
.rank-main { display: flex; flex-direction: column; gap: 6px; }
.rank-main:hover .rank-title, .rank-author:hover { text-decoration: underline; text-underline-offset: 4px; }
.rank-no { font-family: var(--latin); font-size: 1.6rem; color: var(--mute); width: 2.4rem; flex: none; line-height: 1.2; }
.rank-body { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.rank-title { letter-spacing: .15em; }
.rank-line { color: var(--ink-2); line-height: 1.8; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-meta { font-family: var(--sans); font-size: .75rem; color: var(--mute); letter-spacing: .05em; }
.rank-author { color: var(--ink-2); }
.empty { padding: 40px 0; color: var(--mute); }

.toast { position: fixed; z-index: 60; left: 50%; bottom: 72px; transform: translate(-50%, 12px); padding: 12px 22px; background: var(--ink); color: var(--paper); font-family: var(--sans); font-size: .85rem; opacity: 0; pointer-events: none; transition: opacity .3s, transform .3s; max-width: calc(100vw - 40px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 700px) {
  .top { column-gap: 12px; padding: 0 14px; }
  .chips:not(.static-chips) { justify-content: flex-start; padding-left: 18px; padding-right: 28px; }
  .nav { gap: 11px; font-size: .78rem; letter-spacing: .03em; }
  .lang-control { font-size: .72rem; gap: 6px; }
  .logo-mark { letter-spacing: .3em; margin-right: -.3em; }
  .logo-sub { letter-spacing: .15em; font-size: .7rem; }
  .hint { display: none; }
  .poem { padding: calc(var(--header-h) + 52px) 56px calc(var(--header-h) + 52px); }
  .poem-inner { max-width: 100%; }
  /* 좁은 화면에서도 제목과 장르를 한 줄의 중심에 둔다 */
  .poem-meta { top: calc(var(--header-h) + 54px); left: 20px; right: 20px; max-width: none; margin: 0; justify-content: center; flex-wrap: wrap; gap: 8px; font-size: .7rem; letter-spacing: .16em; text-align: center; }
  .poem-meta .genre { font-size: .66rem; padding-left: 8px; }
  .actions { right: 10px; bottom: calc(18px + env(safe-area-inset-bottom)); gap: 10px; }
}
@media (max-width: 370px) {
  .logo-sub { display: none; }
  .top { column-gap: 8px; }
  .nav { gap: 8px; }
  .poem { padding-inline: 48px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition-duration: .01ms !important; transition-delay: 0s !important; }
  .poem .ln, .poem .poem-meta, .poem .poem-author { opacity: 1; transform: none; }
  .poem.long .poem-viewport { overflow-y: auto; -webkit-mask-image: none; mask-image: none; }
  .poem.long .poem-inner { position: relative; top: auto; padding: 36px 0 80px; }
  .poem.long .poem-author { position: static; display: block; margin-top: 2.1rem; }
}
