:root {
  color-scheme: light;
  --bg: #f6f6f4;
  --surface: #ffffff;
  --surface-2: #efeeea;
  --line: #e3e2dd;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #8a8983;
  --high: #6250d6;            /* 1년 고점 */
  --buy: #d92d2d;             /* 매수권장 */
  --buy-soft: #fdeaea;
  --review: #d4600f;          /* 매수검토 */
  --review-soft: #fdeedf;
  --up: #d92d2d;              /* 전일 대비 상승 (국내 관례: 빨강) */
  --down: #2a66d6;            /* 전일 대비 하락 (국내 관례: 파랑) */
  --warn: #8a6100;
  --warn-soft: #fbf3d2;
  --series: #2a78d6;
  --avg: #0f8a5f;             /* 내 평단 */
  --radius: 16px;
  --tab-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #151514;
    --surface: #1f1f1d;
    --surface-2: #2a2a28;
    --line: #34342f;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --text-3: #8f8e86;
    --high: #a49bf2;
    --buy: #ff6b6b;
    --buy-soft: #3b1c1c;
    --review: #f5924f;
    --review-soft: #3a2617;
    --up: #f06767;
    --down: #6aa0ff;
    --warn: #e3b93e;
    --warn-soft: #322a12;
    --series: #3987e5;
    --avg: #3ccf95;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #151514;
  --surface: #1f1f1d;
  --surface-2: #2a2a28;
  --line: #34342f;
  --text: #f0efec;
  --text-2: #c3c2b7;
  --text-3: #8f8e86;
  --high: #a49bf2;
  --buy: #ff6b6b;
  --buy-soft: #3b1c1c;
  --review: #f5924f;
  --review-soft: #3a2617;
  --up: #f06767;
  --down: #6aa0ff;
  --warn: #e3b93e;
  --warn-soft: #322a12;
  --series: #3987e5;
  --avg: #3ccf95;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Pretendard", "Apple SD Gothic Neo",
    "Noto Sans KR", "Malgun Gothic", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(var(--tab-h) + var(--safe-b));
  min-height: 100vh;
}
button { font: inherit; color: inherit; }
a { color: inherit; }
.num { font-variant-numeric: tabular-nums; }

