/* app.css — 모두의 단골 공용 스타일.
   설계 전제: 손님 화면은 대부분 **매장에서 폰으로** 열린다. 그래서
   - 터치 타겟 최소 48px, 본문 16px 이상(iOS 확대 방지)
   - 매장 브랜드 컬러를 --brand 로 주입받아 화면 전체가 그 색을 따른다
   - 다크모드에서도 읽히게 색을 토큰으로만 쓴다

   ★디자인 방향: **실물 쿠폰의 질감.**
   이 쿠폰은 결국 매장에서 직원에게 내미는 물건이다. 종이 티켓처럼 보이면
   "이걸 보여주면 되는구나"가 설명 없이 전달된다. 그래서 펀칭 자국·미싱선·
   종이 두께를 CSS 로 만든다. 유리·그라데이션 계열을 쓰지 않는 이유는 매장마다
   브랜드 색을 직접 고르기 때문이다 — 종이+임의의 색은 무난하지만 유리+임의의 색은
   촌스러워지는 폭이 크다.

   ★웹폰트를 쓰지 않는다: 이 앱의 CSP 는 font-src 'self' data: 라 외부 폰트가 차단된다.
   시스템 폰트 안에서 굵기·자간·크기 대비로 리듬을 만든다. */

:root {
  --brand: #d9432c;
  --bg: #f4f2ee;
  --surface: #ffffff;
  --paper: #fffdf9;          /* 티켓 바탕 — 흰색보다 아주 살짝 따뜻하게 */
  --text: #1c1b19;
  --muted: #6b6862;
  --line: #e4e1dc;
  --ok: #157f4a;
  --warn: #9a6b00;
  --danger: #b3261e;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(28,27,25,.05), 0 8px 24px rgba(28,27,25,.06);
  --shadow-lift: 0 2px 4px rgba(28,27,25,.06), 0 18px 40px rgba(28,27,25,.14);
  --space: 16px;

  /* 모션 — 종이가 떨어져 안착하는 느낌. 되튐이 살짝 있어야 물성이 산다. */
  --ease-settle: cubic-bezier(.18,.89,.32,1.28);
  --ease-out: cubic-bezier(.2,.8,.25,1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15141a; --surface: #201f26; --paper: #262530;
    --text: #f2f0ee; --muted: #a5a1a8; --line: #35323d;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.3);
    --shadow-lift: 0 2px 6px rgba(0,0,0,.5), 0 18px 40px rgba(0,0,0,.45);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Apple SD Gothic Neo',
               'Malgun Gothic', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.6;
  /* 한국어 줄바꿈: 단어 중간에서 끊기지 않게 */
  word-break: keep-all;
  overflow-wrap: break-word;
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: 480px; margin: 0 auto; padding: var(--space); }
.wrap-wide { max-width: 960px; margin: 0 auto; padding: var(--space); }

/* 노치 있는 폰에서 하단 버튼이 홈 인디케이터에 가리지 않게 */
body { padding-bottom: env(safe-area-inset-bottom); }

/* ---- 카드 ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: var(--space);
}

/* 매장 머리 — 브랜드 색 위에 매장명. 아래로 갈수록 살짝 어두워져 깊이를 만든다. */
.store-head {
  position: relative;
  text-align: center;
  padding: 30px 20px 32px;
  border-radius: var(--radius);
  background: var(--brand);
  background-image: linear-gradient(160deg, rgba(255,255,255,.14), rgba(0,0,0,.10));
  color: #fff;
  margin-bottom: var(--space);
  box-shadow: var(--shadow);
  overflow: hidden;
}
/* 종이에 눌린 자국 같은 얇은 하이라이트 */
.store-head::after {
  content: ''; position: absolute; inset: 0;
  background: radial-gradient(120% 80% at 50% -20%, rgba(255,255,255,.22), transparent 60%);
  pointer-events: none;
}
.store-head h1 { margin: 0 0 6px; font-size: 26px; font-weight: 800; letter-spacing: -.03em; }
.store-head .reward { margin: 0; font-size: 16px; opacity: .95; font-weight: 500; }

h2 { font-size: 18px; margin: 0 0 12px; font-weight: 700; letter-spacing: -.015em; }
p  { margin: 0 0 12px; }
.muted { color: var(--muted); font-size: 14px; }
.center { text-align: center; }

/* ---- 버튼 ---- */
.btn {
  display: block; width: 100%; min-height: 52px;
  border: 0; border-radius: 13px;
  background: var(--brand); color: #fff;
  font-size: 17px; font-weight: 700; font-family: inherit;
  cursor: pointer; padding: 14px 18px;
  box-shadow: 0 1px 2px rgba(28,27,25,.10), 0 6px 16px rgba(28,27,25,.10);
  transition: transform .18s var(--ease-out), box-shadow .18s var(--ease-out), filter .15s ease;
}
.btn:hover:not(:disabled) {
  filter: brightness(1.06);
  transform: translateY(-2px);
  box-shadow: 0 2px 4px rgba(28,27,25,.10), 0 12px 26px rgba(28,27,25,.16);
}
.btn:active:not(:disabled) { transform: translateY(0) scale(.985); }
.btn:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; }
.btn.secondary {
  background: transparent; color: var(--text);
  border: 1.5px solid var(--line); box-shadow: none;
}
.btn.secondary:hover:not(:disabled) { border-color: var(--brand); filter: none; }
.btn.ghost {
  background: transparent; color: var(--muted); border: 0; box-shadow: none;
  min-height: 44px; font-size: 15px; font-weight: 600;
}
.btn.ghost:hover:not(:disabled) { color: var(--text); filter: none; transform: none; }
.btn + .btn { margin-top: 10px; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { margin-top: 0; }

/* 키보드 포커스 링 — :focus-visible 이라 마우스 클릭에는 안 뜨고 키보드 탭에만 뜬다.
   .btn 은 배경이 --brand 라 링과 같은 색 — offset 2px 의 틈이 링을 분리해 보이게 한다. */
.btn:focus-visible, a:focus-visible, .linklike:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

/* ---- 폼 ---- */
label { display: block; font-size: 14px; font-weight: 700; margin: 0 0 6px; }
input, select {
  width: 100%; min-height: 52px; padding: 12px 14px;
  border: 1.5px solid var(--line); border-radius: 12px;
  background: var(--surface); color: var(--text);
  font-size: 16px; font-family: inherit; /* 16px 미만이면 iOS 가 확대한다 */
  transition: border-color .15s ease, box-shadow .15s ease;
}
input:hover, select:hover { border-color: var(--muted); }
input:focus, select:focus {
  outline: 2px solid var(--brand); outline-offset: 1px; border-color: transparent;
}
.field { margin-bottom: 14px; }
.hint { font-size: 13px; color: var(--muted); margin-top: 6px; }

/* 동의 체크박스 — 필수/선택을 시각적으로 확실히 구분한다 */
.consent { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 12px; }
.consent input[type=checkbox] { width: 22px; height: 22px; min-height: 22px; margin: 2px 0 0; flex: none; accent-color: var(--brand); }
.consent label { font-weight: 500; font-size: 14.5px; margin: 0; line-height: 1.5; }
.tag-req { color: var(--danger); font-weight: 800; }
.tag-opt { color: var(--muted); font-weight: 800; }

/* 라벨 안의 '보기' — 버튼이지만 링크처럼 보여야 한다(접이식 동의 요약 토글) */
.linklike {
  background: none; border: 0; padding: 0; margin: 0;
  color: var(--brand); font: inherit; font-size: inherit;
  text-decoration: underline; cursor: pointer; min-height: 0;
}

/* 개인정보보호법 4요소 고지 — 접이식이지만 내용은 고정 */
.consent-summary {
  margin: -4px 0 14px 32px; padding: 12px 14px;
  border-left: 3px solid var(--line);
  background: var(--bg);
  border-radius: 0 8px 8px 0;
  font-size: 13.5px; line-height: 1.65; color: var(--muted);
}
.consent-summary p { margin: 0 0 6px; }
.consent-summary p:last-child { margin-bottom: 0; }

/* [선택] 동의 아래 상시 노출 문구 — 체크박스 라벨과 세로선을 맞춘다 */
.consent-note { margin: -6px 0 14px 32px; }

/* 사업자 진위확인 전송 고지(신청 버튼 위) */
/* D-11 다운로드 고지는 여러 줄이라 개행을 살린다 */
.transmit-notice {
  white-space: pre-line;
  font-size: 13.5px; line-height: 1.6; color: var(--muted);
  background: var(--bg); border: 1px solid var(--line);
  border-radius: 10px; padding: 12px 14px; margin-bottom: 14px;
}

/* 친구 화면 하단 쿠키 고지 */
.cookie-note { font-size: 12.5px; line-height: 1.6; }

.swatch { height: 52px; padding: 6px; }

/* ---- 초대 순서별 보상 입력 (사장님 콘솔) ---- */
.reward-set {
  border: 1px solid var(--line); border-radius: 13px;
  padding: 14px 16px 4px; margin: 0 0 16px;
  background: var(--bg);
}
.reward-set legend { font-size: 14px; font-weight: 800; padding: 0 6px; }
.reward-set__lead { margin-top: 0; }
.reward-row { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 12px; }
.reward-row__input { flex: 1; min-width: 0; }
.reward-row__input label { font-weight: 600; }
/* 번호 뱃지 — 손님이 보는 티켓 스터브와 같은 기호를 써서 둘이 같은 것임을 알린다 */
.reward-row__no {
  flex: none; width: 34px; height: 34px; margin-top: 22px;
  border-radius: 10px; background: var(--brand); color: #fff;
  display: grid; place-items: center;
  font-size: 16px; font-weight: 800;
}

/* ══════════════════════════════════════════════════════════════════
   티켓 (실물 쿠폰)
   왼쪽=혜택 본문, 오른쪽=몇 번째 친구인지 적힌 반쪽(스터브).
   그 경계에 펀칭 구멍 2개 + 미싱선을 그려 "뜯는 종이"로 읽히게 한다.
   ══════════════════════════════════════════════════════════════════ */
/* 티켓이 놓이는 자리 — 카드가 아니라 페이지 바닥이다(펀칭 구멍이 배경색을 쓴다). */
.coupon-section { margin-bottom: var(--space); }
.section-head {
  display: flex; align-items: baseline; gap: 8px;
  margin: 0 2px 10px;
}
.section-head h2 { margin: 0; }
.section-count { font-size: 13.5px; color: var(--muted); font-weight: 600; }

.ticket-stack { perspective: 1200px; margin: 4px 0 6px; }

.ticket {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 78px;
  align-items: stretch;
  min-height: 104px;
  margin-bottom: 14px;
  border-radius: 15px;
  background: var(--paper);
  /* 종이결: 아주 옅은 사선. 알파가 낮아 색을 흐리지 않는다. */
  background-image: repeating-linear-gradient(
    135deg, rgba(28,27,25,.014) 0 2px, transparent 2px 6px);
  box-shadow:
    0 0 0 1px var(--line) inset,          /* 종이 테두리 */
    0 1px 1px rgba(28,27,25,.05),
    0 10px 22px rgba(28,27,25,.10);
  transform-style: preserve-3d;
  transition: transform .3s var(--ease-out), box-shadow .3s var(--ease-out);
  /* ★overflow 를 숨기지 않는다 — 펀칭 구멍(::before/::after)이 티켓 바깥으로
     반쯤 걸쳐 있어서, 여기서 잘라내면 "종이를 뚫은 자국"이 사라진다.
     대신 모서리 둥글기는 스터브가 스스로 처리한다. */
}
.ticket:hover { transform: translateY(-5px) rotateX(5deg); box-shadow: var(--shadow-lift); }

/* 펀칭 구멍 — 스터브 경계(오른쪽 78px)의 위·아래를 페이지 배경색으로 도려낸다 */
.ticket::before, .ticket::after {
  content: ''; position: absolute; right: 78px;
  width: 18px; height: 18px; margin-right: -9px;
  border-radius: 50%; background: var(--bg);
  box-shadow: 0 0 0 1px var(--line) inset;
}
.ticket::before { top: -9px; }
.ticket::after  { bottom: -9px; }

.ticket__body { padding: 16px 16px 14px 18px; min-width: 0; }
.ticket__reward {
  font-size: 18px; font-weight: 800; letter-spacing: -.02em;
  line-height: 1.35; margin: 0 0 8px;
}
.ticket__meta {
  font-size: 12.5px; color: var(--muted); margin: 0;
  font-variant-numeric: tabular-nums;
}
.ticket__serial { font-weight: 700; letter-spacing: .04em; }

/* 스터브 — 미싱선(점선)으로 본문과 나뉜다 */
.ticket__stub {
  position: relative;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 1px;
  /* 티켓이 overflow 를 숨기지 않으므로 오른쪽 모서리는 스터브가 직접 둥글린다.
     빛 번짐(::after)이 밖으로 새지 않게 여기서만 잘라낸다. */
  border-radius: 0 15px 15px 0;
  overflow: hidden;
  background: var(--brand);
  color: #fff;
  /* 브랜드 색이 밝을 때 흰 글씨가 뜨는 것을 막는 아주 옅은 어둠 */
  background-image: linear-gradient(180deg, rgba(255,255,255,.10), rgba(0,0,0,.12));
}
.ticket__stub::before {
  content: ''; position: absolute; left: 0; top: 10px; bottom: 10px;
  border-left: 2px dashed rgba(255,255,255,.55);
}
.ticket__slot { font-size: 26px; font-weight: 800; line-height: 1; letter-spacing: -.04em; }
.ticket__slot-label { font-size: 10.5px; font-weight: 700; opacity: .9; letter-spacing: .02em; }

/* 상태 배지 */
.ticket__state {
  display: inline-block; margin-top: 8px;
  font-size: 12px; font-weight: 800; padding: 3px 10px; border-radius: 999px;
  background: var(--line); color: var(--muted);
}
.ticket__state.usable  { color: var(--ok); background: color-mix(in srgb, var(--ok) 14%, transparent); }
.ticket__state.not_yet { color: var(--warn); background: color-mix(in srgb, var(--warn) 16%, transparent); }

/* 사용·만료 — 종이가 힘을 잃은 느낌으로 눕힌다 */
.ticket.is-used, .ticket.is-expired {
  box-shadow: 0 0 0 1px var(--line) inset;
  background-image: none;
}
.ticket.is-used .ticket__body, .ticket.is-expired .ticket__body { opacity: .5; }
.ticket.is-used .ticket__stub, .ticket.is-expired .ticket__stub {
  background: var(--line); color: var(--muted); background-image: none;
}
.ticket.is-used:hover, .ticket.is-expired:hover { transform: none; box-shadow: 0 0 0 1px var(--line) inset; }

/* 아직 안 받은 자리 — 종이가 아직 없다는 뜻이라 점선 윤곽만 남긴다 */
.ticket.is-empty {
  background: transparent; background-image: none;
  box-shadow: 0 0 0 1.5px var(--line) inset;
  border: 0;
}
.ticket.is-empty .ticket__body { opacity: .75; }
.ticket.is-empty .ticket__reward { font-weight: 700; color: var(--muted); }
.ticket.is-empty .ticket__stub {
  background: transparent; background-image: none;
  color: var(--muted);
  box-shadow: 0 0 0 1.5px var(--line) inset;
}
.ticket.is-empty .ticket__stub::before { border-left-color: var(--line); }
.ticket.is-empty::before, .ticket.is-empty::after { box-shadow: 0 0 0 1.5px var(--line) inset; }
.ticket.is-empty:hover { transform: none; box-shadow: 0 0 0 1.5px var(--line) inset; }

/* 사용 완료 도장 — 비스듬히 찍힌 원형 스탬프 */
.ticket__stamp {
  position: absolute; right: 92px; top: 50%;
  transform: translateY(-50%) rotate(-14deg);
  border: 2.5px solid var(--danger); color: var(--danger);
  border-radius: 8px; padding: 4px 10px;
  font-size: 13px; font-weight: 800; letter-spacing: .06em;
  opacity: .62; pointer-events: none;
}

/* 새로 적립된 티켓 — 위에서 떨어져 살짝 되튄 뒤 안착한다 */
@keyframes ticket-drop {
  0%   { opacity: 0; transform: translateY(-58px) rotate(-5deg) scale(.94); }
  60%  { opacity: 1; transform: translateY(6px) rotate(.6deg) scale(1.01); }
  80%  { transform: translateY(-2px) rotate(-.3deg) scale(1); }
  100% { opacity: 1; transform: translateY(0) rotate(0) scale(1); }
}
.ticket.is-new { animation: ticket-drop .62s var(--ease-settle) both; }

/* 적립 순간 스터브에서 번지는 빛 — 한 번만 지나간다 */
@keyframes stub-flash {
  0%   { opacity: 0; }
  35%  { opacity: .85; }
  100% { opacity: 0; }
}
.ticket.is-new .ticket__stub::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(120deg, transparent 30%, rgba(255,255,255,.9), transparent 70%);
  animation: stub-flash .9s ease-out .25s both;
}

