/* =========================================================================
   main.css — 컴포넌트 스타일
   모바일 우선. 앱 컨테이너 최대폭 480px, 중앙 정렬.
   ========================================================================= */

/* ---- Reset ---- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
button { font-family: inherit; cursor: pointer; }
a { color: inherit; }

body {
  font-family: var(--font-sans);
  font-size: var(--text-body);
  line-height: var(--lh-body);
  color: var(--text-primary);
  background: var(--bg-primary);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  /* 한국어가 단어 중간에서 끊기지 않도록(어절 단위 줄바꿈) — 모든 화면 공통.
     아주 긴 토큰은 넘치지 않게 break-word 로 폴백. */
  word-break: keep-all;
  overflow-wrap: break-word;
}

/* ---- App shell ---- */
.app {
  max-width: var(--app-max-width);
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--bg-primary);
  padding: 52px var(--space-5) var(--space-10); /* 상단 고정 토글(언어/테마) 여백 확보 */
  position: relative;
  overflow-x: hidden;
}
/* 은은한 리본·박스 실사 패턴 배경 (opacity 낮게 → 가독성 유지) */
.app::before {
  content: '';
  position: fixed;
  inset: 0;
  background: url('../assets/brand/pattern.jpg') center / cover no-repeat;
  opacity: 0.05;
  pointer-events: none;
  z-index: 0;
}

/* ---- Screen 전환 ---- */
.screen { display: none; position: relative; z-index: 1; } /* 배경 패턴 위로 */
.screen.is-active {
  display: block;
  animation: fadeInUp var(--dur-base) var(--ease-out);
}
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
  .screen.is-active { animation: none; }
  .rx-stamp { animation: none; }
  * { scroll-behavior: auto !important; }
}

/* ---- Typography helpers ---- */
.label {
  font-size: var(--text-caption);
  font-weight: var(--fw-medium);
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--text-secondary);
}
.mono { font-family: var(--font-mono); }
/* 'Rx' 처방 레터마크의 작은 x (유니코드 ℞ 대신 사용 — 글꼴에 따라 Px 로 보이는 문제 방지) */
.rx-sub { font-size: 0.62em; font-weight: 700; }
h1 { font-size: var(--text-h1); font-weight: var(--fw-bold); line-height: var(--lh-tight); margin: 0; }
h2 { font-size: var(--text-h2); font-weight: var(--fw-semibold); line-height: var(--lh-tight); margin: 0; }
p  { margin: 0; }

/* ---- Brand logo (Dr.Jart+) ---- */
.brand-logo {
  font-weight: var(--fw-bold);
  font-size: var(--text-lg);
  letter-spacing: -0.02em;
}
.brand-logo .plus { color: var(--accent-primary); }

/* ---- Rx 처방전 헤더 ---- */
.rx-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: var(--space-3);
  border-bottom: 1px dashed var(--border);
}
.rx-header .rx-symbol {
  display: inline-flex;
  align-items: baseline;
  gap: var(--space-2);
}
.rx-header .rx-symbol .rx-mark {
  font-family: var(--font-mono);
  font-size: var(--text-xl);
  font-weight: var(--fw-bold);
  color: var(--accent-primary);
  line-height: 1;
}
.rx-header .rx-date {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

/* ---- Card / Surface ---- */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  box-shadow: var(--shadow-sm);
}
.dashed-divider {
  border: 0;
  border-top: 1px dashed var(--border);
  margin: var(--space-4) 0;
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  width: 100%;
  padding: var(--space-4);
  font-size: var(--text-body);
  font-weight: var(--fw-semibold);
  border-radius: var(--radius-md);
  border: 1.5px solid transparent;
  transition: transform var(--dur-fast) var(--ease-out),
              border-color var(--dur-fast) var(--ease-out),
              background var(--dur-fast) var(--ease-out);
}
.btn:active { transform: scale(0.98); }
.btn-primary {
  background: var(--accent-primary);
  color: #fff;
}
.btn-primary:hover { filter: brightness(1.05); }
.btn-outline {
  background: transparent;
  color: var(--text-primary);
  border-color: var(--border);
}
.btn-outline:hover { border-color: var(--accent-primary); }
.btn-text {
  width: auto;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: var(--text-sm);
  text-decoration: underline;
  text-underline-offset: 3px;
  padding: var(--space-3);
}
.btn-text:hover { color: var(--accent-primary); }

/* =========================================================================
   INTRO
   ========================================================================= */