/* 상단 */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 4px;
  height: 56px; padding: 0 8px 0 16px;
  background: var(--bg);
}
.topbar h1 { flex: 1; margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -0.02em; }
.icon-btn {
  width: 44px; height: 44px; border: 0; border-radius: 12px;
  background: transparent; display: grid; place-items: center; cursor: pointer;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.back { margin-left: -12px; }

/* 연습 모드 띠 */
.practice {
  margin: 0 16px 8px; padding: 10px 12px;
  border-radius: 12px; border: 1.5px dashed var(--text-3);
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px;
}
.practice-text { flex: 1 1 140px; display: flex; flex-direction: column; font-size: 13px; color: var(--text-2); }
.practice-text strong { color: var(--text); font-size: 14px; }
.practice-actions { display: flex; gap: 6px; }
.chip {
  border: 0; border-radius: 999px; padding: 8px 12px; min-height: 36px;
  background: var(--surface-2); font-size: 14px; font-weight: 600; cursor: pointer;
}
.chip.ghost { background: transparent; color: var(--text-2); }
.chip.on { background: var(--text); color: var(--bg); }
.chip:disabled { opacity: .45; }

main { padding: 0 16px 24px; outline: none; }

/* 카드 */
.card {
  background: var(--surface); border-radius: var(--radius);
  padding: 16px; margin-bottom: 12px;
}
.card h2 { margin: 0 0 4px; font-size: 17px; letter-spacing: -0.01em; }
.card p { margin: 0; color: var(--text-2); font-size: 15px; }
.section-title { margin: 20px 4px 8px; font-size: 15px; font-weight: 700; color: var(--text-2); }
.muted { color: var(--text-3); font-size: 13px; }
.stage {
  display: inline-block; font-size: 12px; font-weight: 700;
  padding: 3px 8px; border-radius: 6px; margin-bottom: 8px;
  background: var(--surface-2); color: var(--text-2);
}

/* 시세판 머리 */
.board-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 0 0 10px; }
.board-time { font-size: 13px; color: var(--text-2); }
.board-time b { color: var(--text); }
.sort { display: flex; gap: 4px; }
.sort .chip { min-height: 32px; padding: 6px 10px; font-size: 13px; }
.summary { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.sum { border-radius: 14px; padding: 12px 14px; border: 2px solid; }
.sum .k { font-size: 13px; font-weight: 700; }
.sum .v { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.2; }
.sum .v small { font-size: 14px; font-weight: 600; color: var(--text-2); }
.sum.buy { border-color: var(--buy); background: var(--buy-soft); color: var(--buy); }
.sum.review { border-color: var(--review); background: var(--review-soft); color: var(--review); }

/* 종목 카드 (시세판 한 줄) */
.stock {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; align-items: baseline;
  background: var(--surface); border-radius: 14px; padding: 14px 16px; margin-bottom: 8px;
  text-decoration: none; border: 2px solid transparent;
}
.stock:active { filter: brightness(.97); }
.stock.buy { border-color: var(--buy); background: var(--buy-soft); }
.stock.review { border-color: var(--review); background: var(--review-soft); }
.stock .name { font-weight: 700; font-size: 17px; display: flex; align-items: center; flex-wrap: wrap; gap: 4px 8px; }
.stock .sym { color: var(--text-3); font-size: 13px; font-weight: 500; }
.stock .price { text-align: right; font-weight: 700; font-size: 17px; }
.stock .chg { text-align: right; font-size: 13px; font-weight: 600; }
.stock .high { font-size: 14px; color: var(--text-2); }
.stock .high b { color: var(--high); font-weight: 800; }
.stock .dd { grid-column: 1 / -1; display: flex; align-items: baseline; gap: 8px; margin-top: 6px; }
.stock .dd .k { font-size: 14px; color: var(--text-2); }
.stock .dd .v { font-size: 24px; font-weight: 800; letter-spacing: -0.02em; }
.stock.buy .dd .v { color: var(--buy); }
.stock.review .dd .v { color: var(--review); }
.up { color: var(--up); }
.down { color: var(--down); }

.tag {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; font-weight: 800; padding: 3px 8px; border-radius: 6px; line-height: 1.3;
}
.tag.buy { background: var(--buy); color: #fff; }
.tag.review { background: var(--review); color: #fff; }
.tag.drop { background: var(--surface-2); color: var(--text-2); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.newhigh { background: var(--high); color: #fff; }
.tag.big { font-size: 14px; padding: 4px 10px; }
.tag.profit { background: var(--up); color: #fff; }
.tag.loss { background: var(--down); color: #fff; }
.tag.held { background: transparent; color: var(--avg); border: 1.5px solid var(--avg); padding: 2px 6px; }
.tag.out { background: var(--surface-2); color: var(--text-2); }

/* 알림 */
.alert-day { margin: 18px 4px 8px; font-size: 13px; font-weight: 700; color: var(--text-3); }
.alert {
  display: block; text-decoration: none; background: var(--surface);
  border-radius: 14px; padding: 14px 16px; margin-bottom: 8px; border: 2px solid transparent;
}
.alert.buy { border-color: var(--buy); }
.alert.review { border-color: var(--review); }
.alert.profit { border-color: var(--up); }
.alert.loss { border-color: var(--down); }
.alert:active { background: var(--surface-2); }
.alert-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.alert-head strong { font-size: 16px; }
.alert-msg { color: var(--text-2); font-size: 14px; }

/* 상세 */
.detail-head .price { font-size: 30px; font-weight: 800; letter-spacing: -0.03em; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; }
.stat { background: var(--surface-2); border-radius: 12px; padding: 10px; }
.stat .k { font-size: 12px; color: var(--text-2); }
.stat .v { font-size: 17px; font-weight: 800; }
.stat.high .v { color: var(--high); }

.chart-wrap { position: relative; touch-action: pan-y; }
.chart-wrap svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart-wrap .grid { stroke: var(--line); stroke-width: 1; }
.chart-wrap .axis { fill: var(--text-3); font-size: 11px; }
.chart-wrap .line { fill: none; stroke: var(--series); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-wrap .ref { stroke-width: 1.5; stroke-dasharray: 5 4; }
.chart-wrap .ref.high { stroke: var(--high); stroke-width: 2; stroke-dasharray: none; }
.chart-wrap .ref.review { stroke: var(--review); }
.chart-wrap .ref.buy { stroke: var(--buy); }
.chart-wrap .ref-label { font-size: 11px; font-weight: 700; }
.chart-wrap .ref-label.high { fill: var(--high); }
.chart-wrap .ref-label.review { fill: var(--review); }
.chart-wrap .ref-label.buy { fill: var(--buy); }
.chart-wrap .ref.avg { stroke: var(--avg); stroke-width: 2; stroke-dasharray: 2 3; }
.chart-wrap .ref-label.avg { fill: var(--avg); }
.chart-wrap .now { fill: var(--series); stroke: var(--surface); stroke-width: 2; }
.chart-wrap .cross { stroke: var(--text-3); stroke-width: 1; }
.chart-wrap .hover-dot { fill: var(--series); stroke: var(--surface); stroke-width: 2; }
.tip {
  position: absolute; top: 0; pointer-events: none;
  background: var(--text); color: var(--bg); border-radius: 8px;
  padding: 6px 8px; font-size: 12px; line-height: 1.35; white-space: nowrap;
  transform: translateX(-50%);
}
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--text-2); margin-top: 8px; }
.legend i { display: inline-block; width: 14px; height: 0; border-top: 2px solid; vertical-align: middle; margin-right: 4px; }

table.zones { width: 100%; border-collapse: collapse; font-size: 15px; }
table.zones th { text-align: left; font-size: 12px; color: var(--text-3); font-weight: 600; padding: 0 0 8px; }
table.zones td { padding: 9px 0; border-top: 1px solid var(--line); }
table.zones td:last-child, table.zones th:last-child { text-align: right; }
table.zones tr.hit td:first-child { font-weight: 800; }
table.zones .lbl { margin-left: 6px; }

/* 내 종목 */
.total .k { font-size: 14px; color: var(--text-2); }
.total .big { font-size: 30px; font-weight: 800; letter-spacing: -0.03em; margin: 2px 0; }
.total .krw { font-size: 15px; color: var(--text-2); }
.total .row2 { display: flex; gap: 16px; margin-top: 10px; font-size: 15px; }
.total .row2 b { font-weight: 800; }
.mine {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; align-items: baseline;
  background: var(--surface); border-radius: 14px; padding: 14px 16px; margin-bottom: 8px;
  text-decoration: none; border: 2px solid transparent;
}
.mine.profit { border-color: var(--up); }
.mine.loss { border-color: var(--down); }
.mine .name { font-weight: 700; font-size: 17px; display: flex; align-items: center; flex-wrap: wrap; gap: 4px 8px; }
.mine .sym { color: var(--text-3); font-size: 13px; font-weight: 500; }
.mine .ret { text-align: right; font-size: 24px; font-weight: 800; letter-spacing: -0.02em; }
.mine .sub { font-size: 14px; color: var(--text-2); }
.mine .sub b { color: var(--avg); }
.mine .val { text-align: right; font-size: 14px; color: var(--text-2); }

/* 3분할 계산기 */
.split-form { display: flex; gap: 8px; margin: 10px 0 4px; }
.split-form input {
  flex: 1; min-width: 0; font: inherit; font-size: 17px; padding: 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
}
.split-form .btn { width: auto; padding: 12px 16px; }
table.split { width: 100%; border-collapse: collapse; font-size: 15px; margin-top: 8px; }
table.split th { text-align: left; font-size: 12px; color: var(--text-3); font-weight: 600; padding: 0 0 6px; }
table.split td { padding: 10px 0; border-top: 1px solid var(--line); }
table.split td:not(:first-child), table.split th:not(:first-child) { text-align: right; }
table.split tr.done td { color: var(--text-3); }
table.split tr.next td { font-weight: 800; }

/* 설정 */
.setting { display: flex; justify-content: space-between; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); font-size: 15px; }
.setting:first-of-type { border-top: 0; }
.setting .k { color: var(--text-2); }
.setting .v { text-align: right; font-weight: 600; }
.btn {
  display: block; width: 100%; border: 0; border-radius: 12px;
  padding: 14px; min-height: 48px; font-size: 16px; font-weight: 700; cursor: pointer;
  background: var(--text); color: var(--bg);
}
.btn.secondary { background: var(--surface-2); color: var(--text); }
.btn + .btn { margin-top: 8px; }

/* 로그인 */
.login { max-width: 360px; margin: 12vh auto 0; text-align: center; }
.login input {
  width: 100%; font: inherit; font-size: 18px; padding: 14px; margin: 16px 0 10px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--text);
}
.error { color: var(--buy); font-size: 14px; min-height: 20px; }

/* 하단 탭 */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tab-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabs a {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; text-decoration: none; color: var(--text-3); font-size: 11px; font-weight: 600;
}
.tabs a.active { color: var(--text); }
.tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabs a.active svg { stroke-width: 2.2; }
.badge {
  position: absolute; top: 8px; left: calc(50% + 6px);
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--buy); color: #fff; font-size: 11px; font-style: normal; font-weight: 700;
  display: grid; place-items: center;
}

.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(var(--tab-h) + var(--safe-b) + 12px);
  background: var(--text); color: var(--bg); border-radius: 12px; padding: 12px 14px;
  font-size: 14px; opacity: 0; transform: translateY(8px); pointer-events: none;
  transition: opacity .2s, transform .2s; z-index: 10;
}
.toast.show { opacity: 1; transform: none; }

.empty { text-align: center; padding: 32px 16px; color: var(--text-3); }

@media (min-width: 640px) {
  main, .practice { max-width: 600px; margin-left: auto; margin-right: auto; }
  .practice { margin-bottom: 8px; }
}
