/* 오늘의 꽃말 — 종이 일기장 위의 작은 화단. 봉오리에 물을 주면 꽃이 피고 표본 라벨에 꽃말이 적힙니다. */

:root {
  --paper: #f6f1e6;
  --paper-2: #fbf8f1;
  --line: #e2d9c7;
  --ink: #2d3a2e;
  --ink-2: #6b7566;
  --accent: #c9693f; /* 테라코타 */
  --accent-2: #b65a33;
  --leaf: #4f7f5a;
  --leaf-2: #6fa07a;
  --soil: #8b6a4e;
  --soil-2: #6d5038;
  --water: #7fb6d9;
  --tap-ms: 420ms;
  --move-ms: 700ms;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  font-family: 'Gowun Batang', 'Nanum Myeongjo', 'Apple SD Gothic Neo', 'Malgun Gothic', serif;
  color: var(--ink);
  background-color: var(--paper);
  /* 공책 줄 */
  background-image: repeating-linear-gradient(to bottom, transparent 0 31px, var(--line) 31px 32px);
  background-attachment: fixed;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

/* 배경 그림: img/bg.png 또는 img/bg.jpg 가 있으면 공책 줄 대신 씁니다 */
body.has-bg {
  background-image: linear-gradient(rgba(246, 241, 230, 0.75), rgba(246, 241, 230, 0.75)), var(--bg-image);
  background-size: cover;
  background-position: center;
}

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

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.page {
  position: relative;
  width: min(100%, 1040px);
  margin: 0 auto;
  padding: max(24px, env(safe-area-inset-top)) 20px max(32px, env(safe-area-inset-bottom));
}

/* 넓은 화면: 내용이 위에 몰리지 않도록 화면 세로 가운데에 두고, 머리글·안내문 여백을 넉넉히 */
@media (min-width: 820px) {
  .page {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    /* 정가운데보다 조금 위에 오도록 아래 여백을 더 둡니다 */
    padding-top: 32px;
    padding-bottom: 96px;
  }

  .masthead {
    padding-bottom: 20px;
  }

  .lead {
    margin: 28px 0 20px;
  }

  .foot {
    margin-top: 36px;
  }
}

/* ── 머리글 ─────────────────────────────── */

.masthead {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 14px;
  border-bottom: 2px solid var(--ink);
}

.kicker {
  margin: 0 0 2px;
  font-size: 13px;
  letter-spacing: 0.14em;
  color: var(--ink-2);
}

.masthead h1 {
  margin: 0;
  font-size: clamp(34px, 7vw, 54px);
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.02em;
}

/* 날짜 도장 */
.stamp {
  flex: none;
  margin: 0 4px 6px 0;
  padding: 6px 12px;
  border: 2px solid var(--accent);
  border-radius: 4px;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--accent);
  transform: rotate(-4deg);
  opacity: 0.9;
}

.lead {
  min-height: 1.6em;
  margin: 18px 0 10px;
  font-size: clamp(16px, 3.8vw, 19px);
  color: var(--ink-2);
  word-break: keep-all;
  transition: opacity 0.25s;
}

.lead.swap {
  opacity: 0;
}

/* ── 본문: 화단 + 라벨 ──────────────────── */

.board {
  display: grid;
  grid-template-columns: 1fr;
  gap: 22px;
  align-items: stretch;
}

@media (min-width: 820px) {
  .board {
    grid-template-columns: 1.15fr 0.85fr;
    gap: 32px;
  }
}

/* ── 화단 ───────────────────────────────── */

.garden {
  position: relative;
  height: 400px;
  overflow: hidden;
  border: 1.5px solid var(--ink);
  border-radius: 6px;
  background: var(--paper-2);
}

