/* ─────────────────────────────────────────────
   디자인 토큰 (docs/SPEC.md 6장 · docs/PLAN.md 0-1)
   ───────────────────────────────────────────── */
:root {
  /* ZUN 브랜드 — 다크/라이트 공통 */
  --zun-light: #A7C9FF;
  --zun-mid: #4D8BFF;
  --zun-deep: #1E5BFF;

  --font-mono: 'JetBrains Mono', Pretendard, ui-monospace, SFMono-Regular, Menlo, monospace; /* 한글은 Pretendard로 */
  --font-body: Pretendard, -apple-system, BlinkMacSystemFont, system-ui, 'Apple SD Gothic Neo', sans-serif;

  /* 다크 (기본) */
  --bg: #0B0C10;
  --surface: #14161C;
  --surface-2: #1B1E26;
  --text: #F2F4F8;
  --muted: #8E95A3;
  --border: #262A33;
  --accent: var(--zun-mid);
  --accent-press: var(--zun-deep);
  --accent-text: var(--zun-light);       /* 어두운 배경 위 강조 글자 */
  --blank-bg: rgba(77, 139, 255, 0.2);   /* 프롬프트 [ ] 빈칸 */
  --blank-text: var(--zun-light);
  --track: rgba(167, 201, 255, 0.16);    /* 진행률 배경 */
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);

  --radius: 14px;
  --radius-sm: 10px;
  --gutter: 16px;
  --maxw: 480px;
  --topbar-h: 52px;
  --navbar-h: 72px;

  color-scheme: dark;
}

[data-theme="light"] {
  --bg: #F6F8FC;
  --surface: #FFFFFF;
  --surface-2: #EEF2FA;
  --text: #12141A;
  --muted: #5D6270;
  --border: #DFE3EC;
  --accent-text: var(--zun-deep);
  --blank-bg: rgba(77, 139, 255, 0.16);
  --blank-text: var(--zun-deep);
  --track: rgba(77, 139, 255, 0.14);
  --shadow: 0 8px 24px rgba(18, 20, 26, 0.08);

  color-scheme: light;
}

/* ─────────────────────────────────────────────
   기본
   ───────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; } /* .btn 등 display 지정보다 우선 */

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.6;
  word-break: keep-all;
  overflow-wrap: anywhere;
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 20px var(--gutter) 120px;
}
#app:focus { outline: none; }

h1, h2, h3 { line-height: 1.3; margin: 0 0 12px; letter-spacing: -0.01em; }
h1 { font-size: 28px; }
h2 { font-size: 24px; }
h3 { font-size: 18px; }
p { margin: 0 0 12px; }
a { color: var(--accent-text); }

