/* ============================================
 * 운명의 책 — Spellbook aesthetic
 * Aged parchment on dark velvet, burgundy & gold
 * ============================================ */

:root {
  --bg-velvet: #15100a;
  --bg-deep: #0a0705;
  --paper: #ead4a8;
  --paper-shade: #d4ba85;
  --paper-fold: #b89968;
  --ink: #2a1810;
  --ink-soft: #4a3320;
  --ink-faint: #7a5a3a;
  --burgundy: #6e1d20;
  --burgundy-deep: #4a1316;
  --gold: #b89456;
  --gold-bright: #e0c075;
  --gold-faint: #8a6b3a;
  --success: #2d5a2d;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  min-height: 100vh;
  font-family: 'Noto Serif KR', serif;
  color: var(--ink);
  background: var(--bg-deep);
  overflow-x: hidden;
}

/* === BACKDROP === */
body {
  background:
    radial-gradient(ellipse at center, #2a1d10 0%, #15100a 50%, #0a0705 100%),
    var(--bg-deep);
  background-attachment: fixed;
  padding: 40px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}

/* === MASTHEAD (ARTAKUS) === */
.masthead {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 22px;
  margin-bottom: 30px;
  position: relative;
  z-index: 2;
  width: 100%;
  max-width: 680px;
}

.masthead-title {
  font-family: 'Cinzel', serif;
  font-size: clamp(22px, 4vw, 30px);
  font-weight: 700;
  letter-spacing: 0.45em;
  color: var(--gold-bright);
  text-shadow:
    0 0 14px rgba(224, 192, 117, 0.35),
    0 2px 4px rgba(0, 0, 0, 0.5);
  margin: 0;
  padding-left: 0.45em; /* 트래킹 보정 (중앙 정렬) */
}

.masthead-flourish {
  color: var(--gold);
  font-size: 15px;
  text-shadow: 0 0 8px rgba(184, 148, 86, 0.4);
}

@media (max-width: 540px) {
  .masthead {
    gap: 14px;
    margin-bottom: 22px;
  }
  .masthead-title {
    letter-spacing: 0.35em;
  }
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    radial-gradient(circle at 20% 30%, rgba(184, 148, 86, 0.04) 0%, transparent 40%),
    radial-gradient(circle at 80% 70%, rgba(110, 29, 32, 0.05) 0%, transparent 40%);
  pointer-events: none;
  z-index: 0;
}

/* === BOOK === */
.book {
  width: 100%;
  max-width: 680px;
  background: radial-gradient(ellipse at top, var(--paper) 0%, var(--paper-shade) 100%);
  border: 1px solid var(--gold-faint);
  border-radius: 4px;
  box-shadow:
    0 0 0 6px var(--burgundy-deep),
    0 0 0 7px var(--gold-faint),
    0 30px 80px rgba(0, 0, 0, 0.7),
    inset 0 0 80px rgba(74, 51, 32, 0.25);
  padding: 60px 50px;
  position: relative;
  z-index: 1;
  min-height: 600px;
}

/* paper grain texture */
.book::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(0deg,
      transparent 0px, transparent 2px,
      rgba(74, 51, 32, 0.015) 2px, rgba(74, 51, 32, 0.015) 4px),
    repeating-linear-gradient(90deg,
      transparent 0px, transparent 3px,
      rgba(74, 51, 32, 0.01) 3px, rgba(74, 51, 32, 0.01) 5px);
  pointer-events: none;
  border-radius: 4px;
  mix-blend-mode: multiply;
}

/* vignette */
.book::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center,
    transparent 30%,
    rgba(74, 51, 32, 0.1) 80%,
    rgba(42, 24, 16, 0.25) 100%);
  pointer-events: none;
  border-radius: 4px;
}

