:root {
  --paper: #f3ead6;
  --paper-2: #fbf6ea;
  --ink: #3b3026;
  --ink-soft: #7a6a58;
  --accent: #b5654a;
  --leaf: #6d8c55;
  --water: #6e9fb5;
  --warn: #a8473a;
  --wobble: 255px 14px 225px 14px / 14px 225px 14px 255px;
  --font: "Gaegu", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  --font-title: "Nanum Pen Script", "Gaegu", cursive;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  font-size: 18px;
  color: var(--ink);
  background-color: var(--paper);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='260' height='260'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.35 0 0 0 0 0.27 0 0 0 0 0.18 0 0 0 0.11 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
  min-height: 100vh;
}
button, select, input { font: inherit; color: inherit; }

/* ---------- 상단 ---------- */
.hud {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 20px;
  padding: 10px 20px;
  border-bottom: 2px dashed rgba(59, 48, 38, 0.35);
}
.hud h1 {
  font-family: var(--font-title);
  font-size: 40px;
  font-weight: 400;
  margin: 0;
  line-height: 1;
}
.stats { display: flex; gap: 14px; flex-wrap: wrap; }
.stat {
  background: var(--paper-2);
  border: 1.5px solid var(--ink);
  border-radius: var(--wobble);
  padding: 2px 12px;
}
.refill { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-left: auto; }
.refill select {
  background: var(--paper-2);
  border: 1.5px solid var(--ink);
  border-radius: var(--wobble);
  padding: 4px 8px;
  max-width: 230px;
}

