@font-face {
  font-family: Pretendard; font-weight: 45 920; font-style: normal; font-display: swap;
  src: url('/static/fonts/PretendardVariable.woff2') format('woff2-variations');
}

/* ---- 디자인 토큰 --------------------------------------------------------- */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-hover: #f0f2f5;
  --text-primary: #191c21;
  --text-secondary: #4e5663;
  --text-tertiary: #7b8391;
  --divider: #e7e9ee;
  --rise: #d63b3b;
  --fall: #2f6fdb;
  --flat: #7b8391;
  --rise-soft: #fdeeee;
  --fall-soft: #ebf2fd;
  --accent: #3a6ff0;
  --accent-soft: #eaf0fe;
  --skeleton: #eceef2;
  --focus: #3a6ff0;

  --radius-sm: 10px;
  --radius-md: 18px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 40px;
  --page-width: 1120px;
  --font: Pretendard, "Pretendard Variable", -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo",
          "Noto Sans KR", "Noto Sans CJK KR", "Malgun Gothic", sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317; --surface: #1a1d22; --surface-hover: #23272e;
    --text-primary: #eceef2; --text-secondary: #b2b8c2; --text-tertiary: #8a919c;
    --divider: #2b3038; --rise: #f06363; --fall: #5c93f0; --flat: #8a919c;
    --rise-soft: #3a2224; --fall-soft: #1d2a40; --accent: #6f95f5; --accent-soft: #1f2a44;
    --skeleton: #262a31; --focus: #8fb0ff;
  }
}

/* ---- 기본 --------------------------------------------------------------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text-primary);
  font: 15px/1.5 var(--font); letter-spacing: -0.01em; -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
.num { font-variant-numeric: tabular-nums; }
.rise { color: var(--rise); } .fall { color: var(--fall); } .flat { color: var(--flat); }
.muted { color: var(--text-tertiary); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---- 헤더 --------------------------------------------------------------- */
.app-header { position: sticky; top: 0; z-index: 10; background: color-mix(in srgb, var(--bg) 92%, transparent);
              backdrop-filter: blur(8px); border-bottom: 1px solid var(--divider); }
.app-header .inner { max-width: var(--page-width); margin: 0 auto; padding: 10px 20px;
                     display: flex; align-items: center; gap: var(--space-2); }
.brand { font-weight: 800; font-size: 17px; letter-spacing: 0.02em; margin-right: var(--space-4); }
.tabs { display: flex; gap: 2px; }
.tab { padding: 8px 14px; border-radius: var(--radius-sm); color: var(--text-tertiary); font-weight: 600;
       transition: background-color .15s, color .15s; }
.tab:hover { background: var(--surface-hover); color: var(--text-primary); }
.tab[aria-current="page"] { color: var(--text-primary); background: var(--surface); }
.header-right { margin-left: auto; display: flex; align-items: center; gap: var(--space-2); }

.search { position: relative; }
.search input { width: 240px; padding: 9px 14px 9px 36px; border: 1px solid transparent; border-radius: var(--radius-sm);
                background: var(--surface); color: var(--text-primary); font: inherit; font-size: 15px;
                transition: border-color .15s; }
.search input:focus { outline: none; border-color: var(--accent); }
.search .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-tertiary);
                pointer-events: none; }
.search-results { position: absolute; right: 0; top: calc(100% + 6px); width: 320px; max-height: 420px; overflow: auto;
                  background: var(--surface); border: 1px solid var(--divider); border-radius: var(--radius-md);
                  box-shadow: 0 8px 24px rgba(20, 24, 32, .08); padding: 6px; z-index: 20; }
.search-results[hidden] { display: none; }
.search-results .row { border-radius: var(--radius-sm); }
.search-results .empty-line { padding: 14px; color: var(--text-tertiary); font-size: 14px; }