/* === SCREEN MGMT === */
.screen { display: none; position: relative; z-index: 2; }
.screen.active { display: block; animation: fadeIn 0.8s ease-out; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* === COVER === */
.cover {
  text-align: center;
  padding: 40px 0;
}

.cover-frame {
  border: 1px solid var(--gold-faint);
  padding: 50px 30px;
  margin: 20px 0 36px;
  position: relative;
}

.cover-frame::before,
.cover-frame::after {
  content: '✦';
  position: absolute;
  color: var(--gold);
  font-size: 18px;
  background: var(--paper);
  padding: 0 12px;
}
.cover-frame::before { top: -12px; left: 50%; transform: translateX(-50%); }
.cover-frame::after { bottom: -12px; left: 50%; transform: translateX(-50%); }

.cover-eyebrow {
  font-family: 'Cinzel', serif;
  font-size: 11px;
  letter-spacing: 0.5em;
  color: var(--gold-faint);
  margin-bottom: 24px;
  text-transform: uppercase;
}

.cover-title {
  font-family: 'Nanum Myeongjo', serif;
  font-weight: 800;
  font-size: clamp(36px, 7vw, 56px);
  color: var(--ink);
  line-height: 1.1;
  margin-bottom: 18px;
  letter-spacing: -0.02em;
}

.cover-rule {
  width: 60px;
  height: 1px;
  background: var(--gold);
  margin: 24px auto;
}

.cover-subtitle {
  font-family: 'Nanum Myeongjo', serif;
  color: var(--ink);
  font-size: 16px;
  line-height: 1.75;
  font-weight: 500;
  max-width: 460px;
  margin: 0 auto;
}

.cover-body {
  color: var(--ink-soft);
  font-size: 15.5px;
  line-height: 1.9;
  font-weight: 400;
  max-width: 440px;
  margin: 0 auto 36px;
  text-align: left;
}

.cover-body p { margin-bottom: 12px; }

/* === BUTTONS === */
.btn {
  font-family: 'Nanum Myeongjo', serif;
  font-size: 16px;
  font-weight: 700;
  color: var(--paper);
  background: var(--burgundy-deep);
  border: 1px solid var(--gold);
  padding: 14px 36px;
  cursor: pointer;
  letter-spacing: 0.15em;
  transition: all 0.3s ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.btn:hover {
  background: var(--burgundy);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4), 0 0 20px rgba(184, 148, 86, 0.2);
  transform: translateY(-1px);
}

.btn::before, .btn::after {
  content: '◆';
  color: var(--gold);
  font-size: 10px;
  margin: 0 12px;
  opacity: 0.7;
}

.btn-ghost {
  background: transparent;
  color: var(--ink-soft);
  border: 1px solid var(--gold-faint);
  font-size: 13px;
  padding: 10px 24px;
  letter-spacing: 0.1em;
}

.btn-ghost:hover {
  background: rgba(184, 148, 86, 0.1);
  color: var(--ink);
  box-shadow: none;
}

.btn-ghost::before, .btn-ghost::after { display: none; }

/* === QUIZ === */
.quiz-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 36px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--gold-faint);
}

.quiz-page {
  font-family: 'Cinzel', serif;
  font-size: 12px;
  letter-spacing: 0.3em;
  color: var(--gold-faint);
}

.quiz-progress {
  flex: 1;
  margin: 0 24px;
  height: 1px;
  background: rgba(184, 148, 86, 0.2);
  position: relative;
}

.quiz-progress-fill {
  position: absolute;
  left: 0;
  top: -1px;
  height: 3px;
  background: var(--gold);
  transition: width 0.5s ease;
  box-shadow: 0 0 8px rgba(184, 148, 86, 0.5);
  width: 5%;
}

.question-mark {
  font-family: 'Cinzel', serif;
  color: var(--gold);
  font-size: 14px;
  letter-spacing: 0.4em;
  margin-bottom: 18px;
  display: block;
}

.question {
  font-family: 'Nanum Myeongjo', serif;
  font-weight: 700;
  font-size: clamp(22px, 3.2vw, 26px);
  line-height: 1.55;
  color: var(--ink);
  margin-bottom: 36px;
  min-height: 100px;
  letter-spacing: -0.01em;
}

.choices { display: flex; flex-direction: column; gap: 12px; }

.choice {
  background: rgba(255, 251, 240, 0.4);
  border: 1px solid rgba(184, 148, 86, 0.3);
  padding: 18px 22px;
  font-family: 'Noto Serif KR', serif;
  font-size: 16px;
  font-weight: 500;
  line-height: 1.7;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  transition: all 0.25s ease;
  position: relative;
  overflow: hidden;
}

