:root {
  --bg: #070b12;
  --bg2: #0c121c;
  --panel: #121a28;
  --panel2: #172233;
  --line: #243146;
  --text: #e8eef8;
  --muted: #8fa3bd;
  --gold: #ffd36f;
  --blue: #3d9eff;
  --green: #26c281;
  --red: #ef5350;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --tab-h: calc(56px + var(--safe-b));
  --top-h: calc(52px + var(--safe-t));
  --radius: 12px;
  --font: "IBM Plex Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
input {
  width: 100%;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  outline: none;
}
input:focus { border-color: var(--blue); }

#app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  max-width: 560px;
  margin: 0 auto;
  background:
    radial-gradient(800px 400px at 20% -10%, rgba(61, 158, 255, .12), transparent 55%),
    linear-gradient(180deg, var(--bg), var(--bg2));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(10px + var(--safe-t)) 14px 10px;
  background: rgba(7, 11, 18, .92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand {
  font-weight: 700;
  letter-spacing: .02em;
  color: var(--gold);
  font-size: 1.05rem;
}
.topbar-meta { flex: 1; min-width: 0; }
.hdr-symbol { display: block; font-size: .78rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hdr-price { font-weight: 600; font-variant-numeric: tabular-nums; }
.mode-chip {
  font-size: .68rem;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(61, 158, 255, .15);
  color: var(--blue);
  border: 1px solid rgba(61, 158, 255, .35);
}
.mode-chip.paper { color: var(--gold); background: rgba(255, 211, 111, .12); border-color: rgba(255, 211, 111, .35); }

.notice-bar {
  margin: 8px 12px 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(61, 158, 255, .12);
  border: 1px solid rgba(61, 158, 255, .3);
  color: var(--text);
  font-size: .82rem;
  line-height: 1.4;
}
.notice-bar.warn { background: rgba(255, 211, 111, .12); border-color: rgba(255, 211, 111, .35); }
.notice-bar.error { background: rgba(239, 83, 80, .12); border-color: rgba(239, 83, 80, .35); }

.screens {
  flex: 1;
  overflow: auto;
  padding: 12px 12px calc(var(--tab-h) + 12px);
  -webkit-overflow-scrolling: touch;
}
.screen { display: none; }
.screen.active { display: block; }

.toolbar { display: flex; flex-direction: column; gap: 10px; margin-bottom: 10px; }
.seg {
  display: flex;
  gap: 6px;
  background: var(--panel);
  padding: 4px;
  border-radius: 12px;
  border: 1px solid var(--line);
}
.seg-btn {
  flex: 1;
  padding: 10px 8px;
  border-radius: 9px;
  color: var(--muted);
  font-weight: 600;
  font-size: .88rem;
}
.seg-btn.active {
  background: var(--panel2);
  color: var(--text);
  box-shadow: 0 1px 0 rgba(255,255,255,.04);
}
.search { margin: 0; }

.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 8px;
  margin-bottom: 4px;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  font-size: .78rem;
  font-weight: 600;
}
.chip.active { color: var(--gold); border-color: rgba(255, 211, 111, .45); background: rgba(255, 211, 111, .1); }

.quote-list { display: flex; flex-direction: column; gap: 6px; }
.quote-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  text-align: left;
}
.quote-row.selected { border-color: rgba(61, 158, 255, .55); background: rgba(61, 158, 255, .08); }
.q-name { font-weight: 600; font-size: .95rem; }
.q-id { font-size: .72rem; color: var(--muted); margin-top: 2px; }
.q-price { font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
.q-chg { font-size: .78rem; text-align: right; margin-top: 2px; font-variant-numeric: tabular-nums; }
.up { color: var(--green); }
.down { color: var(--red); }

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 12px;
}
.panel-title { font-size: 1.1rem; font-weight: 700; }
.panel-sub { font-size: .8rem; color: var(--muted); margin-top: 2px; }
.panel-sub.right { text-align: right; }
.panel-price { font-size: 1.15rem; font-weight: 700; font-variant-numeric: tabular-nums; }

.tf-row {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  margin-bottom: 10px;
  scrollbar-width: none;
}
.tf-btn {
  flex: 0 0 auto;
  min-width: 44px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  font-size: .8rem;
  font-weight: 600;
}
.tf-btn.active { color: var(--text); border-color: var(--blue); background: rgba(61, 158, 255, .12); }

.chart-wrap {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  height: min(48vh, 380px);
  min-height: 260px;
}
.lw-chart { width: 100%; height: 100%; }
.chart-head-right { text-align: right; }
.chart-pick {
  margin-top: 4px;
  font-size: .72rem;
  color: var(--blue);
}
.chart-pick b { font-variant-numeric: tabular-nums; }
.chart-hint {
  margin: 8px 2px 12px;
  font-size: .72rem;
  color: var(--muted);
  line-height: 1.35;
}
.chart-order { margin-top: 0; }
.chart-bal {
  font-size: .78rem;
  color: var(--muted);
  margin: 4px 0 10px;
  text-align: right;
}
.field-row { display: flex; gap: 10px; }
.field.half { flex: 1; min-width: 0; }
#leverage-chart, #leverage { padding: 0; accent-color: var(--blue); height: 28px; background: transparent; border: none; }
.limit-field.hidden { display: none; }

.empty-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: .9rem;
  pointer-events: none;
  background: rgba(7, 11, 18, .35);
  z-index: 2;
}
.empty-overlay.hidden { display: none; }

