:root {
  --bg: #fbf7fb;
  --bg2: #f3ecf8;
  --surface: #ffffff;
  --text: #2a2433;
  --muted: #7a7086;
  --line: #ece4ef;
  --accent: #c46aa0;
  --accent-ink: #ffffff;
  --chip: #f6eef5;
  --bar: #efe6f1;
  --paper: #fffdf8;
  --blob1: #f7c6dc;
  --blob2: #c9d8fb;
  --blob3: #fbe3b5;
  --shadow: 0 10px 30px rgba(90, 50, 90, .10);
  --font: "Gowun Dodum", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  --font-title: "Jua", var(--font);
  --font-hand: "Gaegu", var(--font);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17141c; --bg2: #1d1826; --surface: #221d29; --text: #efe9f4; --muted: #a99fb5;
    --line: #342c3d; --accent: #e08ac0; --accent-ink: #1b1520; --chip: #2e2636;
    --bar: #362d40; --paper: #f4efe6; --blob1: #5a2f4c; --blob2: #2c3a63; --blob3: #4d3d22;
    --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  }
}
:root[data-theme="dark"] {
  --bg: #17141c; --bg2: #1d1826; --surface: #221d29; --text: #efe9f4; --muted: #a99fb5;
  --line: #342c3d; --accent: #e08ac0; --accent-ink: #1b1520; --chip: #2e2636;
  --bar: #362d40; --paper: #f4efe6; --blob1: #5a2f4c; --blob2: #2c3a63; --blob3: #4d3d22;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { overflow-x: hidden; }
body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, var(--bg), var(--bg2));
  color: var(--text);
  font-family: var(--font);
  line-height: 1.6;
  word-break: keep-all;        /* 한글도 띄어쓰기 단위로 줄바꿈 ("모 / 범생이에요" 방지) */
  overflow-wrap: anywhere;     /* 아주 긴 이름만 글자 단위로 */
}

/* 배경 장식: 흐릿한 색 덩어리 셋 + 반짝이 셋 */
.deco { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 0; }
.deco i { position: absolute; border-radius: 50%; filter: blur(60px); opacity: .55; }
.deco i:nth-child(1) { width: 340px; height: 340px; background: var(--blob1); top: -80px; left: -100px; }
.deco i:nth-child(2) { width: 300px; height: 300px; background: var(--blob2); top: 30%; right: -120px; }
.deco i:nth-child(3) { width: 280px; height: 280px; background: var(--blob3); bottom: -100px; left: 20%; }
.deco i:nth-child(n+4) {
  width: 8px; height: 8px; filter: none; opacity: .8; background: var(--accent);
  clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%);
  animation: twinkle 3.2s ease-in-out infinite;
}
.deco i:nth-child(4) { top: 14%; left: 12%; width: 14px; height: 14px; }
.deco i:nth-child(5) { top: 22%; right: 16%; animation-delay: 1.1s; }
.deco i:nth-child(6) { bottom: 18%; right: 28%; width: 12px; height: 12px; animation-delay: 2s; }
@keyframes twinkle { 0%, 100% { transform: scale(.6); opacity: .3; } 50% { transform: scale(1.1); opacity: .9; } }

