/* =====================================================================
   토박이말 마을 — 바탕 꾸밈
   빛깔은 단청에서, 바탕은 한지에서 가져왔습니다.
   화면은 늘 한 판에 딱 들어오게 짰습니다 (스크롤이 생기지 않습니다).
   ===================================================================== */

:root {
  /* 단청 빛깔 */
  --paper:   #F2E8D5;   /* 한지 */
  --paper-2: #E6D8BC;
  --paper-3: #D8C6A2;
  --white:   #FCF8F0;   /* 호분 */
  --ink:     #2A2520;   /* 먹 */
  --ink-2:   #5D5248;
  --ink-3:   #8E8175;

  --jjok:    #1F4E79;   /* 쪽빛 */
  --jjok-2:  #16395A;
  --jjok-lt: #DCE7F0;
  --dahong:  #C8442C;   /* 다홍 */
  --dahong-2:#9C2F1C;
  --dahong-lt:#F8E2DC;
  --chija:   #E0A526;   /* 치자 */
  --chija-2: #B07F12;
  --chija-lt:#FBEFCF;
  --nok:     #3E7D4E;   /* 풀빛 */
  --nok-2:   #2C5C39;
  --nok-lt:  #E0F0E4;
  --namu:    #8A5A32;   /* 나무 */
  --namu-2:  #6B4526;
  --dol:     #7D8790;   /* 돌 */

  --lv1: var(--nok);
  --lv2: var(--jjok);
  --lv3: #7B4B94;

  --r-s: 8px;
  --r-m: 14px;
  --r-l: 22px;

  --shadow:   0 2px 0 rgba(42,37,32,.14), 0 6px 18px rgba(90,70,40,.10);
  --shadow-lg:0 4px 0 rgba(42,37,32,.16), 0 22px 44px rgba(90,70,40,.20);

  --font: 'Pretendard', 'Pretendard Variable', -apple-system, BlinkMacSystemFont,
          'Apple SD Gothic Neo', 'Malgun Gothic', '맑은 고딕', 'Noto Sans KR', sans-serif;

  --gap: clamp(8px, 2.2vh, 16px);
  --pad: clamp(12px, 3.4vw, 22px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  height: 100%;
  overflow: hidden;                   /* 쪽 전체는 절대 구르지 않습니다 */
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: clamp(15px, 1.9vh, 17px);
  line-height: 1.5;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

/* 한지 결 — 바깥에서 받아 오지 않고 그 자리에서 그립니다 */
body::before {
  content: ''; position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)' opacity='.42'/%3E%3C/svg%3E");
  mix-blend-mode: multiply;
  opacity: .22;
}
/* 한지 섬유 결 */
body::after {
  content: ''; position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    repeating-linear-gradient(94deg, rgba(150,120,70,.05) 0 1px, transparent 1px 7px),
    repeating-linear-gradient(2deg, rgba(150,120,70,.04) 0 1px, transparent 1px 11px);
}

button { font-family: inherit; font-size: inherit; color: inherit; cursor: pointer; border: none; background: none; padding: 0; }
input  { font-family: inherit; font-size: inherit; color: inherit; }
svg.ico { display: block; }
svg.kid { display: block; }

/* ── 놀이터 뼈대 : 늘 한 화면 ─────────────────────────────────────── */
/* 손전화에 맞춰 짠 폭입니다. 넓은 화면에서는 가운데에 세워 둡니다. */
#app {
  position: relative; z-index: 1;
  height: 100vh; height: 100dvh;
  width: 100%; max-width: 560px; margin: 0 auto;
  display: flex; flex-direction: column;
  overflow: hidden;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
/* 넓은 화면에서는 마을이 한 폭 그림처럼 보이게 테를 둘러 줍니다 */
@media (min-width: 620px) {
  body { background: #E6DAC2; }
  #app {
    background: var(--paper);
    box-shadow: 0 0 0 1px rgba(42,37,32,.08), 0 18px 60px rgba(70,50,20,.18);
  }
  body::before, body::after { display: none; }
  #app::before {
    content: ''; position: absolute; inset: 0; z-index: 0; pointer-events: none;
    background-image:
      url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)' opacity='.42'/%3E%3C/svg%3E");
    mix-blend-mode: multiply; opacity: .2;
  }
  #app > * { position: relative; z-index: 1; }
}
.screen {
  position: relative;
  flex: 1; min-height: 0;
  display: flex; flex-direction: column;
  padding: 0 var(--pad);
  animation: rise .26s cubic-bezier(.2,.9,.3,1);
}
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* 안에서만 구르는 칸 */
.sheet { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.sheet::-webkit-scrollbar { width: 7px; }
.sheet::-webkit-scrollbar-thumb { background: var(--paper-3); border-radius: 4px; }

/* ── 위쪽 띠 ─────────────────────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: clamp(8px, 1.8vh, 14px) 0 clamp(6px, 1.4vh, 10px);
  flex: none;
}
.topbar h1 {
  font-size: clamp(17px, 2.6vh, 21px); margin: 0; flex: 1;
  letter-spacing: -.03em; font-weight: 800;
}
.topbar h1 .sub {
  font-size: .68em; color: var(--ink-3); font-weight: 700; margin-left: 6px;
}

.icon-btn {
  width: clamp(36px, 5.4vh, 42px); height: clamp(36px, 5.4vh, 42px);
  border-radius: 50%; flex: none;
  display: grid; place-items: center; color: var(--ink-2);
  background: var(--white); box-shadow: var(--shadow);
  transition: transform .12s;
}
.icon-btn:active { transform: scale(.9); }

/* ── 단추 : 나무 팻말 느낌 ───────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: clamp(11px, 1.7vh, 15px) clamp(18px, 4vw, 26px);
  border-radius: var(--r-m);
  background: var(--jjok); color: var(--white);
  font-weight: 800; font-size: clamp(15px, 2.1vh, 17px); letter-spacing: -.02em;
  box-shadow: 0 4px 0 var(--jjok-2), var(--shadow);
  transition: transform .1s, box-shadow .1s;
  position: relative;
}
.btn::after {                       /* 단청 테두리 한 겹 */
  content: ''; position: absolute; inset: 3px; border-radius: calc(var(--r-m) - 3px);
  border: 1.5px solid rgba(255,255,255,.22); pointer-events: none;
}
.btn:active { transform: translateY(4px); box-shadow: 0 0 0 var(--jjok-2); }
.btn.ghost  { background: var(--white); color: var(--ink); box-shadow: 0 4px 0 var(--paper-3), var(--shadow); }
.btn.ghost::after { border-color: rgba(42,37,32,.07); }
.btn.ghost:active { box-shadow: 0 0 0 var(--paper-3); }
.btn.warm   { background: var(--dahong); box-shadow: 0 4px 0 var(--dahong-2), var(--shadow); }
.btn.warm:active { box-shadow: 0 0 0 var(--dahong-2); }
.btn.gold   { background: var(--chija); color: #3D2A00; box-shadow: 0 4px 0 var(--chija-2), var(--shadow); }
.btn.gold:active { box-shadow: 0 0 0 var(--chija-2); }
.btn.wide   { width: 100%; }
.btn.small  { padding: 9px 16px; font-size: clamp(13px, 1.7vh, 15px); border-radius: var(--r-s); box-shadow: 0 3px 0 var(--paper-3); }
.btn[disabled] { opacity: .45; pointer-events: none; }

/* ── 나무 판 ─────────────────────────────────────────────────────── */
.card {
  background: var(--white); border-radius: var(--r-l);
  box-shadow: var(--shadow); padding: var(--pad);
  position: relative;
}

/* ── 붓글씨 제목 ─────────────────────────────────────────────────── */
.brush {
  font-weight: 900; letter-spacing: -.045em;
  text-shadow: .5px .5px 0 rgba(42,37,32,.16);
}

/* ── 알림 쪽지 ───────────────────────────────────────────────────── */
#toast-layer {
  position: fixed; left: 0; right: 0; bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 300;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: none; padding: 0 16px;
}
.toast {
  background: var(--ink); color: var(--white);
  font-weight: 700; font-size: clamp(13.5px, 1.8vh, 15px);
  padding: 11px 20px; border-radius: 999px; box-shadow: var(--shadow-lg);
  animation: toast-in .22s cubic-bezier(.2,1.2,.4,1); max-width: 100%;
  text-align: center; word-break: keep-all;
}
.toast.good { background: var(--nok); }
.toast.bad  { background: var(--dahong); }
@keyframes toast-in { from { opacity: 0; transform: translateY(14px) scale(.94); } to { opacity: 1; transform: none; } }