.intro-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-8);
}
.intro-badge {
  font-size: var(--text-caption);
  font-weight: var(--fw-semibold);
  letter-spacing: 1.5px;
  color: var(--accent-primary);
  background: var(--bg-accent);
  border-radius: var(--radius-pill);
  padding: var(--space-1) var(--space-3);
}
.intro-hero {
  text-align: center;
  padding: var(--space-8) 0 var(--space-6);
}
.intro-hero .ribbon { margin: 0 auto var(--space-5); display: block; }
.intro-hero-photo {
  width: 100%;
  height: 210px;
  object-fit: cover;
  object-position: center 32%;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  display: block;
  margin: 0 auto var(--space-6);
}
.intro-hero h1 { margin-bottom: var(--space-3); }
.intro-hero .sub {
  color: var(--text-secondary);
  font-size: var(--text-lg);
}
.intro-meta {
  text-align: center;
  margin: var(--space-6) 0;
}
.intro-meta .label { display: block; margin-bottom: var(--space-2); }
.intro-meta .meta-line {
  font-size: var(--text-sm);
  line-height: 1.6;
  color: var(--text-primary);
}
.intro-meta .meta-sub {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-secondary);
  margin-top: var(--space-2);
}
.intro-footer {
  text-align: center;
  margin-top: var(--space-8);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: 1px;
  color: var(--text-secondary);
}

/* 누적 참여수 (시작 버튼 밑) */
.test-count {
  margin-top: var(--space-4);
  text-align: center;
  font-size: var(--text-sm);
  color: var(--text-secondary);
}
.test-count b {
  font-family: var(--font-mono);
  font-weight: var(--fw-bold);
  color: var(--accent-primary);
}

/* 브랜드 이미지 슬롯 */
.brand-lockup { display: inline-flex; align-items: center; }
.brand-logo-img { height: 22px; width: auto; display: block; }
.brand-hero {
  display: block;
  max-width: 200px;
  width: 60%;
  height: auto;
  margin: 0 auto var(--space-5);
}

/* =========================================================================
   QUIZ
   ========================================================================= */
.quiz-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-5);
}
.quiz-back {
  background: none; border: none;
  color: var(--text-secondary);
  font-size: var(--text-sm);
  padding: var(--space-2);
  visibility: hidden;
}
.quiz-back.is-visible { visibility: visible; }
.quiz-counter {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--text-secondary);
}
.quiz-counter b { color: var(--accent-primary); }

.progress-track {
  height: 6px;
  background: var(--border);
  border-radius: var(--radius-pill);
  overflow: hidden;
  margin-bottom: var(--space-8);
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent-primary);
  border-radius: var(--radius-pill);
  transition: width var(--dur-slow) var(--ease-out);
}

.quiz-category {
  margin-bottom: var(--space-3);
}
.quiz-question {
  font-size: var(--text-h2);
  font-weight: var(--fw-semibold);
  line-height: 1.45;
  margin-bottom: var(--space-6);
}
.quiz-options { display: flex; flex-direction: column; gap: var(--space-3); }
.option-card {
  text-align: left;
  width: 100%;
  background: var(--bg-surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-5);
  font-size: var(--text-body);
  line-height: 1.5;
  color: var(--text-primary);
  display: flex;
  gap: var(--space-3);
  align-items: flex-start;
  transition: border-color var(--dur-fast), background var(--dur-fast),
              transform var(--dur-fast);
}
.option-card:hover { border-color: var(--accent-primary); }
.option-card:active { transform: scale(0.99); }
.option-card.is-selected {
  border-color: var(--accent-primary);
  background: var(--bg-accent);
}
.option-key {
  font-family: var(--font-mono);
  font-weight: var(--fw-bold);
  color: var(--accent-primary);
  flex-shrink: 0;
}

/* =========================================================================
   LOADING
   ========================================================================= */
.loading-wrap {
  min-height: 70vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: var(--space-5);
}
.loading-title {
  font-size: var(--text-h2);
  font-weight: var(--fw-semibold);
}
.loading-code {
  font-family: var(--font-mono);
  font-size: var(--text-xl);
  letter-spacing: 3px;
  color: var(--accent-primary);
}
.loading-track {
  width: 200px;
  height: 4px;
  background: var(--border);
  border-radius: var(--radius-pill);
  overflow: hidden;
}
.loading-bar {
  height: 100%;
  width: 40%;
  background: var(--accent-primary);
  border-radius: var(--radius-pill);
  animation: indeterminate 1.1s var(--ease-out) infinite;
}
@keyframes indeterminate {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(350%); }
}
.loading-rx-icon {
  font-family: var(--font-mono);
  font-size: 40px;
  font-weight: var(--fw-bold);
  color: var(--accent-primary);
}

