:root {
  --bg: #3a3f4b; --bg2: #2f3440; --panel: #343a46; --line: #4a5162; --line2: #586074;
  --text: #e6e9ef; --muted: #9aa3b5; --accent: #2f8cff; --accent2: #4fc3f7;
  --up: #ff6b6b; --down: #5aa9ff; --good: #34c38f; --warn: #f1b44c; --bad: #f46a6a;
  --atk: #f1b44c; --def: #34c38f; --radius: 8px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", "Malgun Gothic", "Apple SD Gothic Neo", sans-serif; }
body { min-height: 100vh; }
button, input, select { font: inherit; color: inherit; }
input, select { width: 100%; background: var(--bg2); border: 1px solid var(--line); border-radius: 6px;
  padding: 7px 9px; color: var(--text); }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
label { display: block; font-size: 12px; color: var(--muted); }
label > input, label > select { margin-top: 3px; font-size: 14px; }
code { background: var(--bg2); padding: 1px 5px; border-radius: 4px; }
h1 { font-size: 22px; margin: 2px 0 6px; }
.hidden { display: none !important; }
.muted { color: var(--muted); } .small { font-size: 12px; } .err { color: var(--bad); }
.up { color: var(--up); } .down { color: var(--down); } .good { color: var(--good); } .warn { color: var(--warn); }

.btn { border: 1px solid var(--line2); background: var(--panel); border-radius: 6px; padding: 7px 14px;
  cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--accent2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:disabled { opacity: .6; cursor: wait; }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn.danger { color: var(--bad); }
.btn.wide { width: 100%; padding: 10px; margin-top: 10px; }

/* 상단 */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 14px;
  padding: 8px 14px; background: var(--bg2); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; white-space: nowrap; } .brand.big { font-size: 22px; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav-btn { background: none; border: 0; padding: 6px 10px; border-radius: 6px; cursor: pointer; color: var(--muted); }
.nav-btn.active, .nav-btn:hover { color: var(--text); background: var(--panel); }
.top-right { display: flex; align-items: center; gap: 8px; }
.quote-pill { font-size: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 3px 10px; white-space: nowrap; }

/* 백테스트 */
.bt-layout { display: grid; grid-template-columns: 270px 1fr; min-height: calc(100vh - 50px); }
.side { background: var(--bg2); border-right: 1px solid var(--line); padding: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.side-title { margin: 14px 0 6px; color: var(--accent2); font-weight: 600; font-size: 13px; }
.presets { display: flex; flex-wrap: wrap; gap: 6px; }
.preset { border: 1px solid var(--line2); background: var(--panel); border-radius: 6px; padding: 5px 8px;
  cursor: pointer; font-size: 12px; text-align: left; }
.preset.on { border-color: var(--accent2); background: #1f4f78; }
.preset .fam { font-size: 10px; border-radius: 3px; padding: 0 4px; margin-left: 4px; }
.fam-A { background: #6c5ce7; } .fam-D { background: #00897b; } .fam-B { background: #c0392b; }
.content { padding: 12px; min-width: 0; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 6px; margin-bottom: 10px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; text-align: center; }
.card .k { font-size: 11px; color: var(--muted); } .card .v { font-weight: 700; color: var(--accent2); }
.tabs { display: flex; gap: 2px; flex-wrap: wrap; border-bottom: 1px solid var(--line); margin-bottom: 10px; }
.tab { border: 1px solid var(--line2); border-bottom: 0; background: var(--bg2); padding: 6px 12px; cursor: pointer;
  border-radius: 6px 6px 0 0; }
.tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.empty { color: var(--muted); text-align: center; padding: 60px 10px; }
.years { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 6px; }
.ycard { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; font-size: 12px; }
.ycard .y { font-weight: 700; } .ycard .r { font-size: 15px; font-weight: 700; }
.ycard.total { border-color: var(--warn); } .ycard.bh { border-color: #8e7cc3; }
.chart-tools { display: flex; justify-content: flex-end; margin-bottom: 4px; }
.chk { display: inline-flex; align-items: center; gap: 6px; color: var(--text); font-size: 13px; cursor: pointer; }
.chk input { width: auto; margin: 0; }
.chart-box { position: relative; height: 380px; background: var(--bg2); border-radius: 6px; padding: 6px; }
.chart-box.short { height: 170px; margin-top: 8px; }

/* 표 */
.tbl-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 6px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
th { background: var(--bg2); color: var(--muted); font-weight: 600; position: sticky; top: 0; }
td.l, th.l { text-align: left; }
tr:last-child td { border-bottom: 0; }
.side-buy { color: var(--up); font-weight: 600; } .side-sell { color: var(--down); font-weight: 600; }
.m-loc { color: var(--warn); } .m-moc { color: var(--bad); font-weight: 600; }

/* 주문표 */
.wrap { max-width: 1000px; margin: 0 auto; padding: 16px 14px 60px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.head-btns { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.span2 { grid-column: span 2; }
.form-btns { display: flex; gap: 8px; align-items: center; margin-top: 12px; }
.acc { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 14px; overflow: hidden; }
.acc-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 14px;
  background: var(--bg2); cursor: pointer; flex-wrap: wrap; }
.acc-title { font-weight: 700; font-size: 15px; } .acc-title .badge { margin-left: 6px; }
.badge { font-size: 11px; border-radius: 10px; padding: 1px 8px; background: var(--line); color: var(--text); font-weight: 500; }
.badge.atk { background: #7a5a12; } .badge.def { background: #1d6b4f; }
.acc-meta { font-size: 12px; color: var(--muted); }
.acc-body { padding: 12px 14px; }
.acc-sub { display: flex; gap: 10px; flex-wrap: wrap; align-items: baseline; margin-bottom: 8px; }
.acc-sub h3 { margin: 0; font-size: 15px; color: var(--accent2); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 10px 0; }
.stat { background: var(--bg2); border: 1px solid var(--line); border-radius: 6px; padding: 8px; text-align: center; font-size: 13px; }
.stat .k { color: var(--muted); font-size: 11px; } .stat b { color: var(--accent2); }
.bar { height: 14px; border-radius: 7px; background: var(--line); overflow: hidden; margin-top: 4px; }
.bar > div { height: 100%; background: linear-gradient(90deg, #2f8cff, #4fc3f7); }
.notes { margin: 8px 0 0; padding-left: 18px; font-size: 12px; color: var(--muted); }
.notes li { margin: 2px 0; }
.acc-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.scen { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.scen .panel { margin: 0; background: var(--bg2); font-size: 13px; }
details summary { cursor: pointer; color: var(--muted); font-size: 12px; margin-top: 8px; }
.sum-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; text-align: center; }

/* 전략 설명 */
.g-item { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px; }
.g-item h3 { margin: 0 0 4px; font-size: 15px; }
.g-nums { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 6px; }
.g-nums b { color: var(--text); }

/* 로그인 */
.login-body { display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-box { width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 24px; }
.login-box label { margin-top: 14px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #111a; border: 1px solid var(--line2);
  backdrop-filter: blur(6px); padding: 10px 16px; border-radius: 8px; z-index: 50; max-width: 90vw; }

/* 휴대폰 */
@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; gap: 6px 10px; padding: 8px 10px; }
  .nav { order: 3; width: 100%; flex: none; }
  .nav-btn { flex: 1; padding: 7px 4px; }
  .top-right { margin-left: auto; }
  .bt-layout { grid-template-columns: 1fr; }
  .side { border-right: 0; border-bottom: 1px solid var(--line); }
  .content { padding: 10px; }
  .chart-box { height: 280px; }
  .grid4 { grid-template-columns: 1fr 1fr; }
  .span2 { grid-column: span 2; }
  .stats, .scen { grid-template-columns: 1fr; }
  .sum-grid { grid-template-columns: 1fr 1fr; }
  .wrap { padding: 12px 10px 60px; }
  th, td { padding: 5px 6px; font-size: 12px; }
  input, select { font-size: 16px; }   /* iOS 자동 확대 방지 */
}
.card-title { grid-column: 1 / -1; text-align: left; }
.mb8 { margin-bottom: 8px; } .mt6 { margin-top: 6px; } .mt8 { margin: 8px 0 0; } .mt10 { margin-top: 10px; }
.w320 { max-width: 320px; }
.flow-form { display: grid; grid-template-columns: 1.2fr 0.8fr 1fr 1.4fr auto; gap: 8px; align-items: end; margin: 8px 0; }
@media (max-width: 760px) { .flow-form { grid-template-columns: 1fr 1fr; } .flow-form .btn { grid-column: span 2; } }
.head-right { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.detail-btn { border-color: var(--accent2); color: var(--accent2); }
.fam-X { background: #8e44ad; }

/* ===== 백테스트 v2 ===== */
.bt-wrap { max-width: 1240px; margin: 0 auto; padding: 16px 14px 60px; display: flex; flex-direction: column; gap: 12px; }
.bt-wrap .panel { margin: 0; }
.ctl { background: linear-gradient(180deg, #353b48 0%, #30353f 100%); }
.h-bt { margin: 0 0 2px; font-size: 22px; }
.ctl-grid { display: grid; grid-template-columns: 1.1fr 1fr 1fr 1fr 1fr; gap: 10px; margin-top: 10px; }
.quick { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 10px 0 4px; }
.qbtn { background: var(--bg2); border: 1px solid var(--line); color: var(--muted); border-radius: 16px; padding: 4px 12px; cursor: pointer; font-size: 12px; }
.qbtn:hover, .qbtn.on { color: #fff; border-color: var(--accent2); background: #1f4f78; }
.preset-groups { display: grid; grid-template-columns: 1.6fr 1fr; gap: 10px; margin-top: 10px; }
.pgroup { background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
.pg-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.link-btn { margin-left: auto; background: none; border: 0; color: var(--accent2); cursor: pointer; font-size: 12px; padding: 0; }
.link-btn:hover { text-decoration: underline; }
.preset { padding: 7px 10px; border-radius: 8px; font-size: 13px; transition: all .12s; }
.preset:hover { border-color: var(--accent2); }
.preset.on { box-shadow: 0 0 0 1px var(--accent2) inset; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.btn.big { padding: 10px 20px; font-size: 15px; }
.btn.act { color: #fff; border: 0; font-weight: 600; padding: 10px 16px; }
.act-green { background: #1e8e5a; } .act-purple { background: #7b4fd6; } .act-teal { background: #1b8ba0; } .act-gray { background: #4f5769; }
.btn.act:hover { filter: brightness(1.12); }
.box-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 10px; min-height: 26px; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: #24303f; border: 1px solid var(--line2); border-radius: 14px; padding: 2px 4px 2px 10px; font-size: 12px; }
.chip button { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 14px; line-height: 1; padding: 0 4px; }
.chip button:hover { color: var(--bad); }
.empty-hero { text-align: center; padding: 48px 16px; display: flex; flex-direction: column; gap: 6px; align-items: center; }
.eh-icon { font-size: 40px; }
.res-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.res-title h2 { margin: 0; font-size: 19px; }
.res-pick { min-width: 260px; }
.notes-bar { background: #3d3a2a; border: 1px solid #6b5f2a; border-radius: 8px; padding: 8px 12px; font-size: 12px; color: #f3e4b0; display: flex; flex-direction: column; gap: 3px; }
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.kpi .k { color: var(--muted); font-size: 12px; }
.kpi .v { font-size: 22px; font-weight: 700; margin-top: 2px; color: var(--text); }
.kpi .v.up { color: var(--up); } .kpi .v.down { color: var(--down); }
.kpi .s { color: var(--muted); font-size: 11px; margin-top: 2px; }
#bt-result .tabs { margin: 0; border: 0; gap: 6px; }
#bt-result .tab { border-radius: 8px; border: 1px solid var(--line2); background: var(--panel); padding: 8px 14px; }
#bt-result .tab.active { background: var(--accent); border-color: var(--accent); }
.chart-cap { margin: 8px 0 2px; }
.ytable td, .ytable th { text-align: center; }
.ytable td.mdd, .mtable td.mdd { color: var(--muted); font-size: 12px; }
.ytable tr.sub th { font-size: 11px; font-weight: 500; }
.ytable .th-bh, .mtable .th-y { background: #2b2f3a; }
.ytable tr.sum td, .mtable tr.sum td, .ctable tr.sum td { background: #2b303b; font-weight: 600; }
.mtable td { text-align: center; font-size: 12px; min-width: 46px; }
.mtable td.na { background: transparent; }
.mtable td.yr { border-left: 2px solid var(--line2); }
.mh-head { margin-bottom: 8px; }
.tbl-wrap.tall { max-height: 560px; overflow: auto; }
.famsums { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 10px; font-size: 13px; }
.famsum { background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; }
.ctable th.sortable { cursor: pointer; } .ctable th.sortable.on { color: var(--accent2); }
.ctable td.barcell { min-width: 150px; text-align: right; position: relative; }
.bar2 { position: absolute; left: 8px; right: 70px; top: 50%; height: 6px; transform: translateY(-50%); background: #2a3040; border-radius: 3px; overflow: hidden; }
.bar2 .b-up { height: 100%; background: linear-gradient(90deg, #c0392b, #ff6b6b); }
.bar2 .b-dn { height: 100%; background: linear-gradient(90deg, #2e6fbf, #5aa9ff); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.y30-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.y30-head h2 { margin: 0; font-size: 19px; }
.y30cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; margin: 12px 0; }
.y30card { background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.y30card.bh { border-style: dashed; }
.y30card .t { font-weight: 700; margin-bottom: 4px; }
.y30card .big { font-size: 24px; font-weight: 800; }
.y30card .kv { display: flex; justify-content: space-between; font-size: 12px; margin-top: 4px; color: var(--muted); }
.y30card .kv b { color: var(--text); }
.badge-s { font-size: 10px; background: #3b4d7a; color: #cfe0ff; border-radius: 4px; padding: 0 5px; margin-left: 4px; font-weight: 500; }
.badge-f { font-size: 10px; background: #6b4a1f; color: #ffe2b8; border-radius: 4px; padding: 0 4px; margin-left: 3px; font-weight: 500; }
@media (max-width: 900px) {
  .ctl-grid { grid-template-columns: 1fr 1fr; }
  .preset-groups { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .kpi .v { font-size: 18px; }
  .res-pick { min-width: 0; width: 100%; }
  .actions .btn { flex: 1 1 45%; }
  .btn.big { flex-basis: 100%; }
}