/* 적립 개수 표시 — 채워진 칸이 톡 하고 커진다 */
.pool { display: flex; gap: 8px; justify-content: center; margin: 4px 0 16px; }
.pool .dot {
  width: 44px; height: 9px; border-radius: 999px; background: var(--line);
  transition: background .3s var(--ease-out), transform .3s var(--ease-settle);
}
.pool .dot.on { background: var(--brand); }
@keyframes dot-pop { 0% { transform: scaleX(.2); } 100% { transform: scaleX(1); } }
.pool .dot.just-on { animation: dot-pop .5s var(--ease-settle) both; }

/* 공용 쿠폰 고지 — 이 화면에서 가장 오해가 잦은 지점이라 눈에 띄어야 한다 */
.pool-notice {
  border-radius: 13px; padding: 14px 16px; margin: 0 0 var(--space);
  background: var(--bg);
  border: 1px solid var(--line);
  border-left: 4px solid var(--brand);
}
.pool-notice { background: color-mix(in srgb, var(--brand) 9%, transparent); }
.pool-notice strong {
  display: block; font-size: 15.5px; font-weight: 800; letter-spacing: -.015em;
  margin-bottom: 4px;
}
.pool-notice span { display: block; font-size: 13.5px; color: var(--muted); line-height: 1.55; }

