/* 휴대폰 우선, 한 줄 세로 흐름. 큰 글씨. 국내 관례: 수익 빨강, 손실 파랑. */
:root {
  --bg: #f3f5f8;
  --card: #ffffff;
  --text: #17202b;
  --sub: #5c6877;
  --line: #e1e5eb;
  --brand: #2f6fde;
  --up: #d92b3a;
  --up-bg: #fdecee;
  --down: #2763d6;
  --down-bg: #eaf1fd;
  --even: #6b7684;
  --even-bg: #eef0f3;
  --warn-bg: #fff6df;
  --warn-text: #5c4510;
  --shadow: rgba(23, 32, 43, .07);
  --font: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Malgun Gothic", "Noto Sans KR", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216; --card: #1a1e24; --text: #e9edf2; --sub: #9aa4b0; --line: #2c313a;
    --brand: #5b8ff0; --up: #ff6671; --up-bg: #3a1d21; --down: #6f9fff; --down-bg: #1b2740;
    --even: #a3acb8; --even-bg: #262b33; --warn-bg: #2b2414; --warn-text: #f0d79a;
    --shadow: rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0 auto;
  max-width: 600px;
  padding: 0 max(16px, env(safe-area-inset-right)) max(32px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: var(--bg);
  color: var(--text);
  font: 17px/1.55 var(--font);
  word-break: keep-all;
}
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }
b { font-weight: 700; }
.num-text, .stat b, .cmp td, .table td { font-variant-numeric: tabular-nums; }

.top { padding: max(24px, env(safe-area-inset-top)) 4px 8px; }
.top h1 { margin: 0; font-size: 26px; letter-spacing: -0.02em; }
.top p { margin: 4px 0 0; color: var(--sub); font-size: 15px; }