.choice::before {
  content: attr(data-mark);
  font-family: 'Cinzel', serif;
  color: var(--gold-faint);
  font-size: 13px;
  font-weight: 700;
  margin-right: 14px;
  letter-spacing: 0.1em;
}

.choice:hover {
  background: rgba(255, 251, 240, 0.8);
  border-color: var(--gold);
  transform: translateX(4px);
  box-shadow: -3px 0 0 var(--burgundy);
}

.choice:hover::before { color: var(--burgundy); }

.choice:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

/* === LOADING === */
.loading {
  text-align: center;
  padding: 60px 20px;
}

.sigil {
  width: 90px;
  height: 90px;
  margin: 0 auto 32px;
  position: relative;
  color: var(--gold);
  animation: spin 8s linear infinite;
}

.sigil svg { width: 100%; height: 100%; }
.sigil svg circle, .sigil svg path { stroke: currentColor; fill: none; stroke-width: 1; }
.sigil svg circle[fill="currentColor"] { fill: currentColor; stroke: none; }

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.sigil::after {
  content: '';
  position: absolute;
  inset: -12px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(224, 192, 117, 0.3) 0%, transparent 60%);
  animation: pulse 2.4s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.3; transform: scale(0.9); }
  50% { opacity: 0.6; transform: scale(1.15); }
}

.loading-title {
  font-family: 'Nanum Myeongjo', serif;
  font-weight: 700;
  font-size: clamp(22px, 4vw, 28px);
  color: var(--ink);
  margin-bottom: 18px;
  letter-spacing: 0.02em;
}

.loading-title::after {
  content: '';
  display: inline-block;
  width: 1ch;
  text-align: left;
  animation: dots 1.6s steps(4, end) infinite;
}

@keyframes dots {
  0%, 25% { content: ''; }
  26%, 50% { content: '.'; }
  51%, 75% { content: '..'; }
  76%, 100% { content: '...'; }
}

.loading-text {
  font-family: 'Nanum Myeongjo', serif;
  font-style: italic;
  color: var(--ink-soft);
  font-size: 15px;
  line-height: 1.9;
}

.loading-text .step {
  display: block;
  opacity: 0.5;
  margin: 4px 0;
  animation: fadeStep 4s ease-in-out infinite;
}
.loading-text .step:nth-child(2) { animation-delay: 1.3s; }
.loading-text .step:nth-child(3) { animation-delay: 2.6s; }

@keyframes fadeStep {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 1; }
}

/* === RESULT === */
/* === RESULT PORTRAIT === */
.result-portrait-wrap {
  display: flex;
  justify-content: center;
  margin: 0 0 22px;
}
.result-portrait {
  width: 240px;
  height: 240px;
  object-fit: cover;
  display: block;
  background: var(--paper);
  box-shadow:
    0 0 0 1px var(--gold-faint),
    0 0 0 5px var(--paper),
    0 0 0 6px var(--gold-faint),
    0 6px 18px rgba(0, 0, 0, 0.18);
}
.result-portrait[src=""],
.result-portrait:not([src]) {
  display: none;
}

/* === GENDER SELECTOR (COVER) === */
.gender-selector {
  text-align: center;
  margin: 18px 0 22px;
}
.gender-label {
  font-family: 'Cinzel', serif;
  font-size: 12px;
  letter-spacing: 0.35em;
  color: var(--gold);
  text-transform: uppercase;
  margin-bottom: 10px;
}
.gender-buttons {
  display: inline-flex;
  gap: 8px;
}
.gender-btn {
  font-family: 'Nanum Myeongjo', serif;
  font-weight: 700;
  font-size: 15px;
  padding: 8px 22px;
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--gold-faint);
  cursor: pointer;
  letter-spacing: 0.1em;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.gender-btn:hover {
  background: rgba(184, 148, 86, 0.1);
}
.gender-btn.active {
  background: var(--burgundy-deep);
  color: var(--paper);
  border-color: var(--burgundy-deep);
}