/* ---------- 버튼 ---------- */
.btn {
  background: var(--paper-2);
  border: 1.8px solid var(--ink);
  border-radius: var(--wobble);
  padding: 4px 14px;
  cursor: pointer;
  box-shadow: 2px 2px 0 rgba(59, 48, 38, 0.25);
  transition: transform 0.1s;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { transform: rotate(-1deg) translateY(-1px); }
.btn:active:not(:disabled) { transform: translateY(1px); box-shadow: none; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.primary { background: #f0d79a; font-weight: 700; }
.btn.danger { color: var(--warn); }
.btn.ghost { border-style: dashed; box-shadow: none; }
.btn.small { font-size: 15px; padding: 1px 9px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.muted { color: var(--ink-soft); }
.small { font-size: 15px; }
.tag {
  display: inline-block;
  font-size: 14px;
  padding: 0 7px;
  border: 1px solid var(--ink-soft);
  border-radius: var(--wobble);
  color: var(--ink-soft);
}
.hint {
  font-size: 15px;
  color: var(--ink-soft);
  border-left: 3px solid #e3c78a;
  padding-left: 8px;
}

/* ---------- 배치 ---------- */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 400px;
  gap: 16px;
  padding: 16px 20px;
  align-items: start;
}
.garden-wrap {
  position: relative;
  background: var(--paper-2);
  border: 2px solid var(--ink);
  border-radius: 18px 6px 22px 8px / 8px 20px 6px 18px;
  overflow: hidden;
  box-shadow: 4px 5px 0 rgba(59, 48, 38, 0.15);
}
#garden { display: block; width: 100%; height: auto; touch-action: manipulation; }
.panel {
  background: var(--paper-2);
  border: 2px solid var(--ink);
  border-radius: 6px 18px 8px 20px / 20px 8px 18px 6px;
  box-shadow: 4px 5px 0 rgba(59, 48, 38, 0.15);
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 110px);
  position: sticky;
  top: 16px;
}
.tabs { display: flex; flex-wrap: wrap; gap: 2px; padding: 8px 8px 0; border-bottom: 1.5px solid var(--ink); }
.tabs button {
  background: none;
  border: 1.5px solid transparent;
  border-bottom: none;
  padding: 4px 10px;
  cursor: pointer;
  border-radius: 10px 10px 0 0;
}
.tabs button.active { background: #f0e3c2; border-color: var(--ink); font-weight: 700; }
.panel-body { overflow-y: auto; padding: 4px 16px 16px; }
.panel-body h2 { font-family: var(--font-title); font-weight: 400; font-size: 32px; margin: 10px 0 6px; }
.panel-body h2 .muted { font-family: var(--font); font-size: 17px; }
.panel-body h3 { margin: 16px 0 6px; font-size: 19px; border-bottom: 1px dashed var(--ink-soft); }

/* ---------- 정원 위 표시 ---------- */
.ln { fill: none; stroke: var(--ink); stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; filter: url(#pencil); }
.cr { filter: url(#crayon); }
.levels {
  position: absolute;
  left: 10px;
  top: 10px;
  background: rgba(251, 246, 234, 0.85);
  border: 1.5px solid var(--ink);
  border-radius: var(--wobble);
  padding: 4px 12px;
  font-size: 15px;
}
.bar {
  display: inline-block;
  width: 70px;
  height: 9px;
  border: 1.2px solid var(--ink);
  border-radius: 6px;
  vertical-align: middle;
  overflow: hidden;
}
.bar i { display: block; height: 100%; background: repeating-linear-gradient(45deg, #d9b56a 0 3px, #c79a50 3px 5px); }
.levels div:nth-child(2) .bar i { background: repeating-linear-gradient(45deg, #8fb7c9 0 3px, #6e9fb5 3px 5px); }

.bird { cursor: pointer; }
.bird .tag { opacity: 0; transition: opacity 0.2s; pointer-events: none; }
.bird .tag rect { fill: var(--paper-2); stroke: var(--ink); stroke-width: 1.2; }
.bird .tag text { font-family: var(--font); font-size: 15px; text-anchor: middle; fill: var(--ink); }
.bird:hover .tag, .bird.selected .tag { opacity: 1; }
.bird.selected .pose { filter: drop-shadow(0 0 3px #f0c64a) drop-shadow(0 0 2px #f0c64a); }
.pose { transform-box: fill-box; transform-origin: 50% 100%; }
.pose-stand { animation: bob 2.6s ease-in-out infinite; }
.pose-peck { animation: peck 0.9s ease-in-out infinite; }
.pose-rest { animation: breathe 3.6s ease-in-out infinite; }
.pose-bath { animation: splash 0.5s ease-in-out infinite; }
.pose-fly .flap { animation: flap 0.22s linear infinite alternate; }
.pose-preen { animation: peck 1.4s ease-in-out infinite; }
.pose.custom { animation: none; } /* 전용 그림은 부위별 SMIL 애니메이션을 쓴다 */
@keyframes bob { 50% { transform: translateY(-1.5px); } }
@keyframes peck { 40% { transform: rotate(6deg); } 60% { transform: rotate(0); } }
@keyframes breathe { 50% { transform: scale(1.03, 0.98); } }
@keyframes splash { 50% { transform: rotate(-4deg); } }
@keyframes flap { from { opacity: 0.1; } to { opacity: 0.7; } }
.pop .pop-inner { animation: pop 2.6s ease-out forwards; }
@keyframes pop {
  0% { transform: translateY(0) scale(0.4); opacity: 0; }
  15% { transform: translateY(-20px) scale(1.1); opacity: 1; }
  70% { transform: translateY(-40px) scale(1); opacity: 1; }
  100% { transform: translateY(-55px) scale(1); opacity: 0; }
}

.bird-card {
  position: absolute;
  right: 12px;
  bottom: 12px;
  width: 300px;
  background: var(--paper-2);
  border: 1.8px solid var(--ink);
  border-radius: var(--wobble);
  padding: 10px 14px;
  font-size: 16px;
  box-shadow: 3px 3px 0 rgba(59, 48, 38, 0.2);
}
.card-head { display: flex; gap: 10px; align-items: center; }
.hidden { display: none !important; }

.toasts {
  position: absolute;
  left: 50%;
  top: 10px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
  width: min(90%, 460px);
}
.toast {
  background: var(--paper-2);
  border: 1.5px solid var(--ink);
  border-radius: var(--wobble);
  padding: 4px 14px;
  font-size: 16px;
  display: flex;
  align-items: center;
  gap: 6px;
  animation: toastIn 0.3s ease-out;
  transition: opacity 0.6s, transform 0.6s;
}
.toast.arrive { background: #eef3e0; }
.toast.gift { background: #f8ecc8; }
.toast.away { background: #f3dfd6; }
.toast.out { opacity: 0; transform: translateY(-8px); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-8px) rotate(-1deg); } }

/* ---------- 패널 목록 ---------- */
ul.guests, ul.items, ul.shop, ul.plain, ul.log, ul.gifts { list-style: none; margin: 0; padding: 0; }
.guest {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  margin-bottom: 6px;
  border: 1.5px solid var(--ink);
  border-radius: var(--wobble);
  background: #fffdf6;
  cursor: pointer;
}
.guest.sel { background: #fbf0cf; }
.guest.empty { border-style: dashed; color: var(--ink-soft); justify-content: center; cursor: default; min-height: 44px; }
.grow { flex: 1; min-width: 0; }
.gift-cell { width: 34px; text-align: center; line-height: 1.1; }
.items li, .shop li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  border-bottom: 1px dotted rgba(59, 48, 38, 0.3);
}
.shop li.owned { opacity: 0.7; }
.plain li { padding: 2px 0; }
.log li { padding: 4px 0; border-bottom: 1px dotted rgba(59, 48, 38, 0.25); font-size: 16px; }
.log time { font-weight: 700; margin-right: 4px; }
.log li.away { color: var(--ink-soft); }

.dex { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
.dex-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 4px;
  background: #fffdf6;
  border: 1.5px solid var(--ink);
  border-radius: var(--wobble);
  cursor: pointer;
  line-height: 1.2;
}
.dex-card.unknown { border-style: dashed; background: transparent; }
/* 1~2번 만난 새는 연필 스케치처럼 흑백으로 보인다 */
.sketch .portrait { filter: grayscale(1) contrast(1.15) brightness(1.08); }
.portrait.unknown { opacity: 0.8; }
.icon { vertical-align: middle; flex: none; }

/* ---------- 모달 ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(59, 48, 38, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 10;
}
.sheet {
  position: relative;
  background: var(--paper-2);
  border: 2px solid var(--ink);
  border-radius: 10px 22px 12px 20px / 20px 10px 22px 12px;
  padding: 18px 22px;
  max-width: 520px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 6px 6px 0 rgba(59, 48, 38, 0.2);
}
.sheet h2 { font-family: var(--font-title); font-weight: 400; font-size: 36px; margin: 4px 0 8px; }
.close { position: absolute; right: 10px; top: 6px; background: none; border: none; font-size: 28px; cursor: pointer; }
.dex-detail { text-align: center; }
.dex-detail .memo { font-style: italic; }
.dex-detail ul.plain { text-align: left; }
table.rec { width: 100%; border-collapse: collapse; text-align: left; font-size: 16px; margin-top: 8px; }
table.rec th { font-weight: 400; color: var(--ink-soft); width: 38%; padding: 3px 6px 3px 0; vertical-align: top; }
table.rec td { padding: 3px 0; border-bottom: 1px dotted rgba(59, 48, 38, 0.3); }
ul.gifts { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
ul.gifts li { display: flex; flex-direction: column; align-items: center; font-size: 14px; width: 74px; }
.gift-row { display: flex; flex-wrap: wrap; gap: 4px; margin: 8px 0; }

/* ---------- 판정 기록 (디버그) ---------- */
.scroll-x { overflow-x: auto; }
table.trace { font-size: 14px; }
table.trace th { width: auto; }
table.trace .num { text-align: right; padding-right: 6px; white-space: nowrap; }
.trace-log { list-style: none; margin: 0; padding: 0; }
.tr-entry { border-bottom: 1px dashed var(--ink-soft); padding: 6px 0; }
.tr-entry ul { list-style: none; margin: 4px 0 0; padding: 0; }
.tr-head { display: flex; gap: 6px; align-items: center; }
.tag.off { background: #efe1d6; }
.tr-row { padding: 3px 0 3px 8px; border-left: 3px solid transparent; font-size: 15px; }
.tr-row.out-arrived { border-left-color: var(--leaf); }
.tr-row.out-miss { border-left-color: #d8c3a8; }
.tr-row.out-full { border-left-color: var(--warn); }
.tr-row.out-blocked { border-left-color: #9a8f86; color: var(--ink-soft); }
.tr-row.out-present { color: var(--ink-soft); font-size: 14px; }
.tr-out { font-weight: 700; }
.out-arrived .tr-out { color: var(--leaf); }
.out-full .tr-out { color: var(--warn); }
.fx { white-space: nowrap; }
.fx.low { color: var(--warn); }
.fx.high { color: var(--leaf); }

/* ---------- 휴대폰 ---------- */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; padding: 10px 16px; }
  .panel { position: static; max-height: none; }
  .refill { margin-left: 0; }
  .hud { padding: 8px 16px; }
  .bird-card { position: static; width: auto; border-radius: 0; border-width: 1.5px 0 0; }
  .levels { font-size: 13px; padding: 2px 8px; }
  .bar { width: 46px; }
}
