:root {
  --bg: #f2f4f6;
  --card: #ffffff;
  --text: #191f28;
  --muted: #6b7684;
  --line: #e5e8eb;
  --accent: #3182f6;
  --accent-ink: #ffffff;
  --good: #1b9c5a;
  --bad: #e5484d;
  --radius: 16px;
  --text-muted: #8b95a1;
  /* 차트 시리즈 (고정 순서) */
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #6250d6;
  --s-muted: #8b95a1;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101113;
    --card: #1c1d20;
    --text: #f2f4f6;
    --muted: #9ea4ad;
    --line: #2c2e33;
    --accent: #4c94ff;
    --text-muted: #8d939c;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #9085e9;
    --s-muted: #7e858f;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR", sans-serif;
  line-height: 1.5;
}
.top, .tabs, main, footer { max-width: 560px; margin: 0 auto; padding: 0 16px; }
.top { padding-top: 28px; }
.top h1 { margin: 0; font-size: 26px; }
.sub { margin: 4px 0 16px; color: var(--muted); font-size: 14px; }

.tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding-bottom: 12px; }
.tabs button {
  border: 0; border-radius: 12px; padding: 9px 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: -0.3px;
  background: var(--card); color: var(--muted); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
}
.tabs button[aria-selected="true"] { background: var(--accent); color: var(--accent-ink); }

.card { background: var(--card); border-radius: var(--radius); padding: 18px; margin-bottom: 12px; }
form label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
form input, form select {
  display: block; width: 100%; margin-top: 4px; padding: 11px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: transparent; color: var(--text);
  font: inherit; font-size: 16px;
}
form input:focus, form select:focus { outline: 2px solid var(--accent); border-color: transparent; }
.row { display: flex; gap: 10px; }
.row > label { flex: 1; min-width: 0; }

button.primary {
  width: 100%; border: 0; border-radius: 12px; padding: 14px; margin-top: 4px;
  background: var(--accent); color: var(--accent-ink); font: inherit; font-size: 16px; font-weight: 700; cursor: pointer;
}
button.ghost {
  border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px;
  background: transparent; color: var(--text); font: inherit; font-size: 14px; cursor: pointer;
}