/* ---- 페이지 ------------------------------------------------------------- */
main { max-width: var(--page-width); margin: 0 auto; padding: 32px 20px 80px; }
.page-header { margin-bottom: var(--space-6); }
.page-header h1 { font-size: 30px; line-height: 1.25; margin: 0; letter-spacing: -0.03em; overflow-wrap: anywhere; }
.page-header .sub { color: var(--text-tertiary); font-size: 15px; margin-top: 6px; }
.back { display: inline-flex; align-items: center; gap: 4px; margin: 0 0 16px -8px; padding: 6px 8px;
        color: var(--text-secondary); font-size: 15px; font-weight: 600; border-radius: 8px; border: 0;
        background: none; cursor: pointer; }
.back:hover { background: var(--surface-hover); }

.home-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 32px 48px; align-items: start; }
.home-grid > .wide { grid-column: 1 / -1; }

.section { margin-bottom: 48px; min-width: 0; }
.home-grid .section { margin-bottom: 0; }
.section-header { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.section-header h2 { font-size: 20px; margin: 0; letter-spacing: -0.02em; }
.section-header .aside { color: var(--text-tertiary); font-size: 14px; white-space: nowrap; }
.section-desc { color: var(--text-tertiary); font-size: 14px; margin: -6px 0 12px; }
.more-link { display: flex; justify-content: center; align-items: center; gap: 4px; margin-top: 4px; padding: 12px;
             border-radius: var(--radius-sm); color: var(--text-secondary); font-weight: 600; font-size: 15px;
             transition: background-color .15s; }
.more-link:hover { background: var(--surface-hover); }
.more-list > summary { list-style: none; cursor: pointer; }
.more-list > summary::-webkit-details-marker { display: none; }
.more-list[open] > summary { display: none; }

.panel { background: var(--surface); border-radius: var(--radius-md); padding: 8px; }
.panel.pad { padding: 20px; }

/* ---- 테마 카드 ---------------------------------------------------------- */
.theme-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.theme-card { background: var(--surface); border-radius: 20px; padding: 10px 12px 12px; cursor: pointer; min-width: 0; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px;
             padding: 12px 12px 10px; border-radius: 12px; }
.card-head h2 { margin: 0; font-size: 19px; line-height: 1.35; letter-spacing: -0.02em; min-width: 0; overflow-wrap: anywhere; }
.card-head .rate { flex: none; font-size: 19px; font-weight: 700; line-height: 1.35; }
.card-stocks { list-style: none; margin: 4px 0 0; padding: 0; }
.card-stock { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 9px 12px;
              border-radius: 10px; font-size: 16px; transition: background-color .12s; }
.card-stock .name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-stock .num { flex: none; font-weight: 600; }
.card-stock:hover, .card-head:hover { background: var(--surface-hover); }
.card-empty { margin: 4px 12px 8px; color: var(--text-tertiary); font-size: 14px; }
.theme-grid + .more-link { margin-top: 16px; }
.app-footer { max-width: var(--page-width); margin: 0 auto; padding: 0 20px 40px; font-size: 13px; }
.app-footer a { color: var(--text-tertiary); }
.app-footer a:hover { color: var(--text-secondary); }

/* ---- 리스트 행 (종목·테마) ---------------------------------------------- */
.list { list-style: none; margin: 0; padding: 0; }
.list.two-col { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); column-gap: 8px; }
.row { display: flex; align-items: center; gap: 14px; padding: 12px; border-radius: var(--radius-sm);
       transition: background-color .12s; min-width: 0; }
