:root {
  --bg: #f4f5f7; --card: #ffffff; --text: #16181d; --muted: #6b7280; --line: #e5e7eb;
  --accent: #2f6fed; --up: #d62d2d; --down: #1f5fd6; --chip: #eef0f3; --chip-on: #16181d; --chip-on-text: #fff;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115; --card: #181b21; --text: #e8eaed; --muted: #9aa0a8; --line: #2a2e36;
    --accent: #6c9bff; --up: #ff5d5d; --down: #5b9bff; --chip: #23272f; --chip-on: #e8eaed; --chip-on-text: #0f1115;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
  font-size: 15px; -webkit-text-size-adjust: 100%; }
button, input, select { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--up); }
.up { color: var(--up); }
.down { color: var(--down); }

.login-box { max-width: 360px; margin: 18vh auto 0; padding: 0 16px; text-align: center; }
.login-box input { width: 100%; padding: 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); margin: 12px 0; }
.login-box button, #more { width: 100%; padding: 12px; border: 0; border-radius: 10px; background: var(--accent);
  color: #fff; font-weight: 600; }

.top { position: sticky; top: 0; z-index: 2; display: flex; justify-content: space-between; align-items: center;
  gap: 8px; padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: var(--bg);
  border-bottom: 1px solid var(--line); }
.top h1 { font-size: 20px; margin: 0; }
.top select { padding: 6px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); }

main { padding: 12px 16px calc(80px + env(safe-area-inset-bottom)); max-width: 640px; margin: 0 auto; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin-bottom: 12px; }
.card.empty { color: var(--muted); text-align: center; padding: 32px 14px; }

.today-head { display: flex; justify-content: space-between; align-items: baseline; }
.today-pnl { font-size: 26px; font-weight: 700; margin: 4px 0; font-variant-numeric: tabular-nums; }
.today-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.today-grid div { background: var(--chip); border-radius: 10px; padding: 8px; }
.today-grid b { display: block; font-size: 15px; font-variant-numeric: tabular-nums; }

.chips { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 12px; scrollbar-width: none; }
.chips button { flex: none; border: 0; border-radius: 999px; padding: 6px 12px; background: var(--chip); }
.chips button.on { background: var(--chip-on); color: var(--chip-on-text); }

