:root {
  --ink: #262626;
  --paper: #fbfaf4;
  --yellow: #f3e56a;
  --gray: #e6e6e2;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--paper); color: var(--ink);
  font-family: 'Gaegu', 'Malgun Gothic', system-ui, sans-serif;
  -webkit-user-select: none; user-select: none;
  touch-action: none;
}
#app { position: fixed; inset: 0; }
#app canvas { display: block; touch-action: none; }
.label-layer { position: fixed !important; inset: 0; pointer-events: none; }

/* 3D 라벨 */
.name-tag {
  font-weight: 700; font-size: 15px; line-height: 1.2; padding: 0 7px;
  background: rgba(255, 255, 255, 0.9); border: 1.5px solid var(--ink); border-radius: 8px; white-space: nowrap;
}
.name-tag.me { background: var(--yellow); }
.bubble {
  position: relative; max-width: 190px; padding: 4px 10px; margin-bottom: 8px;
  background: #fff; border: 2px solid var(--ink); border-radius: 12px;
  font-size: 17px; font-weight: 700; line-height: 1.2; word-break: keep-all; text-align: center;
}
.bubble::after {
  content: ''; position: absolute; left: 50%; bottom: -7px; width: 10px; height: 10px;
  background: #fff; border-right: 2px solid var(--ink); border-bottom: 2px solid var(--ink);
  transform: translateX(-50%) rotate(45deg);
}
.cat-label {
  font-size: 14px; font-weight: 700; padding: 0 6px;
  background: rgba(255, 255, 255, 0.85); border: 1.5px dashed var(--ink); border-radius: 6px; white-space: nowrap;
}
.heart {
  display: inline-block; font-size: 24px; color: var(--yellow);
  -webkit-text-stroke: 1.5px var(--ink); opacity: 0;
  animation: heart 1.3s ease-out forwards;
}
.heart.big { font-size: 34px; animation: heartBig 2s ease-out forwards; }
@keyframes heartBig {
  0% { opacity: 0; transform: translate(0, 0) scale(0.4); }
  15% { opacity: 1; transform: translate(calc(var(--dx) * 0.2), -14px) scale(1.2); }
  100% { opacity: 0; transform: translate(var(--dx), -120px) scale(0.9); }
}
@keyframes heart {
  0% { opacity: 0; transform: translate(0, 0) scale(0.5); }
  15% { opacity: 1; transform: translate(calc(var(--dx) * 0.3), -10px) scale(1.15); }
  100% { opacity: 0; transform: translate(var(--dx), -64px) scale(0.9); }
}

/* HUD */
#hud { position: fixed; inset: 0; pointer-events: none; }
#hud[hidden] { display: none; }
.hud-top {
  position: absolute; top: 12px; left: 12px; right: 12px;
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
}
.hud-top > * { pointer-events: auto; }
.sk-btn {
  font-family: inherit; font-weight: 700; font-size: 19px; color: var(--ink);
  background: var(--gray); border: 2px solid var(--ink); border-radius: 10px;
  padding: 3px 12px; box-shadow: 0 3px 0 var(--ink); cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; line-height: 1.3;
}
.sk-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.sk-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.sk-btn b { background: #fff; border: 1.5px solid var(--ink); border-radius: 7px; padding: 0 6px; font-size: 17px; }
.sk-btn.big { font-size: 24px; padding: 6px 20px; width: 100%; justify-content: center; background: var(--yellow); }
.sk-btn.small { font-size: 16px; padding: 0 9px; }
.sk-chip {
  background: rgba(255, 255, 255, 0.9); border: 2px solid var(--ink); border-radius: 10px;
  padding: 3px 10px; font-weight: 700; font-size: 17px;
}
.sk-chip.small { font-size: 14px; border-width: 1.5px; }
#online { margin-left: auto; cursor: pointer; user-select: none; }
#online:active { transform: translateY(1px); }
/* 마을 이동 목록(접속 표시를 누르면 그 아래에 열림) */
.map-menu {
  position: fixed; z-index: 30; width: min(280px, calc(100vw - 16px));
  background: #fff; border: 2px solid var(--ink); border-radius: 12px; box-shadow: 0 4px 0 var(--ink);
  padding: 8px; display: grid; gap: 6px;
}
.map-menu.hidden { display: none; }
.map-menu-title { font-weight: 700; font-size: 17px; padding: 0 2px; }
.map-menu .map-card:disabled { cursor: default; opacity: 1; }

#toast {
  position: absolute; top: 66px; left: 50%; transform: translate(-50%, -8px);
  max-width: calc(100vw - 32px); width: max-content;
  background: #fff; border: 2px solid var(--ink); border-radius: 12px; box-shadow: 0 3px 0 var(--ink);
  padding: 5px 16px; font-size: 20px; font-weight: 700; text-align: center;
  opacity: 0; transition: opacity 0.2s, transform 0.2s; pointer-events: none;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.big { background: var(--yellow); font-size: 23px; }

#actions {
  position: absolute; left: 50%; bottom: 74px; transform: translateX(-50%);
  background: #d9d9d5; border: 2px solid var(--ink); border-radius: 14px; box-shadow: 0 3px 0 var(--ink);
  padding: 4px 10px 10px; text-align: center; pointer-events: auto;
}
#actions.hidden { display: none; }
.act-name { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.act-name .love { color: var(--ink); font-size: 16px; letter-spacing: 1px; }
.act-row { display: flex; gap: 8px; }
.act-row button {
  width: 76px; height: 76px; font-family: inherit; font-weight: 700; font-size: 17px; color: var(--ink);
  background: #f3f3f0; border: 2px solid var(--ink); border-radius: 10px; box-shadow: 0 3px 0 var(--ink);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; cursor: pointer;
}
.act-row button:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.act-row svg { width: 38px; height: 38px; fill: none; stroke: var(--ink); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }

#chatForm { position: absolute; left: 12px; bottom: 12px; width: min(330px, calc(100vw - 24px)); pointer-events: auto; margin: 0; }
#chatInput {
  width: 100%; font-family: inherit; font-size: 18px; font-weight: 700; color: var(--ink);
  padding: 5px 12px; border: 2px solid var(--ink); border-radius: 10px; background: rgba(255, 255, 255, 0.92); outline: none;
  -webkit-user-select: text; user-select: text;
}
#chatInput:focus { background: #fff; box-shadow: 0 0 0 3px var(--yellow); }
#help { position: absolute; right: 12px; bottom: 12px; }

