:root {
  --bg: #FFE9C7;
  --paper: #FFF8EC;
  --ink: #3A2A1E;
  --ink-soft: #7A6555;
  --red: #E8503A;
  --blue: #2F6FDB;
  --yellow: #FFC93C;
  --green: #3BAA6E;
  --line: #EAD7BC;
  --radius: 22px;
}

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

html, body { height: 100%; }

body {
  background:
    radial-gradient(circle at 15% 20%, #FFD9A0 0 120px, transparent 121px),
    radial-gradient(circle at 85% 80%, #FFCFB0 0 160px, transparent 161px),
    var(--bg);
  color: var(--ink);
  font-family: 'Gowun Dodum', 'Apple SD Gothic Neo', sans-serif;
  display: flex;
  justify-content: center;
  -webkit-font-smoothing: antialiased;
}

.frame {
  width: 100%;
  max-width: 460px;
  min-height: 100vh;
  background: var(--paper);
  position: relative;
  box-shadow: 0 0 0 3px var(--ink), 0 20px 60px rgba(58, 42, 30, .25);
  overflow-x: hidden;
}

h1, h2, h3, .btn-main, .btn-sub, .badge, .r-code, .count, .q-num, .tag { font-family: 'Jua', 'BM JUA', sans-serif; font-weight: 400; }

.screen { display: none; padding: 28px 22px 40px; min-height: 100vh; }
.screen.active { display: flex; flex-direction: column; animation: fadeUp .35s ease; }

@keyframes fadeUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

/* 시작 */
#screen-start { align-items: center; justify-content: center; text-align: center; gap: 18px; }
.badge { background: var(--red); color: #fff; padding: 6px 16px; border-radius: 99px; font-size: 18px; border: 3px solid var(--ink); transform: rotate(-3deg); }
.title { font-size: 44px; line-height: 1.1; }
.title .big { font-size: 120px; color: var(--red); -webkit-text-stroke: 3px var(--ink); text-shadow: 6px 6px 0 var(--yellow); }
.hook { font-size: 24px; line-height: 1.5; }
.hook b { color: var(--blue); }
.axes-preview { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.axes-preview span { background: #fff; border: 2px solid var(--line); padding: 5px 12px; border-radius: 99px; font-size: 15px; }
.axes-preview .kr { background: var(--yellow); border-color: var(--ink); font-weight: 700; }
.meta { color: var(--ink-soft); font-size: 15px; }

/* 버튼 */
.btn-main, .btn-sub {
  width: 100%; border: 3px solid var(--ink); border-radius: var(--radius);
  padding: 18px; font-size: 24px; cursor: pointer; transition: transform .1s, box-shadow .1s;
}
.btn-main { background: var(--red); color: #fff; box-shadow: 0 6px 0 var(--ink); }
.btn-sub { background: #fff; color: var(--ink); box-shadow: 0 5px 0 var(--ink); margin-top: 12px; }
.btn-main:active, .btn-sub:active { transform: translateY(5px); box-shadow: 0 1px 0 var(--ink); }
.btn-link { background: none; border: none; color: var(--ink-soft); font-size: 16px; text-decoration: underline; cursor: pointer; margin-top: 10px; font-family: inherit; }
.btn-back { background: #fff; border: 3px solid var(--ink); border-radius: 14px; width: 44px; height: 44px; font-size: 28px; line-height: 1; cursor: pointer; flex-shrink: 0; }
.btn-back:disabled { opacity: .3; cursor: default; }

/* 문항 */
.quiz-top { display: flex; align-items: center; gap: 12px; margin-bottom: 30px; }
.progress { flex: 1; height: 16px; background: #fff; border: 3px solid var(--ink); border-radius: 99px; overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: var(--yellow); transition: width .3s ease; }
.count { font-size: 20px; min-width: 64px; text-align: right; }

.q-card { flex: 1; display: flex; flex-direction: column; }
.q-num { color: var(--red); font-size: 26px; margin-bottom: 8px; }
.q-text { font-size: 30px; line-height: 1.4; margin-bottom: 34px; word-break: keep-all; min-height: 126px; }
.options { display: flex; flex-direction: column; gap: 14px; }
.opt {
  text-align: left; background: #fff; border: 3px solid var(--ink); border-radius: var(--radius);
  padding: 20px 20px 20px 62px; font-size: 21px; line-height: 1.45; cursor: pointer; position: relative;
  font-family: inherit; color: var(--ink); box-shadow: 0 5px 0 var(--ink); word-break: keep-all;
  transition: transform .1s, box-shadow .1s, background .15s;
}
.opt::before {
  content: attr(data-key); position: absolute; left: 16px; top: 50%; transform: translateY(-50%);
  width: 34px; height: 34px; border-radius: 50%; background: var(--yellow); border: 3px solid var(--ink);
  font-family: 'Jua', sans-serif; font-size: 18px; display: grid; place-items: center;
}
.opt:hover { background: #FFF3D6; }
.opt:active, .opt.picked { transform: translateY(5px); box-shadow: 0 0 0 var(--ink); background: var(--yellow); }

/* 계산 중 */
#screen-loading { align-items: center; justify-content: center; gap: 28px; }
.spinner { width: 90px; height: 90px; border: 10px solid #fff; border-top-color: var(--red); border-right-color: var(--yellow); border-radius: 50%; animation: spin .8s linear infinite; outline: 3px solid var(--ink); outline-offset: -3px; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { font-size: 24px; font-family: 'Jua', sans-serif; }

/* 결과 */
#screen-result { align-items: stretch; text-align: center; }
.r-label { font-size: 18px; color: var(--ink-soft); }
.r-img-wrap { margin: 16px auto 10px; width: 280px; height: 280px; border: 4px solid var(--ink); border-radius: 28px; overflow: hidden; background: #FFF6E5; box-shadow: 8px 8px 0 var(--yellow); position: relative; }
.r-img-wrap img { width: 100%; height: 100%; object-fit: cover; display: block; }
.r-img-fallback { position: absolute; inset: 0; display: none; place-items: center; font-family: 'Jua', sans-serif; font-size: 60px; color: var(--red); }
.r-img-wrap.noimg img { display: none; }
.r-img-wrap.noimg .r-img-fallback { display: grid; }
.r-code { font-size: 34px; margin-top: 14px; letter-spacing: 1px; }
.r-code .sp { color: var(--blue); }
.r-code .ds { color: var(--red); }
.r-nick { font-size: 30px; line-height: 1.3; margin: 6px 0 10px; word-break: keep-all; }
.r-line { font-size: 19px; line-height: 1.5; color: var(--ink-soft); margin-bottom: 22px; word-break: keep-all; }

.card { background: #fff; border: 3px solid var(--ink); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 14px; text-align: left; }
.card h3 { font-size: 22px; margin-bottom: 8px; }
.card p { font-size: 18px; line-height: 1.6; word-break: keep-all; }

.bar-row { margin: 12px 0; }
.bar-labels { display: flex; justify-content: space-between; font-size: 15px; margin-bottom: 4px; }
.bar-labels .win { font-weight: 700; color: var(--ink); }
.bar-labels span { color: var(--ink-soft); }
.bar { height: 18px; border: 2px solid var(--ink); border-radius: 99px; overflow: hidden; display: flex; background: #EEE; }
.bar .l { background: var(--blue); }
.bar .r { background: var(--red); }

.match-row { display: flex; gap: 12px; }
.match-item { flex: 1; border-radius: 16px; padding: 12px; text-align: center; border: 2px solid var(--ink); }
.match-item.good { background: #E6F6EC; }
.match-item.bad { background: #FDE7E3; }
.match-item .tag { display: block; font-size: 16px; margin-bottom: 4px; }
.match-item b { display: block; font-size: 22px; font-family: 'Jua', sans-serif; font-weight: 400; }
.match-item small { font-size: 14px; color: var(--ink-soft); }

.disclaimer { font-size: 13px; color: var(--ink-soft); margin-top: 18px; }

/* 전체 유형 */
.all-top { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.all-top h2 { font-size: 28px; }
.all-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.all-item { background: #fff; border: 3px solid var(--ink); border-radius: 18px; padding: 10px; text-align: center; cursor: pointer; }
.all-item .thumb { width: 100%; aspect-ratio: 1; border-radius: 12px; background: #FFF6E5; overflow: hidden; display: grid; place-items: center; font-family: 'Jua', sans-serif; font-size: 26px; color: var(--red); }
.all-item .thumb img { width: 100%; height: 100%; object-fit: cover; }
.all-item .code { font-family: 'Jua', sans-serif; font-size: 15px; margin-top: 6px; }
.all-item .nick { font-size: 13px; color: var(--ink-soft); line-height: 1.35; word-break: keep-all; }

.toast { position: fixed; left: 50%; bottom: 30px; transform: translateX(-50%) translateY(80px); background: var(--ink); color: #fff; padding: 12px 22px; border-radius: 99px; font-size: 16px; transition: transform .25s; z-index: 10; }
.toast.show { transform: translateX(-50%) translateY(0); }