.day { font-weight: 700; margin: 16px 0 8px; font-size: 14px; }
.item { display: flex; gap: 10px; background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 12px; margin-bottom: 8px; }
.item .time { flex: none; width: 44px; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.item .body { flex: 1; min-width: 0; }
.item .msg { white-space: pre-wrap; word-break: break-word; font-size: 14px; line-height: 1.45; }
.item .tag { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 6px; background: var(--chip);
  color: var(--muted); margin-bottom: 4px; }
.item.trade { border-left: 3px solid var(--accent); }
.trade-line { display: flex; justify-content: space-between; gap: 8px; font-variant-numeric: tabular-nums; }
.trade-line .pnl { font-weight: 700; }
.item .msg.folded { max-height: 4.4em; overflow: hidden; }

.tabbar { position: fixed; left: 0; right: 0; bottom: 0; display: flex; background: var(--card);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabbar button { flex: 1; border: 0; background: none; padding: 8px 0 10px; font-size: 12px; color: var(--muted); }
.tabbar button.on { color: var(--text); font-weight: 600; }
.tabbar .ico { display: block; font-size: 20px; }
.ghost { margin-top: 4px; }

/* ===== 백테스트 ===== */
:root { --s-bt: #6250d6; --s-live: #eb6834; }
@media (prefers-color-scheme: dark) { :root { --s-bt: #9085e9; --s-live: #d95926; } }
.group-title { font-size: 13px; color: var(--muted); margin: 16px 2px 8px; }
.run { display: block; width: 100%; text-align: left; background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; cursor: pointer; }
.run-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.run-head b { font-size: 15px; }
.run-stats { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 4px; font-size: 13px; color: var(--muted);
  font-variant-numeric: tabular-nums; }
.run-stats span b { color: var(--text); font-weight: 600; }
.back { border: 0; background: none; color: var(--accent); padding: 4px 0 10px; font-weight: 600; }
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat-grid div { background: var(--chip); border-radius: 10px; padding: 8px; min-width: 0; }
.stat-grid b { display: block; font-size: 15px; font-variant-numeric: tabular-nums; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; }
.card h2 { font-size: 15px; margin: 0 0 2px; }
.card .sub { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.chart { position: relative; width: 100%; height: 190px; touch-action: pan-y; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .zero { stroke: var(--muted); stroke-width: 1; opacity: .6; }
.chart .axis { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .hair { stroke: var(--muted); stroke-width: 1; }
.chart .dot { stroke: var(--card); stroke-width: 2; }
.tip { position: absolute; top: 0; pointer-events: none; background: var(--card); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 8px; font-size: 12px; line-height: 1.5; white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0,0,0,.12); font-variant-numeric: tabular-nums; }
.tip .sw { display: inline-block; width: 10px; height: 2px; vertical-align: middle; margin-right: 4px; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.legend i { display: inline-block; width: 14px; height: 2px; vertical-align: middle; margin-right: 5px; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
table.data th { text-align: right; font-weight: 500; color: var(--muted); font-size: 12px; padding: 4px 4px 6px; }
table.data td { text-align: right; padding: 6px 4px; border-top: 1px solid var(--line); }
table.data th:first-child, table.data td:first-child { text-align: left; }
.scroll-x { overflow-x: auto; }
details summary { cursor: pointer; font-weight: 600; font-size: 15px; }

/* ===== 일자별 매매 차트 ===== */
:root { --m-buy: var(--s-bt); --m-sell: var(--s-live); }
.hint { margin: -4px 2px 4px; }
.day, .item { cursor: pointer; -webkit-user-select: none; user-select: none; touch-action: manipulation; }
.chart.candle { height: 300px; }
.chart .mark { stroke: var(--card); stroke-width: 2; }
.chart .mark-label { fill: var(--text); font-size: 11px; font-weight: 600; }
.legend .tri { display: inline-block; width: 0; height: 0; margin-right: 5px; vertical-align: middle;
  border-left: 5px solid transparent; border-right: 5px solid transparent; }
.legend .tri.buy { border-bottom: 9px solid var(--m-buy); }
.legend .tri.sell { border-top: 9px solid var(--m-sell); }
.legend .bar-up, .legend .bar-down { display: inline-block; width: 6px; height: 10px; margin-right: 5px; vertical-align: middle; border-radius: 1px; }
.legend .bar-up { background: var(--up); }
.legend .bar-down { background: var(--down); }
.trade-card { border-top: 1px solid var(--line); padding: 10px 0 2px; }
.trade-card:first-of-type { border-top: 0; padding-top: 0; }
.kv { display: grid; grid-template-columns: 64px 1fr; gap: 3px 8px; font-size: 13px; margin-top: 6px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; }

/* 설정 화면 */
.kv.wide { grid-template-columns: 88px 1fr; }
.search { width: 100%; padding: 10px 12px; margin-bottom: 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); }
.params-sec summary { display: flex; align-items: center; gap: 6px; }
.params-sec[open] summary { margin-bottom: 8px; }
.params-sec .tag, .param .tag { font-size: 11px; padding: 1px 6px; border-radius: 6px; background: var(--chip); font-weight: 400; }
.param { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.param:first-of-type { border-top: 0; }
.param code { font-size: 12px; word-break: break-all; }
.param .val { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.param .desc { grid-column: 1 / -1; font-size: 12px; color: var(--muted); }

/* 설정 초안 - 현재 설정은 회색 기준선, 초안은 백테스트 보라 */
:root { --s-base: #868c96; }
@media (prefers-color-scheme: dark) { :root { --s-base: #666c75; } }
button.primary { display: block; width: 100%; margin-top: 10px; padding: 11px; border: 0; border-radius: 10px;
  background: var(--accent); color: #fff; font-weight: 600; }
button.primary:disabled { opacity: 0.45; }
.ghost-btn { padding: 11px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); }
.notice { margin-top: 10px; padding: 8px 10px; border-radius: 8px; background: var(--chip); font-size: 13px; }
.edit { grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.edit input[type=number], .edit input[type=time], .edit select { width: 120px; padding: 7px 8px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--bg); font-variant-numeric: tabular-nums; }
.edit input:disabled { opacity: 0.4; }
.edit .off { display: flex; align-items: center; gap: 4px; font-size: 13px; }
.param.changed { background: color-mix(in srgb, var(--s-bt) 10%, transparent); margin: 0 -8px; padding: 8px; border-radius: 8px; }
.edit-bar { position: sticky; bottom: calc(64px + env(safe-area-inset-bottom)); box-shadow: 0 -2px 12px rgba(0, 0, 0, .12); }
.edit-bar .search { margin-bottom: 8px; }
.edit-actions { display: flex; gap: 8px; }
.edit-actions .primary { margin-top: 0; flex: 1; }
.draft-row { padding: 9px 0; border-top: 1px solid var(--line); cursor: pointer; }
.draft-row:first-of-type { border-top: 0; }
.draft-line { display: flex; align-items: center; gap: 8px; }
.draft-line .x { margin-left: auto; border: 0; background: none; color: var(--muted); font-size: 20px; line-height: 1; padding: 0 4px; }
.draft-row .tag { font-size: 11px; padding: 1px 6px; border-radius: 6px; background: var(--chip); }
.draft-row .st-done { background: var(--chip-on); color: var(--chip-on-text); }
h3.seg { font-size: 13px; margin: 12px 0 2px; color: var(--muted); font-weight: 600; }

/* 길게 눌렀을 때 글자 선택·크롬 "탭하여 검색"·메뉴가 뜨지 않게 (차트·알람 목록) */
.chart, .chart *, .day, .item { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }

/* 알람 화면 월 조회 - 날짜 머리글 오른쪽에 그날 손익 */
.month-bar { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.month-bar select { flex: 1; padding: 9px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--card);
  font-weight: 600; text-align: center; text-align-last: center; }
.month-bar button { width: 40px; height: 40px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); font-size: 20px; line-height: 1; }
.month-bar button:disabled { opacity: 0.35; }
.day { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.day-sum { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.chart.month-cum { height: 150px; margin: 6px 0 2px; }
.month-chips { display: flex; gap: 6px; overflow-x: auto; margin-top: 6px; scrollbar-width: none; }
.month-chips button { flex: none; display: flex; flex-direction: column; align-items: flex-start; gap: 2px; min-width: 96px;
  border: 0; border-radius: 10px; padding: 7px 10px; background: var(--chip); font-size: 12px; text-align: left; }
.month-chips button b { font-size: 14px; font-variant-numeric: tabular-nums; }
.month-chips button.on { background: var(--chip-on); color: var(--chip-on-text); }
