:root {
  --bg: #fafafa;
  --fg: #18181b;
  --muted: #71717a;
  --border: #e4e4e7;
  --accent: #2563eb;
  --up: #16a34a;
  --down: #dc2626;
  --card: #ffffff;
  --card-bg: #f4f4f5;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0a0a;
    --fg: #fafafa;
    --muted: #a1a1aa;
    --border: #27272a;
    --accent: #60a5fa;
    --up: #4ade80;
    --down: #f87171;
    --card: #18181b;
    --card-bg: #1f1f23;
  }
}

* { box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Pretendard", "Segoe UI",
               "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  font-size: 14px;
  color: var(--fg);
  background: var(--bg);
  margin: 0;
  padding: 24px;
  max-width: 980px;
  margin-inline: auto;
  line-height: 1.55;
}

.hdr {
  border-bottom: 1px solid var(--border);
  padding-bottom: 16px;
  margin-bottom: 24px;
}
.hdr .hdr-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.hdr h1 { font-size: 22px; margin: 0 0 4px; }
.hdr .meta { font-size: 12px; color: var(--muted); }

/* ─────────── 언어 토글 (KO/EN/LT) ─────────── */
:root[data-lang="ko"] .en-only,
:root[data-lang="ko"] .lt-only { display: none !important; }
:root[data-lang="en"] .ko-only,
:root[data-lang="en"] .lt-only { display: none !important; }
:root[data-lang="lt"] .ko-only,
:root[data-lang="lt"] .en-only { display: none !important; }

.lang-toggle {
  display: inline-flex;
  gap: 0;
  margin-right: 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  background: var(--card);
}
.lang-btn {
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  padding: 5px 9px;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  line-height: 1;
}
.lang-btn + .lang-btn { border-left: 1px solid var(--border); }
.lang-btn:hover { color: var(--fg); }
.lang-btn.active {
  background: var(--accent);
  color: #fff;
}

.archive-nav {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.archive-label { font-size: 14px; color: var(--muted); }
.archive-select {
  font-family: inherit;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card);
  color: var(--fg);
  cursor: pointer;
  min-width: 140px;
}
.archive-select:focus { outline: 1px solid var(--accent); }
.archive-home {
  color: var(--muted);
  text-decoration: none;
  font-size: 16px;
  line-height: 1;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card);
}
.archive-home:hover { color: var(--accent); border-color: var(--accent); }
.hdr .oneliner {
  margin-top: 12px;
  padding: 12px 14px;
  background: var(--card-bg);
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
}

section {
  margin: 28px 0;
}

/* Commentary (Key Points / Wavebridge View) — 페이지 최상단 */
section.commentary {
  margin: 24px 0 36px;
}
.commentary-block {
  background: var(--card);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 18px 22px;
  margin-bottom: 14px;
}
.commentary-block:last-child { margin-bottom: 0; }
.commentary-title {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 14px;
  padding: 0;
  border: 0;
}
.key-points {
  margin: 0;
  padding-left: 20px;
}
.key-points li {
  margin-bottom: 10px;
  line-height: 1.65;
  font-size: 13.5px;
  color: var(--fg);
}
.key-points li:last-child { margin-bottom: 0; }
.key-points li strong {
  color: var(--fg);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.005em;
  margin-right: 2px;
}
.wavebridge-body {
  white-space: pre-line;
  font-size: 13.5px;
  line-height: 1.75;
  color: var(--fg);
}

