/* ===== 테마: 동화책 느낌 (갈색 손그림 테두리 + 파스텔) ===== */
:root, [data-theme="day"] {
  --sky: linear-gradient(180deg, #c9eef3 0%, #e6f6e4 38%, #fff4cf 70%, #fff8e2 100%);
  --ray: rgba(255, 255, 255, .38);
  --cloud-fill: #fffdf7;
  --outline-soft: #a48466;
  --hill-back: #b5dc84;
  --hill-front: #93c95e;
  --star: #ffe27a;

  --ink: #4a2c17;          /* 글자 */
  --line: #6b4a2f;         /* 테두리 */
  --muted: #8f7258;
  --paper: #fffaf0;        /* 시트·카드 */
  --title-ink: #4a2c17;
  --title-outline: #ffffff;
  --bear: #fff0bf;         /* 곰 말풍선 */
  --rabbit: #ffe1e8;       /* 토끼 말풍선 */
  --accent: #ff9fb2;
  --accent-ink: #4a2c17;
  --pop: 0 3px 0 rgba(107, 74, 47, .22);
  color-scheme: light;
}
[data-theme="night"] {
  --sky: linear-gradient(180deg, #232a5a 0%, #3b3f7a 45%, #6a5c9c 85%, #8a74ad 100%);
  --ray: transparent;
  --cloud-fill: #c9c3e6;
  --outline-soft: #5a4f86;
  --hill-back: #3f5b78;
  --hill-front: #2f4a63;
  --star: #fff1a6;
  --title-ink: #fff6e0;
  --title-outline: #2b2a55;
  --muted: #8f7258;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body { font-family: "Gaegu", "Jua", -apple-system, sans-serif; color: var(--ink); -webkit-text-size-adjust: 100%; }
/* 한글은 기본값이면 글자 단위로 줄이 바뀜 → 단어(띄어쓰기) 단위로 바꾸기.
   띄어쓰기 없이 아주 긴 글자(링크 등)만 어쩔 수 없이 중간에서 끊음 */
body, textarea, input, button { word-break: keep-all; overflow-wrap: anywhere; }
.bubble, .result, .memory, .empty, .date, .composer { text-wrap: pretty; }
.hint { text-wrap: balance; }
button { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.ic { width: 28px; height: 28px; flex-shrink: 0; }
.ic.sm { width: 20px; height: 20px; vertical-align: -4px; }
.jua { font-family: "Jua", sans-serif; }

/* ===== 배경 장면 ===== */
.scene { position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; }
.sky { position: absolute; inset: 0; background: var(--sky); transition: background 1s; }
.rays {
  position: absolute; inset: -20% -20% 30% -40%;
  background: repeating-conic-gradient(from 100deg at 8% 0%, var(--ray) 0deg 5deg, transparent 5deg 14deg);
  -webkit-mask-image: radial-gradient(circle at 8% 0%, #000 0%, transparent 70%);
          mask-image: radial-gradient(circle at 8% 0%, #000 0%, transparent 70%);
  animation: rays 12s ease-in-out infinite alternate;
}
@keyframes rays { from { opacity: .7; } to { opacity: 1; } }
.moon { position: absolute; width: 64px; height: 64px; top: 41%; right: 18px; display: none; animation: bob 6s ease-in-out infinite; }
[data-theme="night"] .moon { display: block; }
.cloud { position: absolute; }
.c1 { width: 150px; height: 70px; top: 12%; left: -10px; animation: drift 38s ease-in-out infinite alternate; }
.c2 { width: 190px; height: 88px; top: 4%; right: -40px; animation: drift 52s ease-in-out infinite alternate-reverse; }
.c3 { width: 120px; height: 56px; top: 40%; right: -20px; opacity: .9; animation: drift 44s ease-in-out infinite alternate; }
[data-theme="night"] .cloud { opacity: .45; }
@keyframes drift { from { transform: translateX(-18px); } to { transform: translateX(26px); } }
@keyframes bob { 50% { transform: translateY(-6px) rotate(-4deg); } }
.hills { position: absolute; left: 0; right: 0; bottom: 0; width: 100%; height: 15vh; }

#particles > * { position: absolute; }
.petal {
  top: -20px; width: 13px; height: 9px; border-radius: 80% 0 80% 0;
  background: #ffc8d3; border: 1.5px solid #e795a6;
  animation: fall linear infinite;
}
@keyframes fall {
  0% { transform: translate(0, 0) rotate(0); opacity: 0; }
  8% { opacity: 1; }
  100% { transform: translate(-30vw, 105vh) rotate(600deg); opacity: .9; }
}
.twinkle { width: 18px; height: 18px; animation: twinkle 2.8s ease-in-out infinite; }
@keyframes twinkle { 0%, 100% { transform: scale(.6) rotate(0); opacity: .5; } 50% { transform: scale(1) rotate(20deg); opacity: 1; } }
.firefly { width: 6px; height: 6px; border-radius: 50%; background: #fff6b0; box-shadow: 0 0 8px 3px rgba(255, 238, 140, .7); animation: firefly 7s ease-in-out infinite; }
@keyframes firefly { 0%, 100% { transform: translate(0, 0); opacity: .2; } 30% { opacity: 1; } 50% { transform: translate(18px, -26px); opacity: .6; } 75% { transform: translate(-12px, -10px); opacity: 1; } }
[data-theme="day"] .night-only, [data-theme="night"] .day-only { display: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .petal { display: none; }
}

/* ===== 상단 바 ===== */
.topbar {
  position: fixed; inset: 0 0 auto 0; z-index: 5;
  height: calc(56px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 10px 0;
  display: flex; align-items: center; justify-content: space-between;
}
.brand { font-family: "Jua", sans-serif; font-size: 1.05rem; color: var(--title-ink); text-shadow: 0 0 3px var(--title-outline), 0 0 3px var(--title-outline), 0 0 3px var(--title-outline); }
.icon {
  border: 2px solid var(--line); background: var(--paper); width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center; box-shadow: var(--pop); transition: transform .1s;
}
.icon:active { transform: translateY(2px); box-shadow: none; }
.icon.small { width: 36px; height: 36px; font-family: "Jua", sans-serif; font-size: 1.2rem; line-height: 1; color: var(--ink); }

/* ===== 피드: 하루 = 한 화면 ===== */
.feed { height: 100dvh; overflow-y: auto; scroll-snap-type: y mandatory; overscroll-behavior: contain; }
.page {
  height: 100dvh; scroll-snap-align: start; scroll-snap-stop: always;
  max-width: 560px; margin: 0 auto;
  padding: calc(60px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 12px; overflow-y: auto;
}
.date { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.date .rel {
  font-family: "Jua", sans-serif; font-size: .85rem; color: var(--accent-ink); background: var(--accent);
  border: 2px solid var(--line); border-radius: 999px; padding: 1px 12px; box-shadow: var(--pop);
}
.date h2 {
  margin: 4px 0 0; font-family: "Jua", sans-serif; font-weight: 400; font-size: 1.75rem; color: var(--title-ink);
  display: flex; align-items: center; gap: 6px;
  text-shadow: 2px 0 var(--title-outline), -2px 0 var(--title-outline), 0 2px var(--title-outline), 0 -2px var(--title-outline),
    1.5px 1.5px var(--title-outline), -1.5px -1.5px var(--title-outline), 1.5px -1.5px var(--title-outline), -1.5px 1.5px var(--title-outline);
}
.date h2 .ic { width: 34px; height: 34px; }
.date .sub, .count {
  font-size: 1.15rem; color: var(--title-ink); font-weight: 700;
  text-shadow: 0 0 3px var(--title-outline), 0 0 3px var(--title-outline), 0 0 4px var(--title-outline);
}
.count { display: inline-flex; align-items: center; gap: 4px; font-size: 1rem; }
.count .ic { width: 20px; height: 20px; }

.memory {
  border: 2px solid var(--line); text-align: left; width: 100%; color: var(--ink);
  background: #fff7d6; border-radius: 18px; padding: 9px 14px; box-shadow: var(--pop);
  font-size: 1.1rem; line-height: 1.4; display: flex; gap: 8px; align-items: center;
}
.memory .ic { width: 30px; height: 30px; }
.memory b { display: block; font-family: "Jua", sans-serif; font-weight: 400; font-size: .85rem; color: var(--muted); }

.bubbles { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 16px; }
.empty {
  text-align: center; white-space: pre-line; line-height: 1.5; font-size: 1.25rem; font-weight: 700; color: var(--title-ink);
  text-shadow: 0 0 3px var(--title-outline), 0 0 3px var(--title-outline), 0 0 4px var(--title-outline);
  display: flex; flex-direction: column; align-items: center; gap: 6px; margin: 0;
}
.duo { display: flex; gap: 4px; }
.duo svg { width: 76px; height: 76px; animation: bob 3s ease-in-out infinite; }
.duo svg:last-child { animation-delay: -1.5s; }

.row { display: flex; gap: 6px; align-items: flex-start; }
.row.me { flex-direction: row-reverse; }
.avatar { width: 58px; height: 58px; flex-shrink: 0; }
.avatar svg { width: 100%; height: 100%; overflow: visible; }
.avatar.lock { display: grid; place-items: center; }
.avatar.lock svg { width: 46px; height: 46px; animation: bob 2.4s ease-in-out infinite; }
.col { display: flex; flex-direction: column; gap: 2px; max-width: 78%; min-width: 0; }
.row.me .col { align-items: flex-end; }
.name {
  font-family: "Jua", sans-serif; font-size: .85rem; color: var(--title-ink); padding: 0 8px;
  text-shadow: 0 0 3px var(--title-outline), 0 0 3px var(--title-outline);
}
.bubble {
  background: var(--paper); color: var(--ink); border: 2px solid var(--line); box-shadow: var(--pop);
  border-radius: 8px 22px 22px 22px; padding: 9px 15px;
  white-space: pre-wrap; line-height: 1.45; font-size: 1.25rem;
}
.row.bear .bubble { background: var(--bear); }
.row.rabbit .bubble { background: var(--rabbit); }
.row.me .bubble { border-radius: 22px 8px 22px 22px; cursor: pointer; }
.bubble img { display: block; width: 100%; max-height: 46vh; object-fit: cover; border-radius: 14px; border: 2px solid var(--line); margin-top: 8px; }
.bubble.locked { background: rgba(255, 250, 240, .85); color: var(--muted); border-style: dashed; font-size: 1.1rem; }
.time { font-size: .95rem; color: var(--title-ink); padding: 0 8px; text-shadow: 0 0 3px var(--title-outline), 0 0 3px var(--title-outline); }

.row.reveal .bubble { animation: pop .6s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes pop { from { transform: scale(.4); opacity: 0; } to { transform: none; opacity: 1; } }
.burst { position: fixed; z-index: 30; width: 24px; height: 24px; pointer-events: none; animation: burst 1.1s ease-out forwards; }
@keyframes burst { from { transform: translate(-50%, -50%) scale(.4); opacity: 1; } to { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(1.1) rotate(var(--rot)); opacity: 0; } }

.composer {
  border: 2px solid var(--line); background: var(--paper); border-radius: 999px; box-shadow: var(--pop);
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 6px 6px 6px 18px; color: var(--muted); text-align: left; width: 100%; min-height: 56px; font-size: 1.2rem;
}
.composer .send { background: var(--accent); border: 2px solid var(--line); border-radius: 50%; width: 42px; height: 42px; display: grid; place-items: center; flex-shrink: 0; }
.composer .send .ic { width: 26px; height: 26px; }
.composer:active { transform: translateY(2px); box-shadow: none; }
.hint { text-align: center; font-size: 1rem; color: var(--title-ink); margin: -4px 0 0; text-shadow: 0 0 3px var(--title-outline), 0 0 3px var(--title-outline); }

.to-today {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 5;
  bottom: calc(18px + env(safe-area-inset-bottom));
  border: 2px solid var(--line); border-radius: 999px; padding: 6px 16px; background: var(--paper); color: var(--ink);
  font-family: "Jua", sans-serif; font-size: .95rem; box-shadow: var(--pop); display: flex; align-items: center; gap: 2px;
}
.toast {
  position: fixed; left: 0; right: 0; margin: 0 auto; width: max-content; z-index: 20;
  bottom: calc(92px + env(safe-area-inset-bottom));
  background: var(--paper); color: var(--ink); border: 2px solid var(--line); box-shadow: var(--pop);
  padding: 6px 16px; border-radius: 999px; font-family: "Jua", sans-serif; font-size: .95rem; max-width: 90vw;
  display: flex; align-items: center; gap: 6px; white-space: nowrap; animation: pop .4s cubic-bezier(.3, 1.6, .5, 1);
}
.toast .ic { width: 22px; height: 22px; }

/* ===== 아래에서 올라오는 시트 ===== */
dialog.sheet {
  margin: auto auto 0; width: 100%; max-width: 560px; max-height: 92dvh;
  border: 2.5px solid var(--line); border-bottom: 0; border-radius: 28px 28px 0 0; padding: 0; background: var(--paper); color: var(--ink);
}
dialog.sheet[open] { animation: up .3s cubic-bezier(.3, 1.3, .5, 1); }
@keyframes up { from { transform: translateY(40px); } to { transform: none; } }
dialog.sheet::backdrop { background: rgba(60, 40, 20, .3); }
dialog.sheet { overflow-x: hidden; }
.sheet form, .sheet-body { padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 12px; }
.sheet-head { display: flex; align-items: center; gap: 10px; justify-content: space-between; }
.sheet-title { font-family: "Jua", sans-serif; font-weight: 400; font-size: 1.3rem; }
.field-label { margin: 0 0 4px; font-family: "Jua", sans-serif; font-size: .9rem; color: var(--muted); }
.text-btn { border: 0; background: none; color: var(--muted); padding: 6px; white-space: nowrap; flex-shrink: 0; font-family: "Jua", sans-serif; }
.text-btn.small { font-size: .8rem; text-decoration: underline; }

.moods { display: flex; justify-content: space-between; }
.mood { border: 0; background: none; display: flex; flex-direction: column; align-items: center; gap: 6px; font-family: "Jua", sans-serif; font-size: .85rem; color: var(--muted); padding: 0; }
.mood .w { width: 60px; height: 60px; border-radius: 50%; display: grid; place-items: center; transition: transform .15s; opacity: .55; filter: saturate(.5); }
.mood .w svg { width: 54px; height: 54px; overflow: visible; }
.mood[aria-checked="true"] { color: var(--ink); }
.mood[aria-checked="true"] .w { opacity: 1; filter: none; transform: scale(1.06); background: #fff3c4; box-shadow: 0 0 0 2px var(--line); }

textarea {
  width: 100%; border: 2px solid var(--line); border-radius: 18px; padding: 12px 14px;
  font-family: "Gaegu", sans-serif; font-size: 1.3rem; line-height: 1.5; resize: none;
  background: #fff repeating-linear-gradient(transparent 0 calc(1.95rem - 1px), #f3e2c9 calc(1.95rem - 1px) 1.95rem);
  background-attachment: local; background-position: 0 12px; color: inherit; min-height: 32dvh;
}
textarea:focus, input[type="search"]:focus { outline: none; box-shadow: 0 0 0 3px #ffd1db; }
textarea::placeholder, input::placeholder { color: #b49a80; }
.preview { width: 100%; max-height: 180px; object-fit: cover; border-radius: 16px; border: 2px solid var(--line); }
.editor-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.spacer { flex: 1; }
.btn {
  border: 2px solid var(--line); border-radius: 999px; padding: 6px 14px; background: var(--paper); box-shadow: var(--pop);
  font-family: "Jua", sans-serif; font-size: .95rem; display: inline-flex; align-items: center; gap: 4px;
}
.btn:active { transform: translateY(2px); box-shadow: none; }
.btn.primary { background: var(--accent); color: var(--accent-ink); padding: 8px 20px; font-size: 1.05rem; }
.btn.danger { color: #c4485a; box-shadow: none; border-color: transparent; background: none; }
.btn:disabled { opacity: .5; }
.error { color: #c4485a; margin: 0; font-size: 1.1rem; font-weight: 700; }

/* ===== 달력 + 검색 ===== */
input[type="search"] { flex: 1; min-width: 0; border: 2px solid var(--line); border-radius: 999px; padding: 8px 16px; font-family: "Gaegu", sans-serif; font-size: 1.2rem; background: #fff; color: inherit; }
.cal-nav { display: flex; align-items: center; justify-content: space-between; }
.weekdays, .cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.weekdays span { text-align: center; font-family: "Jua", sans-serif; font-size: .8rem; color: var(--muted); }
.weekdays span:first-child { color: #d9647a; }
.cal-day { border: 0; background: none; aspect-ratio: 1; border-radius: 14px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0; font-family: "Jua", sans-serif; font-size: .9rem; padding: 0; }
.cal-day.has { background: #fff; border: 2px solid var(--line); box-shadow: var(--pop); }
.cal-day.today { background: #fff3c4; border: 2px solid var(--line); }
.cal-day:disabled { color: #c9b6a0; cursor: default; }
.faces { display: flex; height: 18px; margin-top: -1px; }
.faces svg { width: 18px; height: 18px; overflow: visible; }
.faces svg + svg { margin-left: -4px; }
.legend { display: flex; align-items: center; gap: 4px; justify-content: center; margin: 0; font-family: "Jua", sans-serif; font-size: .85rem; color: var(--muted); }
.legend svg { width: 22px; height: 22px; overflow: visible; }
.legend span + svg { margin-left: 10px; }
.results { display: flex; flex-direction: column; gap: 8px; max-height: 60dvh; overflow-y: auto; padding: 2px 2px 6px; }
.result { border: 2px solid var(--line); text-align: left; background: #fff; border-radius: 16px; padding: 8px 12px; font-size: 1.15rem; line-height: 1.4; box-shadow: var(--pop); }
.result b { display: flex; align-items: center; gap: 4px; font-family: "Jua", sans-serif; font-weight: 400; font-size: .8rem; color: var(--muted); }
.result b svg { width: 24px; height: 24px; overflow: visible; }
.result mark { background: #ffd1db; color: inherit; border-radius: 4px; padding: 0 2px; }
.sheet-foot { display: flex; justify-content: space-between; align-items: center; font-family: "Jua", sans-serif; font-size: .8rem; color: var(--muted); border-top: 2px dashed #e8d6bd; padding-top: 10px; }
