/* 모바일 우선. 폰 홈 화면에 추가했을 때 앱처럼 보이도록.
   계열 색(--f-*)은 engine.js의 FAMILY_LIGHT/DARK와 같은 값이다 — 실제로 화면에
   칠해지는 건 JS가 인라인으로 넣어주므로 여긴 참고용 문서일 뿐이다.
   도넛은 비중이 아니라 고정 순서(blue→yellow→violet→green→red)로 도는데, 그
   순서에서 이웃한 쌍은 전부 dataviz 검증 스크립트(all adjacent pairs)를 통과했다. */

:root {
  color-scheme: light;
  --page: #f3f3f0;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --hair: #e1e0d9;
  --rule: #c3c2b7;

  /* 상태 — 예약된 토큰. 계열 색으로 재사용하지 않는다 */
  --critical: #d03b3b;
  --serious: #ec835a;
  --good: #0ca30c;
  --calm: #c3c2b7;
  --hold: #6f9bd8;          /* 쉬어가도 되는 것 */

  --gain: #d03b3b;          /* 이익 = 빨강 (한국 관습) */
  --loss: #2a78d6;          /* 손실 = 파랑 */

  /* 계열 기준색 */
  --f-blue: #2a78d6;
  --f-orange: #eb6834;
  --f-yellow: #eda100;
  --f-green: #008300;
  --f-violet: #4a3aa7;
  --f-red: #e34948;
  --f-magenta: #e87ba4;

  --shadow: 0 1px 2px rgba(11, 11, 11, .04);
  --radius: 14px;
  --pad: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --hair: #2c2c2a;
    --rule: #383835;
    --calm: #4a4a46;
    --hold: #7ba7e0;
    --gain: #e66767;
    --loss: #3987e5;
    --f-blue: #3987e5;
    --f-orange: #d95926;
    --f-yellow: #c98500;
    --f-green: #008300;
    --f-violet: #9085e9;
    --f-red: #e66767;
    --f-magenta: #d55181;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, BlinkMacSystemFont,
        "Apple SD Gothic Neo", "Malgun Gothic", "Segoe UI", sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}

main { max-width: 940px; margin: 0 auto; padding: 0 18px 72px; }

/* ---------------------------------------------------------------- 헤더 */

header {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; flex-wrap: wrap;
  background: var(--page);
  padding: calc(env(safe-area-inset-top) + 18px) 0 15px;
  border-bottom: 1px solid var(--rule);
}
header .brand { min-width: 0; }
header h1 {
  font-size: 18px; font-weight: 700; margin: 0; letter-spacing: -.01em;
}
/* 명언은 sticky 헤더 밖에 둔다 — 안에 두면 스크롤 내내 자리를 차지한다.
   길어서 폰에서 잘렸으므로 줄바꿈해서 다 보이게 한다. */