/* 모달 */
.modal {
  position: fixed; inset: 0; z-index: 10; padding: 16px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(251, 250, 244, 0.5);
}
.modal.hidden { display: none; }
.card {
  background: #fff; border: 2.5px solid var(--ink); border-radius: 16px; box-shadow: 0 5px 0 var(--ink);
  padding: 18px 22px 22px; width: 100%; max-width: 440px;
}
.intro-card h1 { margin: 0; font-size: 48px; line-height: 1.1; }
.intro-card h1::after { content: ''; display: block; width: 120px; height: 10px; margin-top: -10px; background: var(--yellow); position: relative; z-index: -1; }
.lead { font-size: 21px; margin: 10px 0 8px; line-height: 1.3; }
.how { margin: 0 0 14px; padding-left: 0; list-style: none; font-size: 17px; line-height: 1.35; }
.how li { margin: 4px 0; }
.how b { display: inline-block; background: var(--yellow); border: 1.5px solid var(--ink); border-radius: 6px; padding: 0 6px; margin-right: 6px; }
/* 마을 고르기 */
.map-pick-title { font-size: 18px; font-weight: 700; margin: 2px 0 6px; }
.map-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.map-card {
  font-family: inherit; text-align: left; cursor: pointer; color: var(--ink);
  background: #fff; border: 2px solid var(--ink); border-radius: 10px; padding: 6px 9px; box-shadow: 0 2px 0 var(--ink);
}
.map-card b { display: block; font-size: 17px; }
.map-card span { display: block; font-size: 13px; line-height: 1.2; }
.map-card.on { background: var(--yellow); }
.map-card:active { transform: translateY(1px); box-shadow: 0 1px 0 var(--ink); }
.intro-card { max-height: calc(100vh - 32px); overflow: auto; }
/* 폰 브라우저는 주소창·아래 막대가 화면을 가려서 100vh보다 실제로 보이는 높이(dvh)가 작음 → 그 높이에 맞춤 */
@supports (height: 100dvh) {
  .modal { height: 100dvh; }
  .intro-card, .dex-card { max-height: calc(100dvh - 32px); }
}
#nameInput {
  width: 100%; font-family: inherit; font-size: 21px; font-weight: 700; padding: 6px 12px; margin-bottom: 12px;
  border: 2px solid var(--ink); border-radius: 10px; outline: none; -webkit-user-select: text; user-select: text;
}
#nameInput:focus { box-shadow: 0 0 0 3px var(--yellow); }

.dex-card { max-width: 760px; max-height: calc(100vh - 32px); overflow: auto; }
.dex-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.dex-head h2 { margin: 0; font-size: 30px; }
.dex-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.dex-item { border: 2px solid var(--ink); border-radius: 12px; padding: 8px; text-align: center; background: var(--paper); }
.dex-item.unknown { opacity: 0.6; }
.dex-item canvas { display: block; margin: 0 auto; }
.dex-name { font-size: 22px; font-weight: 700; }
.dex-sub { font-size: 15px; }
.dex-desc { font-size: 15px; margin-top: 4px; line-height: 1.2; }

