:root {
  color-scheme: light;
  --page: #f7f7f5; --surface: #ffffff; --border: rgba(11,11,11,.08);
  --ink: #0b0b0a; --ink-2: #55544f; --muted: #8a8880;
  --accent: #1f5fd6; --accent-soft: #eaf0fd;
  --good: #0a7d34; --good-soft: #e4f6ea;
  --bad: #d0392f; --bad-soft: #fbe9e7;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0c0c0b; --surface: #191917; --border: rgba(255,255,255,.09);
    --ink: #f6f6f3; --ink-2: #c6c4bb; --muted: #8a8880;
    --accent: #6f9bef; --accent-soft: #16233f;
    --good: #37c96a; --good-soft: #10301c;
    --bad: #ef6a5f; --bad-soft: #3a1613;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0c0c0b; --surface: #191917; --border: rgba(255,255,255,.09);
  --ink: #f6f6f3; --ink-2: #c6c4bb; --muted: #8a8880;
  --accent: #6f9bef; --accent-soft: #16233f;
  --good: #37c96a; --good-soft: #10301c;
  --bad: #ef6a5f; --bad-soft: #3a1613;
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--page); color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans KR", sans-serif;
  line-height: 1.5;
}
.wrap { max-width: 900px; margin: 0 auto; padding: 0 20px; }
.muted { color: var(--muted); }
h2 { font-size: 16px; margin: 0 0 16px; }

.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; }
.brand { font-weight: 800; font-size: 19px; }
.brand-btn { background: none; border: none; color: var(--ink); padding: 0; cursor: pointer; font-family: inherit; }

.btn-ghost {
  background: transparent; border: 1px solid var(--border); color: var(--ink-2);
  border-radius: 8px; padding: 8px 14px; font-size: 13px; cursor: pointer; font-family: inherit;
}
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn-primary {
  width: 100%; background: var(--accent); color: #fff; border: 0; border-radius: 10px;
  padding: 14px; font-size: 15px; font-weight: 700; cursor: pointer; font-family: inherit; margin-top: 16px;
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }

