/* tub. 꽃글씨 — 미니멀 팝
   레이아웃: 화면 전체가 하나의 앱. 왼쪽(휴대폰은 위) 하늘색 판 위에 종이 사진 한 장, 오른쪽(휴대폰은 아래)에 입력과 도구.
   색은 세 가지만 아껴 씁니다: 하늘(판), 포피 레드(저장), 해바라기(작은 포인트). */
:root {
  --paper: #ffffff;
  --ink: #111111;
  --muted: #6f6f73;
  --line: #e6e6e3;
  --sky: #b9cdec;
  --sky-ink: #24324d;
  --poppy: #ee3524;
  --poppy-ink: #ffffff;
  --sun: #ffb81c;
  --font: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  --r-pill: 999px;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--paper); }
body { color: var(--ink); font-family: var(--font); font-size: 15px; line-height: 1.5; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; overflow: hidden; overscroll-behavior: none; word-break: keep-all; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- 앱 틀 (휴대폰 우선) ---------- */
.app {
  position: fixed; left: 0; right: 0; top: 0;
  height: var(--app-h, 100dvh);
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  grid-template-areas: "top" "stage" "tools" "composer";
  opacity: 0; transition: opacity .5s ease;
}
.app.ready { opacity: 1; }
.top { grid-area: top; display: flex; align-items: center; justify-content: space-between; padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 10px; }
.logo { height: 24px; width: auto; display: block; }
.top-r { display: flex; align-items: center; gap: 10px; }
.top .pill.save { height: 34px; padding: 0 16px; margin: 0; }
.icon-btn { width: 32px; height: 32px; border-radius: 50%; border: 0; background: var(--sun); color: var(--ink); font-weight: 800; font-size: 15px; line-height: 32px; cursor: pointer; padding: 0; transition: transform .15s ease; }
.icon-btn:active { transform: scale(.92); }

.stage-area { grid-area: stage; position: relative; min-height: 0; background: var(--sky); display: grid; place-items: center; overflow: hidden; touch-action: none; }
#stage { display: block; box-shadow: 0 1px 2px rgba(20, 30, 60, .12), 0 18px 36px -18px rgba(20, 30, 60, .45); }
.stage-area.editing #stage { cursor: grab; }
.stage-area.editing #stage:active { cursor: grabbing; }
.loading { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); margin: 0; padding: 6px 12px; border-radius: var(--r-pill); background: rgba(255, 255, 255, .85); color: var(--sky-ink); font-size: 12px; font-weight: 600; letter-spacing: .02em; white-space: nowrap; transition: opacity .4s ease; }
.loading.gone { opacity: 0; pointer-events: none; }

