:root {
  --paper:        #E9E0D2;
  --paper-deep:   #DED3C0;
  --paper-edge:   #CFC3AC;
  --ink:          #2B3450;
  --ink-soft:     #6E7488;
  --seal:         #8A7657;
  --card:         #F6F1E7;

  --r-card:   22px;
  --r-field:  16px;
  --r-pill:   999px;

  --font-ui:    'Pretendard Variable', Pretendard, -apple-system, BlinkMacSystemFont,
                'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  --font-voice: 'Noto Serif KR', 'Nanum Myeongjo', Batang, serif;

  --shell: 34rem;

  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)'/%3E%3C/svg%3E");
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--paper);
  background-image:
    radial-gradient(120% 80% at 50% 0%, rgba(255,255,255,.5), transparent 60%),
    radial-gradient(90% 60% at 50% 100%, rgba(160,145,115,.14), transparent 65%);
  position: relative;
  color: var(--ink);
  font-family: var(--font-ui);
  font-weight: 400;
  line-height: 1.75;
  letter-spacing: -.01em;
  word-break: keep-all;
  overflow-wrap: break-word;
  text-wrap: pretty;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: clamp(1.5rem, 5vw, 3rem) 1.25rem clamp(3rem, 8vw, 4.5rem);
}

.shell {
  width: 100%;
  max-width: var(--shell);
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image: var(--grain);
  opacity: .055;
  mix-blend-mode: multiply;
  pointer-events: none;
  z-index: 0;
}

.shell, .modal { position: relative; z-index: 1; }

/* ---------- 공통 ---------- */

.rule {
  border: 0;
  border-top: 1px solid var(--paper-edge);
  margin: 1.75rem 0;
}

.eyebrow {
  font-size: .74rem;
  font-weight: 500;
  letter-spacing: .16em;
  color: var(--ink-soft);
  text-align: center;
  margin: 0;
}

.sprig {
  display: block;
  margin: 2rem auto 0;
  width: 74px;
  height: auto;
  opacity: .9;
}

/* ---------- 표지 ---------- */

.cover { text-align: center; }

.wordmark {
  margin: 1.6rem 0 1.2rem;
  line-height: 0;
}

.wordmark img {
  width: clamp(238px, 68vw, 320px);
  height: auto;
  display: block;
  margin: 0 auto;
  filter: drop-shadow(0 2px 3px rgba(140,124,96,.18));
}

.wordmark-text {
  display: none;
  font-family: var(--font-voice);
  font-size: clamp(4rem, 19vw, 5.75rem);
  font-weight: 500;
  line-height: 1.15;
  letter-spacing: .04em;
  color: #EFE8DA;
  text-shadow:
     0 -1px 1px rgba(138,118,87,.55),
     0 -3px 4px rgba(138,118,87,.22),
     0  1px 0  #FFFDF7,
     0  2px 2px rgba(255,253,247,.85),
     0  7px 16px rgba(138,118,87,.20);
}

.wordmark.fallback img { display: none; }
.wordmark.fallback .wordmark-text { display: block; }

.cover-sub {
  font-family: var(--font-voice);
  font-size: 1.05rem;
  font-weight: 500;
  letter-spacing: -.005em;
  color: var(--ink);
  margin: 0 0 .45rem;
}

.cover-meta {
  font-size: .82rem;
  font-weight: 400;
  color: var(--ink-soft);
  margin: 0;
  line-height: 1.9;
}

.cover-lede {
  font-family: var(--font-voice);
  font-size: .9rem;
  font-weight: 400;
  line-height: 1.95;
  letter-spacing: -.005em;
  color: var(--ink-soft);
  margin: 2.5rem auto 0;
  max-width: 20rem;
  text-wrap: balance;
}

/* ---------- 버튼 ---------- */

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
  border-radius: var(--r-field);
}

.begin {
  margin-top: 2.25rem;
  padding: 1rem 3rem;
  background: transparent;
  border: 1px solid var(--ink);
  border-radius: var(--r-pill);
  color: var(--ink);
  font-size: .95rem;
  font-weight: 600;
  letter-spacing: 0;
  transition: background .25s, color .25s;
}
.begin:hover { background: var(--ink); color: var(--card); }