.result-eyebrow {
  font-family: 'Cinzel', serif;
  font-size: 11px;
  letter-spacing: 0.5em;
  color: var(--gold-faint);
  text-align: center;
  margin-bottom: 20px;
}

.result-class {
  font-family: 'Nanum Myeongjo', serif;
  font-weight: 800;
  font-size: clamp(36px, 6vw, 48px);
  color: var(--ink);
  text-align: center;
  line-height: 1.1;
  margin-bottom: 8px;
}

.result-race {
  font-family: 'Nanum Myeongjo', serif;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.3em;
  color: var(--gold);
  text-align: center;
  margin-bottom: 14px;
  padding-left: 0.3em;
}

.result-race::before,
.result-race::after {
  content: '·';
  color: var(--gold-faint);
  margin: 0 14px;
  font-size: 14px;
}

.result-tagline {
  font-family: 'Nanum Myeongjo', serif;
  font-style: italic;
  color: var(--burgundy);
  font-size: 16px;
  text-align: center;
  margin-bottom: 32px;
  line-height: 1.6;
}

.result-divider {
  display: flex;
  align-items: center;
  margin: 36px 0 28px;
  gap: 14px;
}

.result-divider::before,
.result-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--gold-faint);
}

.result-divider-mark {
  color: var(--gold);
  font-size: 12px;
}

.result-section-title {
  font-family: 'Cinzel', serif;
  font-size: 12px;
  letter-spacing: 0.4em;
  color: var(--gold-faint);
  text-transform: uppercase;
  margin-bottom: 14px;
  text-align: center;
}

.weapons {
  text-align: center;
  margin-bottom: 28px;
}

.weapon-row {
  font-family: 'Nanum Myeongjo', serif;
  font-size: 16.5px;
  font-weight: 500;
  color: var(--ink);
  margin: 6px 0;
  line-height: 1.7;
}

.weapon-label {
  color: var(--ink-faint);
  font-size: 12px;
  letter-spacing: 0.2em;
  margin-right: 10px;
}

.skills {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(85px, 1fr));
  gap: 8px;
  margin-bottom: 28px;
}

.skill {
  background: rgba(184, 148, 86, 0.08);
  border: 1px solid var(--gold-faint);
  padding: 7px 10px;
  text-align: center;
  font-family: 'Nanum Myeongjo', serif;
  font-weight: 700;
  color: var(--ink);
  font-size: 13px;
  letter-spacing: 0.03em;
}

.perks { margin-bottom: 28px; }

.perk {
  border-left: 3px solid var(--burgundy);
  background: rgba(110, 29, 32, 0.05);
  padding: 14px 18px;
  margin-bottom: 12px;
}

.perk-name {
  font-family: 'Nanum Myeongjo', serif;
  font-weight: 700;
  color: var(--ink);
  font-size: 17px;
  margin-bottom: 8px;
}

.perk-effects {
  font-size: 14px;
  line-height: 1.8;
  font-weight: 500;
  color: var(--ink-soft);
}

.perk-positive::before {
  content: '＋';
  color: var(--success);
  font-weight: 700;
  margin-right: 6px;
}

.perk-negative {
  margin-top: 4px;
  display: block;
}
.perk-negative::before {
  content: '－';
  color: var(--burgundy);
  font-weight: 700;
  margin-right: 6px;
}

.interpretation {
  font-family: 'Nanum Myeongjo', serif;
  font-size: 17px;
  font-weight: 500;
  line-height: 2.0;
  color: var(--ink);
  text-align: left;
  background: rgba(74, 51, 32, 0.04);
  padding: 26px 28px;
  border-top: 1px solid var(--gold-faint);
  border-bottom: 1px solid var(--gold-faint);
  margin-bottom: 32px;
  letter-spacing: -0.005em;
}

.interpretation::first-letter {
  font-family: 'Nanum Myeongjo', serif;
  font-weight: 800;
  color: var(--burgundy);
  font-size: 2.4em;
  float: left;
  line-height: 0.9;
  margin: 6px 6px 0 0;
}