/* hero */
.hero-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 20px;
  padding: 32px; margin: 24px 0; display: flex; justify-content: space-between; align-items: center; gap: 20px; flex-wrap: wrap;
}
.hero-label { color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.hero-value { font-size: 42px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.hero-change { margin-top: 8px; font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; }
.hero-change.good { color: var(--good); } .hero-change.bad { color: var(--bad); }
.hero-right { display: flex; gap: 28px; }
.stat-label { color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.stat-value { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* panels */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 22px; margin-bottom: 20px; }

/* holdings */
.holdings-list { display: flex; flex-direction: column; gap: 10px; }
.holding-row {
  display: flex; align-items: center; justify-content: space-between; padding: 14px 16px;
  border: 1px solid var(--border); border-radius: 12px; cursor: pointer;
}
.holding-row:hover { border-color: var(--accent); }
.holding-main { display: flex; flex-direction: column; }
.holding-name { font-weight: 700; font-size: 14px; }
.holding-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.holding-right { text-align: right; }
.holding-value { font-weight: 700; font-variant-numeric: tabular-nums; }
.holding-pl { font-size: 12px; font-weight: 600; margin-top: 2px; font-variant-numeric: tabular-nums; }
.holding-pl.good { color: var(--good); } .holding-pl.bad { color: var(--bad); }

/* tabs */
.tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.tab {
  background: var(--page); border: 1px solid var(--border); color: var(--ink-2);
  border-radius: 999px; padding: 8px 16px; font-size: 13px; font-weight: 600; cursor: pointer; font-family: inherit;
}
.tab.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

.search-row { margin-bottom: 16px; }
.search-row input {
  width: 100%; padding: 11px 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--page); color: var(--ink); font-size: 14px; font-family: inherit;
}

.discover-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.discover-card {
  border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; cursor: pointer; background: var(--page);
}
.discover-card:hover { border-color: var(--accent); }
.discover-card .name { font-weight: 700; font-size: 13px; }
.discover-card .symbol { color: var(--muted); font-size: 11px; margin-top: 1px; }
.discover-card .price { font-weight: 700; margin-top: 10px; font-variant-numeric: tabular-nums; }
.discover-card .change { font-size: 12px; font-weight: 600; margin-top: 2px; font-variant-numeric: tabular-nums; }
.discover-card .change.good { color: var(--good); } .discover-card .change.bad { color: var(--bad); }

/* transactions table */
.scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 8px 10px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--border); font-variant-numeric: tabular-nums; }
th { text-align: right; color: var(--muted); font-weight: 600; font-size: 12px; }
th:first-child, td:first-child { text-align: left; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.badge.buy { background: var(--accent-soft); color: var(--accent); }
.badge.sell { background: var(--bad-soft); color: var(--bad); }

/* 종목 상세 페이지 (차트 + 매매 패널) */
.back-link {
  background: none; border: none; color: var(--ink-2); font-size: 13px; cursor: pointer;
  padding: 0; margin-bottom: 18px; font-family: inherit;
}
.back-link:hover { color: var(--accent); }

.detail-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.detail-name { font-weight: 800; font-size: 20px; }
.detail-symbol { font-size: 13px; margin-top: 2px; }
.detail-price-block { text-align: right; }
.detail-price { font-size: 28px; font-weight: 800; font-variant-numeric: tabular-nums; }
.detail-change { font-size: 14px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.detail-change.good { color: var(--good); } .detail-change.bad { color: var(--bad); }

.detail-layout { display: flex; gap: 24px; align-items: flex-start; flex-wrap: wrap; }
.detail-chart-col { flex: 2; min-width: 280px; }
.detail-trade-col { flex: 1; min-width: 260px; max-width: 340px; }
.trade-panel { margin-bottom: 0; }

.chart-range { display: flex; gap: 6px; margin-bottom: 10px; overflow-x: auto; }
.range-btn {
  background: var(--page); border: 1px solid var(--border); color: var(--ink-2);
  border-radius: 999px; padding: 4px 10px; font-size: 11px; font-weight: 600; cursor: pointer; font-family: inherit;
  white-space: nowrap; flex-shrink: 0;
}
.range-btn.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.chart-wrap { margin-bottom: 18px; position: relative; }
.chart-wrap-lg { height: 460px; }
#detailChartCanvas { width: 100%; height: 100%; display: block; cursor: crosshair; touch-action: none; }
.chart-empty { text-align: center; font-size: 12px; padding: 34px 0; margin: 0; }
.chart-wrap-lg .chart-empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 0; }
.chart-ohlc {
  position: absolute; top: 4px; left: 4px; z-index: 2; display: flex; gap: 10px;
  font-size: 11px; color: var(--ink-2); font-variant-numeric: tabular-nums; pointer-events: none;
}
.chart-ohlc b { color: var(--ink); font-weight: 700; }
.chart-ohlc .good { color: var(--good); } .chart-ohlc .bad { color: var(--bad); }

@media (max-width: 700px) {
  .detail-layout { flex-direction: column; }
  .detail-trade-col { max-width: none; width: 100%; }
  .detail-price-block { text-align: left; }
  .chart-wrap-lg { height: 320px; }
}

.quote-stats {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px 16px; margin-bottom: 18px;
  padding-bottom: 16px; border-bottom: 1px solid var(--border);
}
.qs-item { display: flex; justify-content: space-between; font-size: 12px; font-variant-numeric: tabular-nums; }
.qs-item span:last-child { font-weight: 700; }

.qty-input-row { flex: 1; display: flex; gap: 6px; }
.qty-input-row input { flex: 1; }
.qty-btn {
  background: var(--page); border: 1px solid var(--border); color: var(--ink-2);
  border-radius: 8px; padding: 0 10px; font-size: 12px; font-weight: 600; cursor: pointer; font-family: inherit;
}
.qty-btn:hover { border-color: var(--accent); color: var(--accent); }

.qty-pct-row { display: flex; gap: 6px; margin: -6px 0 14px; }
.qty-pct-btn {
  flex: 1; background: var(--page); border: 1px solid var(--border); color: var(--ink-2);
  border-radius: 8px; padding: 6px 0; font-size: 12px; font-weight: 600; cursor: pointer; font-family: inherit;
}
.qty-pct-btn:hover { border-color: var(--accent); color: var(--accent); }

.order-type-toggle { display: flex; gap: 8px; margin-bottom: 14px; }
.order-type-btn {
  flex: 1; padding: 8px; border-radius: 10px; border: 1px solid var(--border); background: var(--page);
  color: var(--ink-2); font-weight: 600; font-size: 13px; cursor: pointer; font-family: inherit;
}
.order-type-btn.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

.side-toggle { display: flex; gap: 8px; margin-bottom: 18px; }
.side-btn {
  flex: 1; padding: 10px; border-radius: 10px; border: 1px solid var(--border); background: var(--page);
  color: var(--ink-2); font-weight: 700; font-size: 14px; cursor: pointer; font-family: inherit;
}
.side-btn.buy.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.side-btn.sell.active { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }

.modal-field { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 12px; }
.modal-field label { font-size: 13px; color: var(--ink-2); }
.modal-field input {
  flex: 1; text-align: right; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--page); color: var(--ink); font-size: 15px; font-family: inherit; font-variant-numeric: tabular-nums;
}
.modal-total-row {
  display: flex; justify-content: space-between; padding-top: 12px; border-top: 1px solid var(--border);
  font-weight: 700; font-size: 15px; font-variant-numeric: tabular-nums;
}
.modal-error { color: var(--bad); font-size: 13px; margin: 10px 0 0; min-height: 18px; }
.modal-error.good { color: var(--good); }

/* auth screen */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: 20px; padding: 32px; width: 100%; max-width: 360px; }
.auth-card .tabs { margin-bottom: 0; }

/* topbar extras */
.topbar-right { display: flex; align-items: center; gap: 10px; }
.main-tabs { border-top: 1px solid var(--border); padding: 10px 0; margin: 0; }

/* ranking table */
#rankTable th, #rankTable td { text-align: right; }
#rankTable th:nth-child(1), #rankTable td:nth-child(1),
#rankTable th:nth-child(2), #rankTable td:nth-child(2) { text-align: left; }
.rank-badge { display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; border-radius: 999px; font-weight: 800; font-size: 12px; background: var(--page); }
.rank-badge.top1 { background: #f6c945; color: #4a3800; }
.rank-badge.top2 { background: #d7dade; color: #33363b; }
.rank-badge.top3 { background: #dba36a; color: #402705; }
tr.me { background: var(--accent-soft); }

@media (max-width: 560px) {
  .hero-value { font-size: 32px; }
  .hero-card { flex-direction: column; align-items: flex-start; }
  .topbar-inner { flex-direction: column; align-items: flex-start; gap: 10px; }
}
