:root {
  --night: #111D35; --night2: #1a2a4a; --pine: #176B4E; --red: #D7474C; --gold: #F6CA63; --snow: #ECF5F6; --muted: #b9c6d8;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--night); color: var(--snow); font: 16px/1.6 system-ui, -apple-system, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif; }
body { min-height: 100vh; overflow-x: hidden; }
img { image-rendering: pixelated; }
a { color: var(--gold); }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
h1 { font-size: 1.5rem; line-height: 1.3; margin: .2em 0 .5em; }
h2 { font-size: 1.15rem; }

.btn { white-space: nowrap; display: inline-flex; align-items: center; justify-content: center; min-height: 44px; min-width: 44px; padding: 0 18px; border: 0; border-radius: 12px;
  background: var(--red); color: #fff; font: inherit; font-weight: 700; text-decoration: none; cursor: pointer; }
.btn:hover { filter: brightness(1.1); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.big { min-height: 52px; font-size: 1.05rem; padding: 0 24px; }
.btn.small { min-height: 44px; padding: 0 12px; font-size: .9rem; }
.btn.ghost { background: transparent; color: var(--snow); box-shadow: inset 0 0 0 2px rgba(236,245,246,.5); }
.btn.ghost[aria-pressed="false"] { opacity: .6; }
.btn.kakao { background: #FEE500; color: #191919; }
.btn.sso { background: var(--pine); }

.top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 10px; padding: 8px 16px; background: rgba(17,29,53,.92); backdrop-filter: blur(4px); }
.logo { display: flex; align-items: center; gap: 6px; color: var(--snow); font-weight: 800; text-decoration: none; min-height: 44px; }
.logo img { width: 28px; height: 28px; }
.dday { color: var(--gold); font-weight: 700; white-space: nowrap; }
.topnav { margin-left: auto; display: flex; gap: 6px; }

.scene { position: relative; width: 100%; aspect-ratio: 3 / 2; overflow: hidden; }
.scene .bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.village { max-height: 78vh; }
.spot { position: absolute; display: flex; align-items: flex-start; justify-content: center; border-radius: 10px; text-decoration: none; }
.spot span { margin-top: -4px; padding: 4px 10px; border-radius: 99px; background: rgba(17,29,53,.85); color: var(--snow); font-weight: 700; font-size: .9rem; white-space: nowrap; }
.spot:hover, .spot:focus-visible { background: rgba(246,202,99,.18); }
.hero { position: absolute; left: 50%; top: 8%; transform: translateX(-50%); width: min(92%, 560px); text-align: center; text-shadow: 0 2px 6px #000a; }
.hero h1 { font-size: clamp(1.3rem, 4vw, 2.2rem); }
.hero p { margin: 0 0 14px; }
.cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; padding: 16px; max-width: 900px; margin: 0 auto; }
.card { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 14px 8px; border-radius: 14px; background: var(--night2); color: var(--snow); text-decoration: none; text-align: center; min-height: 44px; }
.card img { width: 64px; height: 64px; object-fit: contain; }
.card b { word-break: keep-all; }
.card small { color: var(--muted); }
.card.soon { opacity: .55; }
.foot { text-align: center; color: var(--muted); padding: 8px 16px 40px; font-size: .9rem; }
.foot .total { font-size: 1.05rem; color: var(--snow); }
.foot b { color: var(--gold); }

.panel { max-width: 640px; margin: 0 auto; padding: 24px 16px 48px; }
.panel.center { text-align: center; }
.panel.admin { max-width: 1000px; }
.stack { display: grid; gap: 12px; margin-top: 16px; }
.form { display: grid; gap: 8px; }
.form label { font-weight: 700; margin-top: 6px; }
input, textarea, select { width: 100%; min-height: 44px; padding: 10px 12px; border-radius: 10px; border: 2px solid #3b4d70; background: #0b1428; color: var(--snow); font: inherit; }
textarea { resize: vertical; }
fieldset { min-width: 0; border: 2px solid #3b4d70; border-radius: 12px; padding: 10px; margin: 6px 0; }
legend { font-weight: 700; padding: 0 6px; }
.style { display: flex; align-items: center; gap: 10px; }
.style input { width: 22px; min-height: 22px; }
.style img { width: 64px; height: 64px; }
.hint { margin: 0; color: var(--muted); font-size: .85rem; word-break: break-all; }
.err { color: #ff9b9e; min-height: 1em; margin: 4px 0; }
.note { color: var(--muted); }
.trap { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }

/* 개인 트리 */
.treepage { display: grid; grid-template-columns: minmax(0, 3fr) minmax(300px, 2fr); max-width: 1200px; margin: 0 auto; }
.treescene { aspect-ratio: 3 / 2; }
.treescene .tree { position: absolute; left: 50%; bottom: 4%; height: 92%; aspect-ratio: 1; transform: translateX(-50%); object-fit: contain; }
.treecard { padding: 20px 16px 32px; }
.cardhead { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.cardhead h1 { margin: 0; flex: 1 1 auto; }
.live { font-size: .8rem; font-weight: 800; padding: 2px 10px; border-radius: 99px; background: #3b4d70; color: var(--muted); }
.live.on { background: var(--red); color: #fff; }
.counter { font-size: 1.1rem; margin: 12px 0 0; }
.count { font-size: 3rem; color: var(--gold); font-variant-numeric: tabular-nums; margin: 0 4px; }
.lv { font-weight: 800; margin: 0; }
.bar { height: 14px; border-radius: 99px; background: #0b1428; box-shadow: inset 0 0 0 2px #3b4d70; overflow: hidden; margin: 6px 0; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--pine), var(--gold)); transition: width .6s; }
.remain { color: var(--muted); margin: 0; }
.sealed { display: flex; align-items: center; gap: 8px; margin: 14px 0 0; color: var(--gold); }
.sealed img { width: 48px; }
.ctas { display: grid; gap: 10px; margin-top: 18px; }
.levelup .tree { animation: grow 2.4s ease-out; }
.levelup::after { content: ""; position: absolute; inset: 0; background: radial-gradient(circle at 50% 55%, rgba(246,202,99,.55), transparent 60%); animation: glow 2.4s ease-out forwards; pointer-events: none; }
@keyframes grow { 0% { transform: translateX(-50%) scale(.85); filter: brightness(2); } 60% { transform: translateX(-50%) scale(1.05); } 100% { transform: translateX(-50%) scale(1); filter: none; } }
@keyframes glow { from { opacity: 1; } to { opacity: 0; } }

/* 대화상자 */
.dlg { width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 32px); padding: 0; border: 0; border-radius: 16px; background: var(--night2); color: var(--snow); }
.dlg::backdrop { background: rgba(0,0,0,.6); }
.dlghead { display: flex; align-items: center; padding: 12px 16px 0; }
.dlghead h2 { flex: 1; margin: 0; }
.x { min-width: 44px; min-height: 44px; border: 0; background: none; color: var(--snow); font-size: 1.8rem; cursor: pointer; }
.dlgbody { padding: 8px 16px 20px; }
.cnt { text-align: right; color: var(--muted); }
.stickers { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 6px; }
.stickers label { margin: 0; display: grid; place-items: center; min-height: 44px; border-radius: 10px; cursor: pointer; }
.stickers input { position: absolute; opacity: 0; width: 1px; min-height: 0; }
.stickers img { width: 44px; height: 44px; }
.stickers label:has(input:checked) { background: rgba(246,202,99,.25); box-shadow: inset 0 0 0 2px var(--gold); }
.stickers label:has(input:focus-visible) { outline: 3px solid var(--gold); }
.preview { background: var(--snow); color: var(--night); border-radius: 12px; padding: 10px 14px; min-height: 60px; }
.preview small { color: #556; }
.pvsticker { float: right; width: 48px; }
.pvtext { white-space: pre-wrap; word-break: break-word; margin: 0; }
.done { text-align: center; }
.done img { width: 180px; }

/* 편지함 */
.lettershead { display: flex; align-items: center; gap: 10px; justify-content: space-between; }
.env { width: min(260px, 70vw); }
.big { font-size: 1.3rem; }
.big b { color: var(--gold); }
.letters { list-style: none; padding: 0; display: grid; gap: 12px; }
.letter { background: var(--snow); color: var(--night); border-radius: 14px; padding: 12px 14px; }
.letter.hidden { opacity: .55; }
.lhead { display: flex; align-items: center; gap: 8px; }
.lhead img { width: 36px; height: 36px; object-fit: contain; }
.lhead small { margin-left: auto; color: #556; }
.lbody { white-space: pre-wrap; word-break: break-word; }
.lacts { display: flex; gap: 6px; justify-content: flex-end; }
.letter .btn.ghost { color: var(--night); box-shadow: inset 0 0 0 2px #8894a8; }
.inline { display: flex; align-items: center; gap: 6px; }
.inline input { width: 22px; min-height: 22px; }
.empty { color: var(--muted); }
.admin table { width: 100%; border-collapse: collapse; font-size: .9rem; display: block; overflow-x: auto; }
.admin td, .admin th { border-bottom: 1px solid #3b4d70; padding: 4px 6px; text-align: left; }
.admin .form label { display: grid; gap: 2px; font-weight: 400; }
.row { display: flex; gap: 8px; }
dt { font-weight: 800; margin-top: 12px; }
dd { margin: 2px 0 0; color: var(--muted); }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 100; padding: 12px 18px; border-radius: 12px; background: var(--gold); color: var(--night); font-weight: 700; max-width: calc(100vw - 32px); }

/* 눈 */
.snow { position: fixed; inset: 0; pointer-events: none; z-index: 5; overflow: hidden; }
.snow i { position: absolute; top: -10px; width: 6px; height: 6px; background: var(--snow); animation: fall linear infinite; }
@keyframes fall { to { transform: translate3d(30px, 105vh, 0); } }

@media (max-width: 760px) {
  .treepage { grid-template-columns: 1fr; }
  .spot { display: none; } /* 모바일: 건물 핫스팟 대신 카드 내비게이션 */
  .hero { top: 4%; }
  .hero p { display: none; }
  .village { aspect-ratio: 4 / 3; }
  .cards { grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 12px 16px; }
  .card img { width: 48px; height: 48px; }
  .card small { display: none; }
  .count { font-size: 2.4rem; }
  .top { padding: 6px 16px; gap: 6px; }
  .logo { font-size: .95rem; white-space: nowrap; }
  .logo span { display: none; }
  .topnav .ghost { padding: 0 8px; }
  .ctas { padding-bottom: env(safe-area-inset-bottom); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .snow { display: none; }
}

/* 게스트·로그인 안내, 승계 선택 */
.guestbox { margin-top: 18px; padding: 12px 14px; border-radius: 12px; background: var(--night2); box-shadow: inset 0 0 0 2px #3b4d70; }
.guestbox p { margin: 4px 0 10px; color: var(--muted); font-size: .9rem; }
.guestbox .row { flex-wrap: wrap; }
.choice { display: flex; gap: 10px; align-items: flex-start; padding: 12px; border-radius: 12px; background: var(--night2); cursor: pointer; font-weight: 400 !important; }
.choice input { width: 22px; min-height: 22px; margin-top: 2px; }
.choice span { display: grid; }
.choice small { color: var(--muted); word-break: break-all; }
.choice:has(input:checked) { box-shadow: inset 0 0 0 2px var(--gold); }

/* 서버 렌더 본문(/about·/guide·/privacy·첫 화면) */
.ssr h2 { margin-top: 1.4em; }
.ssr ul, .ssr ol { padding-left: 1.2em; }
.ssr .steps { list-style: none; padding: 0; display: grid; gap: 14px; }
.ssr .steps li { display: flex; gap: 14px; align-items: flex-start; }
.ssr .steps img { flex: 0 0 auto; width: 72px; height: auto; }
.ssr .steps h2 { margin: 0; font-size: 1.05rem; }
.ssr .steps p { margin: 4px 0 0; }
.ssr .faq dd { margin-bottom: 8px; }
.ptable { width: 100%; border-collapse: collapse; margin: 12px 0; font-size: .92rem; }
.ptable caption { text-align: left; font-weight: 800; margin-bottom: 6px; }
.ptable th, .ptable td { border: 1px solid #3b4d70; padding: 6px 8px; text-align: left; vertical-align: top; }
.ptable th { width: 34%; background: var(--night2); }
.todo { color: var(--gold); }

/* 공통 푸터 */
.sitefoot { text-align: center; padding: 20px 16px calc(28px + env(safe-area-inset-bottom)); color: var(--muted); font-size: .9rem; }
.sitefoot nav { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 0; }
.sitefoot a { display: inline-flex; align-items: center; min-height: 44px; padding: 0 10px; color: var(--muted); }
.sitefoot small { display: block; margin-top: 4px; }

/* 광고(라벨은 '광고' 한 단어, 버튼과 48px+구분선, 고정 배치 없음, 눈 효과보다 위) */
.cw-ad { position: relative; z-index: 6; margin: 48px auto 24px; padding: 12px 12px 8px; max-width: 970px; border-top: 1px dashed rgba(255,255,255,.15);
  background: rgba(17, 29, 53, .6); border-radius: 12px; min-height: 120px; overflow: hidden; }
.cw-ad__label { display: block; font-size: 11px; color: rgba(255,255,255,.55); margin-bottom: 6px; }
@media (max-width: 640px) { .cw-ad { margin: 40px 8px 16px; min-height: 100px; } }
ins.adsbygoogle[data-ad-status="unfilled"] { display: none !important; }
.cw-ad:has(ins[data-ad-status="unfilled"]) { display: none; }
