:root {
  --bg: #F4EEE3;
  --ink: #2B2620;
  --ink-2: #4E463D;
  --accent: #3F5A4C;
  --soft: #DDD3C3;
  --seal: #A8322A;
  --glass: rgba(255, 253, 248, 0.86);
  --line: rgba(43, 38, 32, 0.12);
  --radius: 18px;
  --brush: 'East Sea Dokdo', cursive;
  --verse: 'Nanum Myeongjo', 'Gowun Batang', serif;
  --body: 'Gowun Batang', 'Apple SD Gothic Neo', 'Malgun Gothic', serif;
}
/* 오행 색 (오방색에서 따옴) */
body[data-el="wood"]  { --bg: #E9EFE4; --ink: #22382A; --accent: #3F6B4A; --soft: #C9D8C2; }
body[data-el="fire"]  { --bg: #F6E8E2; --ink: #3A1F18; --accent: #B5432F; --soft: #EBC4B8; }
body[data-el="earth"] { --bg: #F3EBDA; --ink: #36291A; --accent: #A47A2C; --soft: #E2CFA6; }
body[data-el="metal"] { --bg: #EDEDEA; --ink: #26292B; --accent: #5E6468; --soft: #D3D4D0; }
body[data-el="water"] { --bg: #E4E9F0; --ink: #16243A; --accent: #2E4A6B; --soft: #BFCADA; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) body {
    --bg: #17150F; --ink: #EFE8DC; --ink-2: #B8AE9F; --glass: rgba(34, 31, 26, 0.78); --line: rgba(239, 232, 220, 0.14);
  }
  :root:not([data-theme="light"]) body[data-el="wood"]  { --bg: #121A14; --accent: #8DBB98; }
  :root:not([data-theme="light"]) body[data-el="fire"]  { --bg: #1D1210; --accent: #E58C76; }
  :root:not([data-theme="light"]) body[data-el="earth"] { --bg: #1B160D; --accent: #D8B266; }
  :root:not([data-theme="light"]) body[data-el="metal"] { --bg: #151617; --accent: #B9BEC2; }
  :root:not([data-theme="light"]) body[data-el="water"] { --bg: #0F1520; --accent: #8FB0D6; }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg); color: var(--ink); font-family: var(--body); line-height: 1.7; font-size: 17px;
  -webkit-text-size-adjust: 100%; transition: background .6s ease;
}
.bg {
  position: fixed; inset: 0; background-size: cover; background-position: center bottom; z-index: 0;
  opacity: .95; transition: opacity .6s ease;
}
.bg.scroll { transition: background-position 1.1s cubic-bezier(.4, .1, .2, 1); }
#app { position: relative; z-index: 1; max-width: 480px; margin: 0 auto; padding: 20px 18px calc(28px + env(safe-area-inset-bottom)); }
.screen { display: none; min-height: calc(100dvh - 48px); }
.screen.active { display: flex; flex-direction: column; animation: rise .5s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }

/* 글씨 */
.brand { font-family: var(--brush); font-size: 40px; color: var(--seal); margin: 0; line-height: 1; letter-spacing: .02em; }
.brand.small { font-size: 30px; }
.title { font-family: var(--verse); font-weight: 800; font-size: 32px; line-height: 1.35; margin: 14px 0 10px; }
.lead { color: var(--ink-2); margin: 0 0 14px; font-size: 17px; font-weight: 700; }
.eyebrow { font-size: 14px; letter-spacing: .08em; color: var(--ink-2); font-weight: 700; margin: 18px 0 6px; }
.slide-title { font-family: var(--verse); font-weight: 800; font-size: 38px; margin: 10px 0 2px; text-align: center; }
.slide-sub { text-align: center; color: var(--ink); margin: 0; font-size: 18px; font-weight: 700; }
.slide-note { text-align: center; color: var(--accent); font-size: 16px; font-weight: 700; margin: 8px 0 0; }
.verse { font-family: var(--verse); font-weight: 800; font-size: 29px; line-height: 1.6; margin: 6px 0 14px; word-break: keep-all; }
.small-verse { font-size: 24px; }
.small-text { font-size: 17px; margin: 6px 0; word-break: keep-all; font-weight: 700; }
.soft { color: var(--ink-2); }
.center { text-align: center; }
.badge {
  display: inline-block; font-size: 14px; font-weight: 700; padding: 5px 12px; border-radius: 999px;
  background: var(--glass); border: 1px solid var(--line); color: var(--ink-2); backdrop-filter: blur(6px);
}
.debug {
  pointer-events: auto; font: 12px/1.5 ui-monospace, Consolas, monospace; background: rgba(0,0,0,.72); color: #fff;
  padding: 10px; border-radius: 10px; margin: 12px 0 0; white-space: pre-wrap; text-align: left;
}
.classic { font-size: 15px; font-weight: 700; color: var(--ink-2); border-left: 3px solid var(--seal); padding-left: 10px; margin: 4px 0 0; }
.note { font-size: 13px; color: var(--ink-2); text-align: center; margin: 10px 0 0; }
.error { color: var(--seal); font-size: 14px; min-height: 1.2em; margin: 6px 0; }

/* 도장 */
.seal {
  background: var(--seal); color: #fff; font-family: var(--verse); font-weight: 800; display: flex; align-items: center; justify-content: center;
  border-radius: 16px; box-shadow: inset 0 0 0 3px rgba(255,255,255,.35); transform: rotate(-5deg);
}
.seal-hero { width: 76px; height: 76px; font-size: 48px; margin: 18px 0 0; }
.seal-big { width: 128px; height: 128px; font-size: 84px; margin: 34px auto 8px; }
.stamp { animation: stamp .6s cubic-bezier(.2, .9, .3, 1.4) both; animation-delay: .25s; }
@keyframes stamp { 0% { opacity: 0; transform: scale(2.2) rotate(-14deg); } 70% { opacity: 1; transform: scale(.94) rotate(-4deg); } 100% { transform: scale(1) rotate(-5deg); } }

/* 유리 상자 */
.hero { padding-top: 6px; }
.glass {
  background: var(--glass); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 16px; margin: 16px 0; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.returning-summary { font-family: var(--verse); font-weight: 800; font-size: 24px; margin: 0 0 6px; }
.daily { margin: 6px 0; font-size: 17px; font-weight: 700; }

/* 입력 */
.field { display: block; border: 0; padding: 0; margin: 0 0 16px; }
.field > span, .field > legend { display: block; font-size: 15px; font-weight: 700; color: var(--ink-2); margin-bottom: 6px; padding: 0; }
select {
  width: 100%; font: inherit; padding: 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg); color: var(--ink); appearance: none;
}
.seg { display: flex; gap: 8px; }
.seg label {
  flex: 1 1 0; text-align: center; padding: 10px 4px; border-radius: 12px; border: 1px solid var(--line);
  cursor: pointer; font-size: 16px; font-weight: 700; transition: all .2s;
}
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label:has(input:checked) { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.seg.small label { font-size: 14px; padding: 7px 4px; }
.check { display: flex; gap: 8px; align-items: flex-start; font-size: 15px; margin: 0 0 12px; color: var(--ink-2); }
.check input { margin-top: 4px; accent-color: var(--accent); }
.check a { color: var(--accent); }

/* 버튼: 엄지 닿는 아래쪽 */
.dock { margin-top: auto; padding-top: 14px; }
button, .file {
  display: block; width: 100%; font: inherit; font-size: 17px; padding: 15px; border-radius: 999px;
  margin: 10px 0 0; cursor: pointer; text-align: center; border: 1px solid transparent; transition: transform .1s;
}
button:active { transform: scale(.98); }
.primary { background: var(--ink); color: var(--bg); font-weight: 700; }
.primary:disabled { opacity: .4; }
.ghost { background: var(--glass); color: var(--ink); border-color: var(--line); }
.text { background: transparent; color: var(--ink-2); font-size: 16px; font-weight: 700; padding: 8px; }

/* 촬영 */
.step-title { font-family: var(--verse); font-weight: 800; font-size: 26px; text-align: center; margin: 8px 0 12px; }
.camera {
  position: relative; width: 100%; aspect-ratio: 3 / 4; border-radius: 26px; overflow: hidden; background: #0d0c0a;
}
.camera video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.guide {
  position: absolute; left: 50%; top: 46%; width: 60%; height: 68%; transform: translate(-50%, -50%);
  border: 2px dashed rgba(255,255,255,.7); border-radius: 50%; transition: border-color .3s;
}
.guide.ok { border: 3px solid #E9D9A6; box-shadow: 0 0 0 9999px rgba(0,0,0,.18); }
.cam-hint {
  position: absolute; left: 12px; right: 12px; bottom: 12px; margin: 0; text-align: center; color: #fff;
  font-size: 16px; font-weight: 700; background: rgba(0,0,0,.55); border-radius: 999px; padding: 8px 12px;
}
#capture-tip { color: var(--seal); font-weight: 800; }
.shutter {
  width: 76px; height: 76px; padding: 0; margin: 4px auto 0; border-radius: 50%; background: transparent;
  border: 3px solid var(--ink); display: flex; align-items: center; justify-content: center;
}
.shutter span { width: 60px; height: 60px; border-radius: 50%; background: var(--seal); display: block; }
.shutter:disabled { opacity: .35; }

/* 기다림: 먹물 번짐 */
.ink { position: relative; width: 220px; height: 220px; margin: 18vh auto 24px; }
.ink i {
  position: absolute; inset: 0; margin: auto; width: 40px; height: 40px; border-radius: 50%;
  background: var(--ink); filter: blur(10px); opacity: .0; animation: ink 2.4s ease-out infinite;
}
.ink i:nth-child(2) { animation-delay: .8s; }
.ink i:nth-child(3) { animation-delay: 1.6s; }
@keyframes ink { 0% { transform: scale(.2); opacity: .55; } 100% { transform: scale(5); opacity: 0; } }
.loading-text { font-family: var(--verse); font-weight: 800; text-align: center; font-size: 24px; }
.loading-text::after { content: ''; animation: dots 1.4s steps(4) infinite; }
@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }

/* 결과 스토리 */
.story { position: relative; padding-top: 18px; }
.progress { position: absolute; top: 0; left: 0; right: 40px; display: flex; gap: 4px; z-index: 3; }
.progress i { flex: 1; height: 3px; border-radius: 3px; background: var(--line); overflow: hidden; }
.progress i.done { background: var(--ink); }
.progress i.now { background: linear-gradient(90deg, var(--ink) 50%, var(--line) 50%); background-size: 200% 100%; animation: fill .5s ease forwards; }
@keyframes fill { from { background-position: 100% 0; } to { background-position: 0 0; } }
.story-close {
  position: absolute; top: -8px; right: -4px; width: 36px; height: 36px; padding: 0; margin: 0; z-index: 4;
  background: transparent; color: var(--ink-2); font-size: 18px;
}
.slide { display: none; flex-direction: column; flex: 1; position: relative; z-index: 2; padding-top: 18px; pointer-events: none; }
.slide button, .slide select, .slide label, .slide a, .slide input, .slide .dock, .slide .mbti, .slide img { pointer-events: auto; }
.slide.on { display: flex; animation: rise .45s ease both; }
.tap-hint { margin-top: auto; text-align: center; font-size: 14px; font-weight: 700; color: var(--ink-2); animation: blink 2s ease-in-out infinite; }
@keyframes blink { 50% { opacity: .35; } }
.next-pill {
  position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  width: auto; min-width: 220px; margin: 0; padding: 12px 26px 10px; z-index: 6; border-radius: 999px;
  background: var(--ink); color: var(--bg); font-weight: 800; font-size: 17px; line-height: 1.3;
  box-shadow: 0 10px 26px rgba(0,0,0,.22); animation: nudge 1.6s ease-in-out infinite;
}
.next-pill span { display: inline-block; font-size: 20px; }
.next-pill small { display: block; font-size: 12px; font-weight: 700; opacity: .8; margin-top: 2px; }
.next-pill:active { transform: translateX(-50%) scale(.97); }
@keyframes nudge { 0%, 100% { transform: translate(-50%, 0); } 50% { transform: translate(-50%, -6px); } }
.slide.on { padding-bottom: 96px; }
.slide-share.on { padding-bottom: 0; }
.tap-zone { position: absolute; top: 30px; bottom: 0; z-index: 1; cursor: pointer; }
.tap-zone.left { left: 0; width: 30%; } .tap-zone.right { right: 0; width: 70%; }

.sj-bars { display: flex; flex-direction: column; gap: 6px; margin: 4px 0; }
.sj-bar { display: grid; grid-template-columns: 92px 1fr 32px; align-items: center; gap: 8px; font-size: 15px; font-weight: 700; white-space: nowrap; }
.sj-bar b { height: 8px; border-radius: 8px; background: var(--accent); display: block; transform-origin: left; animation: grow .8s ease both; }
@keyframes grow { from { transform: scaleX(0); } }
.chips { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 14px 0; }
.chip { height: 86px; border-radius: 16px; position: relative; animation: rise .5s ease both; }
.chips.avoid { grid-template-columns: 1fr 1fr; margin-top: 4px; }
.chips.avoid .chip { height: 56px; opacity: .9; }
.chips.avoid .chip::after { content: '✕'; position: absolute; right: 10px; top: 6px; font-size: 16px; color: rgba(0,0,0,.55); }
.chip span { position: absolute; left: 10px; bottom: 8px; font-size: 14px; font-weight: 700; color: rgba(0,0,0,.7); }
.rx { list-style: none; padding: 0; margin: 4px 0; }
.rx li { padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 17px; font-weight: 700; display: flex; gap: 10px; }
.rx li b { min-width: 64px; color: var(--accent); font-weight: 700; }
.try-box { background: var(--glass); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin: 16px 0; }
.try { font-family: var(--verse); font-weight: 800; font-size: 22px; margin: 0; }
#card-img { width: 78%; align-self: center; border-radius: 16px; box-shadow: 0 18px 40px rgba(0,0,0,.18); margin: 8px 0 6px; }
.mbti { margin: 4px 0; }
.m-title { font-family: var(--verse); font-weight: 800; font-size: 21px; margin: 12px 0 4px; }

/* 아래에서 올라오는 안내 */
.sheet { position: fixed; inset: 0; z-index: 10; background: rgba(0,0,0,.4); display: flex; align-items: flex-end; justify-content: center; }
.sheet-body { background: var(--bg); width: 100%; max-width: 480px; border-radius: 22px 22px 0 0; padding: 22px 18px calc(26px + env(safe-area-inset-bottom)); }

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

/* 십이궁 */
.gung-face, .spot-face { width: min(200px, 52vw); margin: 4px auto 6px; }
.spot-face { width: min(110px, 30vw); float: left; margin: 2px 12px 4px 0; }
.spot-box::after { content: ''; display: block; clear: both; }
.gung-face svg, .spot-face svg { width: 100%; height: auto; display: block; }
.gung-face .line, .spot-face .line { fill: none; stroke: #6B5446; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.gung-face .eye, .spot-face .eye { stroke-width: 3; }
/* 얼굴 그림은 밝은·어두운 화면 모두 같은 색 (그림처럼) */
.gung-face .skin, .spot-face .skin { fill: #F8E6D3; stroke: #C9A88E; stroke-width: 2; }
.gung-face .hair, .spot-face .hair { fill: #4A3A30; }
.gung-face .blush, .spot-face .blush { fill: #F29C8F; opacity: .45; }
.gung-face .glow, .spot-face .glow { fill: var(--seal); opacity: .22; animation: gungGlow 2.4s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes gungGlow { 50% { opacity: .08; transform: scale(1.25); } }
.gung-face .dot, .spot-face .dot { fill: var(--seal); }
.gung-face .ring { fill: none; stroke: var(--seal); stroke-width: 2.5; stroke-dasharray: 2 6; stroke-linecap: round; }
.gung-face text, .spot-face text { fill: #fff; font: 800 13px var(--body); text-anchor: middle; dominant-baseline: central; }
.gung-face .dot, .gung-face .ring { animation: gungPop .5s ease both; }
.gung-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; text-align: left; }
.gung-list li { background: var(--glass); border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px; }
.gung-list h3 { margin: 0 0 4px; font-family: var(--verse); font-weight: 800; font-size: 19px; }
.gung-list h3 .no { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%;
  background: var(--seal); color: #fff; font: 800 14px var(--body); margin-right: 6px; vertical-align: 2px; }
.gung-list h3 small { font-weight: 700; font-size: 14px; color: var(--ink-2); margin-left: 4px; }
.gung-list p { margin: 4px 0 0; font-size: 16px; }
.gung-list .gung-classic { color: var(--ink-2); font-size: 15px; }
.gung-list .gung-today { font-weight: 700; }
@keyframes gungPop { from { opacity: 0; transform: scale(.4); transform-origin: center; transform-box: fill-box; } }
