:root {
  --bg: #ffffff;
  --ink: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --soft: #f3f4f6;
  --ok: #15803d;
  --err: #dc2626;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Pretendard", "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: 520px; margin: 0 auto; padding: 14px 16px 64px; }
.hidden { display: none !important; }

h1 { font-size: 22px; letter-spacing: -.01em; margin: 0; }
h2 { font-size: 17px; margin: 0; }
.sub { color: var(--muted); margin: 8px 0 22px; }
.notice { color: var(--muted); font-size: 12px; margin: 20px 0 0; line-height: 1.65; }
.back { display: inline-block; margin: 2px 0 14px; color: var(--muted); font-size: 14px; text-decoration: none; }
.back:hover { color: var(--ink); }

/* ---------- 상단 메뉴 ---------- */
.nav { display: flex; align-items: center; gap: 4px; margin-bottom: 18px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.nav a {
  padding: 7px 14px; border-radius: 999px; color: var(--muted);
  text-decoration: none; font-size: 14px; font-weight: 600;
}
.nav a:hover { background: var(--soft); }
.nav a.on { background: var(--ink); color: #fff; }
.nav .btn { margin-left: auto; }

/* ---------- 패널 / 폼 ---------- */
.panel {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 14px;
}
.sec { font-size: 15px; margin: 0 0 16px; font-weight: 700; }
.sec em { font-style: normal; font-weight: 500; font-size: 12px; color: var(--muted); margin-left: 6px; }

.field { display: block; margin-bottom: 18px; }
.field.last { margin-bottom: 0; }
.field > span { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.field small, .hint { display: block; color: var(--muted); font-size: 12px; margin-top: 5px; }
.hint { margin-top: 8px; }

input[type="text"] {
  width: 100%;
  font: inherit;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
}
textarea {
  width: 100%;
  font: inherit;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  resize: vertical;
  min-height: 78px;
  line-height: 1.45;
}
textarea:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px rgba(17, 24, 39, .08); }
input[type="text"]::placeholder, textarea::placeholder { color: #9ca3af; }
input[type="text"]:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px rgba(17, 24, 39, .08); }
.field > input[type="text"] { margin-top: 0; }
.field > input[type="file"] + small + input[type="text"] { margin-top: 8px; }

input[type="file"] { font-size: 13px; max-width: 100%; }

.block-row { display: grid; grid-template-columns: 1fr 2fr; gap: 8px; margin-bottom: 8px; }

.msg { margin: 12px 0 0; font-size: 14px; color: var(--muted); min-height: 1.4em; }
.msg.ok { color: var(--ok); }
.msg.err, .error { color: var(--err); }
.error { margin-top: 12px; font-size: 14px; min-height: 1.4em; }

.frame-label { font-size: 12px; color: var(--muted); margin: 0 0 6px; }
.card-frame, .banner-frame { margin-bottom: 16px; }

/* ---------- 버튼 ---------- */
.btn {
  display: inline-block;
  font: inherit;
  font-size: 14px;
  text-align: center;
  text-decoration: none;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 10px 16px;
  border-radius: 10px;
  cursor: pointer;
}
.btn:hover { background: var(--soft); }
.btn.primary { background: var(--ink); border-color: var(--ink); color: #fff; font-weight: 600; width: 100%; padding: 12px 16px; font-size: 15px; }
.btn.primary:hover { background: #000; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--soft); }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }

/* ---------- 템플릿 칩 ---------- */
.swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
.swatch {
  height: 46px;
  border-radius: 12px;
  border: 1px solid rgba(0, 0, 0, .08);
  font: inherit; font-size: 12px; font-weight: 600;
  cursor: pointer;
}
.swatch.tone-light { color: #1f2937; }
.swatch.tone-dark { color: #fff; }
.swatch-free { background: conic-gradient(from 200deg, #ff7e5f, #feb47b, #86a8e7, #7f7fd5, #ff7e5f); }
.swatch.on { outline: 2px solid var(--ink); outline-offset: 2px; }

/* ---------- 자유 디자인 ---------- */
.free { border-top: 1px solid var(--line); padding-top: 16px; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg-btn {
  font: inherit; font-size: 13px; font-weight: 600;
  padding: 7px 12px; border-radius: 999px;
  border: 1px solid var(--line); background: #fff; color: var(--muted);
  cursor: pointer;
}
.seg-btn.on { background: var(--ink); border-color: var(--ink); color: #fff; }

.colors { display: flex; gap: 12px; flex-wrap: wrap; }
.color { display: flex; align-items: center; gap: 10px; flex: 1 1 200px; border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; }
.color span { flex: 1; font-size: 13px; font-weight: 600; }
.color input[type="color"] { width: 44px; height: 34px; padding: 0; border: 0; border-radius: 8px; background: none; cursor: pointer; }

/* ---------- 명함 카드 (가로형 7:4) ---------- */
.card {
  position: relative;
  --fg: #1f2937;
  --fg-sub: rgba(31, 41, 55, .62);
  --chip: rgba(255, 255, 255, .62);
  --ring: #ffffff;
  --avatar-bg: rgba(255, 255, 255, .5);

  container-type: inline-size;
  aspect-ratio: 7 / 4;
  width: 100%;
  display: grid;
  grid-template-columns: 29% 1fr;
  gap: 3.6%;
  padding: 5%;
  border-radius: 20px;
  color: var(--fg);
  line-height: 1.3;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .07), 0 14px 34px -12px rgba(17, 24, 39, .28);
  overflow: hidden;
}
.card.tone-dark {
  --fg: #ffffff;
  --fg-sub: rgba(255, 255, 255, .74);
  --chip: rgba(0, 0, 0, .28);
  --ring: rgba(255, 255, 255, .85);
  --avatar-bg: rgba(255, 255, 255, .18);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .08), 0 14px 34px -12px rgba(17, 24, 39, .45);
}

.c-avatar {
  align-self: start;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  overflow: hidden;
  background: var(--avatar-bg);
  border: 2px solid var(--ring);
}
.c-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.c-avatar img:not([src]) { visibility: hidden; }

.c-main { min-width: 0; display: flex; flex-direction: column; }
.c-nick { font-size: 5.6cqw; font-weight: 700; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.c-handle { font-size: 3cqw; color: var(--fg-sub); }
.c-bio { font-size: 3.3cqw; margin-top: 1.8cqw; white-space: pre-line; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; }

.c-blocks { list-style: none; margin: auto 0 0; padding: 0; display: flex; flex-direction: column; gap: 1.1cqw; }
.c-blocks li {
  display: flex; gap: 1.8cqw; align-items: baseline;
  font-size: 2.9cqw;
  line-height: 1.25;
  background: var(--chip);
  border-radius: 1.8cqw;
  padding: .9cqw 2.2cqw;
  min-width: 0;
}
.c-blocks .b-label { font-weight: 700; opacity: .75; flex: none; }
.c-blocks .b-value { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.c-blocks a { color: inherit; text-decoration: underline; }

/* ---------- 배너 (1.91:1 섬네일 + 제목/링크) ---------- */
.banner {
  container-type: inline-size;
  display: block;
  position: relative;
  aspect-ratio: 1.91 / 1;
  width: 100%;
  border-radius: 16px;
  overflow: hidden;
  background: linear-gradient(135deg, #f3f4f6, #e5e7eb);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .06);
  color: inherit;
  text-decoration: none;
}
.banner img { width: 100%; height: 100%; object-fit: cover; display: block; }
.banner img:not([src]) { visibility: hidden; }
.banner-empty { display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 14px; aspect-ratio: auto; height: 84px; }

.b-info {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 3cqw 4cqw;
  background: linear-gradient(to top, rgba(0, 0, 0, .64), rgba(0, 0, 0, 0));
  color: #fff;
}
.b-title { font-size: 5cqw; font-weight: 700; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.b-url { font-size: 3.2cqw; opacity: .85; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- 명함 보기 화면 ---------- */
.actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.actions .btn { flex: 1; }
.actions .btn.primary { flex: 1 0 100%; }
.done { margin: 0; font-weight: 700; color: var(--ok); flex: 1 0 100%; }

.addr { flex: 1 0 100%; display: flex; align-items: center; gap: 10px; margin-top: 2px; color: var(--muted); font-size: 13px; }
.addr span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.addr .btn { flex: none; }

.people { margin-top: 26px; padding-top: 20px; border-top: 1px solid var(--line); }
.people h2 { margin-bottom: 12px; }

/* ---------- 명함지갑 ---------- */
.wallet-head { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.wallet-head input {
  font-size: 22px; font-weight: 700; letter-spacing: -.01em;
  border: 1px solid transparent; background: transparent; padding: 6px 8px; margin-left: -8px;
}
.wallet-head input:hover { border-color: var(--line); }
.wallet-count { color: var(--muted); font-size: 14px; white-space: nowrap; }

.toggle { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); margin: 2px 0 4px; cursor: pointer; }
.toggle input { width: 16px; height: 16px; accent-color: var(--ink); }

.stack { display: flex; flex-direction: column; gap: 26px; margin-top: 18px; }
.slide { min-width: 0; }
.slide-row { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.slide-who { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.slide-who span { color: var(--muted); }
.empty { color: var(--muted); font-size: 14px; padding: 24px 4px; }

/* ---------- 시작 화면 ---------- */
.welcome { min-height: 72vh; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 14px; }
.welcome .logo { font-size: 64px; font-weight: 800; letter-spacing: .06em; line-height: 1; }
.welcome .tagline { margin: 0 0 18px; color: var(--muted); font-size: 16px; }
.welcome .btn.primary { width: auto; min-width: 200px; }
.inapp { background: #fff7ed; border: 1px solid #fed7aa; color: #9a3412; border-radius: 10px; padding: 10px 12px; font-size: 13px; line-height: 1.55; margin: 14px 0 0; }

/* ---------- 스티커 ---------- */
.sticker { position: absolute; height: auto; max-width: none; z-index: 2; pointer-events: none; user-select: none; -webkit-user-drag: none; }
.sticker.editable { pointer-events: auto; cursor: grab; touch-action: none; outline: 1px dashed rgba(17, 24, 39, .35); outline-offset: 2px; }
.sticker.editable:active { cursor: grabbing; }

.sticker-list { margin-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.sticker-row { display: flex; align-items: center; gap: 12px; border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; }
.sticker-thumb { width: 44px; height: 44px; object-fit: contain; border-radius: 8px; background: repeating-conic-gradient(#f3f4f6 0 25%, #fff 0 50%) 0 0/12px 12px; flex: none; }
.sticker-ctl { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.range { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.range span { width: 28px; flex: none; }
.range input { flex: 1; min-width: 0; accent-color: var(--ink); }

.btn.more { width: 100%; margin-top: 4px; background: #fff; color: var(--ink); border: 1px solid var(--line); }

/* ---------- 받은 신청 · 알림 숫자 ---------- */
.wallet-tabs { margin-bottom: 14px; }
.badge { display: inline-block; min-width: 18px; padding: 0 6px; margin-left: 6px; border-radius: 999px; background: #ef4444; color: #fff; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center; vertical-align: 1px; }
.badge.hidden { display: none; }
.seg-btn.on .badge, .nav a.on .badge { background: #fff; color: #ef4444; }

/* ---------- PNG 저장 ---------- */
.export-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.png-modal { position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .7); display: flex; align-items: center; justify-content: center; padding: 20px; }
.png-box { background: #fff; border-radius: 16px; padding: 16px; max-width: 520px; width: 100%; max-height: 100%; overflow: auto; text-align: center; }
.png-box img { width: 100%; height: auto; border-radius: 10px; background: repeating-conic-gradient(#f3f4f6 0 25%, #fff 0 50%) 0 0/16px 16px; }
.png-box p { margin: 12px 0; color: var(--muted); font-size: 14px; }

/* ---------- 폰트 선택 ---------- */
.fonts .font-row { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.fonts .font-row b { width: 52px; flex: none; font-size: 13px; }
.fonts select { flex: 1; min-width: 0; font: inherit; padding: 9px 10px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink); }
.export-row .btn.ghost { border: 1px solid var(--line); background: #fff; color: var(--ink); }

/* ---------- 레이아웃: 옆 사진형 / 위 사진형 ---------- */
/* 카드 자신에게는 cqw를 쓸 수 없어서(화면 너비 기준이 됨) % 로 칸을 나눠요 */
.card.layout-side, .card.layout-top { padding: 0; gap: 0; }
.layout-side .c-main, .layout-top .c-main { display: contents; }
.layout-side .c-avatar, .layout-top .c-avatar { width: 100%; height: 100%; aspect-ratio: auto; border-radius: 0; border: 0; align-self: stretch; }

/* 옆 사진형: 왼쪽 사진 | 위 닉네임 | 아래 본문 */
.card.layout-side {
  grid-template-columns: 25.1% 4.8% 1fr 3.1%;
  grid-template-rows: 5.2% 27.8% 3.9% auto 1fr 4.5%; /* 마지막 칸이 아래쪽 여백. 사진은 이 칸까지 이어져 카드 아래 끝에 닿아요 */
}
.layout-side .c-avatar { grid-column: 1; grid-row: 1 / -1; }
.layout-side .c-head { grid-column: 3; grid-row: 2; align-self: center; min-width: 0; }
.layout-side .c-bio { grid-column: 3; grid-row: 4; min-width: 0; margin-top: 0; }
.layout-side .c-blocks { grid-column: 3; grid-row: 5; align-self: end; margin: 0; min-width: 0; }

/* 위 사진형: 맨 위 가로 사진 | 아래 왼쪽 닉네임, 오른쪽 본문 */
.card.layout-top {
  grid-template-columns: 9.4% 23.5% 6.8% 57.2% 3.1%;
  grid-template-rows: 30% 6.8% auto 1fr;
  padding-bottom: 4%;
}
.layout-top .c-avatar { grid-column: 1 / -1; grid-row: 1; }
.layout-top .c-head { grid-column: 2; grid-row: 3 / 5; align-self: center; min-width: 0; }
.layout-top .c-nick { font-size: 4.6cqw; white-space: normal; word-break: break-all; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.layout-top .c-handle { font-size: 2.7cqw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layout-top .c-bio { grid-column: 4; grid-row: 3; min-width: 0; margin-top: 0; font-size: 3.1cqw; }
.layout-top .c-blocks { grid-column: 4; grid-row: 4; align-self: end; margin: 0; min-width: 0; }

/* ---------- 사진 자르기 창 ---------- */
.crop-modal { position: fixed; inset: 0; z-index: 60; background: rgba(0, 0, 0, .72); display: flex; align-items: center; justify-content: center; padding: 20px; }
.crop-box { background: #fff; border-radius: 16px; padding: 18px; width: min(100%, 392px); text-align: center; }
.crop-box h3 { margin: 0 0 12px; font-size: 16px; }
.crop-frame { position: relative; margin: 0 auto; overflow: hidden; background: #111; border-radius: 8px; touch-action: none; cursor: grab; }
.crop-frame:active { cursor: grabbing; }
.crop-img { position: absolute; left: 0; top: 0; transform-origin: 0 0; max-width: none; user-select: none; -webkit-user-drag: none; pointer-events: none; }
.crop-frame.round::after { content: ""; position: absolute; inset: 0; border-radius: 50%; box-shadow: 0 0 0 999px rgba(0, 0, 0, .5), inset 0 0 0 2px #fff; pointer-events: none; }
.crop-zoom { display: flex; align-items: center; gap: 10px; margin: 14px 0 6px; font-size: 13px; color: var(--muted); }
.crop-zoom input { flex: 1; accent-color: var(--ink); }
.crop-hint { margin: 0 0 14px; font-size: 12px; color: var(--muted); }
.crop-actions { display: flex; gap: 8px; }
.crop-actions .btn { flex: 1; }

.sticker-btns { display: flex; flex-direction: column; gap: 6px; flex: none; }
.layout-hint { margin-top: 6px; }
