/* 생각동산 — EP01과 같은 무대: 빈 하늘, 손으로 그은 땅, 하나의 빛. 그 위에 글자만 얹는다 */

:root {
  /* 화면(글자·패널). 웹폰트를 받지 않고 기기 기본 글씨를 쓴다 */
  --sans: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", system-ui, sans-serif;
  --paper: rgba(248, 244, 234, 0.92);
  --paper-solid: #f8f4ea;
  --rule: rgba(38, 42, 52, 0.16);
  --text: #26283a;
  --text-soft: #6a6c7a;
  --accent: #2c3560;
  --accent-soft: rgba(44, 53, 96, 0.08);
  --warm-soft: #f3e2d6;
  --rust: #c4573a; /* 붓 버튼 한 가지에만 쓰는 강조색 (우체통과 같은 빨강 계열) */

  /* 그림: 채널 stage.css 색 그대로 */
  --night: #1c2140;
  --ink: #0e1124;
  --warm: #ffd98a;
  --cream: #efe4cb;
  --mascot: #7389c6;
  --skin: #f3e8d2;
  --red: #d2513f;
  --green: #79a95a;
  --gold: #e4b24c;

  /* 시간대별: EP01 board/scenes.js의 팔레트 (기본은 밤) */
  --sky: linear-gradient(#171c38, #222846 70%, #1c2140);
  --on-scene: #f4ecd9;
  --on-scene-shadow: rgba(0, 0, 0, 0.45);
  --scrim: rgba(10, 12, 26, 0.35);
}
html[data-time="dusk"] {
  --sky: linear-gradient(#56649e, #b58fb0 55%, #f1bf9b);
  --scrim: rgba(30, 24, 50, 0.3);
}
/* 낮은 크림 종이 (EP01 #09·#17). 잉크와 글자가 어두워진다 */
html[data-time="day"] {
  --sky: linear-gradient(#f3e9d4, #ecdfc4);
  --ink: #3a2f26;
  --on-scene: #3a2f26;
  --on-scene-shadow: transparent;
  --scrim: transparent;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }

body {
  font-family: var(--sans);
  color: var(--text);
  background: var(--sky);
  background-attachment: fixed;
  overflow-x: hidden;
  word-break: keep-all;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, .btn, .back, .time-toggle {
  font-family: var(--sans);
  font-weight: 400;
}

/* ── 그림 + 필름 느낌(채널과 같은 그레인·비네트, 천천히 다가가는 카메라) ── */

#garden {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: block;
  z-index: 0;
  transform-origin: 70% 75%;
  animation: reveal 1.8s ease-out both, push 60s ease-in-out 1.8s infinite alternate;
}
body::before, body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}
body::before {
  background: radial-gradient(ellipse at 50% 45%, transparent 55%, rgba(0, 0, 0, 0.35) 100%);
}
body::after {
  opacity: 0.35;
  mix-blend-mode: soft-light;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='240' height='240'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='1.1' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='1 0 0 0 0  1 0 0 0 0  1 0 0 0 0  0 0 0 0 1'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

.star { animation: twinkle 3.6s ease-in-out infinite alternate; }
.drift { animation: drift 90s ease-in-out infinite alternate; }
.drift.slow { animation-duration: 120s; animation-direction: alternate-reverse; }
/* 마스코트: 숨쉬기, 4초마다 눈 깜빡임 (눈 뜬 그림과 감은 그림을 번갈아) */
.mascot { transform-box: fill-box; transform-origin: 50% 100%; animation: breathe 3.3s ease-in-out infinite; }
.eyes-shut { opacity: 0; animation: blink 4.1s steps(1) infinite; }
.eyes-open { animation: blink-open 4.1s steps(1) infinite; }

@keyframes reveal { from { opacity: 0; } to { opacity: 1; } }
@keyframes push { from { transform: scale(1); } to { transform: scale(1.04); } }
@keyframes twinkle { from { opacity: 0.35; } to { opacity: 1; } }
@keyframes drift { from { transform: translateX(-40px); } to { transform: translateX(60px); } }
@keyframes breathe { 0%, 100% { transform: scaleY(1); } 50% { transform: scaleY(1.008); } }
@keyframes blink { 0%, 96.5% { opacity: 0; } 97%, 100% { opacity: 1; } }
@keyframes blink-open { 0%, 96.5% { opacity: 1; } 97%, 100% { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  #garden, #garden *, .home * { animation: none !important; }
  .eyes-shut { opacity: 0; }
  .brand .brush-draw { stroke-dashoffset: 0 !important; }
}

/* ── 겉 틀 ────────────────────────────────────────── */

.stage {
  position: relative;
  z-index: 2;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 32px 20px 56px;
}

.time-toggle {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 3;
  font-size: 13px;
  letter-spacing: 0.1em;
  color: var(--on-scene);
  background: rgba(18, 26, 22, 0.35);
  border: 1px solid rgba(251, 248, 241, 0.4);
  border-radius: 2px;
  padding: 5px 12px;
  cursor: pointer;
}

/* ── 첫 화면: 그림 위에 글자만 ─────────────────────── */

.home {
  position: relative;
  max-width: 1200px;
  margin: 0 auto;
  padding: 15vh 4vw 4vh;
}
/* 제목은 글꼴이 아니라 붓으로 그린 SVG (js/brand.js). 획이 한 번에 하나씩 그어진다 */
.title { margin: 0; line-height: 0; }
.brand {
  width: clamp(280px, 40vw, 560px);
  height: auto;
  overflow: visible;
  filter: drop-shadow(0 3px 18px var(--on-scene-shadow));
}
.brush-draw { stroke-dasharray: 1 1; stroke-dashoffset: 1; animation: brush 0.5s cubic-bezier(.45, .05, .3, 1) both; }
@keyframes brush { to { stroke-dashoffset: 0; } }

.about-link {
  position: absolute;
  top: 2px;
  left: 4px;
  font-size: 12.5px;
  letter-spacing: 0.24em;
  color: var(--on-scene);
  text-decoration: none;
  opacity: 0.85;
  text-shadow: 0 1px 8px var(--on-scene-shadow);
}
.about-link:hover { opacity: 1; }
.tagline {
  margin: 22px 0 0 6px;
  font-size: 15px;
  letter-spacing: 0.05em;
  line-height: 1.7;
  color: var(--on-scene);
  text-shadow: 0 1px 12px var(--on-scene-shadow);
  animation: fade 1.6s ease 1.8s both;
}

/* 편지 쓰기: 붓 한 획 위에 글자. 제목이 다 그어진 뒤 붓이 왼쪽에서 오른쪽으로 지나간다 */
.actions { display: flex; align-items: center; gap: 30px; margin: 40px 0 0 2px; }
.cta {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 196px;
  height: 58px;
  text-decoration: none;
}
.cta .swatch {
  position: absolute;
  inset: -4px -8px;
  width: calc(100% + 16px);
  height: calc(100% + 8px);
  fill: var(--rust);
  transform-origin: 0 50%;
  transition: transform 0.5s cubic-bezier(.2, .7, .2, 1);
  animation: swipe 0.9s cubic-bezier(.5, 0, .2, 1) 2.4s both;
}
.cta-text {
  position: relative;
  color: #fff8ef;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.14em;
  animation: fade 0.8s ease 3s both;
}
.cta:hover .swatch, .cta:focus-visible .swatch { transform: scaleX(1.07) rotate(-1deg); }
.cta:focus-visible { outline: none; }
.cta:focus-visible .cta-text { text-decoration: underline; text-underline-offset: 6px; }
.link {
  color: var(--on-scene);
  font-size: 16px;
  letter-spacing: 0.08em;
  text-decoration: none;
  padding-bottom: 4px;
  border-bottom: 1px solid currentColor;
  text-shadow: 0 1px 10px var(--on-scene-shadow);
  animation: fade 1s ease 3s both;
}
.link .arrow { display: inline-block; transition: transform 0.35s ease; }
.link:hover .arrow { transform: translateX(5px); }
.chip {
  margin: 18px 0 0 4px;
  font-size: 14px;
  color: var(--on-scene);
  text-shadow: 0 1px 8px var(--on-scene-shadow);
}
@keyframes swipe { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0 0 0 0); } }

/* 글자가 밝은 하늘 위에서도 읽히도록 첫 화면에만 왼쪽 위를 살짝 어둡게 */
body[data-view="home"] .stage::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: radial-gradient(ellipse 70% 60% at 20% 30%, var(--scrim), transparent 70%);
}

@media (max-width: 640px) {
  /* 휴대폰: 제목과 버튼을 빈 하늘에 모아 두고, 아래 동산은 가리지 않는다 */
  .home { text-align: center; padding: 11vh 0 0; }
  .brand { width: min(300px, 82vw); }
  .tagline { margin: 18px auto 0; font-size: 14.5px; }
  .actions { justify-content: center; gap: 22px; margin: 34px 0 0; }
  .cta { width: 170px; height: 54px; }
  .cta-text { font-size: 17px; }
  .about-link { position: fixed; top: 18px; left: 18px; }
  body[data-view="home"] .stage::before {
    background: radial-gradient(ellipse 120% 50% at 50% 22%, var(--scrim), transparent 75%);
  }
}

/* ── 안쪽 화면: 바랜 종이 한 장 ─────────────────────── */

.paper {
  position: relative;
  background: var(--paper);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-radius: 3px;
  box-shadow: 0 30px 80px rgba(10, 16, 12, 0.35);
  padding: 44px 48px;
  animation: fade 0.8s ease both;
}
.page { max-width: 640px; margin: 6vh auto 0; }
.page h2 { margin: 0 0 10px; font-size: 30px; letter-spacing: 0.06em; color: var(--accent); }
.page .lead { margin: 0 0 30px; color: var(--text-soft); line-height: 1.8; }
.back {
  display: inline-block;
  margin-bottom: 26px;
  font-size: 14px;
  letter-spacing: 0.08em;
  color: var(--text-soft);
  text-decoration: none;
}
.back:hover { color: var(--accent); }

.field { margin: 0 0 28px; }
.field > .label { display: block; margin-bottom: 10px; font: 16px var(--sans); letter-spacing: 0.04em; color: var(--accent); }
.hint { font: 13px var(--sans); color: var(--text-soft); letter-spacing: 0; }

/* 주제 목록: 휴대폰에서는 기기 기본 선택 창이 뜬다 */
.select-wrap { position: relative; }
.select-wrap::after {
  content: "";
  position: absolute;
  right: 6px;
  top: 50%;
  width: 8px;
  height: 8px;
  border-right: 1.5px solid var(--text-soft);
  border-bottom: 1.5px solid var(--text-soft);
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
}
.select {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  font: 16px var(--sans);
  color: var(--text);
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--rule);
  border-radius: 0;
  padding: 9px 28px 9px 2px;
  cursor: pointer;
  text-overflow: ellipsis;
}
.select:focus { outline: none; border-bottom-color: var(--accent); }

