:root {
  --bg: #fff4e6;
  --bg2: #ffe9d2;
  --card: #ffffff;
  --ink: #3b2f2a;
  --ink2: #7a6658;
  --ink3: #a8968a;
  --accent: #ff8a5b;
  --accent-d: #f06a3a;
  --mint: #4cb88a;
  --rose: #ef6f82;
  --line: rgba(90, 60, 40, 0.1);
  --shadow: 0 6px 20px rgba(150, 90, 40, 0.12), 0 1px 3px rgba(150, 90, 40, 0.08);
  --r: 22px;
  color-scheme: light;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at 20% 0%, #fff9f0 0, transparent 55%), linear-gradient(180deg, var(--bg) 0%, var(--bg2) 100%) fixed;
  color: var(--ink);
  font-family: system-ui, -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
  word-break: keep-all;
  overflow-wrap: anywhere;
}
#app {
  max-width: 440px;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}
.screen { display: flex; flex-direction: column; gap: 12px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* 버튼 */
.btn {
  appearance: none; border: 0; cursor: pointer; font: inherit; font-weight: 700;
  min-height: 48px; padding: 12px 18px; border-radius: 16px;
  background: var(--card); color: var(--ink); box-shadow: var(--shadow);
  transition: transform .12s ease, box-shadow .12s ease, background .12s;
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center; text-align: center;
}
.btn:active { transform: scale(0.97); }
.btn:focus-visible { outline: 3px solid #ffb48f; outline-offset: 2px; }
.btn.primary { background: linear-gradient(180deg, var(--accent) 0%, var(--accent-d) 100%); color: #fff; box-shadow: 0 6px 16px rgba(240, 106, 58, 0.35); }
.btn.ghost { background: rgba(255, 255, 255, 0.7); box-shadow: inset 0 0 0 1.5px var(--line); }
.btn.big { min-height: 56px; font-size: 18px; border-radius: 18px; width: 100%; }

/* 카드 */
.card { background: var(--card); border-radius: var(--r); padding: 16px; box-shadow: var(--shadow); }
.label { font-size: 13px; font-weight: 700; color: var(--ink3); margin-bottom: 6px; }
.value { font-size: 18px; font-weight: 800; }
.sub { font-size: 13px; color: var(--ink2); }
.big-emoji { font-size: 40px; line-height: 1; }
.hint { font-size: 13px; color: var(--ink2); text-align: center; margin: 4px 0; }
.fine { font-size: 12px; color: var(--ink3); text-align: center; margin: 6px 0 0; }
.notice { font-size: 12px; color: #b4552e; background: #ffe2d3; border-radius: 10px; padding: 6px 10px; text-align: center; }
.seed-tag { align-self: center; margin: 0; font-size: 12px; font-weight: 700; color: var(--ink2); background: rgba(255, 255, 255, 0.7); padding: 4px 12px; border-radius: 99px; }
.h2 { margin: 0; text-align: center; font-size: 22px; }

/* 시작 */
.home { min-height: calc(100vh - 60px); justify-content: center; align-items: stretch; text-align: center; padding: 20px 4px; }
.home-deco { display: flex; justify-content: center; gap: 10px; font-size: 26px; }
.home-deco span { animation: bob 2.4s ease-in-out infinite; display: inline-block; }
.logo { font-size: 72px; line-height: 1; margin-top: 18px; animation: sway 3s ease-in-out infinite; transform-origin: bottom center; }
.title { margin: 4px 0 0; font-size: 44px; font-weight: 900; letter-spacing: -0.5px; color: #2d221d; }
.subtitle { margin: 0; font-size: 18px; font-weight: 800; color: var(--accent-d); }
.tagline { margin: 10px 0 22px; color: var(--ink2); font-size: 16px; text-align: center; }

.home .resume { margin-bottom: 2px; }
.home .sub-start { min-height: 48px; font-size: 16px; }
.btn:disabled { opacity: .45; cursor: default; transform: none; }
.btn.small { min-height: 40px; padding: 8px 14px; font-size: 14px; border-radius: 12px; }

/* 직접 만든 인생 */
.custom { gap: 10px; }
.cu-head { display: flex; align-items: center; gap: 8px; }
.cu-head .h2 { flex: 1; text-align: left; font-size: 20px; }
.btn.back { min-height: 40px; width: 40px; padding: 0; border-radius: 12px; font-size: 18px; }
.cu-card { padding: 12px; }
.cu-card .label { margin-bottom: 8px; }
.cu-count { color: var(--accent-d); }
.cu-note { margin: 8px 0 0; font-size: 13px; font-weight: 700; color: var(--accent-d); text-align: center; }
.fam-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.fam-opt, .trait-opt {
  appearance: none; font: inherit; color: var(--ink); cursor: pointer; border: 0; border-radius: 14px;
  background: #fff8f1; box-shadow: inset 0 0 0 1.5px #ffe0cc; transition: background .12s, box-shadow .12s, transform .12s;
}
.fam-opt:active, .trait-opt:active, .al-btn:active { transform: scale(0.96); }
.fam-opt { display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 8px 4px; min-height: 76px; }
.fo-icon { font-size: 24px; line-height: 1.1; }
.fo-name { font-size: 13px; font-weight: 800; }
.fo-pts { font-size: 11px; color: var(--ink2); font-weight: 700; }
.fam-opt.on, .trait-opt.on { background: #fff0e4; box-shadow: inset 0 0 0 2.5px var(--accent); }
.fam-opt.on .fo-pts { color: var(--accent-d); }
.trait-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.trait-opt { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 8px 10px; text-align: left; position: relative; }
.trait-opt.on::after { content: '✓'; position: absolute; top: 6px; right: 8px; font-weight: 900; color: var(--accent-d); }
.to-name { font-size: 15px; font-weight: 800; }
.to-desc { font-size: 12px; color: var(--ink2); line-height: 1.35; }
.to-weak { font-size: 11px; color: #c4453a; line-height: 1.35; }
.cu-pts-head { display: flex; align-items: flex-start; justify-content: space-between; }
.cu-left { display: flex; align-items: baseline; gap: 6px; font-size: 12px; font-weight: 700; color: var(--ink2); }
.cu-left-num { font-size: 30px; line-height: 1; color: var(--accent-d); font-variant-numeric: tabular-nums; min-width: 2ch; text-align: right; }
/* 칸이 내용보다 좁아질 수 있게 minmax(0, 1fr): 375px에서 오른쪽 칸이 카드 가장자리에 붙지 않도록 */
.al-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin-bottom: 10px; }
.al-row { min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); grid-template-areas: "n n n" "m v p"; align-items: center; justify-items: center; gap: 2px; background: #fff7ef; border-radius: 12px; padding: 5px 3px 6px; }
.al-name { grid-area: n; max-width: 100%; overflow: hidden; text-overflow: clip; font-size: 12px; font-weight: 700; color: var(--ink2); white-space: nowrap; }
.al-cost { font-size: 10px; font-weight: 800; color: var(--accent-d); }
.al-row .al-btn:first-of-type { grid-area: m; }
.al-row .al-btn:last-of-type { grid-area: p; }
.al-val { grid-area: v; min-width: 24px; text-align: center; font-size: 17px; font-variant-numeric: tabular-nums; }
.al-btn { appearance: none; border: 0; font: inherit; font-size: 20px; font-weight: 800; width: 100%; max-width: 32px; height: 32px; border-radius: 10px; background: #fff; color: var(--accent-d); box-shadow: inset 0 0 0 1.5px #ffd9c2; cursor: pointer; padding: 0; line-height: 1; }
@media (max-width: 330px) { .al-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.btn.loading { opacity: .7; }
.al-btn:disabled { color: #d9c9bd; box-shadow: inset 0 0 0 1.5px #f1e6dd; cursor: default; }
.cu-card .btn.small { width: 100%; }
.cu-start-note { margin-top: -4px; }

/* 시작 조건 */
.family { display: flex; gap: 14px; align-items: center; }
.traits { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.trait { text-align: center; display: flex; flex-direction: column; gap: 4px; align-items: center; }
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat-cell { background: #fff7ef; border-radius: 12px; padding: 8px; display: flex; flex-direction: column; align-items: center; font-size: 12px; color: var(--ink2); }
.stat-cell b { font-size: 18px; color: var(--ink); }

/* 상단 상태 */
.hud { position: sticky; top: 0; z-index: 5; background: rgba(255, 247, 238, 0.94); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); border-radius: 18px; padding: 10px; box-shadow: var(--shadow); margin-top: 2px; }
.hud-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.pill { font-size: 13px; font-weight: 700; background: #fff; border-radius: 99px; padding: 4px 10px; white-space: nowrap; }
.pill.money { margin-left: auto; }
.pill.neg { color: #c4453a; background: #ffe5e0; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px 10px; }
.stat { display: flex; align-items: center; gap: 4px; font-size: 12px; }
.stat-icon { width: 18px; text-align: center; }
.stat-bar { flex: 1; height: 6px; background: rgba(90, 60, 40, 0.1); border-radius: 99px; overflow: hidden; }
.stat-bar i { display: block; height: 100%; background: linear-gradient(90deg, #ffb48f, var(--accent)); border-radius: 99px; transition: width .5s ease; }
.stat-bar i.low { background: #e66a5c; }
.stat-num { width: 22px; text-align: right; font-weight: 700; color: var(--ink2); font-variant-numeric: tabular-nums; }
.bump { animation: bump .5s ease; }

/* 이벤트 */
.turn-no { margin: 2px 0 -4px; font-size: 12px; font-weight: 700; color: var(--ink3); text-align: center; }
.event { text-align: center; padding: 22px 18px 18px; }
.event-icon { font-size: 64px; line-height: 1.1; animation: bob 2.6s ease-in-out infinite; }
.event-icon.small { font-size: 40px; animation: none; }
.cat { display: inline-block; margin-top: 8px; font-size: 12px; font-weight: 700; color: var(--accent-d); background: #fff0e6; padding: 2px 10px; border-radius: 99px; }
.event-title { margin: 8px 0 4px; font-size: 21px; line-height: 1.3; }
.event-text { margin: 0 0 16px; color: var(--ink2); }
.choices { display: flex; flex-direction: column; gap: 10px; }
.choice { width: 100%; background: #fff8f1; box-shadow: inset 0 0 0 1.5px #ffd9c2, 0 2px 0 #ffd2b6; font-size: 16px; animation: rise .35s both; }
.choice:hover { background: #fff1e5; }
.choice.picked { background: var(--accent); color: #fff; box-shadow: none; }

/* 결과 */
.picked-label { margin: 6px 0; font-weight: 800; color: var(--accent-d); }
.outcome { font-size: 18px; font-weight: 700; margin: 6px 0 12px; }
.chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-bottom: 10px; }
.chip { font-size: 13px; font-weight: 700; padding: 4px 10px; border-radius: 99px; background: #f3ede8; animation: floatIn .5s both; }
.chip.up { background: #e2f6ec; color: #2f8a62; }
.chip.down { background: #ffe5e0; color: #c4453a; }
.chip.job { background: #eae6ff; color: #5a4bc4; }
.time { font-size: 13px; color: var(--ink2); margin: 4px 0; }
.death { font-size: 16px; font-weight: 800; margin: 12px 0 4px; }
.next { margin-top: 14px; }
.defy { background: linear-gradient(180deg, #fff0f0, #ffe3e3); border: 2px dashed #f2a0a0; border-radius: 18px; padding: 12px; margin: 8px 0 10px; }
.defy-head { margin: 0; font-weight: 800; color: #c4453a; }
.defy-line { margin: 6px 0; font-size: 19px; font-weight: 800; }
.defy-sub { margin: 0; font-size: 13px; color: var(--ink2); }
.shake { animation: shake .6s cubic-bezier(.36, .07, .19, .97) both, flash 1s ease; }

/* 결산 */
.ending-hero { --c: #9b8cff; text-align: center; border-radius: 26px; padding: 26px 18px 22px; color: #2d221d; background: linear-gradient(160deg, var(--c) 0%, #fff6ec 92%); box-shadow: var(--shadow); }
.ending-icon { font-size: 76px; line-height: 1.1; animation: pop .6s .1s both, bob 3s 1s ease-in-out infinite; }
/* 엔딩 그림(배포본에만): 위쪽을 꽉 채우고 이모지는 숨긴다 */
.ending-hero.has-art { padding-top: 0; overflow: hidden; }
.ending-art { display: block; width: calc(100% + 36px); max-width: none; height: auto; aspect-ratio: 720 / 403; object-fit: cover; margin: 0 -18px 4px; animation: artin .5s ease both;
  -webkit-mask-image: linear-gradient(180deg, #000 70%, transparent); mask-image: linear-gradient(180deg, #000 70%, transparent); }
.ending-hero.has-art .ending-icon { display: none; }
@keyframes artin { from { opacity: 0; } to { opacity: 1; } }
.ending-name { margin: 8px 0 0; font-size: 14px; font-weight: 800; opacity: .8; }
.ending-headline { margin: 4px 0 6px; font-size: 26px; line-height: 1.3; }
.ending-desc { margin: 0; color: #5a463c; }
.bio { margin: 0; background: #fffdf8; border-radius: var(--r); padding: 18px; box-shadow: var(--shadow); font-size: 17px; font-weight: 600; line-height: 1.6; position: relative; }
.bio-label { display: block; font-size: 12px; color: var(--ink3); font-weight: 700; margin-bottom: 4px; }
.summary { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.sum-cell { display: flex; flex-direction: column; background: #fff7ef; border-radius: 14px; padding: 10px; }
.sum-cell.wide { grid-column: span 2; }
.sum-cell span { font-size: 12px; color: var(--ink2); }
.sum-cell b { font-size: 17px; }
b.neg { color: #c4453a; }
.chart-card canvas { display: block; width: 100%; }
.lg { font-size: 12px; }
.lg.money { color: #f08a4b; }
.lg.happy { color: var(--mint); }
.top { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.top-age { font-weight: 800; color: var(--accent-d); }
.tag-defy { margin-left: 6px; font-size: 11px; font-weight: 800; color: #fff; background: #ef6f82; padding: 1px 6px; border-radius: 6px; }
.achs { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.achs small { display: block; color: var(--ink3); margin-left: 24px; }
.new { margin-left: 6px; font-size: 10px; font-weight: 900; color: #fff; background: var(--mint); padding: 1px 6px; border-radius: 6px; }
.actions { display: flex; flex-direction: column; gap: 10px; margin-top: 4px; }
.power { display: flex; align-items: center; gap: 12px; padding: 12px 16px; }
.power-icon { font-size: 32px; line-height: 1; }
.power-body { display: flex; flex-direction: column; min-width: 0; }
.power-label { font-size: 12px; color: var(--ink3); font-weight: 700; }
.power-body b { font-size: 16px; }

/* 도감 */
.dex-links { display: flex; gap: 8px; justify-content: center; margin-top: 4px; }
.dex-links .dex-link { flex: 1; max-width: 160px; min-height: 36px; padding: 6px 10px; font-size: 13px; }
.card .dex-links { margin-top: 10px; }
.dex-tabs { display: flex; gap: 6px; background: rgba(255, 255, 255, 0.6); border-radius: 14px; padding: 4px; }
.dex-tab { flex: 1; min-height: 40px; border: 0; border-radius: 10px; background: transparent; font: inherit; font-size: 14px; font-weight: 700; color: var(--ink2); cursor: pointer; }
.dex-tab.on { background: #fff; color: var(--ink); box-shadow: var(--shadow); }
.dex-card { padding: 8px 12px; }
.dex-list { list-style: none; margin: 0; padding: 0; }
.dex-item { --c: transparent; display: flex; align-items: center; gap: 10px; padding: 10px 2px; border-top: 1px solid var(--line); border-left: 4px solid var(--c); padding-left: 8px; }
.dex-item:first-child { border-top: 0; }
.dex-icon { font-size: 24px; width: 32px; text-align: center; flex: none; }
.dex-body { display: flex; flex-direction: column; min-width: 0; }
.dex-body b { font-size: 15px; }
.dex-body small { font-size: 12px; color: var(--ink2); }
.dex-item.locked { opacity: .55; }
.dex-item.locked .dex-icon { filter: grayscale(1); }
.compare .cmp { width: 100%; border-collapse: collapse; font-size: 14px; margin-bottom: 10px; table-layout: fixed; }
.cmp th { font-size: 12px; color: var(--ink3); padding: 4px; }
.cmp td { padding: 8px 4px; border-top: 1px solid var(--line); text-align: center; font-weight: 700; }
.cmp td:first-child { color: var(--ink2); font-weight: 600; font-size: 12px; text-align: left; }
.cmp td.win { color: #2f8a62; background: #e9f8f0; border-radius: 8px; }
.compare .btn { width: 100%; }

/* 모달·알림 */
.overlay { position: fixed; inset: 0; background: rgba(40, 25, 15, 0.5); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { background: #fff; border-radius: 22px; padding: 16px; width: 100%; max-width: 400px; max-height: 92vh; overflow: auto; display: flex; flex-direction: column; gap: 10px; text-align: center; }
.modal > div { display: flex; flex-direction: column; gap: 10px; }
.modal-title { margin: 0; font-weight: 800; }
.card-img { width: 100%; height: auto; border-radius: 14px; box-shadow: var(--shadow); -webkit-touch-callout: default; }
.copy-box { width: 100%; font: inherit; font-size: 14px; border-radius: 12px; border: 1.5px solid var(--line); padding: 10px; resize: none; }
.toast { position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translate(-50%, 30px); opacity: 0; background: #2d221d; color: #fff; padding: 10px 18px; border-radius: 99px; font-size: 14px; font-weight: 700; transition: all .25s ease; pointer-events: none; z-index: 60; max-width: calc(100% - 32px); text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.boot { text-align: center; padding-top: 30vh; color: var(--ink2); }
.boot-icon { font-size: 56px; animation: bob 1.6s ease-in-out infinite; }
.noscript { text-align: center; padding: 40px 16px; }

/* 연출 */
.pop { animation: pop .38s cubic-bezier(.2, 1.4, .4, 1) both; }
.rise { animation: rise .45s ease both; }
@keyframes pop { from { opacity: 0; transform: scale(.92); } to { opacity: 1; transform: none; } }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes floatIn { from { opacity: 0; transform: translateY(6px) scale(.9); } to { opacity: 1; transform: none; } }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
@keyframes sway { 0%, 100% { transform: rotate(-4deg); } 50% { transform: rotate(4deg); } }
@keyframes bump { 0% { transform: scale(1); } 40% { transform: scale(1.12); background: #fff1c9; } 100% { transform: scale(1); } }
@keyframes shake { 10%, 90% { transform: translateX(-2px) rotate(-.5deg); } 20%, 80% { transform: translateX(4px) rotate(.5deg); } 30%, 50%, 70% { transform: translateX(-7px) rotate(-1deg); } 40%, 60% { transform: translateX(7px) rotate(1deg); } }
@keyframes flash { 0% { box-shadow: 0 0 0 0 rgba(239, 111, 130, .6); } 100% { box-shadow: 0 0 0 14px rgba(239, 111, 130, 0); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
@media (max-width: 359px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .title { font-size: 38px; }
}
