:root {
  --bg: #0e1117;
  --panel: #161b24;
  --panel-2: #1c2330;
  --line: #262e3d;
  --text: #e6e9ef;
  --muted: #8b93a4;
  --up: #f04452;      /* 한국식: 상승 빨강 */
  --down: #3485fa;    /* 하락 파랑 */
  --accent: #7c5cff;
  --ok: #22c55e;
  --warn: #f59e0b;
  --radius: 12px;
  font-family: "Pretendard", "Malgun Gothic", "Apple SD Gothic Neo", system-ui, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.strong { font-weight: 700; }
.r { text-align: right; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 10px; }

.top {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 24px; border-bottom: 1px solid var(--line); background: var(--panel);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.ticker { font-size: 22px; font-weight: 800; letter-spacing: .5px; }
.sub { color: var(--muted); }
.top-right { display: flex; align-items: center; gap: 16px; }
.clock { text-align: right; font-variant-numeric: tabular-nums; line-height: 1.2; }
.badge { padding: 4px 10px; border-radius: 99px; font-size: 12px; font-weight: 700; background: var(--panel-2); }
.badge.demo { background: #1f3a2a; color: #6ee7a0; }
.badge.real { background: #4a1d24; color: #ff8a95; }

.errors { margin: 12px 24px 0; padding: 10px 14px; border-radius: 10px; background: #3a2a12; color: #fcd58a; font-size: 13px; }
.errors div + div { margin-top: 4px; }

.grid {
  display: grid; gap: 16px; padding: 16px 24px 40px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; min-width: 0; }
.price-card { grid-column: span 2; }
.control-card { grid-column: span 2; }
.plan-card { grid-column: span 2; }
.summary-card { grid-column: span 2; }
.wide { grid-column: span 4; }
.span2 { grid-column: span 2; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.card-head h2 { margin: 0; font-size: 15px; font-weight: 700; }

.price-row { display: flex; align-items: baseline; gap: 14px; margin-bottom: 12px; }
.price { font-size: 40px; font-weight: 800; font-variant-numeric: tabular-nums; }
.change { font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; }
.up { color: var(--up); } .down { color: var(--down); }

.kv { display: grid; gap: 8px 16px; margin: 0 0 10px; }
.kv.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.kv.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.kv div { background: var(--panel-2); border-radius: 8px; padding: 8px 10px; min-width: 0; }
.kv dt { font-size: 11px; color: var(--muted); margin-bottom: 3px; }
.kv dd { margin: 0; font-weight: 700; font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; }

.control-row { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.label { color: var(--muted); min-width: 64px; }
.switch { position: relative; width: 52px; height: 28px; flex: none; }
.switch input { display: none; }
.slider { position: absolute; inset: 0; background: #394154; border-radius: 99px; cursor: pointer; transition: .2s; }
.slider::before { content: ""; position: absolute; width: 22px; height: 22px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + .slider { background: var(--ok); }
.switch input:checked + .slider::before { transform: translateX(24px); }

.seg { display: inline-flex; background: var(--panel-2); border-radius: 8px; padding: 3px; gap: 3px; }
.seg.full { display: flex; }
.seg button { flex: 1; border: 0; background: transparent; color: var(--muted); padding: 7px 16px; border-radius: 6px; cursor: pointer; font-weight: 700; font-family: inherit; }
.seg button.on { background: var(--accent); color: #fff; }
.seg button.on.buy { background: var(--up); }
.seg button.on.sell { background: var(--down); }

.btn-row { display: flex; gap: 8px; margin: 14px 0 10px; flex-wrap: wrap; }
.btn { border: 1px solid var(--line); background: var(--panel-2); color: var(--text); padding: 9px 14px; border-radius: 8px; cursor: pointer; font-weight: 600; font-family: inherit; }
.btn:hover { border-color: #3a4459; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.tiny { padding: 4px 10px; font-size: 12px; }
.btn.full { width: 100%; }
.btn:disabled { opacity: .5; cursor: wait; }

.plan-tag { display: inline-block; font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 6px; margin: 4px 0 8px; }
.plan-tag.buy { background: rgba(240, 68, 82, .15); color: var(--up); }
.plan-tag.sell { background: rgba(52, 133, 250, .15); color: var(--down); }
.judge { font-size: 13px; padding: 8px 10px; border-radius: 8px; background: var(--panel-2); margin-bottom: 12px; }

.tbl-wrap { overflow-x: auto; }
.tbl-wrap.short { max-height: 320px; overflow-y: auto; }
.tbl { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.tbl th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl th.r, .tbl td.r { text-align: right; }
.tbl.compact td, .tbl.compact th { padding: 6px; font-size: 13px; }
.tbl tr.closed td { color: var(--muted); }
.pill { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 700; background: var(--panel-2); }
.pill.tp { background: rgba(240, 68, 82, .18); color: var(--up); }
.pill.exp { background: rgba(245, 158, 11, .18); color: var(--warn); }
.pill.hold { background: rgba(139, 147, 164, .15); color: var(--muted); }
.pill.done { background: rgba(34, 197, 94, .15); color: var(--ok); }
.pill.fail { background: rgba(240, 68, 82, .18); color: var(--up); }
.memo { max-width: 220px; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }

.form { display: flex; flex-direction: column; gap: 10px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.form input, .form select {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  padding: 9px 10px; border-radius: 8px; font-size: 14px; font-family: inherit;
}

.log { list-style: none; margin: 0; padding: 0; max-height: 340px; overflow-y: auto; font-size: 12px; }
.log li { padding: 5px 0; border-bottom: 1px dashed var(--line); line-height: 1.4; word-break: break-all; }
.log .t { color: var(--muted); margin-right: 6px; font-variant-numeric: tabular-nums; }
.log .warn { color: var(--warn); }
.log .error { color: var(--up); }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #262e3d; padding: 12px 18px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.4); max-width: 90vw; z-index: 20; }
.toast.err { background: #4a1d24; }

@media (max-width: 1100px) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .wide { grid-column: span 2; }
  .span2 { grid-column: span 2; }
}
@media (max-width: 720px) {
  .grid { grid-template-columns: 1fr; padding: 12px 16px 32px; }
  .price-card, .control-card, .plan-card, .summary-card, .wide, .span2 { grid-column: span 1; }
  .kv.four { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .top { padding: 12px 16px; }
  .price { font-size: 32px; }
}
.badge { white-space: nowrap; }
@media (max-width: 720px) { .sub { display: none; } .clock { font-size: 12px; } }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 30; padding: 16px; }
.modal-box { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; width: 100%; max-width: 440px; box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.modal-box p { line-height: 1.5; margin: 0 0 14px; }
.modal-box code { background: var(--panel-2); padding: 1px 5px; border-radius: 4px; }
.pw { display: flex; gap: 6px; }
.pw input { flex: 1; min-width: 0; }
#keyMsg.ok { color: var(--ok); } #keyMsg.err { color: var(--up); }
.badge.sim { background: #2a2447; color: #b7a6ff; }

.tbl.rules td, .tbl.rules th { white-space: normal; vertical-align: top; }
.tbl.rules th.cur, .tbl.rules td.cur { background: rgba(124, 92, 255, .12); }
.tbl.rules th.cur { color: #c9bbff; }
.tbl.rules td.formula { color: var(--muted); font-size: 12px; }
.flow { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-top: 12px; }
.flow div { background: var(--panel-2); border-radius: 8px; padding: 8px 10px; font-size: 12px; display: flex; flex-direction: column; gap: 3px; }
.flow span { color: var(--muted); }
.xl-guide { display: grid; gap: 6px; margin-bottom: 12px; font-size: 13px; line-height: 1.5; }
.xl-guide b { color: #c9bbff; }
.cells { white-space: normal !important; font-size: 12px; }
.cells span { display: inline-block; background: var(--panel-2); border-radius: 5px; padding: 1px 6px; margin: 1px 3px 1px 0; }
.errors .fix { margin-left: 8px; }
@media (max-width: 720px) { .flow { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.conn-card { border-color: #3a3368; }
.conn-grid { display: grid; grid-template-columns: 1.3fr 1fr 1.2fr; gap: 18px; align-items: start; }
.conn-grid .label { margin-bottom: 6px; display: block; }
.seg.big button { padding: 10px 8px; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 14px; }
.seg.big button small { font-size: 11px; font-weight: 500; opacity: .8; }
.seg.big button[data-sw="real"].on { background: #c2323f; }
.seg.big button[data-sw="demo"].on { background: #1f8a4c; }
#modeInfo { margin-top: 8px; line-height: 1.5; }
.tbl.keys td { padding: 6px 4px; }
.tbl.keys td:first-child { color: var(--muted); width: 70px; }
.chips { display: grid; gap: 6px; font-size: 13px; }
.chips div { display: flex; align-items: flex-start; gap: 8px; line-height: 1.4; }
.chips b { font-weight: 600; word-break: break-all; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #394154; flex: none; margin-top: 5px; }
.dot.ok { background: var(--ok); } .dot.bad { background: var(--up); } .dot.warn { background: var(--warn); }
.btn-row.tight { margin: 0; }
.test-steps { list-style: none; margin: 12px 0 0; padding: 10px 12px; background: var(--panel-2); border-radius: 8px; font-size: 13px; }
.test-steps li { padding: 3px 0; }
.test-steps .ok { color: var(--ok); } .test-steps .bad { color: var(--up); }
@media (max-width: 1100px) { .conn-grid { grid-template-columns: 1fr; } }

.seeds { margin-top: 4px; background: var(--panel-2); border-radius: 8px; padding: 10px 12px; }
.seeds-head { margin-bottom: 8px; font-size: 13px; }
.seed-bar { display: grid; grid-template-columns: repeat(var(--n, 7), minmax(0, 1fr)); gap: 5px; margin-bottom: 8px; }
.seed { border-radius: 6px; padding: 6px 4px; text-align: center; font-size: 11px; line-height: 1.3; background: #232b3a; color: var(--muted); border: 1px dashed #394154; }
.seed.used { background: rgba(124, 92, 255, .22); color: var(--text); border: 1px solid rgba(124, 92, 255, .6); }
.seed b { display: block; font-size: 12px; }

.reinvest { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; font-size: 13px; }
.reinvest select { background: var(--panel); border: 1px solid var(--line); color: var(--text); padding: 5px 8px; border-radius: 6px; font-family: inherit; }

.kk-grid { display: grid; grid-template-columns: 1fr 0.8fr 1.3fr; gap: 18px; align-items: start; }
.kk-grid .label { display: block; margin-bottom: 8px; }
.kk-help { margin-top: 10px; font-size: 12px; color: var(--muted); }
.kk-help summary { cursor: pointer; color: #c9bbff; }
.kk-help ol { padding-left: 18px; margin: 8px 0; line-height: 1.7; }
.kk-help code { background: var(--panel-2); padding: 1px 5px; border-radius: 4px; color: var(--text); }
.kk-preview { background: var(--panel-2); border-radius: 8px; padding: 10px 12px; font-size: 12.5px; line-height: 1.55; white-space: pre-wrap; min-height: 150px; margin: 10px 0 0; font-family: inherit; }
.form label.row { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 13px; }
a.btn { text-decoration: none; display: inline-block; }
@media (max-width: 1100px) { .kk-grid { grid-template-columns: 1fr; } }