input[type="text"], textarea {
  width: 100%;
  font: 16.5px var(--sans);
  color: var(--text);
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--rule);
  border-radius: 0;
  padding: 8px 2px;
}
input[type="text"]:focus, textarea:focus { outline: none; border-bottom-color: var(--accent); }

textarea.letter-pad {
  min-height: 300px;
  line-height: 34px;
  padding: 2px 2px;
  resize: vertical;
  background-image: repeating-linear-gradient(transparent 0 33px, var(--rule) 33px 34px);
  background-attachment: local;
  border-bottom: none;
}
.counter { text-align: right; font-size: 12px; color: var(--text-soft); margin-top: 6px; letter-spacing: 0.05em; }

.checks { display: grid; gap: 12px; }
.check { display: flex; gap: 10px; align-items: flex-start; line-height: 1.6; cursor: pointer; font-size: 15px; }
.check input { margin-top: 4px; width: 16px; height: 16px; accent-color: var(--accent); flex: none; }
.check .opt { display: block; color: var(--text-soft); font-size: 13px; }

.btn {
  display: inline-block;
  font-size: 16px;
  letter-spacing: 0.12em;
  padding: 14px 30px;
  border-radius: 2px;
  border: 1px solid var(--accent);
  cursor: pointer;
  text-decoration: none;
  color: var(--paper-solid);
  background: var(--accent);
  transition: background 0.3s, color 0.3s, letter-spacing 0.3s;
}
.btn:hover { letter-spacing: 0.18em; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.ghost:hover { background: var(--accent-soft); }
.btn.small { font-size: 13.5px; padding: 9px 16px; letter-spacing: 0.08em; }
.btn.danger { background: transparent; color: var(--warm); border-color: rgba(180, 100, 63, 0.4); }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

.error { margin: 0 0 16px; padding: 10px 14px; border-left: 2px solid var(--warm); background: var(--warm-soft); color: #7a3b1f; }
.note { padding: 14px 16px; border-left: 2px solid var(--rule); background: var(--accent-soft); line-height: 1.75; font-size: 14.5px; }
.note.warm { border-left-color: var(--warm); background: var(--warm-soft); }

/* ── 답장 링크 ───────────────────────────────────── */

.key-box {
  margin: 10px 0 16px;
  padding: 14px 16px;
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid var(--rule);
  font: 14px/1.6 ui-monospace, "Consolas", monospace;
  word-break: break-all;
  user-select: all;
}
.key-warn { font: 18px var(--sans); letter-spacing: 0.04em; color: var(--accent); margin: 22px 0 6px; }

/* ── 편지함 ───────────────────────────────────────── */

.thread { display: grid; gap: 22px; margin: 0 0 34px; }
.letter {
  padding: 4px 0 4px 20px;
  border-left: 1px solid var(--rule);
  line-height: 1.95;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.letter .who { display: block; margin-bottom: 8px; font: 13px var(--sans); letter-spacing: 0.08em; color: var(--text-soft); white-space: normal; }
.letter.reply { border-left: 2px solid var(--accent); background: linear-gradient(90deg, var(--accent-soft), transparent 70%); padding: 14px 0 14px 20px; }
.letter.reply .who { color: var(--accent); }
.waiting { color: var(--text-soft); line-height: 1.8; font-size: 14.5px; }
.saved-boxes { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }


/* ── 안내 ─────────────────────────────────────────── */

.about h3 { margin: 32px 0 10px; font-size: 18px; letter-spacing: 0.06em; color: var(--accent); }
.about p, .about li { line-height: 1.9; }
.about ul { padding-left: 18px; margin: 0; }
.about .fine { margin-top: 28px; font-size: 13.5px; color: var(--text-soft); }
.numbers { display: grid; gap: 0; margin: 14px 0; border-top: 1px solid var(--rule); }
.numbers a {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 2px;
  border-bottom: 1px solid var(--rule);
  color: var(--text);
  text-decoration: none;
}
.numbers b { font: 20px var(--sans); color: var(--warm); }

/* ── 위기 안내 창 ─────────────────────────────────── */

.modal-back {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(12, 16, 14, 0.55);
  animation: fade 0.4s ease both;
}
.modal { max-width: 500px; width: 100%; max-height: 90vh; overflow: auto; }
.modal h2 { margin: 0 0 12px; font-size: 24px; color: var(--accent); }
.modal p { line-height: 1.8; }

@media (max-width: 520px) {
  .stage { padding: 0 0 40px; }
  .paper { padding: 34px 22px 30px; box-shadow: none; }
  .page { margin: 0; min-height: 100dvh; }
  .page h2 { font-size: 26px; }
  .modal { padding: 30px 22px; }
  textarea.letter-pad { min-height: 240px; }
  .btn { width: 100%; text-align: center; }
  .btn.small { width: auto; }
}