.quote {
  font-size: 11.5px; color: var(--muted); font-style: italic;
  line-height: 1.6; margin: 6px 0 0; max-width: 52ch;
}
.hdr-actions { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.hdr-links { display: flex; align-items: center; gap: 12px; }
.hdr-links button.link {
  font-size: 11.5px; font-weight: 500; color: var(--muted);
}
.hdr-links button.link:hover { color: var(--loss); }
/* 지금 화면이 어느 날짜 내보내기 기준인지 — 새 파일을 넣었는지 바로 구분되게 */
.asof {
  font-size: 11px; color: var(--muted); white-space: nowrap;
  padding: 3px 8px; border-radius: 999px; background: var(--surface);
  font-variant-numeric: tabular-nums;
}
.asof.stale { color: var(--serious); }

.btn {
  font: inherit; font-size: 13.5px; font-weight: 600;
  border: 0; cursor: pointer; border-radius: 999px; padding: 9px 18px;
  background: var(--loss); color: #fff;
  transition: opacity .15s;
}
.btn:active { opacity: .7; }
.btn[disabled] { opacity: .45; cursor: default; }

button.link {
  font: inherit; font-size: 12.5px; font-weight: 600;
  background: none; border: 0; padding: 3px 0;
  color: var(--loss); cursor: pointer;
}

.status { font-size: 11.5px; color: var(--muted); margin: 8px 0 0; min-height: 1.3em; }
.status.err { color: var(--critical); }

.pw-panel[hidden] { display: none; }
.pw-panel {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 10px 0 0;
}
.pw-panel input {
  font: inherit; font-size: 13.5px; padding: 8px 11px; border-radius: 9px;
  border: 1px solid var(--hair); background: var(--surface); color: var(--ink); flex: 1 1 160px;
}
.pw-panel input:focus { outline: none; border-color: var(--loss); }
.pw-panel .msg { flex-basis: 100%; margin: 2px 0 0; }

/* ---------------------------------------------------------------- 배너 */

.banner {
  border-radius: var(--radius); padding: 12px 14px; margin-top: 14px;
  font-size: 13px; background: color-mix(in srgb, var(--serious) 14%, transparent);
  color: var(--serious);
  border: 1px solid color-mix(in srgb, var(--serious) 32%, transparent);
}
.banner .actions { margin-top: 8px; display: flex; gap: 8px; flex-wrap: wrap; }
.banner button {
  font: inherit; font-size: 12px; padding: 5px 12px; border-radius: 999px;
  border: 1px solid currentColor; background: transparent; color: inherit; cursor: pointer;
}

/* ---------------------------------------------------------------- 요약 타일 */

.summary {
  display: grid; grid-template-columns: 1.5fr 1fr 1fr; gap: 1px;
  background: var(--hair); border-radius: var(--radius); overflow: hidden;
  margin-top: 16px; box-shadow: var(--shadow);
}
.tile { background: var(--surface); padding: 16px 18px; }
.tile .k { font-size: 11px; color: var(--muted); letter-spacing: .03em; }
.tile .v { font-size: 23px; font-weight: 600; margin-top: 5px; letter-spacing: -.01em; }
.tile.hero .v { font-size: 42px; line-height: 1.05; letter-spacing: -.02em; }
.tile .d { font-size: 11.5px; color: var(--ink-2); margin-top: 4px; }
.up { color: var(--gain); }
.down { color: var(--loss); }

/* ---------------------------------------------------------------- 섹션 */

section {
  background: var(--surface); border-radius: var(--radius); padding: 18px;
  margin-top: 14px; box-shadow: var(--shadow);
}
.shead {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; margin-bottom: 8px; flex-wrap: wrap;
}
h2 { font-size: 12.5px; font-weight: 600; margin: 0; }
.shead .meta { font-size: 11.5px; color: var(--muted); }
.note { font-size: 11.5px; color: var(--muted); margin: 12px 0 0; line-height: 1.7; }
.msg { font-size: 12px; color: var(--muted); margin: 10px 0 0; min-height: 1.3em; }
.msg.warn { color: var(--serious); }

/* ---------------------------------------------------------------- 내러티브 */

.narrative p { margin: 0 0 10px; font-size: 14.5px; line-height: 1.65; }
.narrative p:last-child { margin-bottom: 0; }
.narrative p.flag { color: var(--serious); font-weight: 500; }
.narrative .headline { font-size: 16px; font-weight: 600; margin-bottom: 12px; line-height: 1.55; }
/* 위반·주의가 헤드라인이면 문장이 아니라 배너처럼 — 눈에 먼저 걸려야 하니까 */
.narrative .headline.flag {
  font-size: 14.5px; font-weight: 500; color: var(--serious);
  background: color-mix(in srgb, var(--serious) 12%, transparent);
  border-radius: 10px; padding: 12px 14px;
}

/* 갈래별로 따로 접는 상세 — 손익 / 원칙 위반·주의 / 적립 제안 / 그 외.
   각자 옅은 카드로 떼어놔야 "글 뭉치"가 아니라 훑어볼 수 있는 목록으로 읽힌다. */
.narrative .ngroup + .ngroup { margin-top: 8px; }
.narrative .ngroup {
  border-radius: 10px; background: var(--page); padding: 11px 14px;
}
.narrative .ngToggle {
  display: flex; width: 100%; justify-content: space-between; align-items: center;
  font-size: 13px; font-weight: 600; padding: 0; color: var(--ink);
}
.narrative .ngToggle .lbl { display: flex; align-items: center; gap: 8px; }
.narrative .ngToggle .lbl i { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.narrative .ngToggle .cnt { font-size: 11.5px; font-weight: 500; color: var(--muted); }
.narrative .ngBody { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--rule); }
.narrative .ngBody p { font-size: 13.5px; color: var(--ink-2); }
.narrative .ngBody p:last-child { margin-bottom: 0; }

/* ---------------------------------------------------------------- 도넛 (목표+실제 한 원) */

.pair {
  display: grid; grid-template-columns: 248px 1fr; gap: 26px;
  align-items: center; margin-top: 10px;
}
.diff .r {
  display: grid; grid-template-columns: 76px 1fr 98px;
  align-items: center; gap: 8px; padding: 7px 0; font-size: 12px;
}
.diff .r + .r { border-top: 1px solid var(--hair); }
.diff .nm {
  display: flex; align-items: center; gap: 6px; color: var(--ink-2);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.diff .nm i { width: 8px; height: 8px; border-radius: 2px; flex: none; }
.diffHead {
  font-size: 10px; color: var(--muted); padding-bottom: 6px;
  border-bottom: 1px solid var(--rule); letter-spacing: .03em;
}
/* 미니 막대: 얇은 눈금이 목표, 채운 막대가 실제 — 도넛과 같은 문법 */
.mini { position: relative; height: 14px; }
.mini .fill { position: absolute; top: 5px; height: 5px; border-radius: 0 3px 3px 0; left: 0; }
.mini .tgt { position: absolute; top: 1px; height: 13px; width: 2px; background: var(--ink); opacity: .55; }
.diff .dv {
  font-variant-numeric: tabular-nums;
  white-space: nowrap; text-align: right; font-size: 11px;
}
/* 실제 비중만 굵게+색으로 강조하고 목표치는 수수하게 둔다 — 수익률 표처럼 보이지 않게 */
.diff .dv .val { font-weight: 700; }
.diff .dv .tv { color: var(--ink); font-weight: 400; }
/* 늘려야 함 = critical(빨강, 액션 카드의 '살 것'과 같은 색), 줄여야 함(넘침) = hold(파랑),
   밴드 안 = 괜찮음(회색) — renderActionCards()의 배지 색과 같은 규칙 */
.diff .dv .val.up { color: var(--critical); }
.diff .dv .val.down { color: var(--hold); }
.diff .dv .val.ok { color: var(--muted); font-weight: 400; }

.legend { display: flex; flex-wrap: wrap; gap: 10px 14px; margin-top: 12px; font-size: 11.5px; }
.legend span { display: flex; align-items: center; gap: 6px; color: var(--ink-2); }
.legend i { width: 9px; height: 9px; border-radius: 2px; flex: none; }
.legend b { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
/* 투자성 안쪽 갈래(주식·펀드 / 금 현물) — 자산군보다 한 단계 낮게 보이도록 */
.legend span.sub { font-size: 10.5px; color: var(--muted); padding-left: 8px; }
.legend span.sub i { width: 7px; height: 7px; }
.legend span.sub b { color: var(--ink-2); font-weight: 500; }

/* 막대가 화면보다 넓어지면 좌우로 밀어서 본다 — 슬라이더 없이 자연스러운 스크롤 */
.ts-scroll { overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch; }
.ts-scroll svg { display: block; }

/* ---------------------------------------------------------------- 개선 제안 카드 */

.cards { display: grid; gap: 10px; margin-top: 4px; }
.card {
  display: grid; grid-template-columns: 34px 1fr; gap: 12px;
  padding: 14px; border-radius: 12px; background: var(--page);
}
.card .badge {
  width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center; font-size: 15px; font-weight: 700; color: #fff;
}
.card .body .t { font-size: 14.5px; line-height: 1.55; font-weight: 500; }
.card .body .t em { font-style: normal; font-weight: 700; }
.card .body .why {
  font-size: 11.5px; color: var(--muted); margin-top: 5px;
  line-height: 1.6; font-variant-numeric: tabular-nums;
}
.card .body .act { font-size: 12.5px; margin-top: 8px; font-weight: 600; }
/* 쉬어가도 되는 카드는 무게를 낮춘다 — 눈이 붉은 카드만 좇게 */
.card.hold { opacity: .72; }

/* ---------------------------------------------------------------- 예산 / 실행 계획 */

.budget { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin: 10px 0 14px; }
.amt { display: flex; align-items: baseline; gap: 5px; }
.amt input {
  font: inherit; font-size: 30px; font-weight: 600; letter-spacing: -.02em;
  width: 150px; border: 0; border-bottom: 2px solid var(--loss);
  background: transparent; color: var(--ink); padding: 2px 0;
  font-variant-numeric: tabular-nums;
}
.amt input:focus { outline: none; }
.amt span { font-size: 15px; color: var(--muted); }
.presets { display: flex; gap: 7px; flex-wrap: wrap; }
.presets button {
  font: inherit; font-size: 12.5px; padding: 6px 13px; border-radius: 999px;
  border: 1px solid var(--hair); background: var(--surface); color: var(--ink-2); cursor: pointer;
}
.presets button.on { border-color: var(--loss); color: var(--loss); font-weight: 600; }

.opts { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; }
.opt {
  border: 1px solid var(--hair); border-radius: 12px; padding: 14px;
  display: flex; flex-direction: column;
}
.optHead { margin-bottom: 10px; }
.optHead .tag {
  display: inline-block; font-size: 10px; font-weight: 700; letter-spacing: .06em;
  color: var(--loss); background: color-mix(in srgb, var(--loss) 12%, transparent);
  padding: 2px 7px; border-radius: 999px;
}
.optHead .ttl { display: block; font-size: 15px; font-weight: 600; margin-top: 6px; }
.optHead .dsc { display: block; font-size: 11.5px; color: var(--muted); margin-top: 2px; line-height: 1.5; }
.optBody { flex: 1; }
.line { display: grid; grid-template-columns: 8px 1fr auto; gap: 9px; align-items: center; padding: 8px 0; }
.line + .line { border-top: 1px solid var(--hair); }
.line .dot { width: 8px; height: 8px; border-radius: 2px; }
.line .lnm { font-size: 13px; font-weight: 600; display: block; line-height: 1.3; }
.line .lsub { font-size: 10.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.line .lamt {
  text-align: right; font-size: 13.5px; font-weight: 700;
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.line .lq { font-size: 14px; font-weight: 700; }
.line .lqty { display: block; font-size: 10.5px; color: var(--muted); font-weight: 400; margin-top: 1px; }
.optFoot {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-top: 11px; padding-top: 10px; border-top: 1px solid var(--rule);
  font-size: 12px; font-variant-numeric: tabular-nums;
}
.optFoot .left { color: var(--muted); }

/* ---------------------------------------------------------------- 오늘의 투자 리포트 */

.reco { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 12px; }
.rc {
  border: 1px solid var(--hair); border-radius: 12px; padding: 14px;
  display: flex; flex-direction: column; gap: 9px;
}
.rc .top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.rc .tk { font-size: 10.5px; font-weight: 700; letter-spacing: .04em; color: var(--muted); font-variant-numeric: tabular-nums; }
.rc .nm { font-size: 15px; font-weight: 600; line-height: 1.3; margin-top: 2px; }
.rc .for { font-size: 10px; font-weight: 600; padding: 3px 8px; border-radius: 999px; white-space: nowrap; flex: none; }
.rc .why { font-size: 12px; color: var(--ink-2); line-height: 1.6; }
.rc .meta {
  display: flex; gap: 12px; font-size: 11px; color: var(--muted);
  font-variant-numeric: tabular-nums; padding-top: 9px;
  border-top: 1px solid var(--hair); margin-top: auto;
}
.rc .meta b { color: var(--ink); font-weight: 600; }
.rc .afford { font-size: 11px; font-weight: 600; }
.rc .afford.no { color: var(--serious); }

/* ---------------------------------------------------------------- 투자 성향 진단 */

.profileNow { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 4px; }
.profileNow .grade { font-size: 20px; font-weight: 700; letter-spacing: -.01em; }
.profileNow .desc { font-size: 12px; color: var(--muted); line-height: 1.6; }

.sliders { margin-top: 6px; }
.sl { padding: 15px 0; border-top: 1px solid var(--hair); }
.sl:first-child { border-top: 0; padding-top: 6px; }
.sl .top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.sl .q { font-size: 13.5px; font-weight: 500; }
.sl .val { font-size: 13px; font-weight: 700; color: var(--loss); white-space: nowrap; }
.sl .why { font-size: 11px; color: var(--muted); margin-top: 2px; }
.sl .ticks { display: flex; justify-content: space-between; font-size: 10px; color: var(--muted); margin-top: -2px; }

/* 금 보유량 직접 입력 — 슬라이더 자리에 숫자 칸이 들어간다 */
.goldRow { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.goldRow input {
  flex: 0 1 140px; font: inherit; font-size: 14px; padding: 8px 11px;
  border-radius: 9px; border: 1px solid var(--hair);
  background: var(--page); color: var(--ink);
  font-variant-numeric: tabular-nums; text-align: right;
}
.goldRow input:focus { outline: none; border-color: var(--loss); }
.goldRow .unit { font-size: 12.5px; color: var(--muted); }

input[type=range] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 24px;
  background: transparent; margin: 6px 0 0; cursor: pointer;
}
input[type=range]::-webkit-slider-runnable-track { height: 5px; border-radius: 3px; background: var(--hair); }
input[type=range]::-moz-range-track { height: 5px; border-radius: 3px; background: var(--hair); }
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 19px; height: 19px; border-radius: 50%;
  background: var(--loss); border: 3px solid var(--surface); margin-top: -7px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .28);
}
input[type=range]::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--loss); border: 3px solid var(--surface);
}

.verdict {
  margin-top: 16px; padding: 15px; border-radius: 12px; background: var(--page);
  display: flex; gap: 14px; align-items: center; flex-wrap: wrap;
}
.verdict .score { font-size: 34px; font-weight: 700; line-height: 1; letter-spacing: -.02em; }
.verdict .vt { font-size: 15px; font-weight: 700; }
.verdict .vd { font-size: 12px; color: var(--ink-2); margin-top: 3px; line-height: 1.6; }

/* 현금 대 주식 슬라이더는 기존 .sl 스타일을 그대로 쓴다 (#csSlider가 #sliders와
   별개 컨테이너라 :first-child 테두리 규칙도 그대로 적용된다) */

.reco2 { margin-top: 16px; }
.reco2Head {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 12px; color: var(--muted); margin-bottom: 9px;
}
.allocBar {
  display: flex; height: 26px; border-radius: 5px; overflow: hidden;
  gap: 2px; background: var(--surface);
}
.allocBar > div { position: relative; transition: flex-basis .18s; }
.allocBar > div:first-child { border-radius: 5px 0 0 5px; }
.allocBar > div:last-child { border-radius: 0 5px 5px 0; }
.allocRows { margin-top: 12px; }
.ar { display: grid; grid-template-columns: 92px 1fr 52px; align-items: center; gap: 11px; padding: 7px 0; font-size: 12.5px; }
.ar + .ar { border-top: 1px solid var(--hair); }
.ar .nm { display: flex; align-items: center; gap: 7px; }
.ar .nm i { width: 9px; height: 9px; border-radius: 2px; flex: none; }
.ar .pv { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.ar input[type=range] { height: 20px; margin: 0; }
.ar input[type=range]::-webkit-slider-runnable-track { height: 4px; }
.ar input[type=range]::-webkit-slider-thumb {
  width: 15px; height: 15px; margin-top: -5px; background: var(--ink);
}
.ar input[type=range]::-moz-range-thumb { width: 11px; height: 11px; background: var(--ink); }
.allocRows.locked .ar input { display: none; }
.sumRow {
  display: flex; justify-content: space-between; font-size: 12px; margin-top: 11px;
  padding-top: 10px; border-top: 1px solid var(--rule); font-variant-numeric: tabular-nums;
}
.sumRow.bad { color: var(--serious); }
.confirm { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-top: 18px; }
.confirm .note { margin: 0; }

/* ---------------------------------------------------------------- 표 / 기타 */

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 9px 6px; text-align: left; border-bottom: 1px solid var(--hair); }
th { font-size: 10.5px; color: var(--muted); font-weight: 500; }
td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: 0; }
.badge-sm {
  display: inline-block; font-size: 10px; padding: 1px 6px; border-radius: 999px;
  background: var(--hair); color: var(--muted); margin-left: 5px; vertical-align: 1px;
}
.sub-num { font-size: 11px; color: var(--muted); font-weight: 400; }

svg text { font-size: 10.5px; fill: var(--muted); }
.tip {
  position: fixed; pointer-events: none; opacity: 0; transition: opacity .12s;
  background: var(--ink); color: var(--page); font-size: 11.5px; line-height: 1.55;
  padding: 7px 10px; border-radius: 8px; z-index: 20; white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.tip b { font-weight: 600; }

.foot { margin-top: 24px; text-align: center; }
.foot p { font-size: 11px; color: var(--muted); margin: 4px 0; }

@media (max-width: 700px) {
  .pair { grid-template-columns: 1fr; gap: 16px; justify-items: center; }
  .diff { width: 100%; }
  .summary { grid-template-columns: 1fr 1fr; }
  .tile.hero { grid-column: 1 / -1; }
}