.choice {
  display: block;
  width: 100%;
  text-align: left;
  padding: 1rem 1.25rem;
  margin-bottom: .6rem;
  background: rgba(251,248,242,.62);
  border: 1px solid var(--paper-edge);
  border-radius: var(--r-field);
  font-size: .94rem;
  font-weight: 400;
  line-height: 1.55;
  transition: background .2s, border-color .2s, transform .2s;
}
.choice:hover { background: var(--card); border-color: var(--ink-soft); }
.choice:active { transform: scale(.985); }
.choice[aria-pressed='true'] { background: var(--ink); border-color: var(--ink); color: var(--card); }

.plain {
  background: none;
  border: 0;
  padding: .5rem .25rem;
  color: var(--ink-soft);
  font-size: .85rem;
  text-decoration: underline;
  text-underline-offset: 4px;
}
.plain:hover { color: var(--ink); }

/* ---------- 질문 ---------- */

.progress {
  display: flex;
  justify-content: center;
  gap: .45rem;
  margin-bottom: 2.5rem;
}
.pip {
  width: 24px;
  height: 3px;
  border-radius: var(--r-pill);
  background: var(--paper-edge);
  transition: background .3s;
}
.pip.done { background: var(--ink); }
.pip.now  { background: var(--ink-soft); }

.q-count {
  font-size: .74rem;
  font-weight: 500;
  letter-spacing: .14em;
  color: var(--ink-soft);
  text-align: center;
  margin: 0 0 .6rem;
}

.q-text:focus { outline: none; }

.q-text {
  font-family: var(--font-voice);
  font-size: clamp(1.18rem, 4.7vw, 1.4rem);
  font-weight: 500;
  letter-spacing: -.005em;
  line-height: 1.75;
  text-align: center;
  margin: 0 0 2rem;
  word-break: keep-all;
}

.back { display: block; margin: 1.25rem auto 0; }

/* ---------- 이름 ---------- */

#nameStep { text-align: center; }
#nameStep .begin { margin-left: auto; margin-right: auto; }

.name-field { margin: 0 auto 1.75rem; max-width: 20rem; }

#nameInput {
  width: 100%;
  font-family: var(--font-voice);
  font-size: 1.15rem;
  text-align: center;
  color: var(--ink);
  background: rgba(251,248,242,.62);
  border: 1px solid var(--paper-edge);
  border-radius: var(--r-field);
  padding: .95rem 1rem;
  outline: none;
}
#nameInput::placeholder { color: var(--ink-soft); opacity: .75; font-size: 1rem; }
#nameInput:focus { border-color: var(--ink-soft); background: var(--card); }

.name-note {
  font-size: .8rem;
  line-height: 1.7;
  color: var(--ink-soft);
  margin: .85rem 0 0;
  word-break: keep-all;
}

.salutation {
  font-family: var(--font-voice);
  font-size: .95rem;
  font-weight: 500;
  margin: 0 0 1rem;
  color: var(--ink);
}

/* ---------- 결과 ---------- */

.sending {
  text-align: center;
  color: var(--ink-soft);
  font-size: .95rem;
  padding: 4rem 0;
}

.postcard {
  background: var(--card);
  border: 1px solid var(--paper-edge);
  border-radius: var(--r-card);
  padding: clamp(1.9rem, 6vw, 2.9rem) clamp(1.5rem, 5vw, 2.35rem);
  box-shadow: 0 14px 34px rgba(120,105,80,.12);
  position: relative;
}

.postcard-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  font-size: .7rem;
  font-weight: 500;
  letter-spacing: .06em;
  color: var(--ink-soft);
  margin-bottom: 1.5rem;
}

.stamp {
  flex: none;
  width: 44px;
  height: 52px;
  border: 1px dashed var(--paper-edge);
  border-radius: 10px;
  display: grid;
  place-items: center;
  color: var(--seal);
  font-size: .58rem;
  font-weight: 600;
  letter-spacing: .02em;
  line-height: 1.3;
  text-align: center;
}

.letter-body {
  font-family: var(--font-voice);
  font-size: .94rem;
  font-weight: 400;
  line-height: 1.95;
  letter-spacing: -.005em;
  white-space: normal;
  word-break: keep-all;
  margin: 0;
}

