/* 폰트공방 — 말랑말랑 파스텔 테마 🌸 */
:root {
  --bg1: #fff4fb;   /* 블러쉬 */
  --bg2: #f1ecff;   /* 라벤더 */
  --bg3: #e7faf4;   /* 민트 틴트 */
  --card: #ffffff;
  --line: #ffd7ec;         /* 소프트 핑크 테두리 */
  --line2: #ececff;        /* 라벤더 테두리 */
  --text: #6a5566;         /* 따뜻한 플럼 그레이 */
  --dim: #b6a2b6;
  --accent: #ff7eb6;       /* 캔디 핑크 */
  --accent-deep: #ff579d;
  --lav: #a98cff;          /* 라벤더 */
  --mint: #45d3b4;         /* 민트 */
  --peach: #ffb073;        /* 피치 */
  --ink: #5b4a63;          /* 캔버스 잉크 */
  --shadow: 0 12px 30px rgba(255, 138, 190, .22);
  --shadow-sm: 0 6px 16px rgba(255, 138, 190, .18);
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
}
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  background:
    radial-gradient(900px 500px at 12% -8%, #ffe3f3 0%, transparent 55%),
    radial-gradient(900px 520px at 92% 0%, #e6dcff 0%, transparent 55%),
    radial-gradient(1000px 700px at 50% 115%, #d7fbef 0%, transparent 60%),
    linear-gradient(160deg, var(--bg1) 0%, var(--bg2) 55%, var(--bg3) 100%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}

#app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 780px;
  margin: 0 auto;
}

/* ---------- 상단바 ---------- */
.appbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(12px + var(--sat)) 20px 10px;
}
.appbar h1 {
  font-size: 22px; letter-spacing: -.5px; font-weight: 800; color: var(--text);
  cursor: pointer; outline: none;
  transition: transform .12s cubic-bezier(.34,1.56,.64,1);
}
.appbar h1:active { transform: scale(.94); }
.appbar h1::before { content: "🌸 "; }
.appbar h1 em {
  font-style: normal;
  background: linear-gradient(90deg, var(--accent), var(--lav));
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
}
.pill {
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 999px;
  padding: 6px 16px;
  font-size: 13px;
  color: var(--accent-deep);
  font-weight: 800;
  box-shadow: var(--shadow-sm);
}

/* ---------- 화면 ---------- */
main { flex: 1; min-height: 0; }
.view { display: none; height: 100%; }
.view.on { display: flex; flex-direction: column; }
.scroller {
  overflow-y: auto;
  height: 100%;
  padding: 6px 20px calc(16px + var(--sab));
  -webkit-user-select: text;
  user-select: text;
}
h2 { font-size: 14px; color: var(--dim); font-weight: 700; margin: 18px 0 8px; }
h2:first-child { margin-top: 6px; }
.dim { color: var(--dim); font-weight: 500; }

button {
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 16px;
  color: var(--text);
  padding: 11px 16px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  box-shadow: var(--shadow-sm);
  transition: transform .12s cubic-bezier(.34,1.56,.64,1), box-shadow .15s, background .15s;
}
button:active { transform: scale(.94); }
button.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-deep));
  border-color: transparent; color: #fff; font-weight: 800;
  box-shadow: 0 10px 22px rgba(255, 87, 157, .35);
}
button.mint {
  background: linear-gradient(135deg, #6be7cb, var(--mint));
  border-color: transparent; color: #fff; font-weight: 800;
  box-shadow: 0 10px 22px rgba(69, 211, 180, .35);
}
button.toggled {
  background: linear-gradient(135deg, #fff0f7, #ffe1ef);
  border-color: var(--accent); color: var(--accent-deep); font-weight: 800;
}

input[type=text], textarea {
  width: 100%;
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 16px;
  color: var(--text);
  padding: 12px 15px;
  font-size: 15px;
  outline: none;
  font-family: inherit;
  box-shadow: var(--shadow-sm);
}
input[type=text]:focus, textarea:focus { border-color: var(--accent); }

/* ---------- 그리기 화면 ---------- */
#view-draw { padding: 0 16px calc(8px + var(--sab)); gap: 12px; }
.drawHead {
  display: flex; align-items: center; justify-content: center; gap: 22px;
  padding-top: 4px;
}
/* 캔버스 좌우 이동 버튼 — 세로로 긴 캡슐. 길쭉한 화살표와 맞춤 */
.navArrow {
  line-height: 1;
  width: 66px; height: 170px;
  align-self: center;              /* 캔버스 옆 세로 가운데 */
  background: linear-gradient(180deg, #fff, #fff8fc);
  border: 2px solid var(--line);
  border-radius: 999px;            /* 완전 둥근 캡슐 */
  box-shadow: var(--shadow-sm);
  color: var(--accent-deep);
  display: flex; align-items: center; justify-content: center;
  padding: 0;
  flex: 0 0 auto;                  /* 캔버스 옆에서 찌그러지지 않게 */
}
/* viewBox(24×84=3.5)와 같은 비율로 그려야 획 두께가 일그러지지 않는다 */
.navArrow svg { width: 22px; height: 77px; }
.navArrow:active {
  transform: scale(.93);
  background: linear-gradient(180deg, #fff0f7, #ffe4f0);
  border-color: var(--accent);
}
/* 좁은 화면(폰)에선 버튼을 줄여 캔버스가 최소 크기 아래로 밀리지 않게 */
@media (max-width: 560px) {
  .navArrow { width: 44px; height: 128px; }
  .navArrow svg { width: 16px; height: 56px; }
  .canvasRow { gap: 4px; }
}

/* 캔버스 + 좌우 이동 버튼 한 줄.
   stretch 여야 .canvasWrap이 세로로 꽉 차서 캔버스 크기 계산이 맞는다. */
.canvasRow {
  flex: 1; min-height: 0;
  display: flex; align-items: stretch; justify-content: center;
  gap: 10px;
}
.charBadge {
  text-align: center; min-width: 96px;
  background: #fff; border: 2px solid var(--line2);
  border-radius: 20px; padding: 6px 14px 8px;
  box-shadow: var(--shadow-sm);
}
.charBadge #curChar {
  font-size: 40px; font-weight: 900; line-height: 1.1;
  background: linear-gradient(135deg, var(--accent), var(--lav));
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
}
.charBadge #curCat { font-size: 11px; color: var(--dim); font-weight: 700; }

.canvasWrap {
  flex: 1; min-height: 0;
  min-width: 0;   /* flex 기본 min-width:auto면 캔버스 크기에 밀려 가로 넘침 */
  display: flex; align-items: center; justify-content: center;
}
#drawCanvas {
  background: #fffdff;
  border: 3px solid #fff;
  border-radius: 28px;
  touch-action: none;
  cursor: crosshair;
  box-shadow: 0 18px 44px rgba(255, 130, 185, .28), 0 0 0 4px #ffe6f2;
}

.toolbar { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.brushRow {
  display: flex; align-items: center; gap: 10px; justify-content: center;
  font-size: 11px; color: var(--dim); font-weight: 700;
}
.brushRow input { flex: 1; max-width: 280px; accent-color: var(--accent); }
.gapRow { justify-content: flex-start; margin-top: 2px; }
.gapRow input { max-width: none; }

.bigNext {
  background: linear-gradient(135deg, var(--accent), var(--accent-deep));
  border-color: transparent;
  color: #fff;
  font-weight: 900;
  font-size: 16px;
  padding: 15px;
  border-radius: 20px;
  box-shadow: 0 12px 26px rgba(255, 87, 157, .38);
}

/* ---------- 글자 목록 ---------- */
#hangulReady {
  color: var(--mint); font-size: 12px; margin-left: 6px; font-weight: 800;
}
.tabs { display: flex; gap: 7px; flex-wrap: wrap; margin-bottom: 12px; }
.tab {
  padding: 8px 15px; font-size: 13px; border-radius: 999px; font-weight: 700;
}
.tab.on {
  background: linear-gradient(135deg, var(--accent), var(--lav));
  border-color: transparent; color: #fff;
  box-shadow: 0 8px 18px rgba(169, 140, 255, .32);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(58px, 1fr));
  gap: 9px;
}
.cell {
  position: relative;
  border: 2px solid var(--line2);
  border-radius: 16px;
  aspect-ratio: 1;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  background: #fff;
  box-shadow: var(--shadow-sm);
  transition: transform .12s;
}
.cell:active { transform: scale(.94); }
.cell canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.cell span { position: relative; font-size: 22px; color: #e6c9dc; pointer-events: none; font-weight: 700; }
.cell.done span { color: transparent; }
.cell.done { border-color: rgba(69, 211, 180, .55); background: #f4fffb; }
.cell.sel { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255, 126, 182, .3); }

/* ---------- 폰트 화면 ---------- */
textarea { height: 76px; resize: none; }
#previewOut {
  min-height: 140px;
  border: 2px solid var(--line);
  border-radius: 16px;
  margin-top: 10px;
  padding: 18px;
  font-size: 34px;
  line-height: 1.45;
  word-break: break-all;
  background: #fff;
  color: var(--text);
  box-shadow: var(--shadow-sm);
}
#previewOut .nd { color: #d4c2d0; }
.scopeRow { display: flex; gap: 16px; margin: 14px 0 4px; font-size: 14px; color: var(--text); flex-wrap: wrap; }
.scopeRow label { display: flex; align-items: center; gap: 6px; cursor: pointer; font-weight: 600; }
input[type=radio] { accent-color: var(--accent); width: 18px; height: 18px; }
.btnCol { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.btnCol button { width: 100%; padding: 16px; font-size: 15px; border-radius: 16px; }
#status { font-size: 13px; color: var(--accent-deep); margin-top: 8px; min-height: 18px; font-weight: 700; }
.hint { font-size: 12px; color: var(--dim); line-height: 1.7; margin-top: 10px; font-weight: 500; }
button.danger {
  display: inline-flex; align-items: center;
  margin-top: 16px;
  background: #fff; border: 2px solid #ffc2d6;
  color: #ff4f86; font-weight: 700; font-size: 13px;
}
button.danger:active { background: #fff0f5; }

/* ---------- 하단 탭바 ---------- */
.tabbar {
  display: flex;
  border-top: 2px solid #ffe6f2;
  background: rgba(255, 255, 255, .82);
  backdrop-filter: blur(16px);
  padding-bottom: var(--sab);
}
.tabbar button {
  flex: 1;
  background: none; border: none; border-radius: 0; box-shadow: none;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 11px 0 9px;
  color: var(--dim);
  font-size: 11px; font-weight: 700;
}
.tabbar button i { font-style: normal; display: flex; transition: transform .18s cubic-bezier(.34,1.56,.64,1); }
.tabbar button i svg { width: 25px; height: 25px; }
.tabbar button.on { color: var(--accent-deep); }
.tabbar button.on i { transform: translateY(-2px) scale(1.15); }
.tabbar button:active { transform: none; }

/* 버튼 안 인라인 아이콘 */
.ic { width: 17px; height: 17px; vertical-align: -3.5px; margin-right: 6px; }