/* ---- 알림 ---- */
.notice {
  border-radius: 12px; padding: 13px 15px; margin-bottom: var(--space);
  font-size: 14.5px; line-height: 1.55;
  /* 폴백 먼저(구형 브라우저), 그다음 color-mix(지원 시 덮어씀) */
  background: var(--bg);
  border: 1px solid var(--line);
  border-left: 4px solid var(--brand);
}
.notice { background: color-mix(in srgb, var(--brand) 8%, transparent); }
.notice.warn   { border-left-color: var(--warn); }
.notice.warn   { background: color-mix(in srgb, var(--warn) 10%, transparent); }
.notice.danger { border-left-color: var(--danger); color: var(--danger); }
.notice.danger { background: color-mix(in srgb, var(--danger) 8%, transparent); }
.notice.ok     { border-left-color: var(--ok); }
.notice.ok     { background: color-mix(in srgb, var(--ok) 10%, transparent); }
.notice strong { font-weight: 800; }

/* ---- 모달 (쿠폰 소진 안내 등) ---- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center; padding: 20px;
  background: rgba(20,19,17,.55);
  animation: fade-in .2s ease both;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-in {
  from { opacity: 0; transform: translateY(18px) scale(.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.modal {
  width: 100%; max-width: 360px;
  background: var(--surface); color: var(--text);
  border-radius: 20px; padding: 26px 22px 20px;
  text-align: center;
  box-shadow: 0 24px 60px rgba(0,0,0,.3);
  animation: modal-in .3s var(--ease-settle) both;
}
.modal__mark {
  width: 56px; height: 56px; margin: 0 auto 14px;
  border-radius: 50%; display: grid; place-items: center;
  font-size: 26px; font-weight: 800; color: #fff; background: var(--brand);
}
.modal h2 { font-size: 19px; margin: 0 0 8px; }
.modal p { font-size: 14.5px; color: var(--muted); margin: 0 0 6px; }
.modal p.strong-line { color: var(--text); font-weight: 700; font-size: 15px; }
.modal .btn { margin-top: 18px; }

/* ---- QR / 포스터 ---- */
.qr-box { text-align: center; padding: 20px; background: #fff; border-radius: 12px; }
.qr-box canvas { image-rendering: pixelated; max-width: 100%; height: auto; }
.qr-meta { font-size: 13px; color: var(--muted); margin-top: 10px; font-variant-numeric: tabular-nums; }

/* ---- 표 ---- */
.table-scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-weight: 700; color: var(--muted); font-size: 13px; }