/* 종목 탭 */
.stocks { display: flex; gap: 8px; overflow-x: auto; padding: 8px 2px 12px; scrollbar-width: none; }
.stocks::-webkit-scrollbar { display: none; }
.stocks button {
  flex: 0 0 auto; min-height: 44px; padding: 0 16px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  font: inherit; font-size: 16px; cursor: pointer; max-width: 12em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.stocks button[aria-current="true"] { background: var(--text); color: var(--bg); border-color: var(--text); font-weight: 700; }
.stocks .add { color: var(--brand); border-style: dashed; }

.card {
  background: var(--card); border-radius: 18px; padding: 20px 18px; margin: 0 0 14px;
  box-shadow: 0 1px 3px var(--shadow);
}
.card.quiet { background: transparent; box-shadow: none; border: 1px solid var(--line); }
.card h2 { display: flex; align-items: center; gap: 8px; margin: 0 0 14px; font-size: 20px; letter-spacing: -0.01em; }
.step {
  display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%;
  background: var(--brand); color: #fff; font-size: 15px; font-weight: 700; flex: none;
}

.field { display: block; margin: 0 0 12px; font-size: 15px; color: var(--sub); font-weight: 600; }
.field input { margin-top: 6px; }
.field.big input { font-size: 24px; font-weight: 700; min-height: 58px; }
input {
  display: block; width: 100%; min-height: 50px; padding: 10px 14px;
  border: 1.5px solid var(--line); border-radius: 12px; background: var(--card); color: var(--text);
  font: inherit; font-size: 19px;
}
input::placeholder { color: var(--sub); opacity: .7; font-size: 16px; font-weight: 400; }
input:focus { border-color: var(--brand); outline: none; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* 산 기록 */
.buys-head, .buy { display: grid; grid-template-columns: 1fr 1.4fr 44px; gap: 8px; align-items: center; }
.buys-head { font-size: 14px; color: var(--sub); font-weight: 600; margin-bottom: 6px; }
.buy { margin-bottom: 8px; }
.buy input { font-size: 18px; }
.icon-btn {
  width: 44px; height: 44px; border: 0; border-radius: 12px; background: transparent;
  color: var(--sub); font-size: 22px; cursor: pointer;
}
.icon-btn:hover { background: var(--even-bg); }
.sum { margin: 10px 0 16px; padding: 12px 14px; border-radius: 12px; background: var(--even-bg); font-size: 16px; }
.sum:empty { display: none; }

.hint { margin: 6px 0 0; color: var(--sub); font-size: 14px; }

/* 버튼 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 48px; padding: 0 18px;
  border: 1.5px solid var(--line); border-radius: 12px; background: var(--card); color: var(--text);
  font: inherit; font-size: 16px; font-weight: 600; cursor: pointer;
}
.btn.ghost { border-color: transparent; background: transparent; color: var(--brand); padding: 0 6px; }
.btn.small { min-height: 44px; font-size: 15px; }
.btn.danger { color: var(--up); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 8px; }

/* ⓘ 설명 */
.info {
  display: inline-grid; place-items: center; width: 24px; height: 24px; padding: 0; margin: 0 2px;
  border: 1.5px solid var(--sub); border-radius: 50%; background: transparent; color: var(--sub);
  font: italic 700 13px/1 Georgia, serif; cursor: pointer; vertical-align: middle; flex: none;
  position: relative;
}
.info::after { content: ""; position: absolute; inset: -10px; } /* 손가락으로 누르기 쉽게 */
.tip {
  position: absolute; z-index: 20; max-width: min(300px, calc(100vw - 32px)); padding: 12px 14px;
  border-radius: 12px; background: var(--text); color: var(--bg); font-size: 15px; line-height: 1.5;
  box-shadow: 0 8px 24px var(--shadow);
}
.tip b { display: block; margin-bottom: 2px; }

/* ② 상태 */
.empty { margin: 0; padding: 18px; border-radius: 14px; background: var(--even-bg); color: var(--sub); text-align: center; }
.verdict {
  display: flex; gap: 14px; align-items: flex-start; padding: 18px; border-radius: 16px; margin-bottom: 14px;
  background: var(--even-bg);
}
.verdict.up { background: var(--up-bg); }
.verdict.down { background: var(--down-bg); }
.light {
  flex: none; width: 22px; height: 22px; margin-top: 4px; border-radius: 50%; background: var(--even);
  box-shadow: 0 0 0 5px color-mix(in srgb, var(--even) 22%, transparent);
}
.up .light { background: var(--up); box-shadow: 0 0 0 5px color-mix(in srgb, var(--up) 22%, transparent); }
.down .light { background: var(--down); box-shadow: 0 0 0 5px color-mix(in srgb, var(--down) 22%, transparent); }
.verdict p { margin: 0; font-size: 20px; font-weight: 700; line-height: 1.45; }
.verdict p + p { margin-top: 4px; font-size: 17px; font-weight: 600; }
.up .t { color: var(--up); }
.down .t { color: var(--down); }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { padding: 14px; border-radius: 14px; border: 1px solid var(--line); min-width: 0; }
.stat span { display: flex; align-items: center; gap: 2px; font-size: 14px; color: var(--sub); font-weight: 600; }
.stat b { display: block; margin-top: 4px; font-size: 22px; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.stat.wide { grid-column: 1 / -1; }
.stat .up { color: var(--up); }
.stat .down { color: var(--down); }

/* ③ 시뮬레이터 */
.cmp { width: 100%; border-collapse: collapse; margin: 6px 0 14px; font-size: 16px; }
.cmp th, .cmp td { padding: 12px 6px; border-bottom: 1px solid var(--line); text-align: right; }
.cmp th:first-child, .cmp td:first-child { text-align: left; color: var(--sub); font-weight: 600; font-size: 15px; }
.cmp thead th { font-size: 14px; color: var(--sub); }
.cmp thead th.after { color: var(--brand); }
.cmp td.after { font-weight: 700; font-size: 18px; }
.cmp .delta { display: block; font-size: 13px; font-weight: 600; }
.cmp .lbl { display: inline-flex; align-items: center; gap: 2px; }
.eff { margin: 0 0 14px; padding: 14px 16px; border-radius: 14px; background: var(--even-bg); font-size: 17px; font-weight: 600; }
h3 { margin: 18px 0 6px; font-size: 16px; color: var(--sub); }
.table-wrap { overflow-x: auto; margin: 0 -4px; }
.table { width: 100%; border-collapse: collapse; font-size: 15px; min-width: 340px; }
.table th, .table td { padding: 10px 6px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
.table th { font-size: 13px; color: var(--sub); font-weight: 600; }
.table th:first-child, .table td:first-child { text-align: left; font-weight: 700; }
.table tr.mine td { background: var(--even-bg); }
.up { color: var(--up); }
.down { color: var(--down); }

.warn { margin: 16px 0 0; padding: 14px 16px; border-radius: 14px; background: var(--warn-bg); color: var(--warn-text); font-size: 15px; }

footer { padding: 12px 4px; color: var(--sub); font-size: 14px; }
footer p { margin: 0 0 8px; }
footer a { color: var(--sub); }

.toast {
  position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  padding: 12px 18px; border-radius: 12px; background: var(--text); color: var(--bg); font-size: 15px; z-index: 30;
  max-width: calc(100vw - 32px);
}

/* 개인정보처리방침 */
.doc h2 { font-size: 18px; margin: 22px 0 8px; }
.doc p, .doc li { font-size: 16px; }
.doc table { width: 100%; border-collapse: collapse; font-size: 15px; }
.doc th, .doc td { border: 1px solid var(--line); padding: 8px; text-align: left; vertical-align: top; }

@media (max-width: 380px) {
  body { font-size: 16px; }
  .stat b { font-size: 19px; }
  .row { grid-template-columns: 1fr; gap: 0; }
}
