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

:root {
  /* 화면(글자·패널). 웹폰트를 받지 않고 기기 기본 글씨를 쓴다 */
  --sans: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", system-ui, sans-serif;
  --pen: "Nanum Pen Script", var(--sans);
  --brush: "East Sea Dokdo", var(--pen);
  --pen-ink: #2b2a33; /* 종이 위 글씨와 선 */
  --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(--pen);
  color: var(--text);
  background: var(--sky);
  background-attachment: fixed;
  overflow-x: hidden;
  word-break: keep-all;
  -webkit-font-smoothing: antialiased;
}

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

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

#world {
  position: fixed;
  inset: 0;
  z-index: 0;
  transform-origin: 70% 75%;
  animation: reveal 1.8s ease-out both, push 60s ease-in-out 1.8s infinite alternate;
}
#garden, #live {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
#live { pointer-events: none; }
.plane-trail { fill: none; stroke: var(--on-scene); stroke-width: 3; stroke-linecap: round; stroke-dasharray: 2 12; }
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) {
  #world, #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;
}

.eye {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 3;
  width: 52px;
  height: 44px;
  padding: 9px 10px;
  color: var(--on-scene);
  background: none;
  border: none;
  cursor: pointer;
  filter: drop-shadow(0 1px 5px var(--on-scene-shadow));
}
.eye svg { display: block; width: 100%; height: 100%; }
.eye:focus-visible { outline: 2px solid var(--on-scene); outline-offset: 2px; }
body:not([data-view="home"]) .eye { display: none; }
body.scene-only .home { visibility: hidden; }
body.scene-only .stage::before { display: none; }
.time-toggle {
  position: fixed;
  top: 14px;
  right: 70px;
  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: 20px;
  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: 24px;
  line-height: 1.35;
  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: 28px/1 var(--brush);
  letter-spacing: 0.04em;
  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: 24px;
  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); }