.wrap { position: relative; z-index: 1; max-width: 760px; margin: 0 auto; padding: 32px 16px 48px; }
.head-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.head h1 { margin: 0; font-family: var(--font-title); font-weight: 400; font-size: 34px; letter-spacing: -.01em; color: var(--accent); }
.sub { margin: 4px 0 0; color: var(--muted); }
.clock { margin: 6px 0 0; font-size: 13px; color: var(--muted); }
.clock b { font-variant-numeric: tabular-nums; color: var(--text); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.form { display: flex; gap: 8px; margin-top: 20px; }
.form input {
  flex: 1; min-width: 0; padding: 12px 14px; font-size: 16px; font-family: inherit;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); color: var(--text);
}
.form input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
button {
  padding: 11px 16px; font-size: 15px; font-family: var(--font-title); font-weight: 400; cursor: pointer;
  border: 0; border-radius: 12px; background: var(--accent); color: var(--accent-ink);
  transition: transform .12s ease, opacity .12s ease;
}
button:active { transform: scale(.97); }
button:disabled { opacity: .6; cursor: default; }
button.ghost { background: var(--surface); color: var(--text); border: 1px solid var(--line); }
.theme { padding: 6px 12px; font-size: 13px; background: var(--surface); color: var(--muted); border: 1px solid var(--line); }
.hint { margin: 8px 2px 0; font-size: 13px; color: var(--muted); }
.hint.warn { color: #e0607a; font-weight: 700; }

/* 결과 카드 */
.card {
  position: relative; margin-top: 24px; display: grid; grid-template-columns: 320px 1fr;
  background: var(--surface); border: 1px solid var(--line); border-radius: 22px;
  box-shadow: var(--shadow);
}
.card.is-rare { border-color: transparent; }
.card.is-rare::before {
  content: ""; position: absolute; inset: -2px; border-radius: 24px; z-index: -1;
  background: linear-gradient(110deg, #f6c453, #f08ab8, #8fb7f5, #9be3c4, #f6c453);
  background-size: 300% 100%; animation: shimmer 4s linear infinite;
}
@keyframes shimmer { to { background-position: 300% 0; } }

.art { padding: 26px 22px; display: flex; align-items: flex-start; justify-content: center; }
.polaroid {
  position: relative; width: 100%; max-width: 280px; padding: 12px 12px 0;
  background: var(--paper); border-radius: 4px; transform: rotate(-2deg);
  box-shadow: 0 8px 20px rgba(40, 20, 40, .18), 0 1px 2px rgba(0, 0, 0, .1);
}
.photo { position: relative; aspect-ratio: 3 / 4; overflow: hidden; background: #2b2530; }
.photo img, .art-fallback, .art-fallback svg { width: 100%; height: 100%; display: block; object-fit: cover; }
.caption {
  margin: 0; padding: 8px 4px 12px; text-align: center; color: #4a3f52;
  font-family: var(--font-hand); font-size: 22px; line-height: 1.2;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.rare {
  position: absolute; top: -10px; right: -10px; padding: 2px 10px; border-radius: 999px;
  background: linear-gradient(90deg, #f6c453, #f08ab8, #8fb7f5); color: #241b2b;
  font-family: var(--font-title); font-size: 15px; transform: rotate(8deg);
  box-shadow: 0 3px 8px rgba(0, 0, 0, .2);
}
.developing-label {
  position: absolute; inset: 0; display: grid; place-items: center; opacity: 0; pointer-events: none;
  font-family: var(--font-hand); font-size: 22px; color: #f4eef7; letter-spacing: .05em;
}

.body { padding: 22px 24px 20px 4px; }
.date { margin: 0; font-size: 13px; color: var(--muted); }
.body h2 { margin: 0 0 2px; font-family: var(--font-title); font-weight: 400; font-size: 28px; letter-spacing: -.01em; }
.scene { margin: 0 0 12px; color: var(--accent); font-weight: 700; }
.chips { list-style: none; display: flex; flex-wrap: wrap; gap: 6px; padding: 0; margin: 0 0 14px; }
.chips li { padding: 3px 10px; border-radius: 999px; background: var(--chip); font-size: 13px; }
.fortune { margin: 0 0 14px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: var(--muted); vertical-align: 1px; }
.dot.on { background: #4cc38a; box-shadow: 0 0 0 3px rgba(76, 195, 138, .25); animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(76, 195, 138, 0); } }
/* 문장은 마침표 뒤에서 줄을 바꾼다(app.js 가 ". " → ".\n") */
.sub, .hint, .desc, .reading, .lab-text, .fortune, .note, .ai-note { white-space: pre-line; }
.ai-note { margin: 12px 0 0; padding: 8px 12px; border-radius: 10px; background: var(--chip); font-size: 12px; color: var(--muted); }
.ai-tag {
  position: absolute; right: 8px; bottom: 8px; padding: 1px 7px; border-radius: 6px;
  font-size: 11px; color: #fff; background: rgba(20, 14, 24, .55); backdrop-filter: blur(2px);
}
.desc { margin: 0 0 12px; font-size: 15px; }
.desc b { font-weight: 700; }
.mask {
  display: inline-block; padding: 0 6px; border-radius: 6px; background: var(--chip); color: transparent;
  text-shadow: 0 0 8px var(--muted); user-select: none;
}
.reading.pending { color: var(--muted); }
.reading { margin: -4px 0 14px; padding: 8px 12px; border-left: 3px solid var(--accent); background: var(--chip); border-radius: 0 10px 10px 0; font-size: 14px; }
.lab { margin: 0 0 14px; padding: 12px 14px; border: 1px dashed var(--accent); border-radius: 14px; }
.lab-text { margin: 0 0 8px; font-size: 14px; }
.lab-text:last-child { margin: 0; }
.lab-bar { height: 10px; border-radius: 999px; background: var(--bar); overflow: hidden; margin-bottom: 4px; }
.lab-fill { height: 100%; width: 0; background: var(--accent); border-radius: 999px; transition: width .8s ease; }
.lab button { margin-top: 2px; }
.ts:not(:empty) { margin: 4px 0 8px; }
.photo.undeveloped { background: linear-gradient(160deg, #3a3340, #2b2530); }
.lucky { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.lucky > div { padding: 8px 10px; border: 1px solid var(--line); border-radius: 12px; display: flex; flex-direction: column; }
.k { font-size: 12px; color: var(--muted); }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; border: 1px solid var(--line); }
.stats { display: grid; gap: 6px; margin-bottom: 16px; }
.stat { display: grid; grid-template-columns: 40px 1fr 32px; align-items: center; gap: 8px; font-size: 13px; }
.stat .track { height: 8px; border-radius: 999px; background: var(--bar); overflow: hidden; }
.stat .fill { height: 100%; border-radius: 999px; background: var(--accent); transform-origin: left; }
.stat .v { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.note { margin: 10px 0 0; font-size: 12px; color: var(--muted); min-height: 1em; word-break: break-all; }
.foot { margin-top: 28px; font-size: 12px; color: var(--muted); text-align: center; white-space: pre-line; }
.foot a { color: inherit; }

/* 인화 연출: 사진이 하얗게 바랜 상태에서 서서히 맺히고, 오른쪽 내용이 차례로 올라온다 */
.card.reveal .polaroid { animation: drop .6s cubic-bezier(.2, .9, .3, 1.2) both; }
.card.reveal .photo img, .card.reveal .art-fallback { animation: develop 2.6s ease-out .3s both; }
.card.reveal .developing-label { animation: label 2.2s ease-out .2s both; }
.card.reveal .body > * { animation: rise .5s ease-out both; animation-delay: calc(1.2s + var(--i, 0) * 90ms); }
.card.reveal .stat .fill { animation: grow .8s ease-out both; animation-delay: calc(1.9s + var(--i, 0) * 80ms); }
.card.reveal .rare { animation: pop .5s cubic-bezier(.2, .9, .3, 1.6) 2.6s both; }
@keyframes drop { from { transform: translateY(-24px) rotate(-8deg); opacity: 0; } to { transform: rotate(-2deg); opacity: 1; } }
@keyframes develop {
  0% { filter: brightness(2.2) contrast(.3) saturate(0) blur(8px); opacity: .25; }
  60% { filter: brightness(1.2) contrast(.8) saturate(.6) blur(1px); opacity: .9; }
  100% { filter: none; opacity: 1; }
}
@keyframes label { 0%, 50% { opacity: 1; } 100% { opacity: 0; } }
@keyframes rise { from { transform: translateY(10px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes grow { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@keyframes pop { from { transform: rotate(8deg) scale(0); } to { transform: rotate(8deg) scale(1); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0s !important; }
}

@media (max-width: 680px) {
  .card { grid-template-columns: 1fr; }
  .art { padding: 22px 16px 6px; }
  .polaroid { max-width: 260px; }
  .body { padding: 16px 18px 20px; }
}