/* ── 덮개 창 ─────────────────────────────────────────────────────── */
#modal-layer {
  position: fixed; inset: 0; z-index: 250;
  background: rgba(42,37,32,.5); backdrop-filter: blur(3px);
  display: grid; place-items: center; padding: 18px;
  animation: fade .18s;
}
#modal-layer[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--white); border-radius: var(--r-l); box-shadow: var(--shadow-lg);
  width: min(440px, 100%); max-height: 86dvh; overflow-y: auto;
  padding: clamp(18px, 4vw, 26px);
  animation: pop .24s cubic-bezier(.2,1.3,.4,1);
  border-top: 5px solid var(--chija);
}
@keyframes pop { from { transform: scale(.9) translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal h2 { margin: 0 0 4px; font-size: clamp(19px, 2.9vh, 23px); letter-spacing: -.03em; }
.modal .modal-sub { color: var(--ink-2); font-size: clamp(13.5px, 1.8vh, 15px); margin: 0 0 16px; word-break: keep-all; }
.modal-btns { display: flex; gap: 10px; margin-top: 18px; }
.modal-btns .btn { flex: 1; }

/* ── 난이도 딱지 ─────────────────────────────────────────────────── */
.tag {
  display: inline-block; padding: 3px 11px; border-radius: 999px;
  font-size: clamp(11.5px, 1.5vh, 13px); font-weight: 800;
}
.tag.lv1 { background: var(--nok-lt);  color: var(--nok-2); }
.tag.lv2 { background: var(--jjok-lt); color: var(--jjok-2); }
.tag.lv3 { background: #F1E6F7;        color: #5E3872; }

/* ── 진행 막대 ───────────────────────────────────────────────────── */
.bar {
  height: 9px; border-radius: 999px; background: var(--paper-2);
  overflow: hidden; box-shadow: inset 0 1px 2px rgba(42,37,32,.12);
}
.bar > i { display: block; height: 100%; border-radius: 999px; background: var(--nok); transition: width .45s cubic-bezier(.2,.9,.3,1); }
.bar.lv1 > i { background: var(--nok); }
.bar.lv2 > i { background: var(--jjok); }
.bar.lv3 > i { background: var(--lv3); }

/* ── 글쓰기 칸 ───────────────────────────────────────────────────── */
.field { display: block; margin-bottom: 11px; }
.field span { display: block; font-size: clamp(12.5px, 1.6vh, 14px); font-weight: 700; color: var(--ink-2); margin-bottom: 5px; }
.field input {
  width: 100%; padding: clamp(10px, 1.6vh, 13px) 14px; border-radius: var(--r-m);
  border: 2px solid var(--paper-3); background: var(--paper);
  outline: none; font-weight: 600; transition: border-color .15s;
}
.field input:focus { border-color: var(--jjok); background: var(--white); }

/* ── 자잘한 것 ───────────────────────────────────────────────────── */
.center { text-align: center; }
.muted  { color: var(--ink-2); }
.faint  { color: var(--ink-3); }
.tiny   { font-size: clamp(11.5px, 1.5vh, 13px); }
.stack  { display: flex; flex-direction: column; gap: 10px; }
.row    { display: flex; align-items: center; gap: 10px; }
.spacer { flex: 1; }
.big-num {
  font-size: clamp(28px, 4.6vh, 40px); font-weight: 900; line-height: 1;
  letter-spacing: -.05em; font-variant-numeric: tabular-nums;
}
.hr { height: 1px; background: var(--paper-3); margin: 14px 0; border: 0; }

/* 톡톡 튀는 조각 */
.spark {
  position: fixed; width: 8px; height: 8px; border-radius: 50%;
  pointer-events: none; z-index: 400;
  animation: spark .7s cubic-bezier(.2,.7,.4,1) forwards;
}
@keyframes spark {
  from { transform: translate(0,0) scale(1); opacity: 1; }
  to   { transform: translate(var(--dx), var(--dy)) scale(0); opacity: 0; }
}

/* 움직임을 싫어하는 이를 위해 */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