/* 지금 접속자와 최근 편지 소식 */
.live { margin: 24px 0 0 4px; color: var(--on-scene); text-shadow: 0 1px 10px var(--on-scene-shadow); animation: fade 1s ease 3.2s backwards; }
.live p { margin: 0; line-height: 1.3; }
.live-now { font: 30px/1.2 var(--brush); }
.sr-link { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.sr-link:focus-visible { position: static; width: auto; height: auto; clip-path: none; display: inline-block; margin-top: 8px; color: var(--on-scene); font-size: 21px; }
.mailbox-label { font: 50px var(--brush); fill: #fff6e3; }
.me-label { font: 34px var(--pen); fill: var(--on-scene); }
.chip {
  margin: 18px 0 0 4px;
  font-size: 21px;
  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: 7vh 0 0; }
  .brand { width: min(300px, 82vw); }
  .tagline { margin: 18px auto 0; max-width: 300px; font-size: 23px; }
  .actions { justify-content: center; gap: 22px; margin: 34px 0 0; }
  .live { margin: 20px 0 0; }
  .cta { width: 170px; height: 54px; }
  .cta-text { font-size: 27px; }
  .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: #f6edd9;
  border-radius: 4px;
  box-shadow: 0 24px 70px rgba(5, 8, 20, 0.4);
  padding: 46px 50px;
  animation: fade 0.8s ease both;
}
/* 잉크 선 두 번 겹쳐 그은 테두리 (#rough는 js/garden.js에 있다) */
.paper::before, .paper::after {
  content: "";
  position: absolute;
  inset: 12px;
  border: 2.5px solid var(--pen-ink);
  border-radius: 255px 18px 225px 18px / 18px 225px 18px 255px;
  filter: url(#rough);
  pointer-events: none;
}
.paper::after { inset: 15px 11px 11px 15px; border-width: 1.2px; opacity: 0.55; transform: rotate(0.25deg); }
.paper > * { position: relative; z-index: 1; }
.page { max-width: 640px; margin: 6vh auto 0; }
.page h2 { margin: 0 0 8px; font: 46px/1.15 var(--brush); color: var(--pen-ink); }
.page .lead { margin: 0 0 30px; font-size: 21px; color: var(--text-soft); line-height: 1.5; }
.back {
  display: inline-block;
  margin-bottom: 22px;
  font-size: 20px;
  color: var(--text-soft);
  text-decoration: none;
}
.back:hover { color: var(--pen-ink); }

.field { margin: 0 0 28px; }
.field > .label { display: block; margin-bottom: 8px; font: 25px var(--pen); color: var(--pen-ink); }
.hint { font: 18px var(--pen); color: var(--text-soft); }

/* 칸은 모두 삐뚤게 그은 네모 */
.select, input[type="text"], textarea {
  width: 100%;
  font: 23px/1.4 var(--pen);
  color: var(--pen-ink);
  background: #fffaf0;
  border: 2px solid var(--pen-ink);
  border-radius: 255px 14px 225px 14px / 14px 225px 14px 255px;
  padding: 9px 16px;
}
.select:focus, input[type="text"]:focus, textarea:focus { outline: none; border-color: var(--rust); }
input::placeholder, textarea::placeholder { color: #9a917f; }

/* 주제 목록: 휴대폰에서는 기기 기본 선택 창이 뜬다 */
.select-wrap { position: relative; }
.select-wrap::after {
  content: "";
  position: absolute;
  right: 18px;
  top: 50%;
  width: 16px;
  height: 11px;
  transform: translateY(-50%);
  pointer-events: none;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 11'%3E%3Cpath d='M1.5 2 Q5 6 8.2 9.4 Q12 5 14.6 1.2' fill='none' stroke='%232b2a33' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E") center / contain no-repeat;
}
.select { appearance: none; -webkit-appearance: none; padding-right: 44px; cursor: pointer; text-overflow: ellipsis; }

textarea.letter-pad {
  display: block;
  min-height: 330px;
  line-height: 38px;
  padding: 6px 18px;
  resize: vertical;
  background-color: #fffaf0;
  background-image: repeating-linear-gradient(transparent 0 37px, rgba(43, 42, 51, 0.16) 37px 38px);
  background-attachment: local;
  background-position: 0 6px;
  border-radius: 12px 8px 14px 9px / 9px 14px 8px 12px;
}
.counter { text-align: right; font-size: 17px; color: var(--text-soft); margin-top: 4px; }

.checks { display: grid; gap: 14px; }
.check { display: flex; gap: 12px; align-items: flex-start; line-height: 1.3; cursor: pointer; font-size: 21px; color: var(--pen-ink); }
.check input {
  appearance: none;
  -webkit-appearance: none;
  flex: none;
  width: 24px;
  height: 24px;
  margin: 0;
  background: #fffaf0 center / 90% no-repeat;
  border: 2px solid var(--pen-ink);
  border-radius: 40px 6px 30px 6px / 6px 30px 6px 40px;
  cursor: pointer;
}
.check input:checked {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M4 12 Q8 16 10 20 Q14 10 22 3' fill='none' stroke='%23c4573a' stroke-width='3.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
.check input:focus-visible { outline: 2px solid var(--rust); outline-offset: 2px; }
.check .opt { display: block; color: var(--text-soft); font-size: 18px; }

/* 기본 버튼은 붓 한 획, 나머지는 삐뚤게 그은 테두리 */
.btn {
  display: inline-block;
  min-width: 170px;
  font: 27px/1 var(--brush);
  letter-spacing: 0.04em;
  padding: 17px 36px;
  border: none;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  color: #fff8ef;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 240 64' preserveAspectRatio='none'%3E%3Cfilter id='b' x='-5%25' y='-10%25' width='110%25' height='120%25'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.09' numOctaves='2' seed='3'/%3E%3CfeDisplacementMap in='SourceGraphic' scale='5' xChannelSelector='R' yChannelSelector='G'/%3E%3C/filter%3E%3Cpath filter='url(%23b)' fill='%23c4573a' d='M7 17 C44 7 128 9 226 16 C236 24 234 36 229 44 C152 58 66 55 9 49 C3 40 2 26 7 17Z'/%3E%3C/svg%3E") center / 100% 100% no-repeat;
  transition: transform 0.25s ease;
}
.btn:hover { transform: rotate(-0.8deg) scale(1.03); }
.btn:disabled { opacity: 0.5; cursor: default; transform: none; }
.btn.ghost, .btn.danger {
  background: none;
  color: var(--pen-ink);
  border: 2px solid var(--pen-ink);
  border-radius: 255px 14px 225px 14px / 14px 225px 14px 255px;
}
.btn.small { min-width: 0; font: 21px/1 var(--pen); padding: 10px 18px; letter-spacing: 0; }
.btn.small:not(.ghost):not(.danger) { padding: 13px 24px; }
.btn.danger { color: var(--rust); border-color: var(--rust); }
.row { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }

.error { margin: 0 0 16px; padding: 8px 14px; border-left: 3px solid var(--rust); background: var(--warm-soft); color: #7a3b1f; font-size: 20px; }
.note { padding: 12px 16px; background: var(--accent-soft); line-height: 1.45; font-size: 20px; }
.note.warm { background: var(--warm-soft); }

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

.key-box {
  margin: 10px 0 16px;
  padding: 14px 16px;
  background: #fffaf0;
  border: 2px solid var(--pen-ink);
  border-radius: 255px 14px 225px 14px / 14px 225px 14px 255px;
  font: 14px/1.6 ui-monospace, "Consolas", monospace;
  word-break: break-all;
  user-select: all;
}
.key-warn { font: 32px var(--brush); color: var(--rust); margin: 22px 0 4px; }

.push-box { margin: 20px 0 22px; }
.steps { margin: 6px 0 8px; padding-left: 24px; font-size: 21px; line-height: 1.4; color: var(--pen-ink); }
.checks .hint { margin: -6px 0 0 36px; line-height: 1.3; color: var(--rust); }
.push-box:empty { display: none; }
.push-title { margin: 0 0 2px; font: 25px var(--pen); color: var(--pen-ink); }
.push-box .hint { display: block; margin: 0 0 10px; line-height: 1.35; }

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

.thread { display: grid; gap: 18px; margin: 0 0 34px; }
.letter {
  padding: 14px 18px 16px;
  font-size: 22px;
  line-height: 1.5;
  color: var(--pen-ink);
  background: #fffaf0;
  border: 2px solid var(--pen-ink);
  border-radius: 255px 16px 225px 16px / 16px 225px 16px 255px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.letter .who { display: block; margin-bottom: 4px; font: 18px var(--pen); color: var(--text-soft); white-space: normal; }
.letter.reply { background: #f1e6c4; border-color: var(--rust); }
.letter.reply .who { color: var(--rust); }
.waiting { color: var(--text-soft); line-height: 1.4; font-size: 20px; }
.saved-boxes { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

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

.about { font-size: 21px; color: var(--pen-ink); }
.about h3 { margin: 30px 0 6px; font: 32px var(--brush); color: var(--pen-ink); }
.about p, .about li { line-height: 1.5; }
.about ul { padding-left: 20px; margin: 0; }
.about .fine { margin-top: 26px; font-size: 18px; color: var(--text-soft); }
.numbers { display: grid; gap: 0; margin: 14px 0; border-top: 1.5px solid var(--pen-ink); font-size: 21px; }
.numbers a {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 9px 2px;
  border-bottom: 1.5px solid var(--pen-ink);
  color: var(--pen-ink);
  text-decoration: none;
}
.numbers b { font: 28px var(--brush); color: var(--rust); white-space: nowrap; }

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

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

@media (max-width: 520px) {
  .stage { padding: 0 0 40px; }
  .paper { padding: 34px 28px 32px; box-shadow: none; }
  .paper::before { inset: 9px; }
  .paper::after { inset: 11px 8px 8px 11px; }
  .page { margin: 0; min-height: 100dvh; }
  .page h2 { font-size: 42px; }
  .modal { padding: 34px 28px; }
  textarea.letter-pad { min-height: 266px; }
  .btn { width: 100%; }
  .btn.small { width: auto; }
}

/* ── 우편 ─────────────────────────────────────────── */

.mail-card { display: block; text-decoration: none; transition: transform 0.2s ease; }
.mail-card:hover { transform: rotate(-0.3deg) scale(1.01); }
.mail-body { display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden; }
.mail-count { margin: 8px 0 0; color: var(--rust); }
textarea.letter-pad.short { min-height: 152px; }
.reply-tools { justify-content: flex-end; margin-top: 2px; white-space: normal; }
.text-btn { font: 18px var(--pen); color: var(--text-soft); background: none; border: none; padding: 2px 4px; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }

/* 휴대폰은 글자와 하늘이 겹친다. 글자가 보일 때는 비행기를 옅게, 눈 버튼으로 그림만 보면 선명하게 */
@media (max-width: 640px) {
  .planes { opacity: 0.45; transition: opacity 0.3s; }
  body.scene-only .planes { opacity: 1; }
}