.sky {
  position: absolute;
  inset: 0 0 56px;
  background: linear-gradient(to bottom, #f3efe4, #fbf8f1 70%);
}

/* 흙: 아래 띠. 위쪽에 잔디 몇 포기 */
.soil {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 56px;
  background: linear-gradient(to bottom, var(--soil), var(--soil-2));
}

.soil::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: -10px;
  height: 12px;
  background:
    radial-gradient(6px 10px at 10% 100%, var(--leaf-2) 98%, transparent),
    radial-gradient(5px 9px at 23% 100%, var(--leaf) 98%, transparent),
    radial-gradient(6px 11px at 41% 100%, var(--leaf-2) 98%, transparent),
    radial-gradient(5px 8px at 58% 100%, var(--leaf) 98%, transparent),
    radial-gradient(6px 10px at 74% 100%, var(--leaf-2) 98%, transparent),
    radial-gradient(5px 9px at 91% 100%, var(--leaf) 98%, transparent);
}

.soil::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image: radial-gradient(rgba(255, 255, 255, 0.12) 1px, transparent 1.5px);
  background-size: 11px 9px;
  opacity: 0.6;
}

/* 봉오리들: 흙 위에 서 있습니다 */
.buds {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 50px;
  display: flex;
  align-items: flex-end;
  justify-content: space-evenly;
  padding: 0 4%;
}

.bud {
  position: relative;
  width: 27%;
  max-width: 190px;
  padding: 0;
  border: 0;
  background: none;
  transform-origin: 50% 100%;
  transition:
    transform var(--move-ms) cubic-bezier(0.2, 0.8, 0.2, 1),
    opacity 0.4s ease,
    left var(--move-ms) cubic-bezier(0.2, 0.8, 0.2, 1),
    width var(--move-ms) cubic-bezier(0.2, 0.8, 0.2, 1);
}

.bud svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

.garden[data-state='pick'] .bud {
  animation: sway 3.6s ease-in-out infinite;
}

.garden[data-state='pick'] .bud:nth-child(2) {
  animation-delay: -1.2s;
}

.garden[data-state='pick'] .bud:nth-child(3) {
  animation-delay: -2.4s;
}

.garden[data-state='pick'] .bud:hover,
.garden[data-state='pick'] .bud:focus-visible {
  animation-play-state: paused;
  transform: scale(1.05);
}

@keyframes sway {
  0%,
  100% {
    transform: rotate(-2deg);
  }
  50% {
    transform: rotate(2deg);
  }
}

/* 하나를 고르면 나머지는 시들어 사라지고, 고른 것은 가운데로 */
.garden[data-state='chosen'] .bud:not(.chosen),
.garden[data-state='open'] .bud:not(.chosen) {
  opacity: 0;
  transform: scale(0.8) translateY(20px);
  pointer-events: none;
}

.bud.chosen {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: min(62%, 300px);
  max-width: none;
  transform: translateX(-50%);
}

.bud.tap {
  animation: drink var(--tap-ms) ease-out;
}

@keyframes drink {
  30% {
    transform: translateX(-50%) scale(1.04, 0.97);
  }
  60% {
    transform: translateX(-50%) scale(0.98, 1.03);
  }
  100% {
    transform: translateX(-50%);
  }
}

/* 봉오리: 물을 줄 때마다(--open) 꽃받침이 벌어지고, 피면(.open) 사라지면서 아래의 꽃이 드러납니다 */
.closed {
  transform-box: fill-box;
  transform-origin: 50% 50%;
  transition:
    opacity 0.4s ease,
    transform var(--move-ms) cubic-bezier(0.2, 0.8, 0.2, 1);
}