.result .headline { font-size: 14px; color: var(--muted); margin: 0; }
.result .big { font-size: 30px; font-weight: 800; margin: 2px 0 14px; letter-spacing: -0.5px; }
.result dl { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; margin: 0; font-size: 14px; }
.result dt { color: var(--muted); }
.result dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.result dd.minus { color: var(--bad); }
.result dd.plus { color: var(--good); }
.result .note { font-size: 12px; color: var(--muted); margin: 12px 0 0; }
.result details { margin-top: 12px; font-size: 13px; }
.result summary { cursor: pointer; color: var(--accent); }
.schedule { max-height: 280px; overflow: auto; margin-top: 8px; }
.schedule table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.schedule th, .schedule td { padding: 4px 6px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
.schedule th { position: sticky; top: 0; background: var(--card); color: var(--muted); font-weight: 600; }

.affiliate {
  display: block; margin-top: 14px; padding: 12px; border-radius: 12px; text-align: center;
  background: color-mix(in srgb, var(--accent) 10%, transparent); color: var(--accent);
  font-weight: 700; text-decoration: none; font-size: 15px;
}

.support p { margin: 0 0 10px; font-size: 14px; }
.support-btns { display: flex; gap: 8px; }
.support-btns a {
  flex: 1; text-align: center; padding: 11px; border-radius: 12px; text-decoration: none; font-weight: 700; font-size: 14px;
}
.support-btns .toss { background: #0064ff; color: #fff; }
.qr { margin-top: 12px; text-align: center; }
.qr .frame { width: 200px; height: 200px; margin: 0 auto; overflow: hidden; border-radius: 12px; background: #fff; }
.qr img { display: block; width: 340px; height: 340px; margin: -70px; }
.qr p { margin: 8px 0 0; font-size: 12px; color: var(--muted); }
.support-btns .kakao { background: #fee500; color: #191919; }

.share { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 14px; color: var(--muted); }
.ad { min-height: 100px; padding: 8px; }

footer { padding-bottom: 40px; font-size: 12px; color: var(--muted); }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 14px;
}

.intro { margin: 0 0 14px; font-size: 14px; }
.to-compare { width: 100%; margin-top: 14px; padding: 12px; font-weight: 700; }
.cmp { border-top: 1px solid var(--line); padding: 12px 0; }
.cmp-head { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.cmp-head b { font-size: 15px; }
.tag { font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 1px 7px; white-space: nowrap; }
.cmp-main { margin: 0; font-size: 14px; }
.cmp-main b { font-size: 16px; }
.cmp-sub { margin: 4px 0 0; font-size: 12px; color: var(--muted); }
.plus { color: var(--good); }
.minus { color: var(--bad); }

.pick { border-top: 1px dashed var(--line); padding-top: 14px; margin-bottom: 8px; }
.pick small { color: var(--muted); }
.suggest { list-style: none; margin: -6px 0 10px; padding: 4px; border: 1px solid var(--line); border-radius: 10px; max-height: 260px; overflow: auto; }
.suggest button { display: block; width: 100%; text-align: left; border: 0; background: transparent; color: var(--text); font: inherit; font-size: 14px; padding: 9px 8px; border-radius: 8px; cursor: pointer; }
.suggest button:hover, .suggest button:focus { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.suggest small { color: var(--muted); }
.suggest .empty { font-size: 13px; color: var(--muted); padding: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chips button { border: 1px solid var(--line); background: transparent; color: var(--text); border-radius: 999px; padding: 6px 11px; font: inherit; font-size: 13px; cursor: pointer; }
.picked { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; padding: 9px 12px; border-radius: 10px; background: color-mix(in srgb, var(--accent) 10%, transparent); font-size: 14px; font-weight: 600; }
.picked button { padding: 3px 9px; }
.cmp.mine { border: 2px solid var(--accent); border-radius: 12px; padding: 12px; margin-bottom: 4px; }
.others { margin: 14px 0 0; font-size: 12px; font-weight: 700; color: var(--muted); }

.period { margin-bottom: 12px; }
.period-label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.period-label small { color: var(--muted); }
.seg { display: flex; gap: 4px; margin-bottom: 8px; background: color-mix(in srgb, var(--muted) 12%, transparent); border-radius: 10px; padding: 3px; }
.seg button { flex: 1; border: 0; background: transparent; color: var(--muted); font: inherit; font-size: 13px; font-weight: 600; padding: 7px 4px; border-radius: 8px; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--card); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.period .row label { margin-bottom: 0; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; flex: 0 0 auto; }
.swatch.dash { height: 3px; border-radius: 2px; }
.swatch.dot { height: 0; border-top: 2px dotted var(--text-muted); border-radius: 0; background: none; }
.picked .swatch { margin-right: 2px; }
.picked { margin-bottom: 6px; }
.picked span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: 12px; color: var(--muted); margin: 4px 0 6px; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.chart-host { margin: 0 0 6px; touch-action: pan-y; }
.chart { display: block; max-width: 100%; height: auto; overflow: visible; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .line.dash { stroke-dasharray: 5 4; stroke-width: 1.5; }
.chart .end-dot { stroke: var(--card); stroke-width: 2; }
.chart .end-label { fill: var(--text); font-size: 11px; font-weight: 600; }
.chart .cross { stroke: var(--muted); stroke-width: 1; }
.chart-tip { position: absolute; top: 0; pointer-events: none; background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; font-size: 12px; box-shadow: 0 4px 14px rgba(0,0,0,.12); min-width: 150px; }
.chart-tip b { display: block; margin-bottom: 4px; }
.chart-tip div { display: flex; align-items: center; gap: 6px; }
.chart-tip span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 110px; }
.chart-tip em { font-style: normal; font-variant-numeric: tabular-nums; }
.cmp-head .swatch { margin-right: 2px; }

/* 기간: 연·월 선택 */
.ym-range { display: grid; gap: 6px; }
.ym { display: flex; align-items: center; gap: 6px; }
.ym > span { flex: 0 0 30px; font-size: 13px; color: var(--muted); }
.ym select { flex: 1; min-width: 0; margin: 0; padding: 10px 8px; font: inherit; font-size: 15px; border: 1px solid var(--line); border-radius: 10px; background: transparent; color: var(--text); }
.ym select[name$="M"] { flex: 0 0 84px; }
/* 선택된 종목 */
.picked .pk { display: flex; flex-direction: column; line-height: 1.3; }
.picked .pk b { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picked .pk small { font-size: 11px; color: var(--muted); font-weight: 400; }
/* 순위표 */
.board { list-style: none; margin: 4px 0 0; padding: 0; }
.board li { padding: 8px 0; border-top: 1px solid var(--line); }
.board li:first-child { border-top: 0; }
.b-top { display: flex; align-items: flex-start; gap: 6px; font-size: 14px; }
.b-rank { flex: 0 0 18px; width: 18px; text-align: center; font-weight: 800; color: var(--muted); }
.board li:first-child .b-rank { color: var(--accent); }
.b-name { flex: 1; min-width: 0; line-height: 1.3; word-break: keep-all; overflow-wrap: anywhere; }
.b-val { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.b-bar { display: flex; align-items: center; gap: 8px; margin: 5px 0 0 24px; }
.b-bar .track { position: relative; flex: 1; height: 10px; }
.b-bar .track span { display: block; height: 100%; border-radius: 0 4px 4px 0; min-width: 2px; }
.board li.base .track span { opacity: .55; }
.b-bar .track::after { content: ""; position: absolute; left: var(--p); top: -3px; bottom: -3px; border-left: 2px solid var(--text); opacity: .4; }
.b-bar em { flex: 0 0 62px; text-align: right; font-style: normal; font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.b-note { margin: 6px 0 0; font-size: 11px; color: var(--muted); }
.sub-h { margin: 18px 0 6px; font-size: 14px; }
.sub-h small { font-weight: 400; color: var(--muted); font-size: 11px; }
/* 지표 표 */
.metrics { width: 100%; border-collapse: collapse; font-size: 13px; table-layout: fixed; }
.metrics th { font-size: 11px; font-weight: 600; color: var(--muted); text-align: right; padding: 4px 2px; border-bottom: 1px solid var(--line); }
.metrics th:first-child { text-align: left; width: 38%; }
.metrics td { padding: 7px 2px; vertical-align: top; text-align: right; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; white-space: nowrap; }
.metrics td:first-child { text-align: left; white-space: normal; line-height: 1.3; word-break: keep-all; overflow-wrap: anywhere; }
.metrics td:first-child .swatch { margin-right: 4px; vertical-align: 1px; }
/* 자세히 */
.more { margin-top: 12px; font-size: 13px; }
.more summary { cursor: pointer; color: var(--accent); font-weight: 600; padding: 6px 0; }
.more-item { padding: 10px 0; border-top: 1px solid var(--line); }
.more dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; margin: 4px 0 0; }
.more dt { color: var(--muted); }
.more dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.b-top .swatch { margin-top: 5px; }