.mono { font-family: var(--font-mono); letter-spacing: -0.02em; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.center { text-align: center; }
.stack > * + * { margin-top: 12px; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

:focus-visible { outline: 2px solid var(--zun-mid); outline-offset: 2px; }

/* ─────────────────────────────────────────────
   상단 바
   ───────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 20;
  height: var(--topbar-h);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: var(--maxw); height: 100%; margin: 0 auto; padding: 0 var(--gutter);
  display: flex; align-items: center; justify-content: space-between;
}
.logo {
  font-family: var(--font-mono); font-weight: 700; font-size: 17px;
  color: var(--text); text-decoration: none; letter-spacing: 0.02em;
  display: inline-flex; align-items: center; min-height: 48px;
}
.logo b { color: var(--zun-mid); font-weight: 700; }
.icon-btn {
  width: 48px; height: 48px; margin-right: -12px;
  display: grid; place-items: center;
  background: none; border: 0; border-radius: 50%;
  color: var(--text); font-size: 20px; cursor: pointer;
}
.icon-btn:active { background: var(--surface-2); }

/* ─────────────────────────────────────────────
   버튼
   ───────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 20px;
  border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; font-size: 16px; text-decoration: none;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
  transition: transform .08s, background-color .15s, border-color .15s;
}
.btn:active { transform: scale(0.98); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
.btn.primary:active { background: var(--accent-press); border-color: var(--accent-press); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.block { display: flex; width: 100%; }
.btn.sm { position: relative; min-height: 36px; padding: 0 14px; font-size: 14px; border-radius: var(--radius-sm); }
.btn.sm::after { content: ''; position: absolute; inset: -6px -4px; } /* 터치 영역 48px 확보 */
.link-btn {
  min-height: 48px; background: none; border: 0; padding: 8px 12px; color: var(--muted);
  font: inherit; font-size: 14px; text-decoration: underline; cursor: pointer;
}

/* ─────────────────────────────────────────────
   카드 · 배지
   ───────────────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
}
.badges { display: flex; flex-wrap: wrap; gap: 8px; }
.badge {
  display: inline-flex; align-items: center; min-height: 28px; padding: 0 10px;
  border-radius: 99px; background: var(--track); color: var(--accent-text);
  font-family: var(--font-mono); font-size: 13px; font-weight: 500;
}

/* ─────────────────────────────────────────────
   진행률
   ───────────────────────────────────────────── */
.progress { height: 6px; background: var(--track); border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); border-radius: inherit; transition: width .3s; }

/* ─────────────────────────────────────────────
   하단 고정: 팔로우 배너 · 단계 내비
   ───────────────────────────────────────────── */
.bottom-fixed {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: var(--bg); border-top: 1px solid var(--border);
  padding: 8px var(--gutter) calc(8px + env(safe-area-inset-bottom));
}
.bottom-fixed > * { max-width: calc(var(--maxw) - 2 * var(--gutter)); margin: 0 auto; }

.banner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 48px; color: var(--text); text-decoration: none; font-size: 14px; font-weight: 600;
}
.banner .handle { font-family: var(--font-mono); color: var(--accent-text); white-space: nowrap; }

.nav { display: flex; gap: 8px; }
.nav .btn { flex: 1; }
.nav .btn.primary { flex: 2; }

/* ─────────────────────────────────────────────
   토스트
   ───────────────────────────────────────────── */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--navbar-h) + 24px + env(safe-area-inset-bottom)); z-index: 30;
  transform: translate(-50%, 8px);
  max-width: calc(100% - 2 * var(--gutter)); width: max-content;
  background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 99px;
  font-size: 14px; font-weight: 600; text-align: center;
  opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

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

/* ─────────────────────────────────────────────
   ① 랜딩
   ───────────────────────────────────────────── */
.landing { padding-top: 12px; }
.kicker { color: var(--accent-text); font-size: 13px; font-weight: 700; letter-spacing: 0.08em; margin-bottom: 8px; }
.hero-title { font-size: 30px; font-weight: 800; line-height: 1.28; margin-bottom: 14px; }
.landing .badges { margin: 16px 0 24px; }
.cta { display: flex; flex-direction: column; align-items: center; gap: 4px; }

.preview { margin: 32px 0 0; text-align: center; }
.preview figcaption { margin-top: 10px; }