.closing {
  margin: 1.75rem 0 0;
  padding-top: 1.5rem;
  border-top: 1px solid var(--paper-edge);
  font-family: var(--font-voice);
  font-size: .85rem;
  font-weight: 400;
  line-height: 1.9;
  letter-spacing: -.005em;
  white-space: normal;
  color: var(--ink-soft);
  word-break: keep-all;
}

.postcard-foot {
  margin-top: 1.75rem;
  font-size: .7rem;
  font-weight: 500;
  letter-spacing: .06em;
  color: var(--ink-soft);
  text-align: center;
  line-height: 1.85;
}

.actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: .5rem;
  margin-top: 1.5rem;
}
.actions button {
  min-width: 0;
  white-space: nowrap;
  padding: .85rem .4rem;
  background: transparent;
  border: 1px solid var(--paper-edge);
  border-radius: var(--r-pill);
  font-size: .84rem;
  font-weight: 500;
  transition: border-color .2s, background .2s;
}
.actions button:hover { border-color: var(--ink-soft); background: rgba(251,248,242,.7); }

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  background: rgba(58, 50, 38, .55);
  backdrop-filter: blur(3px);
  z-index: 50;
}
.modal[hidden] { display: none; }

.modal-sheet {
  background: var(--card);
  border-radius: var(--r-card);
  padding: 1.1rem 1.1rem 1.4rem;
  width: min(23rem, 100%);
  max-height: 92dvh;
  overflow-y: auto;
  box-shadow: 0 24px 60px rgba(58,50,38,.35);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: .9rem;
}
.modal-head h2 {
  font-family: var(--font-voice);
  font-size: 1rem;
  font-weight: 500;
  margin: 0;
}
.modal-close {
  background: none;
  border: 0;
  font-size: 1rem;
  line-height: 1;
  padding: .45rem .55rem;
  border-radius: var(--r-pill);
  color: var(--ink-soft);
}
.modal-close:hover { background: var(--paper-deep); color: var(--ink); }

.modal img {
  width: 100%;
  display: block;
  border: 1px solid var(--paper-edge);
  border-radius: 14px;
}

.save-hint {
  font-size: .84rem;
  color: var(--ink-soft);
  text-align: center;
  margin: .9rem 0 0;
  line-height: 1.75;
}

.restart { display: block; margin: 2rem auto 0; }

/* ---------- 등장 ---------- */

@keyframes arrive {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: none; }
}
.arrive { animation: arrive .8s cubic-bezier(.2,.7,.3,1) both; }

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

/* ---------- 고대비 대응 ---------- */

@media (prefers-contrast: more) {
  :root { --ink-soft: #3C4358; --paper-edge: #9A8F7A; }
  .wordmark { color: var(--ink); text-shadow: none; }
}

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


/* ---------- 태블릿 이상 ---------- */

@media (min-width: 600px) {
  .letter-body {
    font-size: 1rem;
    line-height: 2.1;
    white-space: pre-line;      /* 폭이 충분할 때만 원래 줄바꿈 사용 */
  }
  .closing {
    font-size: .9rem;
    line-height: 2;
    white-space: pre-line;
  }
  .choice     { font-size: .98rem; }
  .cover-lede { font-size: .95rem; max-width: 22rem; }
  .salutation { font-size: 1rem; }
}

/* ---------- 넓은 화면 ---------- */

@media (min-width: 900px) {
  :root { --shell: 44rem; }

  .wordmark img { width: 380px; }
  .cover-sub    { font-size: 1.25rem; }
  .cover-meta   { font-size: .9rem; }
  .cover-lede   { font-size: 1.08rem; max-width: 27rem; }
  .begin        { font-size: 1rem; padding: 1.05rem 3.4rem; }

  .q-text { font-size: 1.55rem; }
  #options { max-width: 30rem; margin: 0 auto; }

  .postcard     { padding: 3.2rem 3rem; }
  .letter-body  { font-size: 1.06rem; }
  .actions button { font-size: .92rem; }
  .modal-sheet  { width: min(27rem, 100%); }
}