.hidden { display: none !important; }
.spinner { text-align: center; padding: 40px 0; color: var(--muted); }

footer { text-align: center; padding: 24px 16px 40px; font-size: 13px; color: var(--muted); }
footer a { color: var(--muted); }

/* 인쇄: 포스터만 남기고 전부 숨긴다 */
@media print {
  body { background: #fff; }
  .no-print { display: none !important; }
  .qr-box { box-shadow: none; border: 0; }
}

/* ---- 유틸리티 (인라인 style 대체) ---- */
.page-title { font-size: 22px; margin: 8px 0 20px; letter-spacing: -.02em; }
.btn-link { text-decoration: none; text-align: center; }
.mt-sm { margin-top: 12px; }
.mt-lg { margin-top: 24px; }
.url-break { word-break: break-all; font-size: 12px; }
.card.flat { box-shadow: none; margin-bottom: 14px; }
.card.flat p { margin: 0; }
.card.flat p + p { margin-top: 4px; }
.card.flat .muted { margin-top: 8px; }
.stamp { font-size: 20px; font-weight: 800; }
.done-reward { font-size: 18px; font-weight: 700; }
.pre-scroll { overflow-x: auto; font-size: 13px; }

/* ---- A4 포스터 미리보기 ---- */
.poster-preview {
  margin-top: 14px; border: 1px solid var(--line); border-radius: 12px;
  background: #fff; padding: 10px; overflow: hidden;
}
.poster-preview svg { width: 100%; height: auto; display: block; }

/* ══════════════════════════════════════════════════════════════════
   모션 최소화 — 전정기관이 예민한 사용자는 OS 설정으로 끈다.
   끄더라도 **상태는 그대로 보여야** 한다(사라지는 정보가 없게 opacity/transform 만 없앤다).
   ══════════════════════════════════════════════════════════════════ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
  .ticket:hover { transform: none; }
}
