:root {
  --bg: #f2f4f6;
  --surface: #ffffff;
  --surface2: #f7f8fa;
  --text: #191f28;
  --text2: #4e5968;
  --text3: #8b95a1;
  --line: #e5e8eb;
  --hair: #f1f3f5;
  --up: #e2231a;
  --down: #1d4ed8;
  --good: #12b886;
  --amber: #f59f00;
  --danger-bg: #fdeef0;
  --down-bg: #eaf1ff;
  --good-bg: #e6f7ef;
  --r: 18px;
  --shadow: 0 8px 24px rgba(15, 23, 42, .07);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115;
    --surface: #171a20;
    --surface2: #1d2128;
    --text: #e8eaee;
    --text2: #aab2bd;
    --text3: #7d8590;
    --line: #2a2f38;
    --hair: #20242b;
    --up: #ff6159;
    --down: #6ea3ff;
    --good: #2fd49c;
    --down-bg: #1b2740;
    --good-bg: #143329;
    --danger-bg: #39201f;
    --shadow: 0 8px 24px rgba(0, 0, 0, .28);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", sans-serif;
  font-variant-numeric: tabular-nums;
  line-height: 1.55;
  padding-bottom: calc(104px + env(safe-area-inset-bottom));
}
a { color: inherit; }
button, input, select, textarea { font: inherit; }
.wrap { max-width: 440px; margin: 0 auto; padding: 0 16px; }
.appbar { position: sticky; top: 0; z-index: 10; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(18px); padding: max(18px, env(safe-area-inset-top)) 0 10px; }
.appbar-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.appbar h1 { margin: 0; font-size: 24px; letter-spacing: -.03em; }
.appbar p { margin: 4px 0 0; color: var(--text2); font-size: 13px; }
main.wrap { display: grid; gap: 12px; }
.card, .menu-group, .account-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow);
}
.card { padding: 16px; }
.card h2 { margin: 0 0 12px; font-size: 17px; }
.menu-brief { display: grid; gap: 7px; }
.menu-brief h2 { margin: 0; font-size: 18px; line-height: 1.3; }
.menu-brief p { margin: 0; color: var(--text2); font-size: 13px; word-break: keep-all; }
.brief-label { color: var(--down); font-size: 11px; font-weight: 900; }
.hero { min-height: 100svh; display: grid; align-content: center; gap: 18px; padding: 24px 0 80px; }
.brand { display: flex; align-items: center; gap: 10px; font-size: 19px; font-weight: 900; }
.mark { width: 42px; height: 42px; border-radius: 15px; display: inline-grid; place-items: center; background: var(--text); color: var(--bg); font-weight: 900; }
.hero h1 { margin: 0; font-size: clamp(34px, 9vw, 52px); line-height: 1.04; letter-spacing: -.06em; }
.hero p { margin: 0; color: var(--text2); font-size: 16px; word-break: keep-all; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn {
  border: 0;
  border-radius: 14px;
  min-height: 48px;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--text);
  color: var(--bg);
  text-decoration: none;
  font-weight: 850;
  cursor: pointer;
}
.btn.secondary { background: var(--surface); color: var(--text); border: 1px solid var(--line); }
.btn.danger { background: var(--danger-bg); color: var(--up); }
.btn.full { width: 100%; }
.btn.mini { min-height: 34px; border-radius: 11px; padding: 0 10px; font-size: 12px; }
.btn:disabled { opacity: .52; cursor: not-allowed; }
.input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface2);
  color: var(--text);
  border-radius: 13px;
  padding: 14px;
  min-height: 48px;
}
label { display: grid; gap: 7px; color: var(--text2); font-size: 13px; font-weight: 760; }
.form { display: grid; gap: 13px; }
.fine { color: var(--text3); font-size: 12px; line-height: 1.6; }
.guide-card p { margin: 0; color: var(--text2); font-size: 13px; word-break: keep-all; }
.step-list { display: grid; gap: 8px; margin-top: 4px; }
.step { display: grid; grid-template-columns: 26px minmax(0, 1fr); gap: 9px; align-items: start; }
.step > span { width: 26px; height: 26px; border-radius: 9px; display: grid; place-items: center; background: var(--down-bg); color: var(--down); font-size: 12px; font-weight: 900; }
.step p { margin: 2px 0 0; color: var(--text2); font-size: 12.5px; }
.reason-summary { margin: 10px 0 12px; color: var(--text2); font-size: 13px; font-weight: 720; word-break: keep-all; }
.reason-inline { margin-top: 2px; color: var(--text2) !important; }
.reason-detail {
  margin: 12px 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface2);
  overflow: hidden;
}
.reason-detail summary {
  list-style: none;
  cursor: pointer;
  padding: 12px;
  display: grid;
  gap: 2px;
}
.reason-detail summary::-webkit-details-marker { display: none; }
.reason-detail summary span { color: var(--text3); font-size: 11.5px; font-weight: 850; }
.reason-detail summary b { color: var(--text); font-size: 14px; }
.reason-detail[open] summary { border-bottom: 1px solid var(--line); }
.reason-body { display: grid; gap: 10px; padding: 12px; }
.reason-body p { margin: 0; color: var(--text2); font-size: 13px; word-break: keep-all; }
.reason-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.reason-list li { border: 1px solid var(--hair); border-radius: 13px; background: var(--surface); padding: 11px; }
.reason-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.reason-head b { font-size: 13px; }
.reason-head span { flex: none; color: var(--down); font-size: 12px; font-weight: 850; text-align: right; }
.reason-list p { margin: 7px 0 0; color: var(--text2); font-size: 12.5px; line-height: 1.55; word-break: keep-all; }
.notice { background: var(--down-bg); color: var(--down); border-radius: 14px; padding: 12px 13px; font-size: 13px; font-weight: 700; }
.danger-note { background: var(--danger-bg); color: var(--up); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.metric { background: var(--surface2); border-radius: 14px; padding: 12px; min-width: 0; }
.metric span { display: block; color: var(--text3); font-size: 11.5px; font-weight: 780; }
.metric b { display: block; margin-top: 3px; font-size: 17px; overflow: hidden; text-overflow: ellipsis; }
.next-action { margin: 12px 0; padding: 12px; border-radius: 14px; background: var(--good-bg); color: var(--text2); display: grid; gap: 3px; }
.next-action b { color: var(--good); font-size: 13px; }
.next-action span { font-size: 12.5px; word-break: keep-all; }
.row, .stock-row, .menu-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 0;
  border-top: 1px solid var(--hair);
}
.row:first-child, .stock-row:first-child, .menu-card:first-child { border-top: 0; }
.stock-row { text-decoration: none; }
.rich-row { flex-wrap: wrap; }
.rich-row .stock-main { color: inherit; text-decoration: none; flex: 1 1 180px; }
.stock-main { min-width: 0; }
.stock-main b { display: block; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stock-main span { display: block; color: var(--text3); font-size: 12px; }
.stock-side { text-align: right; flex: none; }
.row-actions { width: 100%; display: flex; justify-content: flex-end; gap: 7px; }
.score { display: inline-flex; align-items: center; border-radius: 999px; background: var(--down-bg); color: var(--down); padding: 4px 9px; font-size: 12px; font-weight: 850; }
.up { color: var(--up); }
.down { color: var(--down); }
.good { color: var(--good); }
.muted { color: var(--text3); }
.spark { width: 100%; height: 150px; display: block; }
.tabbar {
  position: fixed;
  left: 50%;
  bottom: calc(10px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: calc(100% - 24px);
  max-width: 424px;
  height: 76px;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 3px;
  padding: 7px;
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: 0 14px 38px rgba(15, 23, 42, .18);
  backdrop-filter: blur(18px) saturate(1.15);
  z-index: 50;
}
.tab {
  min-width: 0;
  border-radius: 16px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 3px;
  color: var(--text3);
  text-decoration: none;
  font-size: 10.5px;
  font-weight: 800;
}
.tab svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.tab.active { color: var(--down); background: var(--down-bg); }
.account-card { display: grid; grid-template-columns: 44px minmax(0, 1fr) auto; align-items: center; gap: 12px; padding: 15px; }
.account-card .avatar { width: 44px; height: 44px; border-radius: 15px; display: grid; place-items: center; background: var(--down-bg); color: var(--down); font-weight: 900; }
.account-card b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-card span { display: block; color: var(--text3); font-size: 12px; }
.menu-group { overflow: hidden; }
.menu-card { min-height: 70px; padding: 14px 16px; color: inherit; text-decoration: none; }
.menu-card b { display: block; }
.menu-card span { display: block; color: var(--text3); font-size: 12px; }
.chip { display: inline-flex; align-items: center; min-height: 28px; padding: 0 10px; border-radius: 999px; background: var(--surface2); color: var(--text2); font-size: 12px; font-weight: 800; }
.position-card { border-top: 1px solid var(--hair); padding: 13px 0; }
.position-card:first-child { border-top: 0; padding-top: 0; }
.position-card:last-child { padding-bottom: 0; }
.empty-state { border: 1px dashed var(--line); border-radius: 14px; padding: 16px; background: var(--surface2); }
.empty-state b { display: block; font-size: 15px; }
.empty-state p { margin: 5px 0 0; color: var(--text2); font-size: 13px; word-break: keep-all; }
.trade-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; padding: 12px 0; border-top: 1px solid var(--hair); }
.trade-row:first-child { border-top: 0; }
.trade-row span { min-width: 0; }
.trade-row b { font-size: 13px; text-align: right; }
.trade-row small { display: block; color: var(--text3); font-size: 12px; }
.horizon-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 7px; margin: 12px 0; }
.horizon { background: var(--surface2); border-radius: 13px; padding: 10px 7px; display: grid; gap: 2px; text-align: center; }
.horizon span, .horizon small { color: var(--text3); font-size: 10.5px; }
.horizon b { font-size: 13px; }
.toggle-row { grid-template-columns: minmax(0, 1fr) auto; align-items: center; border: 1px solid var(--line); background: var(--surface2); border-radius: 14px; padding: 13px; color: var(--text); }
.toggle-row span { display: grid; gap: 2px; }
.toggle-row small { color: var(--text3); font-size: 12px; line-height: 1.45; }
.toggle-row input { width: 22px; height: 22px; accent-color: var(--down); }
.legal { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; color: var(--text3); font-size: 12px; padding: 10px 0; }
.hp-field { position: absolute; left: -9999px; opacity: 0; width: 1px; height: 1px; }
.dialog {
  border: 0;
  border-radius: 22px 22px 0 0;
  padding: 18px;
  background: var(--surface);
  color: var(--text);
  width: 100%;
  max-width: 460px;
  margin: auto auto 0;
}
.dialog::backdrop { background: rgba(0, 0, 0, .45); }
@media (min-width: 720px) {
  .wide { max-width: 880px; }
  .wide main.wrap, main.wrap.wide { max-width: 880px; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
  .wide .span2, main.wrap.wide .span2 { grid-column: 1 / -1; }
}

/* 스파이더맵(레이더) */
.spider-wrap { display: grid; grid-template-columns: 132px minmax(0, 1fr); gap: 12px; align-items: center; margin: 10px 0 4px; }
.spider { width: 132px; height: 132px; display: block; }
.spider .axis-line { stroke: var(--line); stroke-width: 1; }
.spider .grid-ring { fill: none; stroke: var(--hair); stroke-width: 1; }
.spider .shape { fill: color-mix(in srgb, var(--down) 22%, transparent); stroke: var(--down); stroke-width: 2; stroke-linejoin: round; }
.spider .dot { fill: var(--down); }
.spider .axis-label { fill: var(--text3); font-size: 8.5px; font-weight: 800; }
.spider .center-num { fill: var(--text); font-size: 21px; font-weight: 900; }
.spider .center-cap { fill: var(--text3); font-size: 7.5px; font-weight: 800; }
.score-pills { display: flex; flex-wrap: wrap; gap: 6px; }
.rich-row .score-pills { flex: 1 1 100%; margin-top: 6px; }
.pill { display: inline-flex; align-items: baseline; gap: 4px; border-radius: 999px; background: var(--surface2); border: 1px solid var(--hair); padding: 4px 9px; font-size: 11px; font-weight: 800; color: var(--text2); }
.pill b { font-size: 12.5px; color: var(--text); }
.pill.hot { background: var(--down-bg); border-color: transparent; color: var(--down); }
.pill.hot b { color: var(--down); }
.rank-chip { display: inline-flex; align-items: center; gap: 4px; border-radius: 999px; background: var(--good-bg); color: var(--good); padding: 3px 9px; font-size: 11px; font-weight: 850; }

/* 종목정보 */
.info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.info-grid .metric b { font-size: 15px; }
.rationale { margin-top: 10px; padding: 11px 12px; border-radius: 13px; display: grid; gap: 3px; background: var(--surface2); }
.rationale b { font-size: 13px; }
.rationale.저평가-구간 { background: var(--good-bg); } .rationale.저평가-구간 b { color: var(--good); }
.rationale.고평가-주의 { background: var(--danger-bg); } .rationale.고평가-주의 b { color: var(--up); }
.rationale span { color: var(--text2); font-size: 12px; }

/* 평단 바텀시트 */
.sheet { border: 0; border-radius: 22px 22px 0 0; padding: 0; background: var(--surface); color: var(--text); width: 100%; max-width: 460px; margin: auto auto 0; box-shadow: 0 -10px 40px rgba(0,0,0,.22); }
.sheet::backdrop { background: rgba(0,0,0,.45); backdrop-filter: blur(2px); }
.sheet[open] { animation: sheetUp .26s cubic-bezier(.16,1,.3,1); }
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet-inner { padding: 8px 18px max(18px, env(safe-area-inset-bottom)); display: grid; gap: 13px; }
.sheet-grip { width: 38px; height: 4px; border-radius: 999px; background: var(--line); margin: 8px auto 2px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.sheet-head b { font-size: 17px; }
.sheet-head span { color: var(--text3); font-size: 12px; }
.sheet .close-x { border: 0; background: var(--surface2); color: var(--text2); width: 34px; height: 34px; border-radius: 11px; font-size: 16px; cursor: pointer; }

/* 백테스트 정직 고지 배너 */
.warn-banner { border-color: color-mix(in srgb, var(--amber) 45%, var(--line)); background: color-mix(in srgb, var(--amber) 8%, var(--surface)); display: grid; gap: 8px; }
.warn-banner h2 { margin: 0; font-size: 17px; }
.warn-banner p { margin: 0; color: var(--text2); font-size: 13px; word-break: keep-all; }
.brief-label.warn { color: var(--amber); }

/* 내평단 수익률 막대 그래프 */
.hbars { display: grid; gap: 9px; margin-top: 4px; }
.hbar { display: grid; grid-template-columns: 88px 1fr 58px; gap: 8px; align-items: center; }
.hbar .nm { font-size: 12.5px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbar .track { position: relative; height: 16px; border-radius: 8px; background: var(--surface2); overflow: hidden; }
.hbar .fill { position: absolute; top: 0; bottom: 0; border-radius: 8px; }
.hbar .fill.up { background: var(--up); } .hbar .fill.down { background: var(--down); }
.hbar .val { font-size: 12px; font-weight: 850; text-align: right; }