/* === SPECIAL ABILITY (필살/특수능력) === */
.special-ability {
  background:
    linear-gradient(135deg, rgba(110, 29, 32, 0.08), rgba(184, 148, 86, 0.08));
  border: 1.5px solid var(--gold);
  padding: 22px 24px 20px;
  margin: 8px 0 28px;
  position: relative;
  box-shadow:
    0 0 0 1px rgba(184, 148, 86, 0.15),
    0 0 24px rgba(184, 148, 86, 0.08),
    inset 0 0 30px rgba(110, 29, 32, 0.05);
}

.special-ability::before {
  content: '✦';
  position: absolute;
  top: -11px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--paper);
  padding: 0 14px;
  color: var(--gold);
  font-size: 16px;
}

.special-ability-name {
  font-family: 'Nanum Myeongjo', serif;
  font-weight: 800;
  font-size: 20px;
  color: var(--burgundy);
  text-align: center;
  margin-bottom: 12px;
  letter-spacing: 0.05em;
  text-shadow: 0 1px 0 rgba(184, 148, 86, 0.15);
}

.special-ability-desc {
  font-family: 'Nanum Myeongjo', serif;
  font-size: 15.5px;
  font-weight: 500;
  font-style: italic;
  line-height: 1.75;
  color: var(--ink);
  text-align: center;
}

/* === CAPTURING — html2canvas 호환성 패치 === */
/* 장식 의사 요소(vignette, 질감)를 캡쳐 중 비활성화 */
.book.capturing::before,
.book.capturing::after {
  display: none !important;
}
.book.capturing {
  box-shadow:
    0 0 0 6px var(--burgundy-deep),
    0 0 0 7px var(--gold-faint) !important;
  background: var(--paper) !important;
}
/* 특수능력 박스의 그림자도 캡쳐 시 단순화 */
.book.capturing .special-ability {
  box-shadow: 0 0 0 1px rgba(184, 148, 86, 0.15) !important;
}

/* === JOURNEY (당신의 여정) === */
.journey {
  margin-bottom: 32px;
}

.journey-entry {
  display: flex;
  align-items: baseline;
  gap: 18px;
  padding: 12px 6px;
  border-bottom: 1px dashed rgba(184, 148, 86, 0.35);
  font-family: 'Nanum Myeongjo', serif;
}

.journey-entry:last-child {
  border-bottom: none;
}

.journey-mark {
  font-family: 'Cinzel', serif;
  color: var(--gold);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.15em;
  min-width: 42px;
  text-align: right;
  flex-shrink: 0;
}

.journey-text {
  font-size: 16px;
  font-weight: 500;
  line-height: 1.65;
  color: var(--ink);
}

/* 캡쳐 시에만 보이는 푸터 */
.capture-footer {
  display: none;
  text-align: center;
  margin-top: 28px;
  padding-top: 22px;
  border-top: 1px solid var(--gold-faint);
}

.capture-footer-brand {
  font-family: 'Cinzel', serif;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.5em;
  color: var(--gold);
  padding-left: 0.5em;
  margin-bottom: 6px;
}

.capture-footer-sub {
  font-family: 'Nanum Myeongjo', serif;
  font-size: 12px;
  color: var(--ink-faint);
  letter-spacing: 0.05em;
}

.book.capturing .capture-footer {
  display: block;
}
.book.capturing .result-actions {
  display: none;
}

.result-actions {
  padding-top: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.result-actions .btn {
  min-width: 220px;
}

.result-actions-secondary {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.result-actions-secondary .btn-ghost {
  min-width: 0;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  pointer-events: none;
}

/* === ERROR === */
.error-box {
  background: rgba(110, 29, 32, 0.1);
  border: 1px solid var(--burgundy);
  padding: 20px;
  margin: 20px auto 30px;
  max-width: 480px;
  color: var(--burgundy-deep);
  font-size: 14px;
  line-height: 1.7;
  text-align: left;
  font-family: 'Noto Serif KR', serif;
}

/* === MOBILE === */
@media (max-width: 540px) {
  body { padding: 20px 12px; }
  .book { padding: 36px 24px; }
  .cover-frame { padding: 36px 20px; }
  .choice { padding: 14px 16px; font-size: 14px; }
  .quiz-progress { margin: 0 12px; }
  .loading { padding: 40px 10px; }
}
