:root {
  --bg-primary: #0f1117;
  --bg-card: #171a22;
  --bg-hover: #282c3a;
  --border: #2a2f3d;
  --text-primary: #e9ebf2;
  --text-secondary: #7c838f;
  --accent: #4f8cff;
  --red: #ef4444;
  --green: #22c55e;
  --orange: #f59e0b;
  --purple: #a855f7;
  --shadow-drawer: -4px 0 16px rgba(0, 0, 0, 0.4);
  --shadow-cta: 0 2px 8px rgba(79, 140, 255, 0.35);
  --shadow-close: 0 2px 6px rgba(239, 68, 68, 0.3);
  --active-tint: rgba(79, 140, 255, 0.08);
  --disclaimer-tint: rgba(245, 158, 11, 0.08);
}

/* ── 라이트(크림) 테마 ── */
html[data-theme="light"] {
  --bg-primary: #f6efe0;
  --bg-card: #fdf9ed;
  --bg-hover: #ebe2c9;
  --border: #d4c8aa;
  --text-primary: #2a2318;
  --text-secondary: #7a6f5a;
  --accent: #2563eb;
  --red: #dc2626;
  --green: #16a34a;
  --orange: #b45309;
  --purple: #7c3aed;
  --shadow-drawer: -4px 0 16px rgba(80, 60, 20, 0.18);
  --shadow-cta: 0 2px 8px rgba(37, 99, 235, 0.28);
  --shadow-close: 0 2px 6px rgba(220, 38, 38, 0.28);
  --active-tint: rgba(37, 99, 235, 0.08);
  --disclaimer-tint: rgba(180, 83, 9, 0.1);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo",
    "Malgun Gothic", sans-serif;
  font-size: 13px;
}

/* ── 상단 고정 영역 (header + filter + 컬럼 라벨 묶음) ── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border);
}

header {
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--bg-card);
}
header h1 { margin: 0; font-size: 16px; font-weight: 700; }
header .subtitle { color: var(--text-secondary); font-size: 12px; margin-left: 8px; }
header .meta { color: var(--text-secondary); font-size: 11px; }
header .nav-left { display: flex; align-items: baseline; gap: 0; min-width: 0; }
header .nav-right { display: flex; align-items: center; gap: 14px; }

/* ── 햄버거 버튼 (20% 축소) ── */
.nav-toggle {
  width: 26px;
  height: 22px;
  background: transparent;
  border: 0;
  padding: 3px 0;
  cursor: pointer;
  display: inline-flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: stretch;
}
.nav-toggle span {
  display: block;
  height: 2px;
  background: var(--text-primary);
  border-radius: 2px;
  transition: background 0.15s;
}
.nav-toggle:hover span { background: var(--accent); }

/* ── 테마 토글 버튼 ── */
.theme-toggle {
  width: 28px;
  height: 28px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 50%;
  padding: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  line-height: 1;
  color: var(--text-primary);
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.theme-toggle:hover { background: var(--bg-hover); border-color: var(--accent); }
.theme-toggle:active { transform: scale(0.92); }

/* ── 네비게이션 드로어 ── */
.nav-drawer {
  position: fixed;
  top: 0;
  right: -280px;
  width: 260px;
  height: 100vh;
  background: var(--bg-card);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-drawer);
  z-index: 200;
  padding: 72px 0 24px;
  transition: right 0.25s ease;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.nav-drawer.open { right: 0; }
.nav-drawer a {
  display: block;
  padding: 14px 24px;
  color: var(--text-primary);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  border-left: 3px solid transparent;
  transition: background 0.15s, border-color 0.15s;
}
.nav-drawer a:hover { background: var(--bg-hover); }
.nav-drawer a.active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: var(--active-tint);
}

.nav-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 150;
  display: none;
}
.nav-backdrop.show { display: block; }

.filter-bar {
  display: flex;
  gap: 10px;
  padding: 12px 24px;
  align-items: center;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
}
.filter-bar select,
.filter-bar input {
  padding: 6px 10px;
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
}
.filter-bar input { width: 240px; }
.filter-bar .status { margin-left: auto; color: var(--text-secondary); font-size: 12px; }