/* 배경 사진 편집 */
.edit { position: absolute; inset: 0; pointer-events: none; display: flex; flex-direction: column; justify-content: space-between; align-items: center; padding: 12px; }
.edit-hint { margin: 0; padding: 6px 12px; border-radius: var(--r-pill); background: var(--ink); color: #fff; font-size: 12px; font-weight: 600; }
.edit-bar { pointer-events: auto; display: flex; align-items: center; gap: 8px; padding: 6px; border-radius: var(--r-pill); background: #fff; box-shadow: 0 6px 20px -8px rgba(20, 30, 60, .45); max-width: 100%; }
.zoom { display: flex; align-items: center; gap: 8px; padding-left: 10px; font-size: 13px; font-weight: 600; }
.edit-bottom { display: flex; flex-direction: column; align-items: center; gap: 8px; max-width: 100%; pointer-events: none; }
.plate-bar { pointer-events: auto; display: flex; align-items: center; gap: 2px; padding: 4px; border-radius: var(--r-pill); background: #fff; box-shadow: 0 6px 20px -8px rgba(20, 30, 60, .45); max-width: 100%; }
.plate-bar button { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 11px; border: 0; border-radius: var(--r-pill); background: transparent; font-size: 13px; font-weight: 650; white-space: nowrap; cursor: pointer; }
.plate-bar button[aria-checked="true"] { background: var(--ink); color: #fff; }
.pi { display: inline-block; flex: none; width: 15px; height: 11px; border: 1.6px solid currentColor; }
.pi.none { width: 12px; height: 12px; border-radius: 50%; background: linear-gradient(135deg, transparent 43%, currentColor 43%, currentColor 57%, transparent 57%); }
.pi.sq { border-radius: 1px; }
.pi.rd { border-radius: 6px; }
.pi.tr { border-radius: 4px; border-style: dashed; background: color-mix(in srgb, currentColor 28%, transparent); }
.zoom input { width: clamp(80px, 26vw, 160px); accent-color: var(--ink); }

/* 입력 */
.composer { grid-area: composer; padding: 10px 16px calc(env(safe-area-inset-bottom, 0px) + 12px); background: var(--paper); border-top: 1px solid var(--line); }
.field { position: relative; display: flex; align-items: flex-end; gap: 10px; }
.field-cover { position: absolute; inset: 0; z-index: 2; border: 0; padding: 0; margin: 0; background: transparent; border-radius: inherit; cursor: text; }
.app.typing .field-cover { display: none; }
textarea {
  flex: 1; min-width: 0; resize: none; border: 0; outline: 0; background: transparent; color: var(--ink);
  font: 600 18px/1.4 var(--font); letter-spacing: -0.01em; padding: 6px 0; max-height: 4.4em; overflow-y: auto;
}
textarea::placeholder { color: #8d8d89; opacity: 1; }
.done-btn { display: none; flex: none; border: 0; border-radius: var(--r-pill); background: var(--ink); color: #fff; font-weight: 700; font-size: 14px; padding: 8px 14px; cursor: pointer; }
.note { margin: 4px 0 0; font-size: 12.5px; font-weight: 600; color: var(--ink); min-height: 0; }
.note::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--sun); margin-right: 6px; vertical-align: 1px; }
.note:empty { display: none; }

/* 도구 */
.tools { grid-area: tools; display: flex; flex-direction: column; gap: 8px; padding: 10px 16px; }
.tools-row { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.tools-row.two > .pill { flex: 1; }
/* 비율·저장 방식: 하나로 묶인 알약 (선택된 칸만 검정) */
.seg { display: inline-flex; flex: none; gap: 2px; padding: 2px; border: 1.5px solid var(--ink); border-radius: var(--r-pill); background: var(--paper); }
.seg .pill { border: 0; height: 32px; padding: 0 12px; }
.pill {
  flex: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 38px; padding: 0 13px; border-radius: var(--r-pill);
  border: 1.5px solid var(--ink); background: var(--paper); color: var(--ink);
  font-weight: 650; font-size: 14px; letter-spacing: -0.01em; cursor: pointer; white-space: nowrap;
  transition: transform .15s ease, background-color .15s ease, color .15s ease;
}
.pill:active { transform: scale(.95); }
.pill svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.pill[aria-checked="true"], .pill.dark { background: var(--ink); color: #fff; }
.pill.ghost { border-color: transparent; }
.pill.save { background: var(--poppy); border-color: var(--poppy); color: var(--poppy-ink); padding: 0 20px; }
.tools .pill.save { display: none; }
button:focus-visible { outline: 3px solid var(--sun); outline-offset: 2px; }
textarea:focus-visible { outline: none; }

/* 입력 중(휴대폰): 꽃이 키보드 위에 보이도록 위 머리와 도구를 접는다 */
@media (max-width: 899px) {
  .tools { gap: 7px; padding: 9px 12px 10px; }
  .tools .pill { height: 36px; padding: 0 12px; font-size: 13.5px; }
  .tools .seg .pill { height: 30px; padding: 0 10px; }
  .field { background: #f1f1ef; border-radius: 22px; padding: 4px 6px 4px 16px; align-items: center; }
  textarea { padding: 8px 0; }
  .app.typing .top, .app.typing .tools { display: none; }
  .app.typing .done-btn { display: inline-block; }
  .app.typing .stage-area { padding-top: env(safe-area-inset-top, 0px); }
  /* 키보드 높이를 알려 주지 않는 앱(인스타그램 등): 입력칸을 맨 위로, 꽃글씨는 그 아래 키보드 위쪽에 */
  .app.top-typing { grid-template-rows: auto minmax(0, 1fr); grid-template-areas: "composer" "stage"; }
  .app.top-typing .composer { border-top: 0; border-bottom: 1px solid var(--line); padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 10px; }
  .app.top-typing .stage-area { padding-top: 0; }
  html.typing-bg, html.typing-bg body { background: var(--sky); }
}

/* ---------- 넓은 화면 ---------- */
@media (min-width: 900px) {
  body { font-size: 15px; }
  .app {
    grid-template-columns: minmax(0, 1fr) clamp(340px, 30vw, 440px);
    grid-template-rows: auto auto minmax(0, 1fr);
    grid-template-areas: "stage top" "stage composer" "stage tools";
  }
  .top { padding: 28px 36px 0; }
  .logo { height: 30px; }
  .composer { border-top: 0; padding: 18vh 36px 0; }
  textarea { font-size: 34px; font-weight: 700; line-height: 1.25; letter-spacing: -0.025em; padding: 0 0 12px; border-bottom: 2px solid var(--ink); max-height: 5.2em; }
  .note { margin-top: 10px; font-size: 13px; }
  .tools { align-items: stretch; gap: 12px; padding: 28px 36px; }
  .tools-row { justify-content: flex-start; flex-wrap: wrap; }
  .tools-row.two > .pill { flex: 0 1 auto; }
  .seg { align-self: flex-start; }
  .tools .pill.save { display: inline-flex; margin: 6px 0 0; height: 52px; font-size: 16px; }
  .top .pill.save { display: none; }
  textarea:focus { border-bottom-color: var(--poppy); }
  .stage-area { padding: 6vh 6vw; }
}

/* ---------- 인트로: '텁'이 꽃으로 쓰였다가 사라집니다 ---------- */
.intro { position: fixed; inset: 0; z-index: 50; background: #f3f2ee; transition: opacity .7s ease, transform .9s cubic-bezier(.2, .7, .2, 1); }
.intro canvas { display: block; }
.intro.out { opacity: 0; transform: scale(1.04); pointer-events: none; }

/* ---------- 시트 (저장 · 정보) ---------- */
.sheet { border: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 560px; max-height: 92dvh; border-radius: 22px 22px 0 0; background: var(--paper); color: var(--ink); box-shadow: 0 -10px 40px rgba(0, 0, 0, .18); }
.sheet::backdrop { background: rgba(17, 17, 17, .45); }
.sheet[open] { animation: rise .28s cubic-bezier(.2, .8, .2, 1); }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (min-width: 900px) { .sheet { margin: auto; border-radius: 22px; } }
.sheet-in { padding: 18px 18px calc(env(safe-area-inset-bottom, 0px) + 18px); display: flex; flex-direction: column; gap: 14px; overflow-y: auto; max-height: 92dvh; }
.sheet-in > * { flex-shrink: 0; } /* 창이 길어지면 미리보기를 자르지 말고 창이 스크롤되게 */
.save-opts { display: flex; align-items: center; justify-content: space-between; gap: 10px 14px; flex-wrap: wrap; }
.pill.busy { opacity: .55; pointer-events: none; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2:focus { outline: none; }
.sheet-head h2 { margin: 0; font-size: 18px; font-weight: 800; letter-spacing: -0.02em; }
.sheet-head .icon-btn { background: var(--line); font-size: 20px; font-weight: 500; }
.preview { border-radius: 12px; overflow: hidden; background: var(--sky); display: grid; place-items: center; padding: 12px; }
.preview.cut { background-color: #fff; background-image: linear-gradient(45deg, #ececec 25%, transparent 25%), linear-gradient(-45deg, #ececec 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #ececec 75%), linear-gradient(-45deg, transparent 75%, #ececec 75%); background-size: 18px 18px; background-position: 0 0, 0 9px, 9px -9px, -9px 0; }
.preview > canvas, .preview > img { grid-area: 1 / 1; display: block; max-width: 100%; } /* 미리보기 그림 위에 같은 크기의 고화질 이미지가 준비되면 얹힌다 */
.checks { display: flex; gap: 16px; flex-wrap: wrap; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--ink); }
.save-main { display: flex; flex-direction: column; gap: 8px; }
.save-main .pill { height: 52px; font-size: 16px; }
.share-row { display: flex; gap: 8px; }
.share-row .pill { flex: 1; height: 46px; font-size: 15px; }
.pill.kakao { background: #fee500; border-color: #fee500; color: #191919; }
.pill.kakao svg { stroke: none; }
.pill.kakao svg .fill { fill: #191919; }
.link-row { display: flex; justify-content: center; gap: 18px; margin-top: -6px; }
.link-row:not(:has(> :not([hidden]))) { display: none; }
button.as-link { border: 0; background: none; font: inherit; cursor: pointer; }
.as-link { padding: 2px 4px; font-size: 13px; font-weight: 600; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; }
.hint { margin: 0; font-size: 12.5px; line-height: 1.55; color: var(--muted); }
/* 아이폰 안내: 아이폰 저장 창의 '이미지 저장' 줄을 닮은 칩으로 무엇을 고를지 보여 준다 */
.hint.guide { margin-top: -2px; text-align: center; font-size: 13.5px; font-weight: 600; line-height: 1.7; color: var(--ink); }
.hint.guide .sub { display: block; font-size: 12px; font-weight: 500; line-height: 1.5; color: var(--muted); }
.ios-pick { display: inline-flex; align-items: center; gap: 3px; margin: 0 1px; padding: 0 7px 0 5px; border-radius: 7px; background: var(--line); font-weight: 700; line-height: 1.6; white-space: nowrap; }
.ios-pick svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.wide-btn { width: 100%; height: 46px; text-decoration: none; }
.facts { margin: 0; padding-left: 18px; display: grid; gap: 6px; font-size: 14px; }
.shop { margin: 0; font-size: 13px; color: var(--muted); }
.credits summary { cursor: pointer; font-size: 13px; font-weight: 600; }
.credits ul { margin: 8px 0 0; padding-left: 18px; font-size: 11px; color: var(--muted); max-height: 30dvh; overflow: auto; }
.credits a { color: inherit; }

.toast { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom, 0px) + 90px); transform: translate(-50%, 10px); z-index: 60; padding: 10px 16px; border-radius: 20px; background: var(--ink); color: #fff; font-size: 13px; font-weight: 600; line-height: 1.45; text-align: center; width: max-content; max-width: min(calc(100vw - 32px), 440px); opacity: 0; pointer-events: none; transition: opacity .2s ease, transform .2s ease; } /* 긴 안내는 화면 밖으로 나가지 않고 두 줄로 */
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.sheet .toast { bottom: auto; top: calc(env(safe-area-inset-top, 0px) + 14px); transform: translate(-50%, -10px); } /* 저장 창 위에서는 화면 맨 위에 */
.sheet .toast.show { transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; } }