/* 생일 페이지 목업 */
.mock {
  position: relative; overflow: hidden;
  width: 220px; margin: 0 auto; padding: 28px 16px 20px;
  border-radius: 28px; border: 6px solid var(--surface-2);
  background: linear-gradient(180deg, #FFF1F5 0%, #EAF2FF 100%);
  color: #3A2E3F; box-shadow: var(--shadow);
}
.mock-avatar {
  width: 64px; height: 64px; margin: 0 auto 10px; border-radius: 50%;
  display: grid; place-items: center;
  background: #FFD1DC; color: #8A3B55; font-size: 26px; font-weight: 800;
  border: 3px solid #fff;
}
.mock-title { font-weight: 800; font-size: 17px; margin-bottom: 10px; }
.mock-btn {
  display: inline-block; margin-bottom: 12px; padding: 4px 12px; border-radius: 99px;
  background: #FF8FAB; color: #fff; font-size: 12px; font-weight: 700;
}
.mock-card {
  margin: 0 0 6px; padding: 8px 10px; border-radius: 10px;
  background: rgba(255, 255, 255, 0.8); font-size: 12px; text-align: left;
}
.mock-confetti i {
  position: absolute; top: -10px; left: calc(var(--i) * 7%);
  width: 6px; height: 10px; border-radius: 2px;
  background: hsl(calc(var(--i) * 47), 85%, 65%);
  animation: confetti-fall 3.2s linear infinite;
  animation-delay: calc(var(--i) * -0.23s);
}
@keyframes confetti-fall {
  to { transform: translateY(360px) rotate(540deg); }
}

.how { list-style: none; padding: 0; margin: 32px 0 16px; display: grid; gap: 8px; }
.how li {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 16px; font-weight: 600;
}
.how li .mono { color: var(--accent-text); font-size: 14px; }

/* ─────────────────────────────────────────────
   ② 앱 고르기
   ───────────────────────────────────────────── */
.pick h1 { font-size: 26px; }
.cat-title {
  margin: 28px 0 10px; font-size: 13px; font-weight: 700; letter-spacing: 0.04em;
  color: var(--muted);
}
.tpl-list { display: grid; gap: 10px; }
.tpl {
  display: flex; align-items: center; gap: 14px; width: 100%;
  padding: 14px; text-align: left;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  font: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent;
  transition: transform .08s, border-color .15s;
}
.tpl:not(.locked) { border-color: var(--zun-mid); box-shadow: 0 0 0 1px var(--zun-mid) inset; }
.tpl:active { transform: scale(0.99); }
.tpl.locked { opacity: .55; filter: grayscale(1); cursor: default; }
.tpl-thumb {
  flex: none; width: 56px; height: 56px; border-radius: 14px;
  display: grid; place-items: center; overflow: hidden;
  background: var(--surface-2); font-size: 28px;
}
.tpl-thumb img { width: 100%; height: 100%; object-fit: cover; }
.tpl-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.tpl-name { font-weight: 700; font-size: 16px; }
.tpl-desc { color: var(--muted); font-size: 14px; line-height: 1.45; }
.tpl-meta { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 4px; font-size: 12px; color: var(--muted); }
.tpl-meta .mono { color: var(--accent-text); letter-spacing: 0.1em; }
.tpl-hint { font-size: 12px; color: var(--muted); font-family: var(--font-mono); }
.tag {
  display: inline-block; vertical-align: 2px; margin-left: 4px; padding: 0 8px; border-radius: 99px;
  background: var(--zun-mid); color: #fff; font-size: 11px; font-weight: 700; line-height: 20px;
}

/* ─────────────────────────────────────────────
   ③ 단계 화면
   ───────────────────────────────────────────── */
.step { padding-top: 4px; }
.step-label { color: var(--muted); font-size: 13px; margin: 10px 0 18px; }
.step h1 { font-size: 26px; margin-bottom: 8px; }
.learn { font-size: 14px; color: var(--muted); margin-bottom: 16px; }
.learn span {
  display: inline-block; margin-right: 4px; padding: 0 8px; border-radius: 99px;
  background: var(--track); color: var(--accent-text); font-size: 12px; font-weight: 700; line-height: 22px;
}
.desc { font-size: 16px; line-height: 1.7; }

.sub { font-size: 17px; margin: 28px 0 12px; }
.sub-label { font-size: 12px; font-weight: 700; color: var(--accent-text); letter-spacing: 0.06em; margin-bottom: 8px; }

/* 체크리스트 */
.checks { margin: 20px 0 0; padding: 12px 16px 14px; }
.checks legend { padding: 0 6px; margin-left: -6px; font-weight: 700; font-size: 14px; }
.checks label { display: flex; gap: 10px; align-items: flex-start; min-height: 48px; padding: 10px 0; font-size: 15px; cursor: pointer; }
.checks input { flex: none; width: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--zun-mid); }
.checks input:checked + span { color: var(--muted); text-decoration: line-through; }