/* 오늘의 소원 */
.dex-progress { height: 14px; border: 2px solid var(--ink); border-radius: 8px; background: #fff; overflow: hidden; }
#dexBar { height: 100%; width: 0; background: var(--yellow); border-right: 2px solid var(--ink); transition: width 0.4s; }
.dex-subline { font-size: 16px; margin: 6px 0 10px; }
.act-row button[hidden] { display: none; }
/* 친밀도 */
.love-help { border: 2px dashed var(--ink); border-radius: 10px; padding: 4px 10px; margin: 0 0 10px; font-size: 16px; background: #fffdf2; }
.love-help summary { cursor: pointer; font-weight: 700; font-size: 17px; }
.love-help .h { color: var(--yellow); -webkit-text-stroke: 1px var(--ink); }
.love-help ul { margin: 6px 0 4px; padding-left: 18px; line-height: 1.35; }
.love-help b { background: var(--yellow); border-radius: 4px; padding: 0 3px; }
/* 수첩 칸 안의 구역 제목(친밀도 / 오늘의 미션) */
.dex-sec {
  display: inline-block; font-size: 14px; font-weight: 700; color: var(--ink);
  background: var(--yellow); border: 1.5px solid var(--ink); border-radius: 6px; padding: 0 7px; margin-bottom: 3px;
}
.dex-love { margin-top: 6px; padding-top: 6px; border-top: 1.5px dashed var(--ink); }
.dex-love .hearts { font-size: 20px; letter-spacing: 1px; }
.love-bar { height: 8px; border: 1.5px solid var(--ink); border-radius: 5px; background: #fff; overflow: hidden; margin: 3px 14px 0; }
.love-bar > div { height: 100%; background: var(--yellow); }
.love-note { font-size: 15px; font-weight: 700; color: var(--ink); margin-top: 2px; }
.dex-story { font-size: 14px; line-height: 1.3; margin-top: 5px; padding: 4px 6px; border-radius: 6px; background: #fff; border: 1.5px solid var(--ink); color: var(--ink); }
.love-help table { border-collapse: collapse; margin: 4px 0 6px; font-size: 15px; }
.love-help td { padding: 1px 8px 1px 0; vertical-align: top; }
.love-help td:first-child { white-space: nowrap; color: var(--ink); }
.cele-btn { display: block; margin: 0 auto 10px; background: var(--yellow); }
.cele-btn[hidden] { display: none; }
.dex-item { position: relative; }
.dex-item.unknown .dex-wish { opacity: 1; }
.dex-wish { margin-top: 6px; padding-top: 6px; border-top: 1.5px dashed var(--ink); font-size: 15px; line-height: 1.25; font-weight: 700; }
.dex-wish.muted { font-weight: 400; color: var(--ink); }
.dex-wish .dex-sec { display: table; margin: 0 auto 3px; }
.dex-love .dex-sec { display: table; margin: 0 auto 3px; }
.dex-steps { display: flex; flex-wrap: wrap; justify-content: center; gap: 2px 8px; margin-top: 3px; font-weight: 400; }
.dex-steps .ok { font-weight: 700; text-decoration: line-through; }
.dex-item.done { background: #fffbe0; }
.dex-stamp {
  position: absolute; top: 8px; right: 6px; transform: rotate(14deg);
  font-size: 18px; font-weight: 700; color: var(--ink); background: var(--yellow);
  border: 2.5px solid var(--ink); border-radius: 8px; padding: 0 6px; box-shadow: 0 2px 0 var(--ink);
}
.act-wish { font-size: 15px; font-weight: 400; line-height: 1.25; max-width: 250px; margin: 2px auto 0; }
.act-wish b { font-weight: 700; }
.act-wish.done { font-weight: 700; }

@media (max-width: 640px) {
  #help { display: none; }
  .sk-btn span { display: none; }
  #actions { bottom: 64px; }
  .act-row button { width: 68px; height: 68px; }
  .dex-grid { grid-template-columns: repeat(2, 1fr); }
  /* 첫 안내 창: 폰 한 화면에 들어오게 글씨·여백을 조금 줄임(넘치면 창 안에서 스크롤) */
  .modal { padding: 10px; }
  .card { padding: 14px 16px 16px; }
  .intro-card h1 { font-size: 38px; }
  .lead { font-size: 18px; margin: 6px 0; }
  .how { font-size: 15px; line-height: 1.3; margin-bottom: 10px; }
  .how li { margin: 3px 0; }
  .map-pick-title { font-size: 16px; }
  #nameInput { font-size: 18px; margin-bottom: 10px; }
  .sk-btn.big { font-size: 21px; }
}