.screen[data-screen="chart"].active {
  display: flex;
  flex-direction: column;
}
#screen-chart .chart-wrap { flex: 0 0 auto; }

.form-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}
.mode-seg { margin-bottom: 12px; }
.side-row { display: flex; gap: 8px; margin-bottom: 12px; }
.side-btn {
  flex: 1;
  padding: 14px 10px;
  border-radius: 10px;
  font-weight: 700;
  border: 1px solid var(--line);
  background: var(--bg2);
  color: var(--muted);
}
.side-btn.long.active { background: rgba(231, 76, 60, .18); border-color: #e74c3c; color: #ff8a7a; }
.side-btn.short.active { background: rgba(61, 126, 255, .18); border-color: #3d7eff; color: #7eb0ff; }
.side-btn.long { color: #ff8a7a; }
.side-btn.short { color: #7eb0ff; }
.field { display: block; margin: 12px 0; }
.field span { display: flex; justify-content: space-between; font-size: .8rem; color: var(--muted); margin-bottom: 6px; }
.field em { font-style: normal; color: var(--text); font-weight: 600; }
#limit-field.hidden { display: none; }
#leverage { padding: 0; accent-color: var(--blue); height: 28px; background: transparent; border: none; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 16px;
  border-radius: 10px;
  font-weight: 700;
  border: 1px solid transparent;
}
.btn.full { width: 100%; }
.btn.flex { flex: 1; }
.btn.sm { padding: 8px 12px; font-size: .8rem; }
.btn.primary { background: linear-gradient(180deg, #4aa8ff, #2d7fd6); color: #fff; }
.btn.primary:active { filter: brightness(.95); }
.btn.ghost { background: var(--bg2); border-color: var(--line); color: var(--text); }
.btn.danger { background: rgba(239, 83, 80, .18); border-color: var(--red); color: var(--red); }
.btn.success { background: rgba(46, 204, 113, .2); border-color: #2ecc71; color: #7dcea0; }
.close-row { margin: 0 0 12px; gap: 8px; }
.help-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  font-weight: 700;
  flex: 0 0 auto;
}
.ma-legend {
  display: flex;
  gap: 12px;
  padding: 0 4px 8px;
  font-size: .72rem;
  font-weight: 600;
}
.ma-legend.hidden { display: none; }
.ma-legend .ma5 { color: #f0c14a; }
.ma-legend .ma20 { color: #3d9eff; }
.ma-legend .ma60 { color: #b07cf0; }
.tf-btn.ma-toggle.active { color: #f0c14a; border-color: #f0c14a; background: rgba(240, 193, 74, .12); }
.help-card {
  width: min(92vw, 420px);
  max-height: 80vh;
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  margin: auto;
}
.help-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.help-body h4 {
  margin: 12px 0 4px;
  font-size: .92rem;
  color: var(--blue);
}
.help-body p {
  font-size: .82rem;
  color: var(--muted);
  line-height: 1.45;
}
#help-overlay {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
#help-overlay.hidden { display: none; }
.btn:disabled { opacity: .45; pointer-events: none; }
.btn-row { display: flex; gap: 8px; margin-top: 10px; }
.btn-row.wrap { flex-wrap: wrap; }
.msg { margin-top: 10px; font-size: .82rem; color: var(--muted); min-height: 1.2em; }
.msg.err { color: var(--red); }
.msg.ok { color: var(--green); }
.hint { margin-top: 8px; font-size: .75rem; color: var(--muted); line-height: 1.4; }

.section-label {
  font-size: .78rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: .04em;
  margin: 16px 0 8px;
  text-transform: uppercase;
}
.section-label.tight { margin-top: 0; }

.card-list { display: flex; flex-direction: column; gap: 8px; }
.card-list.compact .mini-card { padding: 10px 12px; }
.mini-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.mini-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.mini-title { font-weight: 700; }
.mini-side { font-size: .75rem; font-weight: 700; }
.mini-meta { margin-top: 6px; font-size: .78rem; color: var(--muted); line-height: 1.45; font-variant-numeric: tabular-nums; }
.mini-actions { margin-top: 10px; display: flex; gap: 8px; }
.empty-card {
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
  font-size: .88rem;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}

.bal-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}
.bal-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
}
.bal-card.wide { grid-column: 1 / -1; }
.bal-label { font-size: .72rem; color: var(--muted); }
.bal-val { margin-top: 4px; font-size: 1.05rem; font-weight: 700; font-variant-numeric: tabular-nums; }

.addr-box {
  margin: 10px 0;
  padding: 12px;
  background: var(--bg2);
  border-radius: 10px;
  border: 1px solid var(--line);
}
.addr-text {
  font-size: .78rem;
  word-break: break-all;
  line-height: 1.4;
  margin-bottom: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.qr-wrap { text-align: center; margin: 10px 0; }
.qr-wrap img {
  border-radius: 8px;
  background: #fff;
  padding: 8px;
}
.warnings {
  margin-top: 10px;
  font-size: .75rem;
  color: var(--muted);
  line-height: 1.45;
}
.warnings li { margin-left: 1.1em; }
.deposit-panel.highlight {
  outline: 2px solid rgba(255, 211, 111, .55);
  box-shadow: 0 0 0 4px rgba(255, 211, 111, .12);
}
.field-block { margin: 10px 0; }

.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  display: flex;
  max-width: 560px;
  margin: 0 auto;
  padding: 6px 4px var(--safe-b);
  background: rgba(12, 18, 28, .96);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(12px);
}
.tab {
  flex: 1;
  padding: 10px 4px 8px;
  color: var(--muted);
  font-size: .72rem;
  font-weight: 600;
}
.tab.active { color: var(--gold); }
.tab span { display: block; }

.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(3, 6, 12, .88);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  padding-bottom: calc(20px + var(--safe-b));
}
.overlay.hidden { display: none; }
.login-card {
  width: min(380px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 24px 20px;
  box-shadow: 0 24px 60px rgba(0,0,0,.45);
}
.login-brand { font-size: 1.4rem; font-weight: 800; color: var(--gold); text-align: center; }
.login-sub { text-align: center; color: var(--muted); font-size: .88rem; margin: 6px 0 18px; }

.toast {
  position: fixed;
  left: 50%;
  top: calc(12px + var(--safe-t));
  transform: translateX(-50%);
  z-index: 90;
  max-width: min(420px, calc(100% - 24px));
  padding: 10px 14px;
  border-radius: 10px;
  background: rgba(23, 34, 51, .96);
  border: 1px solid var(--line);
  font-size: .84rem;
  box-shadow: 0 10px 30px rgba(0,0,0,.35);
  pointer-events: none;
}
.toast.hidden { display: none; }
.toast.err { border-color: rgba(239, 83, 80, .5); }
.toast.ok { border-color: rgba(38, 194, 129, .5); }

.hidden { display: none !important; }
