:root {
  --bg: #0b0e11;
  --card: #151a21;
  --card2: #1c232c;
  --border: #252d38;
  --grid: #1f2731;
  --text: #e7eaee;
  --muted: #8b95a5;
  --up: #1fbf75;
  --down: #f6465d;
  --warn: #f0a020;
  --accent: #3d7bfd;
  --c1: #f5a524; /* 빠른 지표선 */
  --c2: #a184ff; /* 느린 지표선 */
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
body {
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  font-variant-numeric: tabular-nums;
}
code { font-size: 0.95em; background: var(--card2); padding: 1px 5px; border-radius: 4px; }
[hidden] { display: none !important; }
[data-tone="up"] { color: var(--up); }
[data-tone="down"] { color: var(--down); }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }

/* 상단 고정 헤더 */
.top {
  position: sticky; top: 0; z-index: 5;
  background: rgba(11, 14, 17, 0.92);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
}
body.live .top { border-bottom: 2px solid var(--down); }
.top-inner { max-width: 560px; margin: 0 auto; }
.title { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.sym { font-weight: 700; font-size: 17px; }
.badges { display: flex; gap: 6px; }
.badge {
  font-size: 12px; font-weight: 600; white-space: nowrap;
  padding: 3px 9px; border-radius: 999px;
  background: var(--card2); color: var(--muted); border: 1px solid var(--border);
}
.mode-paper { color: #a9bdd2; }
.mode-testnet { color: var(--c1); border-color: rgba(245, 165, 36, 0.45); }
.mode-live { color: #fff; background: var(--down); border-color: var(--down); }
.state-ok { color: var(--up); border-color: rgba(31, 191, 117, 0.45); }
.state-warn { color: var(--warn); border-color: rgba(240, 160, 32, 0.45); }
.state-bad { color: var(--down); border-color: rgba(246, 70, 93, 0.55); }
.price-row { display: flex; align-items: baseline; gap: 10px; margin-top: 2px; }
.price { font-size: 28px; font-weight: 700; letter-spacing: -0.5px; }

/* 본문 */
main { max-width: 560px; margin: 0 auto; padding: 12px 16px 16px; display: grid; gap: 12px; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 14px; min-width: 0; }
h2 { font-size: 14px; font-weight: 600; color: var(--muted); margin: 0 0 10px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; }
.card-head h2 { margin: 0; }
.card p { margin: 8px 0 0; line-height: 1.5; }

.stats3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.label { font-size: 12px; color: var(--muted); }
.val { font-size: 16px; font-weight: 650; margin-top: 3px; overflow-wrap: anywhere; }

.kv .row { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--grid); font-size: 14px; }
.kv .row:last-child { border-bottom: 0; }
.kv .k { color: var(--muted); }
.kv .v { font-weight: 600; text-align: right; overflow-wrap: anywhere; }

.side-badge { font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 6px; }
.side-badge:empty { display: none; }
.side-badge.long { background: rgba(31, 191, 117, 0.15); color: var(--up); }
.side-badge.short { background: rgba(246, 70, 93, 0.15); color: var(--down); }
.empty { color: var(--muted); font-size: 14px; padding: 4px 0; }
.trend { font-size: 13px; font-weight: 600; }

#chart { width: 100%; height: 210px; display: block; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--muted); margin: 8px 0 4px; }
.legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; margin-right: 5px; vertical-align: middle; }
.legend i.dash { height: 0; border-top: 2px dashed; background: none !important; }

.controls { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn {
  appearance: none; font: inherit; font-weight: 650; font-size: 15px;
  min-height: 48px; padding: 12px 10px; border-radius: 12px; cursor: pointer;
  border: 1px solid var(--border); background: var(--card2); color: var(--text);
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { background: rgba(246, 70, 93, 0.12); border-color: rgba(246, 70, 93, 0.5); color: var(--down); }
.note { grid-column: 1 / -1; margin: 0 !important; font-size: 13px; color: var(--warn); }

.share-url { font-size: 13px; padding: 10px 12px; border-radius: 10px; background: var(--bg); border: 1px solid var(--border); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; user-select: all; }
.share-btns { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.share-btns .btn { min-height: 42px; font-size: 14px; padding: 8px; }

/* 보기 전용 */
body.viewer .admin-only, body.viewer #logoutBtn { display: none !important; }
#viewBadge { color: var(--c1); border-color: rgba(245, 165, 36, 0.45); }

/* 매매 캘린더 */
.nav-btn { appearance: none; width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--border); background: var(--card2); color: var(--text); font-size: 18px; cursor: pointer; flex: none; }
.nav-btn:disabled { opacity: 0.35; cursor: default; }
.cal-title { text-align: center; font-size: 15px; }
.cal-title .small { margin-top: 2px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cal-dow span { font-size: 12px; color: var(--muted); text-align: center; padding: 2px 0 4px; }
.cal-dow .sat { color: #7aa2ff; }
.cal-dow .sun { color: var(--down); }
.cell {
  appearance: none; font: inherit; color: inherit; text-align: left; cursor: pointer;
  min-height: 50px; padding: 4px 5px; border-radius: 8px; border: 1px solid var(--grid); background: var(--card2);
  display: flex; flex-direction: column; justify-content: space-between; min-width: 0;
}
.cell.blank { visibility: hidden; }
.cell .d { font-size: 12px; color: var(--muted); }
.cell .p { font-size: 10.5px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cell.up { background: rgba(31, 191, 117, 0.12); border-color: rgba(31, 191, 117, 0.35); }
.cell.down { background: rgba(246, 70, 93, 0.12); border-color: rgba(246, 70, 93, 0.35); }
.cell.today .d { color: var(--accent); font-weight: 700; }
.cell.sel { outline: 2px solid var(--accent); outline-offset: -1px; }
.day { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--grid); }
.day-head { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; flex-wrap: wrap; }

/* 관심 종목 */
.watch { list-style: none; margin: 0; padding: 0; }
.watch li { padding: 9px 0; border-bottom: 1px solid var(--grid); }
.watch li:last-child { border-bottom: 0; }
.watch li.w-group { font-size: 12px; font-weight: 650; color: var(--muted); padding: 10px 0 2px; border-bottom: 0; }
.watch li.w-group:first-child { padding-top: 0; }
.watch li.empty-li { color: var(--muted); font-size: 14px; }
.w-row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.w-name { font-weight: 650; font-size: 14px; }
.w-sym { font-size: 11.5px; color: var(--muted); margin-left: 6px; }
.w-sym.open { color: var(--up); }
.w-price { font-weight: 650; font-size: 14px; }
.w-chg { font-size: 12px; font-weight: 650; padding: 1px 6px; border-radius: 5px; margin-left: 6px; }
.w-chg[data-tone="up"] { background: rgba(31, 191, 117, 0.14); }
.w-chg[data-tone="down"] { background: rgba(246, 70, 93, 0.14); }
.range { position: relative; height: 4px; border-radius: 2px; background: var(--grid); margin: 8px 0 3px; }
.range i { position: absolute; top: -3px; width: 2px; height: 10px; border-radius: 1px; background: var(--text); }
.range-lbl { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); }

.new-badge { font-size: 11px; font-weight: 700; color: var(--warn); border: 1px solid rgba(240, 160, 32, 0.5); border-radius: 5px; padding: 1px 5px; margin-left: 4px; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--grid); font-size: 14px; }
.list li:last-child { border-bottom: 0; }
.list li.empty-li { color: var(--muted); justify-content: flex-start; }
.list .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.list .r { text-align: right; white-space: nowrap; }

.logs { list-style: none; margin: 0; padding: 0; max-height: 280px; overflow-y: auto; font-size: 12.5px; line-height: 1.45; }
.logs li { display: flex; gap: 8px; padding: 5px 0; border-bottom: 1px solid var(--grid); }
.logs time { color: var(--muted); flex: none; }
.logs .warning { color: var(--warn); }
.logs .error { color: var(--down); }

.bar { padding: 10px 12px; border-radius: 10px; font-size: 13px; line-height: 1.45; overflow-wrap: anywhere; }
.error-bar { background: rgba(246, 70, 93, 0.12); border: 1px solid rgba(246, 70, 93, 0.4); color: #ffb3bd; }
.conn-bar { background: rgba(240, 160, 32, 0.12); border: 1px solid rgba(240, 160, 32, 0.4); color: #ffd59a; }

footer { max-width: 560px; margin: 0 auto; padding: 0 16px 28px; display: flex; justify-content: space-between; align-items: center; }
.link { background: none; border: 0; color: var(--muted); font: inherit; font-size: 13px; text-decoration: underline; cursor: pointer; padding: 8px 0 8px 8px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 20;
  bottom: calc(20px + env(safe-area-inset-bottom));
  max-width: calc(100% - 32px); padding: 11px 16px; border-radius: 12px;
  background: #222a35; color: var(--text); border: 1px solid var(--border);
  font-size: 14px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}
.toast.err { border-color: var(--down); color: #ffb3bd; }

/* 로그인 */
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: 100%; max-width: 340px; display: grid; gap: 12px; text-align: center; padding: 24px 20px; }
.login img { margin: 0 auto; border-radius: 14px; }
.login h1 { font-size: 20px; margin: 0 0 4px; }
.login input {
  font: inherit; font-size: 16px; padding: 13px 14px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
}
.login input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.login-err { color: var(--down); font-size: 13px; min-height: 1.2em; margin: 0; }