/* =========================================================================
   RESULT
   ========================================================================= */
.result-card {
  position: relative;
  overflow: hidden;
  animation: slideUp var(--dur-slow) var(--ease-out);
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}
/* 처방전용 점선 테두리 프레임 */
.result-card::before {
  content: '';
  position: absolute;
  inset: 8px;
  border: 1px dashed var(--border);
  border-radius: calc(var(--radius-lg) - 4px);
  pointer-events: none;
  z-index: 0;
}
/* 닥터자르트 씰 워터마크 (배경에 살짝 투명하게) */
.result-card::after {
  content: '';
  position: absolute;
  inset: 0;
  background: url('../assets/icons/seal-stamp.svg') no-repeat center 52%;
  background-size: 300px;
  opacity: 0.045;
  pointer-events: none;
  z-index: 0;
}
/* 콘텐츠는 프레임/워터마크 위로 */
.result-card > * { position: relative; z-index: 1; }

/* 처방전 직인 (Rx 박스 우하단 모서리에 쾅) */
.rx-stamp {
  position: absolute;
  right: -6px;
  bottom: -12px;
  width: 84px;
  height: 84px;
  transform: rotate(-13deg);
  opacity: 0.9;
  transform-origin: center;
  pointer-events: none;
  animation: stampIn 0.45s var(--ease-out) both;
  animation-delay: 0.5s;
}
@keyframes stampIn {
  0%   { opacity: 0;    transform: rotate(-12deg) scale(1.8); }
  55%  { opacity: 0.95; transform: rotate(-12deg) scale(0.9); }
  100% { opacity: 0.9;  transform: rotate(-12deg) scale(1); }
}

.patient-info {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin: var(--space-4) 0;
  display: grid;
  gap: var(--space-1);
}
.patient-info .row { display: flex; gap: var(--space-3); }
.patient-info .row .k { color: var(--text-secondary); min-width: 92px; }
.patient-info .row .v { color: var(--text-primary); font-weight: var(--fw-medium); }

.bear-stage {
  display: flex;
  justify-content: center;
  padding: var(--space-4) 0;
}
.bear-stage img {
  width: 220px;
  max-width: 78%;
  height: auto;
  filter: drop-shadow(0 4px 8px rgba(10, 22, 40, 0.08));
}

/* Pink Bear Index gauge */
.pbi { margin: var(--space-5) 0; }
.pbi-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: var(--space-2);
}
.pbi-value {
  font-family: var(--font-mono);
  font-size: var(--text-xl);
  font-weight: var(--fw-bold);
  color: var(--accent-primary);
}
.pbi-track {
  height: 10px;
  background: var(--border);
  border-radius: var(--radius-pill);
  overflow: hidden;
}
.pbi-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent-secondary), var(--accent-primary));
  border-radius: var(--radius-pill);
  transition: width 1s var(--ease-out);
}

.result-name { text-align: center; margin-top: var(--space-4); }
.result-name h1 { margin-bottom: var(--space-2); }
.result-tagline {
  font-family: var(--font-mono);
  font-size: var(--text-caption);
  letter-spacing: 2px;
  color: var(--accent-primary);
}
.result-desc {
  color: var(--text-secondary);
  text-align: center;
  margin-top: var(--space-3);
}

/* Rx prescription box */
.rx-box {
  position: relative;
  background: var(--bg-accent);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-5);
  margin-top: var(--space-6);
}
.rx-box-title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: var(--fw-bold);
  color: var(--accent-secondary);
  margin-bottom: var(--space-3);
}
.rx-box-title .rx-mark { font-family: var(--font-mono); color: var(--accent-primary); }
.rx-lines { display: grid; gap: var(--space-2); margin: var(--space-3) 0; }
.rx-lines .rx-row { display: flex; gap: var(--space-3); font-size: var(--text-sm); }
.rx-lines .rx-row .rx-k {
  font-family: var(--font-mono);
  color: var(--accent-secondary);
  min-width: 96px;
  flex-shrink: 0;
}
.rx-lines .rx-row .rx-v { color: var(--text-primary); }
.rx-note {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  line-height: var(--lh-body);
}
.rx-box-footer {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  text-align: left;
  line-height: 1.6;
  font-style: italic;
  margin-top: var(--space-3);
}