/* 프롬프트 카드 */
.prompt-card {
  margin: 20px 0 12px; padding: 16px;
  background: var(--surface); border: 1px solid var(--zun-mid); border-radius: var(--radius);
  box-shadow: 0 0 0 1px var(--zun-mid) inset;
}
.prompt-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 8px; margin-bottom: 10px; }
.prompt-head .mono { font-size: 12px; font-weight: 700; color: var(--accent-text); letter-spacing: 0.06em; }
.blank-hint { font-size: 12px; color: var(--muted); }
.prompt-card pre, .mini-prompt {
  margin: 0; white-space: pre-wrap; word-break: keep-all; overflow-wrap: anywhere;
  font-family: var(--font-mono); font-size: 14px; line-height: 1.75;
}
.prompt-card pre { margin-bottom: 14px; }
mark.blank { background: var(--blank-bg); color: var(--blank-text); border-radius: 4px; padding: 1px 2px; font-weight: 700; }
.btn.done { background: var(--accent-press); border-color: var(--accent-press); color: #fff; }

.note { color: var(--muted); margin: 0 0 12px; }

/* 고장 목록 */
.fixes { list-style: none; padding: 0; margin: 0 0 12px; display: grid; gap: 10px; }
.fix-symptom { font-weight: 700; margin-bottom: 8px; }
.mini-prompt {
  font-size: 13px; padding: 10px 12px; margin-bottom: 8px;
  background: var(--surface-2); border-radius: var(--radius-sm);
}

/* 예상 결과 */
.expect { margin-top: 20px; }
.expect img { display: block; width: 100%; height: auto; margin-bottom: 10px; border-radius: var(--radius-sm); border: 1px solid var(--border); }
.expect p:last-child { margin: 0; }

/* 막혔을 때 */
.stuck { margin-top: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.stuck summary {
  list-style: none; cursor: pointer; padding: 14px 16px; font-weight: 700;
  display: flex; justify-content: space-between; align-items: center;
}
.stuck summary::-webkit-details-marker { display: none; }
.stuck summary::after { content: '+'; font-family: var(--font-mono); color: var(--muted); font-size: 18px; }
.stuck[open] summary::after { content: '−'; }
.stuck-item { padding: 12px 16px 14px; border-top: 1px solid var(--border); }
.stuck-item .q { font-weight: 700; margin-bottom: 4px; }
.stuck-item .a { color: var(--muted); font-size: 15px; margin-bottom: 8px; }
.stuck-item .a:last-child { margin-bottom: 0; }

/* ─────────────────────────────────────────────
   ④ 완성 화면 · 수료 카드
   ───────────────────────────────────────────── */
.finish h1 { font-size: 26px; }
.field { display: block; margin: 20px 0 8px; }
.field span { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.field input {
  width: 100%; min-height: 48px; padding: 0 14px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font: inherit; font-size: 16px; /* 16px 미만이면 iOS가 확대함 */
}
.field input:focus { outline: none; border-color: var(--zun-mid); box-shadow: 0 0 0 3px var(--blank-bg); }
#open-app { margin-bottom: 4px; }

.card-preview { margin: 24px auto 16px; width: min(100%, 270px); }
.card-preview canvas {
  display: block; width: 100%; height: auto; aspect-ratio: 9 / 16;
  border-radius: 16px; box-shadow: var(--shadow); background: #0B0C10;
}
.regram { text-align: center; color: var(--accent-text); font-weight: 600; margin-top: 12px; }
.finish-more { display: flex; flex-direction: column; align-items: center; gap: 4px; margin-top: 28px; }

.overlay {
  position: fixed; inset: 0; z-index: 50;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  padding: 24px var(--gutter); background: rgba(0, 0, 0, 0.88);
}
.overlay-title { color: #fff; font-weight: 700; margin: 0; }
.overlay img { max-width: min(100%, 300px); max-height: 70vh; border-radius: 12px; -webkit-touch-callout: default; }
.overlay .btn { max-width: 300px; }