/* Wavebridge View — thesis / supports / risks 3분할 */
.wv-thesis {
  font-size: 15.5px;
  font-weight: 600;
  line-height: 1.55;
  color: var(--fg);
  margin: 0 0 14px;
  padding: 12px 14px;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border-left: 3px solid var(--accent);
  border-radius: 0 8px 8px 0;
}
.wv-supports {
  list-style: none;
  margin: 0 0 14px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.wv-supports li {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}
.wv-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.wv-text {
  font-size: 13.5px;
  line-height: 1.7;
  color: var(--fg);
  flex: 1;
}
.wv-risks {
  background: color-mix(in srgb, #f59e0b 10%, var(--card));
  border: 1px solid color-mix(in srgb, #f59e0b 30%, var(--border));
  border-radius: 8px;
  padding: 12px 14px;
}
.wv-risks-label {
  font-size: 11.5px;
  font-weight: 700;
  color: #d97706;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}
.wv-risks-body {
  font-size: 13px;
  line-height: 1.7;
  color: var(--fg);
  white-space: pre-line;
}
@media (prefers-color-scheme: dark) {
  .wv-risks { background: color-mix(in srgb, #f59e0b 16%, var(--card)); }
  .wv-risks-label { color: #fbbf24; }
}
section h2 {
  font-size: 16px;
  margin: 0 0 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
section h3.sub {
  font-size: 13px;
  margin: 16px 0 6px;
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 0.02em;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table th, table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
table th {
  font-weight: 600;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.snap td.num, .flow td.num { text-align: right; font-variant-numeric: tabular-nums; }
.snap td.name, .flow td.name { font-weight: 600; }
/* 헤더도 데이터와 같은 정렬 (첫 컬럼=자산명만 좌측) */
.snap thead th, .flow thead th { text-align: right; }
.snap thead th:first-child, .flow thead th:first-child { text-align: left; }
/* Volume 보조행 — 메인 자산 행보다 작고 흐릿하게 */
.snap tr.volume-row td { font-size: 12px; color: var(--muted); border-bottom-style: dotted; }
.snap tr.volume-row td.sub-name { padding-left: 14px; font-weight: 400; }
.up { color: var(--up); }
.down { color: var(--down); }
.err { color: var(--muted); font-size: 11px; font-style: italic; }

.charts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 8px;
}
.charts figure {
  margin: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
}
.charts figure img { width: 100%; height: auto; display: block; }
.charts figcaption {
  font-size: 11px; color: var(--muted);
  text-align: center; margin-top: 4px;
}
figure.full {
  margin: 16px 0 0;
  padding: 8px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
}
figure.full img { width: 100%; height: auto; display: block; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}
.kpi {
  padding: 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.kpi-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.kpi-value { font-size: 22px; font-weight: 600; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 12px; color: var(--muted); font-weight: 400; }
.kpi-meta { font-size: 12px; color: var(--muted); margin-top: 4px; }

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
@media (max-width: 700px) {
  .charts, .two-col { grid-template-columns: 1fr; }
}

/* ─────────── Mobile (≤768px) ─────────── */
@media (max-width: 768px) {
  body {
    padding: 14px;
    font-size: 13.5px;
  }

  .hdr { padding-bottom: 12px; margin-bottom: 18px; }
  .hdr h1 { font-size: 19px; }
  .hdr .meta { font-size: 11px; }
  .hdr .hdr-top { gap: 10px; }
  .hdr .oneliner { padding: 10px 12px; font-size: 13px; }

  .archive-nav { gap: 5px; }
  .archive-label { font-size: 13px; }
  .archive-select { min-width: 110px; font-size: 11px; padding: 5px 8px; }
  .archive-home { font-size: 14px; padding: 5px 8px; }
  .lang-btn { font-size: 10px; padding: 4px 7px; }

  section { margin: 22px 0; }
  section h2 { font-size: 15px; margin-bottom: 10px; }
  section h3.sub { font-size: 12px; margin: 14px 0 6px; }

  /* Tables — horizontal scroll on narrow screens.
     display:block lets the <table> overflow its container while keeping
     internal table layout (tr/td) for column alignment. */
  table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
    max-width: 100%;
  }
  table th, table td { padding: 6px 8px; font-size: 12.5px; }
  table th { font-size: 11px; }
  /* Volume sub-row label needs a bit less indent on mobile */
  .snap tr.volume-row td.sub-name { padding-left: 10px; }

  /* Commentary */
  section.commentary { margin: 18px 0 26px; }
  .commentary-block { padding: 14px 16px; }
  .commentary-title { font-size: 15px; margin-bottom: 12px; }
  .key-points { padding-left: 18px; }
  .key-points li { font-size: 13px; margin-bottom: 8px; }
  .key-points li strong { font-size: 14.5px; }

  .wv-thesis { font-size: 14px; padding: 12px 14px; margin-bottom: 14px; }
  .wv-supports { gap: 8px; margin-bottom: 14px; }
  .wv-supports li { padding: 10px 12px; gap: 10px; }
  .wv-num { width: 24px; height: 24px; font-size: 12px; }
  .wv-text { font-size: 13px; line-height: 1.6; }
  .wv-risks { padding: 12px 14px; }
  .wv-risks-label { font-size: 11px; }
  .wv-risks-body { font-size: 12.5px; }

  /* KPI grid */
  .kpi-grid {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 10px;
  }
  .kpi { padding: 12px; }
  .kpi-label { font-size: 10.5px; }
  .kpi-value { font-size: 19px; }
  .kpi-sub, .kpi-meta { font-size: 11px; }

  /* Today's Drivers narrative */
  .routine-narrative {
    padding: 14px 16px;
    font-size: 13px;
    line-height: 1.7;
  }
}

/* ─────────── Small phones (≤480px) ─────────── */
@media (max-width: 480px) {
  body { padding: 12px; }

  /* Stack header — title block on top, controls below */
  .hdr .hdr-top { flex-direction: column; align-items: stretch; }
  .archive-nav { width: 100%; justify-content: flex-start; flex-wrap: wrap; }
  .archive-select { flex: 1 1 auto; min-width: 0; }

  .hdr h1 { font-size: 18px; }

  /* 2-column KPI cards on narrow phones (instead of auto-fit) */
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }
  .kpi { padding: 10px; }
  .kpi-value { font-size: 17px; }

  section { margin: 18px 0; }
  section h2 { font-size: 14px; }

  /* Wavebridge thesis a touch smaller on tiny screens */
  .wv-thesis { font-size: 13.5px; padding: 11px 12px; }

  /* Commentary container padding tighter */
  .commentary-block { padding: 12px 14px; }

  /* Footer stacks vertically when cramped */
  footer { flex-direction: column; align-items: flex-start; }
}

.routine-summary {
  background: var(--card-bg);
  padding: 14px;
  border-radius: 8px;
  font-size: 13px;
  white-space: pre-wrap;
}
.routine-narrative {
  background: var(--card);
  border: 1px solid var(--border);
  padding: 18px 22px;
  border-radius: 8px;
  font-size: 13.5px;
  line-height: 1.75;
  color: var(--fg);
  white-space: pre-wrap;
  word-wrap: break-word;
}
.keypoints {
  margin-top: 8px;
  padding-left: 22px;
}
.keypoints li {
  margin-bottom: 4px;
  font-size: 13px;
}

footer {
  margin-top: 40px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}