/* Invitation card */
.invite-card {
  border: 1.5px dashed var(--accent-primary);
  border-radius: var(--radius-md);
  padding: var(--space-5);
  margin-top: var(--space-6);
  background: var(--bg-accent);
}
.invite-photo {
  width: 100%;
  height: 150px;
  object-fit: cover;
  object-position: center 45%;
  border-radius: var(--radius-sm);
  display: block;
  margin-bottom: var(--space-4);
}
.invite-title {
  font-weight: var(--fw-bold);
  color: var(--accent-secondary);
  margin-bottom: var(--space-3);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.invite-list { display: grid; gap: var(--space-2); }
.invite-list .row { display: flex; gap: var(--space-3); font-size: var(--text-sm); }
.invite-list .row .k {
  font-size: var(--text-caption);
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-secondary);
  min-width: 68px;
  flex-shrink: 0;
  padding-top: 2px;
}
.invite-list .row .v { color: var(--text-primary); font-weight: var(--fw-medium); }
.invite-premium {
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px dashed var(--accent-primary);
  font-size: var(--text-sm);
  color: var(--accent-secondary);
  font-weight: var(--fw-medium);
}

/* Share buttons */
.share-actions {
  display: grid;
  gap: var(--space-3);
  margin-top: var(--space-6);
}
.result-restart { text-align: center; margin-top: var(--space-4); }

/* 공식 캠페인 고지 (결과 하단 미션 푸터) */
.campaign-note {
  margin-top: var(--space-6);
  padding-top: var(--space-5);
  border-top: 1px dashed var(--border);
  text-align: center;
}
.campaign-ribbon {
  display: block;
  margin: 0 auto var(--space-3);
  opacity: 0.9;
}
.campaign-note p {
  font-size: var(--text-xs);
  line-height: 1.75;
  color: var(--text-secondary);
  text-align: left;
  margin: 0;
}

/* =========================================================================
   TOAST
   ========================================================================= */
.toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translateX(-50%) translateY(20px);
  background: var(--accent-secondary);
  color: #fff;
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-pill);
  font-size: var(--text-sm);
  font-weight: var(--fw-medium);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-base), transform var(--dur-base) var(--ease-out);
  z-index: 100;
}
.toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---- Language switcher (좌측 상단 고정) ---- */
.lang-switch {
  position: fixed;
  top: 10px;
  left: 10px;
  display: flex;
  gap: 2px;
  padding: 2px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-sm);
  z-index: 90;
}
.lang-switch button {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: var(--fw-bold);
  letter-spacing: 1px;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
}
.lang-switch button.is-active {
  background: var(--accent-primary);
  color: #fff;
}

/* =========================================================================
   CAPTURE MODAL (결과 이미지 미리보기)
   ========================================================================= */
.capture-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: none;
}
.capture-modal.is-open {
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeInUp var(--dur-base) var(--ease-out);
}
.capture-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 22, 40, 0.6);
}
.capture-sheet {
  position: relative;
  width: 88%;
  max-width: calc(var(--app-max-width) - 40px);
  max-height: 90vh;
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  box-shadow: var(--shadow-lg);
}
.capture-hint {
  text-align: center;
  font-size: var(--text-sm);
  color: var(--text-secondary);
  line-height: 1.5;
}
.capture-img-wrap {
  overflow: auto;
  max-height: 58vh;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  -webkit-overflow-scrolling: touch;
}
.capture-img {
  display: block;
  width: 100%;
  height: auto;
}
.capture-actions {
  display: grid;
  gap: var(--space-2);
}
#capture-close { align-self: center; }

/* ---- Theme switcher (개발/데모용, 우측 상단 고정) ---- */
.theme-switch {
  position: fixed;
  top: 10px;
  right: 10px;
  display: flex;
  gap: 6px;
  z-index: 90;
}
.theme-switch button {
  width: 20px; height: 20px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: var(--shadow-sm);
  padding: 0;
}
.theme-switch [data-theme="theme-nude"]     { background: #D4537E; }
.theme-switch [data-theme="theme-milky"]    { background: #E85A85; }
.theme-switch [data-theme="theme-clinical"] { background: #E11D6C; }

/* ---- Focus visibility (접근성) ---- */
:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}