main { padding: 12px 24px 24px; }

.cl-header {
  display: grid;
  grid-template-columns: 110px minmax(0, 9fr) minmax(0, 4fr) 160px;
  gap: 6px;
  padding: 6px 32px;
  font-size: 11px;
  color: var(--text-secondary);
  font-weight: 600;
  background: var(--bg-primary);
}

#stockList {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 4px;
}

.cl-row {
  display: grid;
  grid-template-columns: 110px minmax(0, 9fr) minmax(0, 4fr) 160px;
  grid-template-areas: "info chart supply meta";
  align-items: center;
  gap: 6px;
  padding: 12px 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
  min-width: 0;
}
.cl-row .cl-info { grid-area: info; }
.cl-row .cl-chart { grid-area: chart; }
.cl-row .cl-supply { grid-area: supply; }
.cl-row .cl-meta { grid-area: meta; }
.cl-row:hover { background: var(--bg-hover); }
.cl-row .cl-info { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.cl-row .cl-info .cl-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cl-row .cl-info .cl-code { color: var(--text-secondary); font-family: monospace; font-size: 11px; }
.cl-row .cl-chart { min-width: 0; }
.cl-row .cl-chart canvas { border-radius: 4px; display: block; width: 100%; height: 180px; }
.cl-row .cl-supply { font-size: 9px; line-height: 1.4; overflow: hidden; display: flex; flex-direction: column; gap: 2px; }
.cl-row .cl-supply canvas { width: 100%; height: 100px; border-radius: 4px; }
.cl-row .cl-supply .sup-summary { display: flex; gap: 6px; justify-content: center; font-size: 10px; margin-top: 2px; }
.cl-row .cl-supply .sup-pos { color: var(--red); }
.cl-row .cl-supply .sup-neg { color: var(--accent); }
.cl-row .cl-meta { font-size: 12px; line-height: 1.7; color: var(--text-secondary); }
.cl-row .cl-meta span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.loading, .empty {
  padding: 40px;
  text-align: center;
  color: var(--text-secondary);
}
.spinner {
  display: inline-block;
  width: 22px; height: 22px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.load-more {
  text-align: center;
  padding: 16px;
  color: var(--text-secondary);
  font-size: 12px;
}

/* ── 모달 ── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 100;
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 20px;
  overflow-y: auto;
}
.modal-backdrop.show { display: flex; }

.modal {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 100%;
  max-width: 1100px;
  padding: 20px 24px;
}
.modal-header {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { margin: 0; font-size: 18px; }
.modal-header code { color: var(--text-secondary); font-size: 13px; }
.modal-header .close {
  margin-left: auto;
  background: var(--red);
  color: #fff;
  border: 0;
  border-radius: 6px;
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-close);
  transition: background 0.15s, transform 0.1s;
}
.modal-header .close:hover { background: #dc2626; }
.modal-header .close:active { transform: translateY(1px); }

.section { margin-top: 16px; }
.section h3 { margin: 0 0 8px; font-size: 14px; }

.chart-tabs { display: flex; gap: 4px; margin-top: 12px; border-bottom: 1px solid var(--border); }
.chart-tab {
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
  color: var(--text-secondary);
  border-bottom: 2px solid transparent;
}
.chart-tab:hover { color: var(--text-primary); }
.chart-tab.active { color: var(--text-primary); border-bottom-color: var(--accent); }

.chart-pane { display: none; margin-top: 8px; }
.chart-pane.active { display: block; }

.chart-legend {
  display: flex;
  gap: 16px;
  font-size: 11px;
  color: var(--text-secondary);
  padding: 6px 0;
}
.chart-legend .dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 2px;
  margin-right: 4px;
  vertical-align: middle;
}

.snapshot-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}
.snapshot-cell {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
}
.snapshot-cell .label { color: var(--text-secondary); font-size: 11px; }
.snapshot-cell .value { font-size: 14px; font-weight: 600; margin-top: 2px; }

.cl-tooltip {
  position: fixed;
  z-index: 200;
  background: rgba(15, 17, 23, 0.96);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 11px;
  line-height: 1.7;
  color: var(--text-primary);
  pointer-events: none;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}
.cl-tooltip .tt-label { color: var(--text-secondary); margin-right: 6px; }
.cl-tooltip .tt-up { color: var(--red); }
.cl-tooltip .tt-dn { color: var(--accent); }

.chart-wrap { position: relative; width: 100%; }
.chart-wrap canvas { display: block; width: 100%; }

footer {
  padding: 20px 24px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 11px;
  border-top: 1px solid var(--border);
  margin-top: 40px;
}

/* ─────────────────────────────────────────────
   Home / About 공용 정적 페이지
   ───────────────────────────────────────────── */
.home-main, .static-main {
  max-width: 960px;
  margin: 0 auto;
  padding: 32px 24px 40px;
}

/* Home: Hero */
.hero {
  text-align: center;
  padding: 48px 16px 40px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 40px;
}
.hero h2 {
  margin: 0 0 14px;
  font-size: 28px;
  font-weight: 700;
  line-height: 1.35;
  color: var(--text-primary);
}
.hero .hero-sub {
  color: var(--text-secondary);
  font-size: 15px;
  margin: 0 0 28px;
}
.hero .hero-sub strong { color: var(--orange); }

.cta {
  display: inline-block;
  padding: 12px 28px;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
  transition: background 0.15s, transform 0.1s, opacity 0.15s;
  box-shadow: var(--shadow-cta);
}
.cta:hover { opacity: 0.9; }
.cta:active { transform: translateY(1px); }
.cta.cta-secondary {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
  box-shadow: none;
}
.cta.cta-secondary:hover { background: var(--active-tint); }

/* Home: Features */
.features {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 40px;
}
.feature {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 22px 20px;
  text-align: center;
  transition: border-color 0.15s, transform 0.15s;
}
.feature:hover { border-color: var(--accent); transform: translateY(-2px); }
.feature .feature-icon { font-size: 30px; margin-bottom: 10px; }
.feature h3 {
  margin: 0 0 6px;
  font-size: 14px;
  color: var(--text-primary);
}
.feature p {
  margin: 0;
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.5;
}

.cta-block {
  text-align: center;
  padding: 32px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.cta-block p {
  margin: 0 0 16px;
  font-size: 14px;
  color: var(--text-secondary);
}

/* About 페이지 */
.about-content h2 {
  margin: 0 0 8px;
  font-size: 24px;
  color: var(--accent);
}
.about-content .lead {
  font-size: 15px;
  color: var(--text-primary);
  line-height: 1.7;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}
.about-content section { margin-top: 28px; }
.about-content h3 {
  margin: 0 0 10px;
  font-size: 16px;
  color: var(--text-primary);
}
.about-content p, .about-content li {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.7;
}
.about-content ul { padding-left: 20px; margin: 8px 0; }
.about-content li { margin-bottom: 4px; }
.about-content strong { color: var(--text-primary); }
.about-content a { color: var(--accent); text-decoration: none; }
.about-content a:hover { text-decoration: underline; }
.about-content .disclaimer {
  padding: 12px 14px;
  background: var(--disclaimer-tint);
  border-left: 3px solid var(--orange);
  border-radius: 4px;
}

/* ─────────────────────────────────────────────
   모바일 가로보기 (orientation: landscape, 작은 폰)
   - 종목 + 업종/PER/시총 → 한 컬럼으로 합침 (종목 위, 메타 아래)
   - 차트와 수급 폭을 넓힘
   ───────────────────────────────────────────── */
@media (orientation: landscape) and (max-width: 950px) and (max-height: 500px) {
  header { padding: 8px 14px; }
  header h1 { font-size: 14px; }
  header .subtitle { font-size: 10px; }
  header .meta { font-size: 10px; }

  .filter-bar { padding: 6px 14px; gap: 6px; }
  .filter-bar input { width: 160px; }
  .filter-bar .status { display: none; }

  main { padding: 8px 12px 20px; }

  /* 컬럼 라벨 — 가로보기에서는 숨김 */
  .cl-header { display: none; }

  /* info + meta 한 컬럼으로 합치고 차트/수급을 넓힘 */
  .cl-row {
    grid-template-columns: minmax(110px, 1.2fr) minmax(0, 3fr) minmax(0, 2fr);
    grid-template-areas:
      "info  chart supply"
      "meta  chart supply";
    row-gap: 4px;
    column-gap: 8px;
    padding: 8px 10px;
    align-items: start;
  }
  .cl-row .cl-info { grid-area: info; }
  .cl-row .cl-meta {
    grid-area: meta;
    font-size: 10px;
    line-height: 1.5;
    padding-top: 4px;
    border-top: 1px dashed var(--border);
  }
  .cl-row .cl-meta span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .cl-row .cl-info .cl-name { font-size: 12px; }
  .cl-row .cl-info .cl-code { font-size: 10px; }

  /* 수급 컬럼은 표시하고 폭을 키움 */
  .cl-row .cl-supply {
    display: flex !important;
    grid-area: supply;
    align-self: stretch;
    justify-content: center;
  }
  .cl-row .cl-supply canvas { height: 80px; }
  .cl-row .cl-chart { grid-area: chart; align-self: stretch; }
  .cl-row .cl-chart canvas { height: 120px; }
}

/* ─────────────────────────────────────────────
   모바일 세로보기 (orientation: portrait, 폭 ≤ 640px)
   - 종목명/가격/업종·PER·시총 → 1줄
   - 캔들 차트 → 2줄
   - 수급 컬럼 숨김
   ───────────────────────────────────────────── */
@media (max-width: 640px) and (orientation: portrait) {
  header {
    padding: 10px 14px;
    gap: 8px;
  }
  header h1 { font-size: 15px; }
  header .subtitle { font-size: 10px; margin-left: 6px; }
  header .meta { display: none; }
  header .nav-right { gap: 10px; }

  .filter-bar {
    padding: 8px 14px;
    gap: 6px;
  }
  .filter-bar input { width: 100%; min-width: 140px; flex: 1; }
  .filter-bar .status { display: none; }

  main { padding: 8px 12px 20px; }

  /* 컬럼 라벨은 모바일에서 의미 없음 → 숨김 */
  .cl-header { display: none; }

  /* 행 레이아웃 재배치: info+meta 한 줄 → 차트 한 줄 */
  .cl-row {
    grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
    grid-template-areas:
      "info meta"
      "chart chart";
    row-gap: 8px;
    padding: 10px 10px;
    align-items: start;
  }
  /* 수급 컬럼 숨김 */
  .cl-row .cl-supply { display: none; }

  /* 종목 정보 축소 */
  .cl-row .cl-info .cl-name { font-size: 13px; }
  .cl-row .cl-info .cl-code { font-size: 10px; }

  /* 메타(업종·PER·시총) 오른쪽 정렬 + 압축 */
  .cl-row .cl-meta {
    font-size: 11px;
    line-height: 1.45;
    text-align: right;
  }
  .cl-row .cl-meta span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

  /* 캔들 차트 풀폭 + 높이 축소 */
  .cl-row .cl-chart canvas { height: 140px; }

  /* 모달 여백 */
  .modal-backdrop { padding: 12px 8px; }
  .modal { padding: 14px 14px; border-radius: 8px; }
  .modal-header h2 { font-size: 16px; }
  .snapshot-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
  .snapshot-cell { padding: 6px 8px; }
  .snapshot-cell .value { font-size: 13px; }

  /* Home/About 페이지 모바일 축소 */
  .home-main, .static-main { padding: 20px 16px 32px; }
  .hero { padding: 24px 8px 28px; margin-bottom: 28px; }
  .hero h2 { font-size: 20px; }
  .hero .hero-sub { font-size: 13px; }
  .features { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .feature { padding: 16px 12px; }
  .feature .feature-icon { font-size: 24px; }
  .feature h3 { font-size: 13px; }
  .feature p { font-size: 11px; }
  .cta-block { padding: 22px 12px; }
  .about-content h2 { font-size: 20px; }
  .about-content h3 { font-size: 14px; }
}