a.row:hover { background: var(--surface-hover); }
.row .rank { width: 22px; flex: none; text-align: center; color: var(--text-tertiary); font-weight: 600; font-size: 15px; }
.row .main { flex: 1; min-width: 0; }
.row .title { font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .detail { color: var(--text-tertiary); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .end { flex: none; text-align: right; }
.row .end .value { font-size: 16px; font-weight: 600; }
.row .end .change { font-size: 14px; font-weight: 600; }
.row .end .detail { font-weight: 400; }
.row .code { color: var(--text-tertiary); font-size: 13px; font-weight: 400; margin-left: 6px; }
.row .rate-big { font-size: 17px; font-weight: 700; }

.badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.badge { display: inline-flex; align-items: center; padding: 3px 9px; border-radius: 999px; font-size: 13px;
         font-weight: 600; background: var(--surface-hover); color: var(--text-secondary); white-space: nowrap; }
.badge.accent { background: var(--accent-soft); color: var(--accent); }
a.badge:hover { filter: brightness(0.97); }

.chips { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.chip { border: 0; padding: 8px 14px; border-radius: 999px; background: var(--surface); color: var(--text-secondary);
        font-weight: 600; font-size: 14px; cursor: pointer; transition: background-color .15s; }
.chip:hover { background: var(--surface-hover); }
.chip[aria-pressed="true"] { background: var(--text-primary); color: var(--surface); }

/* ---- 종목 상세 ---------------------------------------------------------- */
.stock-head .name { font-size: 22px; font-weight: 700; margin: 0 0 6px; letter-spacing: -0.02em; overflow-wrap: anywhere; }
.stock-head .name small { font-size: 14px; color: var(--text-tertiary); font-weight: 400; margin-left: 6px; }
.stock-head .price { font-size: 34px; font-weight: 800; letter-spacing: -0.03em; line-height: 1.2; }
.stock-head .change { font-size: 16px; font-weight: 600; margin-top: 2px; }
.stock-head .asof { color: var(--text-tertiary); font-size: 14px; margin-top: 6px; }
.stock-head .badges { margin-top: 14px; }

.detail-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.detail-grid .wide { grid-column: 1 / -1; }
.block { background: var(--surface); border-radius: var(--radius-md); padding: 22px 22px 14px; min-width: 0; }
.block h2 { font-size: 18px; margin: 0; letter-spacing: -0.02em; }
.block .block-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.block .block-head .aside { color: var(--text-tertiary); font-size: 14px; white-space: nowrap; }

.metrics { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 20px; }
.metric .label { color: var(--text-tertiary); font-size: 14px; }
.metric .value { font-size: 20px; font-weight: 700; letter-spacing: -0.02em; margin-top: 2px; }
.metric .note { color: var(--text-tertiary); font-size: 13px; margin-top: 2px; }

.lines { list-style: none; margin: 0; padding: 0; }
.lines li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0;
            border-top: 1px solid var(--divider); font-size: 15px; }
.lines li:first-child { border-top: 0; }
.lines .label { color: var(--text-secondary); }
.lines .value { font-weight: 600; text-align: right; }
.lines .spark { flex: 1; min-width: 60px; max-width: 180px; height: 28px; margin-left: auto; }
.investor-line { display: grid; grid-template-columns: 64px minmax(0, 1fr) auto; align-items: center; gap: 14px; }
.investor-line .value { font-size: 18px; }
.lines .value .muted { font-size: 14px; font-weight: 500; }

details.more-detail { margin-top: 10px; border-top: 1px solid var(--divider); }
details.more-detail > summary { cursor: pointer; list-style: none; padding: 12px 0 4px; color: var(--text-secondary);
                                font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: 4px; }
details.more-detail > summary::-webkit-details-marker { display: none; }
details.more-detail > summary::after { content: '⌄'; font-size: 16px; transform: translateY(-3px); transition: transform .15s; }
details.more-detail[open] > summary::after { transform: rotate(180deg) translateY(-1px); }
details.more-detail .inner { padding-top: 8px; }
.sub-title { font-size: 14px; color: var(--text-tertiary); font-weight: 600; margin: 14px 0 4px; }

.history { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 14px; }
.history th { color: var(--text-tertiary); font-weight: 600; text-align: right; padding: 6px 0 6px 10px; }
.history td { text-align: right; padding: 7px 0 7px 10px; border-top: 1px solid var(--divider); white-space: nowrap; }
.history th:first-child, .history td:first-child { text-align: left; padding-left: 0; }

.source-note { color: var(--text-tertiary); font-size: 13px; margin-top: 28px; }

/* ---- 차트 --------------------------------------------------------------- */
.chart { width: 100%; display: block; overflow: visible; }
.chart .axis { fill: var(--text-tertiary); font-size: 12px; }
.chart .base { stroke: var(--divider); stroke-width: 1; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.chart .bar.rise { fill: var(--rise); } .chart .bar.fall { fill: var(--fall); }
.chart .hit { fill: transparent; }
.chart .pt:hover .bar { opacity: .7; }
.chart .guide { stroke: var(--text-tertiary); stroke-width: 1; stroke-dasharray: 2 3; opacity: 0; }
.chart .hover-dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; opacity: 0; }
.chart .pt:hover .guide, .chart .pt:hover .hover-dot { opacity: 1; }
.tooltip { position: absolute; z-index: 30; pointer-events: none; padding: 6px 10px; border-radius: 8px;
           background: var(--text-primary); color: var(--surface); font-size: 13px; font-weight: 600;
           font-variant-numeric: tabular-nums; white-space: nowrap; }
.tooltip[hidden] { display: none; }
.chart-caption { color: var(--text-tertiary); font-size: 13px; margin-top: 4px; }

/* ---- 상태: 로딩·빈·오류 ------------------------------------------------ */
.sk { background: var(--skeleton); border-radius: 8px; animation: pulse 1.2s ease-in-out infinite; }
.sk-row { display: flex; align-items: center; gap: 14px; padding: 14px 12px; }
.sk-row .sk.a { width: 38%; height: 16px; } .sk-row .sk.b { width: 18%; height: 16px; margin-left: auto; }
.sk.title { width: 180px; height: 30px; margin-bottom: 12px; } .sk.line { width: 120px; height: 16px; }
.sk.big { width: 220px; height: 40px; margin: 8px 0; } .sk.block { height: 180px; border-radius: var(--radius-md); }
@keyframes pulse { 50% { opacity: .55; } }
@media (prefers-reduced-motion: reduce) { .sk { animation: none; } * { transition: none !important; } }

.state { padding: 36px 16px; text-align: center; }
.state .msg { font-weight: 600; color: var(--text-secondary); }
.state .hint { color: var(--text-tertiary); font-size: 14px; margin-top: 4px; }
.state button { margin-top: 12px; border: 0; background: var(--surface-hover); padding: 8px 16px; border-radius: var(--radius-sm);
                font-weight: 600; cursor: pointer; }
.state button:hover { background: var(--divider); }

/* ---- 데이터 상태 -------------------------------------------------------- */
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }
.status-dot.ok { background: #2e9b5f; } .status-dot.bad { background: var(--rise); } .status-dot.idle { background: var(--flat); }
pre.dev { font-size: 12.5px; overflow: auto; background: var(--bg); padding: 12px; border-radius: var(--radius-sm); }

/* ---- 모바일 ------------------------------------------------------------- */
@media (max-width: 760px) {
  .app-header { position: static; }
  .app-header .inner { flex-wrap: wrap; padding: 8px 16px 10px; row-gap: 8px; }
  .brand { margin-right: 6px; }
  .header-right { display: contents; }
  .search { width: 100%; }
  .search input { width: 100%; }
  .search-results { left: 0; right: 0; width: auto; }
  main { padding: 24px 16px 64px; }
  .page-header { margin-bottom: 28px; }
  .page-header h1 { font-size: 26px; }
  .list.two-col, .theme-grid { grid-template-columns: minmax(0, 1fr); }
  .theme-grid { gap: 12px; }
  .app-footer { padding: 0 16px 32px; }
  .home-grid, .detail-grid { grid-template-columns: minmax(0, 1fr); gap: 36px; }
  .detail-grid { gap: 14px; }
  .panel { padding: 4px; margin: 0 -8px; }
  .row { padding: 12px 10px; gap: 12px; }
  .block { padding: 20px 18px 12px; }
  .stock-head .price { font-size: 30px; }
  .investor-line { grid-template-columns: 56px minmax(0, 1fr) auto; gap: 10px; }
}