.closed .bud-petals {
  transform-box: fill-box;
  transform-origin: 50% 88%;
  transform: scale(calc(1 + var(--open, 0) * 0.38), calc(1 - var(--open, 0) * 0.14));
  transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.closed .sepal-l {
  transform-box: fill-box;
  transform-origin: 100% 100%;
  transform: rotate(calc(var(--open, 0) * -32deg));
  transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.closed .sepal-r {
  transform-box: fill-box;
  transform-origin: 0% 100%;
  transform: rotate(calc(var(--open, 0) * 32deg));
  transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.bud.open .closed {
  opacity: 0;
  transform: scale(1.25);
}

/* 꽃: 피기 전에는 숨어 있다가 꽃잎이 하나씩 펼쳐집니다 */
.bloom {
  opacity: 0;
  transform-box: view-box;
  transform-origin: 100px 100px;
  transition: transform 0.9s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.bud.open .bloom {
  opacity: 1;
  transform: scale(1.2);
  filter: drop-shadow(0 6px 5px rgba(45, 58, 46, 0.18));
}

.bloom .petal {
  transform-box: fill-box;
  transform-origin: 50% 100%;
  transform: scale(0.08);
}

.bud.open .bloom .petal {
  animation: unfold 0.9s cubic-bezier(0.2, 0.9, 0.3, 1.25) calc(0.12s + var(--i, 0) * 28ms) forwards;
}

@keyframes unfold {
  from {
    opacity: 0;
    transform: scale(0.08) rotate(-35deg);
  }
  to {
    opacity: 1;
    transform: scale(1) rotate(0);
  }
}

.bloom .core {
  transform-box: fill-box;
  transform-origin: 50% 50%;
  transform: scale(0.1);
}

.bud.open .bloom .core {
  animation: unfold 0.7s cubic-bezier(0.2, 0.9, 0.3, 1.25) 0.5s forwards;
}

.bloom .photo {
  transform-box: fill-box;
  transform-origin: 50% 50%;
  transform: scale(0.2);
}

.bud.open .bloom .photo {
  animation: grow 0.8s cubic-bezier(0.2, 0.9, 0.3, 1.3) 0.15s forwards;
}

@keyframes grow {
  from {
    opacity: 0;
    transform: scale(0.2);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* ── 물뿌리개 ───────────────────────────── */

.can {
  position: absolute;
  left: 58%;
  top: 6%;
  width: clamp(72px, 16%, 110px);
  opacity: 0;
  transform: translateY(-10px) rotate(0);
  transform-origin: 20% 60%;
  transition:
    opacity 0.4s ease 0.3s,
    transform 0.4s ease;
  pointer-events: none;
}

.can svg {
  display: block;
  width: 100%;
  height: auto;
}

.garden[data-state='chosen'] .can {
  opacity: 1;
  transform: translateY(0) rotate(0);
}

.garden[data-state='chosen'] .can.pour {
  animation: pour var(--tap-ms) ease-in-out;
}

@keyframes pour {
  30% {
    transform: translate(-6px, 4px) rotate(-28deg);
  }
  70% {
    transform: translate(-6px, 4px) rotate(-26deg);
  }
  100% {
    transform: translateY(0) rotate(0);
  }
}

/* 물방울: 물뿌리개 주둥이에서 봉오리로 떨어집니다 */
.drop {
  position: absolute;
  left: 58%;
  top: 14%;
  width: 6px;
  height: 9px;
  border-radius: 50% 50% 50% 50% / 40% 40% 60% 60%;
  background: var(--water);
  opacity: 0.9;
  pointer-events: none;
  animation: fall 0.6s cubic-bezier(0.4, 0, 1, 1) forwards;
  animation-delay: var(--delay, 0s);
}

@keyframes fall {
  0% {
    transform: translate(0, 0) scale(0.8);
    opacity: 0;
  }
  15% {
    opacity: 0.9;
  }
  100% {
    transform: translate(var(--dx), var(--dy)) scale(1);
    opacity: 0;
  }
}

/* 꽃잎 조각: 필 때 흩날립니다 */
.piece {
  position: absolute;
  left: 50%;
  top: 40%;
  width: 8px;
  height: 8px;
  border-radius: 60% 60% 60% 0;
  background: var(--piece, #fff);
  pointer-events: none;
  animation: scatter 1.1s ease-out forwards;
}

@keyframes scatter {
  0% {
    transform: translate(-50%, -50%) rotate(0) scale(1);
    opacity: 1;
  }
  100% {
    transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) rotate(300deg) scale(0.5);
    opacity: 0;
  }
}

/* ── 표본 라벨 ──────────────────────────── */

.note {
  position: relative;
  min-height: 240px;
  padding: 28px 24px 24px;
  border: 1.5px dashed var(--ink);
  border-radius: 4px;
  background: var(--paper-2);
  box-shadow: 0 10px 24px rgba(45, 58, 46, 0.08);
}

/* 위에 붙인 마스킹테이프 */
.tape {
  position: absolute;
  left: 50%;
  top: -12px;
  width: 92px;
  height: 24px;
  background: rgba(201, 105, 63, 0.35);
  transform: translateX(-50%) rotate(-2deg);
}

.note-empty {
  margin: 0;
  padding: 16px 0;
  text-align: center;
  color: var(--ink-2);
  line-height: 1.9;
}

.note[data-empty='false'] .note-empty {
  display: none;
}

.note-body[hidden] {
  display: none;
}

.note-body {
  animation: write 0.6s ease-out both;
}

@keyframes write {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.note-no {
  margin: 0 0 6px;
  font-size: 12px;
  letter-spacing: 0.12em;
  color: var(--ink-2);
}

.note-no .latin {
  font-style: italic;
  letter-spacing: 0.02em;
}

.note-name {
  margin: 0;
  font-size: 30px;
  font-weight: 700;
  line-height: 1.2;
}

.note-meaning {
  margin: 6px 0 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
  font-size: 20px;
  color: var(--accent-2);
}

.note-meaning::before {
  content: '꽃말 ';
  font-size: 13px;
  letter-spacing: 0.1em;
  color: var(--ink-2);
}

.note-text {
  margin: 0 0 16px;
  font-size: 16px;
  line-height: 1.8;
  word-break: keep-all;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 18px;
  padding: 0;
  list-style: none;
  font-size: 13px;
  color: var(--ink-2);
}

.tags li {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--paper);
}

.tags b {
  color: var(--ink);
}

.swatch {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  background: var(--swatch, #ccc);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.15);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.btn {
  padding: 10px 16px;
  border: 1.5px solid var(--ink);
  border-radius: 3px;
  background: transparent;
  font-size: 14px;
  font-weight: 700;
  transition:
    background 0.15s,
    color 0.15s;
}

.btn:hover {
  background: var(--ink);
  color: var(--paper);
}

.btn-primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-2);
  border-color: var(--accent-2);
}

.foot {
  margin-top: 28px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--ink-2);
}

.foot p {
  margin: 0;
}

/* 알림: 오른쪽 아래 네모 쪽지 */
.toast {
  position: fixed;
  right: 16px;
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 3;
  max-width: 260px;
  padding: 10px 14px;
  border-left: 3px solid var(--accent);
  background: var(--ink);
  color: var(--paper);
  font-size: 13px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
  transform: translateX(16px);
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.25s,
    transform 0.25s;
}

.toast.show {
  transform: none;
  opacity: 1;
}

/* ── 모바일 ─────────────────────────────── */

@media (max-width: 480px) {
  .masthead {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }

  .stamp {
    align-self: flex-end;
    margin: 0;
  }

  .garden {
    height: 340px;
  }

  .bud {
    width: 30%;
  }

  .bud.chosen {
    width: min(70%, 260px);
  }

  .note {
    padding: 24px 18px 20px;
  }

  .note-name {
    font-size: 26px;
  }

  .note-meaning {
    font-size: 18px;
  }

  .note-text {
    font-size: 15px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .garden[data-state='pick'] .bud,
  .bud.tap,
  .can.pour,
  .note-body {
    animation: none;
  }

  .bud.open .bloom .petal,
  .bud.open .bloom .core,
  .bud.open .bloom .photo {
    animation: none;
    transform: none;
    opacity: 1;
  }

  .bud,
  .closed,
  .closed .bud-petals,
  .closed .sepal-l,
  .closed .sepal-r,
  .bloom,
  .can {
    transition-duration: 0.01ms;
    transition-delay: 0s;
  }
}
