/*
 * MDD 분석기 — achromatic ledger (tasteskill app style)
 * 크롬에는 색이 거의 없다. 색은 데이터에만: 차트 chart-1(청록 강조)·chart-2(주황), 손익 positive(빨강)·negative(파랑, 한국식).
 * 카드는 1px 테두리, 그림자 없음. 기본은 다크(:root), 라이트는 [data-theme="light"] 와 [data-theme="system"]+prefers-color-scheme:light 에 같은 토큰으로 선언.
 */

/* 기본은 다크. 라이트는 [data-theme="light"], 시스템은 [data-theme="system"] 일 때만 OS 를 따른다. */
:root {
  color-scheme: dark;
  --ground: #0e0f12;        /* 페이지 바탕 */
  --surface: #15171c;       /* 카드 */
  --raised: #1d2026;        /* 세그먼트 바탕·막대 트랙 */
  --active: #242830;        /* 사이드바 호버·눌림 */
  --border: #272b33;
  --rule: #1e2228;          /* 행 구분선 */
  --control: #4b515c;       /* 입력 테두리 */
  --text: #f0f1f3;
  --muted: #a3a8b3;
  --faint: #8a8f99;         /* 가장 연한 글자(4.5:1 이상) */
  --ink: #f0f1f3;           /* 기본 버튼·활성 알약 바탕(중립) */
  --accent-color: #2dd4bf;  /* 강조색 청록: 차트 주 선·활성 표시에만 아주 적게 */
  --chart-1: #2dd4bf;       /* 차트 데이터 전용 */
  --chart-1-fill: rgba(45, 212, 191, 0.18);
  --chart-fill-top: rgba(45, 212, 191, 0.18);   /* 면 그라데이션(위→아래), 라이트는 같은 값 = 평면 */
  --chart-fill-bottom: rgba(45, 212, 191, 0);
  --chart-2: #f0a050;       /* 비교 종목 전용 */
  --positive: #ff6f64;      /* 이익·상승(한국식 빨강) */
  --negative: #6ea3ff;      /* 손실·하락(한국식 파랑) */
  --warning: #f2b45a;       /* 오류·오프라인 안내 */
  --warning-bg: #2d2414;
  --pill-bg: #1d2026;
  --pill-ink: #d6d8dd;
  --grid: #22262d;

  /* 간격: 4px 격자 */
  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px; --space-5: 24px; --space-6: 32px;
  --card-pad: 20px;
  --radius: 6px;
  --radius-control: 6px;
  --control-height: 32px;
  --row: 34px;
  --sidebar-width: 248px;

  --font: "Geist", "Noto Sans KR", system-ui, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif; /* 한글 시스템 글꼴을 이름으로: 웹 글꼴 전·부분집합 밖 글자를 글자마다 대체 글꼴 찾기 없이 그린다(3차 폰 성능) */
  --fs-title: 24px;
  --fs-section: 16px;
  --fs-lead: 32px;
  --fs-kpi: 22px;
  --fs-body: 14px;
  --fs-small: 13px; /* 3차 6단계: 라벨·데이터·설명은 13px(검사기 '작은 글자 60%'). 12px 는 칩·캡션·'옆으로' 안내, 11px 는 자 눈금만 */
  --fs-tiny: 12px;

  /* 모션 토큰: 피드백(누름·호버·활성 이동)은 fast, 시트·전환·등장은 base */
  --t-fast: 150ms;
  --t-base: 200ms;
  --ease: cubic-bezier(0.2, 0, 0, 1);
}

:root[data-theme="light"] { /* 시스템 라이트와 같은 값 — 아래 @media 와 동기 유지 */
  color-scheme: light;
  --ground: #f8f8f8; --surface: #ffffff; --raised: #efefef; --active: #e8e8ea;
  --border: #e6e6e6; --rule: #eeeeee; --control: #d2d2d2;
  --text: #0a0a0a; --muted: #5c5c5c; --faint: #6b6b6b;
  --ink: #141414; --accent-color: #0f9d8a;
  --chart-1: #0f9d8a; --chart-1-fill: rgba(15, 157, 138, 0.10);
  --chart-fill-top: rgba(15, 157, 138, 0.10); --chart-fill-bottom: rgba(15, 157, 138, 0.10);
  --chart-2: #c96400;
  --positive: #c8281e; --negative: #1a5cc2;
  --warning: #8f5200; --warning-bg: #fff3df;
  --pill-bg: #efefef; --pill-ink: #3d3d3d;
  --grid: #e8e8e8;
}
@media (prefers-color-scheme: light) {
  :root[data-theme="system"] {
    color-scheme: light;
    --ground: #f8f8f8; --surface: #ffffff; --raised: #efefef; --active: #e8e8ea;
    --border: #e6e6e6; --rule: #eeeeee; --control: #d2d2d2;
    --text: #0a0a0a; --muted: #5c5c5c; --faint: #6b6b6b;
    --ink: #141414; --accent-color: #0f9d8a;
    --chart-1: #0f9d8a; --chart-1-fill: rgba(15, 157, 138, 0.10);
    --chart-fill-top: rgba(15, 157, 138, 0.10); --chart-fill-bottom: rgba(15, 157, 138, 0.10);
    --chart-2: #c96400;
    --positive: #c8281e; --negative: #1a5cc2;
    --warning: #8f5200; --warning-bg: #fff3df;
    --pill-bg: #efefef; --pill-ink: #3d3d3d;
    --grid: #e8e8e8;
  }
}

/* ---------- reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
/* 3차 6단계 CLS: 히어로 큰 숫자(LCP 요소)의 글꼴은 자체 호스팅 + preload — Google Fonts 보다 데이터가 먼저 오면 숫자가 시스템 글꼴로 그려졌다가
   바뀌며 0.1 가까운 이동이 났다. 공유 카드와 같은 Geist 700 부분집합(라틴·숫자·기호 19KB, OFL). 이름을 따로 두어 Google 의 Geist 와 겹치지 않게 */
/* 사이트 글자만 담은 부분집합(scripts/build_fonts.py 가 Google Fonts 에서 받아 둔다, 굵기 가변 400~700, OFL). index.html 이 preload 한다(3차 폰 성능) */
@font-face { font-family: "Geist"; src: url("fonts/Geist-sub.woff2") format("woff2"); font-weight: 400 700; font-style: normal; font-display: swap; }
@font-face { font-family: "Noto Sans KR"; src: url("fonts/NotoSansKR-sub.woff2") format("woff2"); font-weight: 400 700; font-style: normal; font-display: swap; }
html, body { margin: 0; }
body {
  background: var(--ground);
  color: var(--text);
  font: 400 var(--fs-body)/20px var(--font);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p, dl, dd { margin: 0; }
a { color: inherit; }
button, input { font: inherit; color: inherit; }
.num, table, .level-price { font-variant-numeric: tabular-nums; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }

/* ---------- shell: 종목 목록 + 캔버스 ---------- */
.app { display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); min-height: 100svh; }

.sidebar {
  position: sticky; top: 0; height: 100svh; overflow: auto;
  display: flex; flex-direction: column;
  padding: 20px 12px 16px;
  border-right: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; height: 32px; padding: 0 8px; }
.mark { width: 22px; height: 22px; flex: none; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.mark-ath { stroke: var(--faint); stroke-width: 1.5; }
.mark-curve { stroke: var(--text); stroke-width: 2; }
.mark-now { fill: var(--accent-color); } /* 3차 4단계: 마크의 "지금" 점. 아이콘·파비콘·공유 카드와 같은 마크 */
.brand-name { font-size: 16px; font-weight: 700; letter-spacing: -0.01em; }
.sheet-close { display: none; }
.scope { margin: 6px 8px 0; color: var(--faint); font-size: var(--fs-small); line-height: 16px; }
#data-info { min-height: 16px; } /* 3차 6단계 CLS: 갱신 시각이 들어올 자리 */

.search { margin: 16px 0 4px; }
.search input {
  width: 100%; height: var(--control-height); padding: 0 10px;
  border: 1px solid var(--control); border-radius: var(--radius-control);
  background: var(--surface);
}
.search input::placeholder { color: var(--faint); }

.group-label {
  display: flex; justify-content: space-between;
  margin: 18px 8px 6px; color: var(--faint); font-size: var(--fs-small);
}
.watchlist { display: grid; gap: 0; }
.watch {
  display: grid; grid-template-columns: minmax(0, 1fr) 56px auto; align-items: center; gap: 10px;
  height: 32px; margin-bottom: 2px; padding: 0 8px 0 6px; border-left: 2px solid transparent; border-radius: var(--radius-control);
  color: var(--muted); text-decoration: none;
  transition: background-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.watch:hover { background: var(--active); color: var(--text); }
.watch[aria-current="page"] { background: var(--raised); color: var(--text); font-weight: 500; border-left-color: var(--accent-color); } /* 3차 6단계: inset 그림자 → 테두리 */
.watch .watch-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.watch .watch-dd { min-width: 46px; text-align: right; font-variant-numeric: tabular-nums; color: var(--faint); }
.watch[aria-current="page"] .watch-dd { color: var(--text); }
.watch .watch-spark { display: block; width: 56px; height: 16px; overflow: visible; }
/* 즐겨찾기·순서 편집: 고정한 종목은 ★ 로, 편집 중에는 스파크·숫자 대신 버튼 3개 */
.watch-edit { margin-left: 6px; padding: 0 6px; height: 18px; border: 1px solid var(--control); border-radius: 9px; background: transparent; color: var(--faint); font: inherit; font-size: 11px; line-height: 16px; cursor: pointer; vertical-align: 1px; }
.watch-edit:hover, .watch-edit[aria-pressed="true"] { color: var(--text); border-color: var(--text); }
.watch--pinned .watch-name::before { content: "★ "; color: var(--faint); font-size: 10px; }
.watch-tools { display: inline-flex; gap: 2px; justify-content: flex-end; grid-column: 2 / 4; }
.watch-btn { width: 26px; height: 26px; border: 1px solid var(--control); border-radius: 6px; background: var(--surface); color: var(--muted); font: inherit; font-size: 12px; line-height: 1; cursor: pointer; }
.watch-btn:hover { color: var(--text); }
.watch-btn[aria-pressed="true"] { color: var(--text); border-color: var(--text); }
.watch-btn:disabled { opacity: .35; cursor: default; }
.watchlist.editing .watch { cursor: default; }
.watch .watch-spark path { stroke: var(--control); stroke-width: 1; stroke-linejoin: round; }
/* 첫 목록 그리기에서만(.watch--in): 행 순서(--i)대로 40ms 간격, 200ms 페이드 + 살짝 그려짐 */
@keyframes spark-in { from { opacity: 0; stroke-dashoffset: 1; } to { opacity: 1; stroke-dashoffset: 0; } }
@media (prefers-reduced-motion: no-preference) {
  .watch--in .watch-spark path { stroke-dasharray: 1; animation: spark-in 200ms var(--ease, ease-out) both; animation-delay: calc(var(--i, 0) * 40ms); }
}
.watch[aria-current="page"] .watch-spark path { stroke: var(--muted); } /* 2차 디자인 1단계: 선은 회색, 색은 데이터(차트·끝점)에만 */
.watch[hidden] { display: none; }

.sidebar-foot { margin-top: auto; padding: 24px 8px 0; color: var(--faint); font-size: var(--fs-small); line-height: 16px; }
.sidebar-foot .segmented { display: flex; width: 100%; margin: 0 0 var(--space-4); }
.sidebar-foot .segmented button { flex: 1; padding: 0 var(--space-2); }
.sidebar-foot a { display: inline-block; margin-top: 6px; color: var(--text); text-decoration: underline; text-underline-offset: 3px; }

.phonebar { display: none; }
.tabbar { display: none; }

.canvas { min-width: 0; padding: 32px var(--space-6) 48px; }

/* ---------- title row and filters ---------- */
.hero {
  position: relative; display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1.4fr) minmax(180px, 240px); /* 3차 1단계-1: 가운데(숫자·결론) 열을 auto 에서 fr 로 — 결론이 길면 이름 열을 누르지 않고 줄바꿈 */ align-items: center; gap: var(--space-4) var(--space-5);
  margin-bottom: var(--space-4); padding: var(--space-5);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
/* 2차 디자인 1단계-2: 히어로의 상태 그라데이션·글로우·tilt 를 뺐다. 면은 톤 한 단계(--surface) + 헤어라인(--border)으로만 구분한다 */
.hero-id { min-width: 0; min-height: 60px; } /* 3차 6단계 CLS: 이름 아래 칩 줄이 들어올 자리(폰 58px). 링크 복사 단추는 히어로 오른쪽 위(스파크 열 위)라 데스크톱에선 여백이 필요 없다. 폰은 아래 미디어쿼리에서 76px */
.hero h1 { font-size: var(--fs-title); line-height: 30px; font-weight: 500; letter-spacing: -0.01em; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: var(--space-2); }
.chips:empty { display: none; }
.chip { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 11px; background: var(--raised); color: var(--muted); font-size: 12px; line-height: 16px; font-weight: 600; white-space: nowrap; }
.chip--buy { background: color-mix(in srgb, var(--accent-color) 20%, transparent); color: var(--text); }
.chip--below { background: color-mix(in srgb, var(--warning) 20%, transparent); color: var(--text); }
.hero-now { min-width: 0; min-height: 188px; } /* 3차 6단계 CLS: 스켈레톤(28px)에서 실제(188px)로 자라며 아래가 밀리지 않게. 폰은 174px */
.hero-label { color: var(--muted); font-size: var(--fs-small); line-height: 16px; }
.hero-num { font-family: var(--font); margin-top: var(--space-1); font-size: 56px; line-height: 62px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: normal; white-space: nowrap; }
.hero-num.counting { font-variant-numeric: tabular-nums; }
.hero-pair { margin-top: 2px; font-size: 15px; line-height: 20px; color: var(--text); font-variant-numeric: tabular-nums; } /* 등락 한 쌍(2차 3단계-2): 현재가 · 최고가보다 −금액(−%) */
.hero-pair .loss { color: var(--negative); font-weight: 500; }
/* 오늘의 결론(3차 1단계-1): 히어로에서 큰 숫자 다음 2순위. 잉크색 15px, 상태 칩은 같은 줄 끝에 인라인 */
.hero-verdict { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin-top: var(--space-2); color: var(--text); font-size: 15px; line-height: 21px; font-weight: 500; }
.hero-verdict:has(> .verdict-text:empty):has(> .chips:empty) { display: none; }
.hero-verdict strong { color: var(--text); font-weight: 700; }
.chips--inline { display: inline-flex; margin-top: 0; }
.hero-spark { min-width: 0; }
.spark-label { color: var(--faint); font-size: 12px; line-height: 16px; margin-bottom: 4px; }
.spark-wrap { position: relative; height: 64px; }
.spark-wrap svg { display: block; width: 100%; height: 100%; overflow: visible; }
.spark-line { stroke: var(--muted); stroke-width: 1.5; stroke-linejoin: round; } /* 회색 선 + 끝점(.spark-dot)만 색 */
.spark-zero { stroke: var(--faint); stroke-width: 1; stroke-dasharray: 2 3; opacity: 0.6; }
.spark-dot { transform-origin: center; position: absolute; width: 6px; height: 6px; margin: -3px 0 0 -3px; border-radius: 50%; background: var(--accent-color); }
.hero-share { margin-top: 0; position: absolute; top: var(--space-3); left: auto; right: var(--space-3); }
/* 히어로 발치(3차 1단계-2): 설명 문장과 작은 줄(최고가 · 날짜 · 회복까지 · 기간 · 거래일)은 낙폭 자 아래로. 숫자·결론 위에서 자리를 먹지 않는다 */
.hero-foot { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px var(--space-4); margin-top: calc(-1 * var(--space-2)); min-height: 18px; /* 발견·도장 한 줄 자리(빈 상태에서도) — 내용이 오면서 아래가 밀리지 않게(데스크톱 CLS 0.04) */ }
.finding { margin: 0; color: var(--muted); font-size: 13px; line-height: 18px; }
.finding strong { color: var(--text); font-weight: 500; }
.stamp { margin: 0; color: var(--faint); font-size: var(--fs-small); line-height: 18px; }
.stamp > span:not(:empty) + span:not(:empty)::before { content: " · "; }

/* 3차 6단계 CLS: 칩 줄과 조건 줄을 항상 두 줄로 두고 각 줄 높이를 예약한다 — 칩 8개가 들어오며 줄바꿈되어(34 → 78px) 아래가 밀리던 것 */
.filters { --control-height: 36px; display: flex; flex-direction: column; align-items: stretch; gap: var(--space-2) var(--space-3); margin-bottom: 16px; }
.filters-main { min-height: 34px; }
.filters-side { min-height: var(--control-height); }
/* 툴바 한 줄: 왼쪽 기간 칩 + 날짜, 오른쪽 통화 · 배당 반영 · 비교 */
.filters-main, .filters-side { display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-2) var(--space-3); min-width: 0; }
.filters-side { margin-left: auto; }
.filters-side .segmented[hidden] { display: flex; visibility: hidden; } /* 통화 토글 자리를 처음부터 둔다: 데이터 뒤에 나타나면 오른쪽 정렬 그룹이 왼쪽으로 자라며 밀린다(데스크톱 CLS). 폰은 접는다(아래) */
.filters .segmented button { height: calc(var(--control-height) - 4px); }
.segmented {
  display: inline-flex; width: max-content; max-width: 100%;
  padding: 2px; gap: 2px; border-radius: var(--radius); background: var(--raised); position: relative;
}
/* 미끄러지는 알약: 활성 버튼 뒤에서 위치·크기를 따라간다(app.js initSegThumbs) */
.seg-thumb {
  position: absolute; left: 0; top: 0; width: 0; height: 0; z-index: 0; pointer-events: none;
  border-radius: var(--radius-control); background: var(--ink); opacity: 0;
}
.seg-thumb.on { opacity: 1; }
.seg-thumb.snap { transition: none !important; }
@media (prefers-reduced-motion: no-preference) {
  .seg-thumb.ready {
    transition: transform var(--t-fast) var(--ease), width var(--t-fast) var(--ease),
      height var(--t-fast) var(--ease), opacity var(--t-fast) var(--ease);
  }
}
.segmented[hidden] { display: none; }
.segmented button {
  height: 28px; padding: 0 12px; border: 0; border-radius: var(--radius-control);
  background: transparent; color: var(--muted); cursor: pointer; position: relative; z-index: 1;
  transition: background-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.segmented button:hover { color: var(--text); }
.segmented button:not([aria-pressed="true"]):not(:disabled):active { background: var(--active); }
.segmented button[aria-pressed="true"] { background: transparent; color: var(--surface); font-weight: 500; }
.segmented button:disabled { cursor: not-allowed; opacity: 0.5; }
.dates { display: flex; align-items: center; gap: 6px; color: var(--faint); }
.dates input {
  height: var(--control-height); padding: 0 8px; width: 138px;
  border: 1px solid var(--control); border-radius: var(--radius-control); background: var(--surface);
}
.check { display: inline-flex; align-items: center; gap: 8px; color: var(--text); cursor: pointer; }
.check input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent-color); }
.check:has(input:disabled) { color: var(--faint); cursor: not-allowed; }

.status { margin: -4px 0 16px; padding: 8px 12px; border-radius: var(--radius-control); background: var(--pill-bg); color: var(--pill-ink); }
.status.error { background: var(--warning-bg); color: var(--warning); }
.status[hidden] { display: none; }
.status .status-retry { margin-left: 8px; font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }

/* 다시 계산·불러오는 동안 기존 화면을 그대로 두고 흐리게 */
body.loading #result { opacity: 0.5; transition: opacity var(--t-fast) var(--ease); }
/* 종목 전환 크로스페이드: 결과 영역만 전환 대상으로 두고(나머지 화면은 그대로) 흐림은 전환 중 고정하지 않는다 */
body.vt #result { transition: none; }
@media (prefers-reduced-motion: no-preference) {
  :root { view-transition-name: none; }
  #result { view-transition-name: result; }
  #hero { view-transition-name: hero; }
  ::view-transition-old(result), ::view-transition-new(result), ::view-transition-old(hero), ::view-transition-new(hero) { animation-duration: var(--t-base); animation-timing-function: var(--ease); }
}

/* ---------- KPI: 한 카드를 1px 세로선으로 나눈다 ---------- */
/* KPI 띠(2차 디자인 4단계-1): 카드가 아니라 글자. 상자 없이 헤어라인으로만 나눈 한 줄, 라벨 위·값 24px.
   히어로 56px 하나만 크고 나머지 숫자는 그 절반 이하 → 위계가 한눈에 */
.kpis {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
  border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule);
  margin-bottom: var(--space-3);
}
.kpi { padding: var(--space-3) var(--space-4); min-width: 0; }
.kpi:first-child { padding-left: var(--space-2); }
.kpi + .kpi { border-left: 1px solid var(--rule); }
.kpi-label { color: var(--muted); font-size: var(--fs-small); line-height: 16px; }
.kpi-value { margin-top: 2px; font-size: 24px; line-height: 30px; font-weight: 600; letter-spacing: -0.01em; font-variant-numeric: normal; white-space: nowrap; }
.kpi-value.counting { font-variant-numeric: tabular-nums; } /* 보간 중에만 숫자 폭을 고정해 글자 폭 변화로 흔들리지 않게 */
.kpi-value small { font-size: 13px; font-weight: 400; color: var(--muted); margin: 0 4px 0 1px; }
.kpi-sub { margin-top: 2px; color: var(--faint); font-size: var(--fs-small); line-height: 16px; }

/* ---------- panels ---------- */
.grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: var(--space-3); align-items: stretch; } /* 3차 6단계: 한 줄의 카드 쌍(분포·하락장 기록)은 바닥을 맞춘다(검사기 ragged-row) */
.span-12 { grid-column: 1 / -1; }
.span-8 { grid-column: span 8; }
.span-7 { grid-column: span 7; }
.span-6 { grid-column: span 6; }
.span-5 { grid-column: span 5; }
.span-4 { grid-column: span 4; }
.panel {
  min-width: 0; padding: var(--card-pad);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 4px 12px; flex-wrap: wrap; margin-bottom: 12px; }
.panel-head h2 { font-size: var(--fs-section); line-height: 22px; font-weight: 500; }
.meta { color: var(--faint); font-size: var(--fs-small); }
.panel-note { margin-top: 10px; color: var(--faint); font-size: var(--fs-small); }
.lede { margin: -4px 0 12px; color: var(--muted); font-size: 13px; line-height: 18px; } /* 용어 첫 등장 풀이(3차 3단계-1): 패널 머리 아래 한 줄 */
.panel-note:empty { display: none; }
/* 하락 달력: 하락장 기록 위의 접이식 블록, 캔버스 하나 */
.calendar { margin-top: 10px; }
.calendar[hidden] { display: none; }
.calendar summary { display: flex; align-items: baseline; gap: 8px; cursor: pointer; color: var(--muted); font-size: var(--fs-small); line-height: 20px; list-style: none; user-select: none; }
.calendar summary::-webkit-details-marker { display: none; }
.calendar summary::before { content: "▸"; color: var(--faint); font-size: 11px; }
.calendar[open] summary::before { content: "▾"; }
.calendar summary:hover { color: var(--text); }
.calendar-body { margin-top: 8px; }
.calendar-canvas { display: block; width: 100%; cursor: pointer; touch-action: manipulation; }
.calendar-tip { margin-top: 6px; }
.mini-stats { display: flex; flex-wrap: wrap; gap: 6px 22px; margin-top: 10px; }
.mini-stats[hidden] { display: none; }
.mini-stats > div { display: flex; flex-direction: column; gap: 2px; }
.mini-label { color: var(--faint); font-size: var(--fs-small); }
.mini-value { color: var(--text); font-variant-numeric: tabular-nums; }

/* 차트 카드는 옆의 매수 기준가 카드와 같은 높이로 늘어나고, 늘어난 만큼 차트가 채운다 */
.chart-panel { align-self: stretch; display: flex; flex-direction: column; }
.chart-box { position: relative; flex: 1 1 0; min-height: 300px; }
.chart-reveal { position: absolute; inset: 0; background: var(--surface); transform-origin: right; pointer-events: none; z-index: 1; }
.brush { position: absolute; z-index: 0; pointer-events: none; background: color-mix(in srgb, var(--accent-color) 10%, transparent); border-left: 1px solid var(--accent-color); border-right: 1px solid var(--accent-color); box-sizing: border-box; }
.brush[hidden] { display: none; }
@media (hover: hover) { #chart-sub:not(.live)::after { content: " · 드래그해서 구간 확대 · 더블클릭으로 전체"; opacity: .55; } }
#chart-sub.no-brush::after { content: none; }
#chart:focus-visible { outline: 2px solid var(--accent-color); outline-offset: 2px; border-radius: var(--radius-control); }
.pulse { position: absolute; width: 10px; height: 10px; margin: -5px 0 0 -5px; border-radius: 50%; pointer-events: none; z-index: 1; }
.pulse[hidden] { display: none; }
.pulse::before, .spark-dot::before { content: ""; position: absolute; inset: 0; border-radius: 50%; border: 1.5px solid var(--accent-color); box-sizing: border-box; opacity: 0; }
@media (prefers-reduced-motion: no-preference) {
  .pulse::before, .spark-dot.live::before { animation: dot-pulse 2s ease-out infinite; }
}
@keyframes dot-pulse { from { transform: scale(1); opacity: .55; } to { transform: scale(2.4); opacity: 0; } }
.chart-box canvas { position: absolute; inset: 0; touch-action: pan-y; }
/* 크로스헤어 한 줄 안내가 들어가도 레이아웃이 움직이지 않도록 항상 한 줄을 차지한다 */
#chart-sub { flex: 1 0 100%; min-height: 16px; line-height: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- 매수 기준가 ---------- */
.levels { display: grid; }
.level { padding: 12px 0; }
.level + .level { border-top: 1px solid var(--rule); }
.level:first-child { padding-top: 2px; }
.level-line { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.level-name { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); white-space: nowrap; }
.level-name input, .panel-foot input {
  width: 52px; height: 28px; padding: 0 6px; text-align: right;
  border: 1px solid var(--control); border-radius: var(--radius-control); background: var(--surface);
  font-variant-numeric: tabular-nums;
}
.unit { color: var(--faint); }
.level-price { font-size: 18px; line-height: 24px; font-weight: 700; }
.level-right { display: inline-flex; align-items: center; gap: 8px; min-width: 0; }
.level-copy { margin-top: 0; height: 22px; padding: 0 8px; font-size: 11px; line-height: 20px; flex: none; }
.plan-link { margin-top: 0; height: 24px; }
.is-buy .level-name { color: var(--text); font-weight: 500; }
.level-tag { font-weight: 400; color: var(--faint); }
.track { position: relative; height: 4px; margin-top: 10px; border-radius: 0; background: color-mix(in srgb, var(--accent-color) 18%, var(--raised)); overflow: hidden; }
.track > span { position: absolute; inset: 0 auto 0 0; width: 0; border-radius: 0 999px 999px 0; background: var(--accent-color); }
.level-sub { margin-top: 6px; color: var(--faint); font-size: var(--fs-small); line-height: 16px; }
.level-sub .reached { color: var(--text); font-weight: 500; }
.panel-foot { margin-top: 4px; padding-top: 12px; border-top: 1px solid var(--rule); color: var(--muted); line-height: 30px; }
.panel-foot input { margin: 0 2px; }
.panel-foot .hint { color: var(--faint); font-size: var(--fs-small); line-height: 16px; }
.cost-box { margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--rule); display: flex; flex-wrap: wrap; gap: 0 14px; align-items: center; }
.cost-box label { white-space: nowrap; }
.cost-box .hint, .cost-box .cost-note { flex: 1 0 100%; }
.cost-box .cost-note { margin-top: 4px; color: var(--text); }
#cost { width: 92px; }
#qty { width: 68px; }

/* ---------- tables ---------- */
.scroll-hint { position: relative; margin: 0 -4px; }
.scroll-hint::after {
  content: ''; position: absolute; top: 0; right: 0; bottom: 0; width: 28px; pointer-events: none;
  background: linear-gradient(to right, transparent, var(--surface)); opacity: 0; transition: opacity var(--t-fast) var(--ease);
}
.scroll-hint.more-right::after { opacity: 1; }
.table-wrap { overflow-x: auto; }
/* 첫 열 고정: 가로로 밀 때 행 이름이 남는다. 밀린 뒤에만 오른쪽 1px 선 */
.table th:first-child, .table td:first-child { position: sticky; left: 0; z-index: 1; background-color: var(--surface); }
.scroll-hint.scrolled .table th:first-child, .scroll-hint.scrolled .table td:first-child {
  background-image: linear-gradient(var(--border), var(--border)); background-repeat: no-repeat; background-position: right top; background-size: 1px 100%;
}
.sim-detail { display: none; }
.row-toggle { display: none; } /* 폰에서만 보이는 행 펼침 단추(3차 6단계 접근성) */
#episodes th, #episodes td, #dist th, #dist td { padding: 0 4px; }
.table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; } /* 2차 4단계-2: 네 표 공통 — 숫자 폭 고정, 제브라·머리 밴드 없음, 숫자 우측 정렬 */
.table th {
  height: 32px; padding: 0 8px; text-align: right; vertical-align: middle;
  color: var(--faint); font-size: var(--fs-small); font-weight: 400; white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
.table .rank { display: inline-block; min-width: 1.6em; margin-right: 4px; color: var(--muted); font-size: 12px; } /* 기록 표 순위(깊이순). --faint 는 라이트의 현재 행(--active 바탕)에서 4.36:1 라 --muted */
:where(.table td) { color: var(--muted); }
/* 핵심 열만 진하게 */
:where(.table td:first-child, #ladder-table td:nth-child(7), #dist td:nth-child(2), #dist td:nth-child(3), #episodes td:nth-child(2), #yearly td:nth-child(3)) { color: var(--text); }
.table td {
  height: var(--row); padding: 0 8px; text-align: right; vertical-align: middle; white-space: nowrap;
  border-bottom: 1px solid var(--rule);
}
.table tr:last-child td { border-bottom: 0; }
.table th:first-child, .table td:first-child { text-align: left; }
.table td.quiet { color: var(--faint); }
.table td.gain { color: var(--positive); }
.table td.loss { color: var(--negative); }
.table td { transition: background-color var(--t-fast) var(--ease); }
#episodes tbody tr[data-from] { cursor: pointer; }
.table tbody tr:not(.current):not(.linked):not(.empty-row):not(.sim-detail):hover td { background-color: var(--raised); }
.table tr.current td, .table tr.current + .sim-detail td { background-color: var(--active); }
.table tr.linked td, .table tr.linked + .sim-detail td { background-color: var(--raised); }
.table tr.current.linked td, .table tr.current.linked + .sim-detail td { background-color: var(--active); }
.table tr.beyond td { color: var(--faint); }
.table strong { font-weight: 500; }
.table .empty-row td { color: var(--muted); text-align: left; white-space: normal; height: 48px; }

.pill {
  display: inline-flex; flex: none; align-items: center; height: 20px; padding: 0 7px; margin-left: 6px;
  border-radius: 999px; font-size: var(--fs-small); font-weight: 500; white-space: nowrap; vertical-align: middle;
  background: var(--pill-bg); color: var(--pill-ink);
}
.pill.ink { background: var(--ink); color: var(--surface); }

/* 회복률: 얇은 회색 막대 + 기준선 눈금 */
.meter { position: relative; display: inline-block; width: 48px; height: 3px; margin-right: 8px; vertical-align: middle; border-radius: 0; background: var(--raised); }
.meter > span { position: absolute; inset: 0 auto 0 0; border-radius: 0 999px 999px 0; background: var(--control); }
/* 비교 중에는 막대 없이 숫자만(폭 확보) */
#dist.cmp .meter { display: none; }
#dist.cmp th, #dist.cmp td { padding: 0 2px; }
.meter > i { position: absolute; top: -3px; bottom: -3px; width: 1px; background: var(--text); }
tr.buy .meter > span { background: var(--ink); }

.card-link {
  display: inline-flex; align-items: center; gap: 4px; margin-top: 10px; padding: 0;
  border: 0; background: none; color: var(--text); font-weight: 500; cursor: pointer; text-underline-offset: 3px;
}
.card-link:hover { text-decoration: underline; }
.card-link[hidden] { display: none; }

/* ---------- 읽는 법 ---------- */
/* ---------- ⓘ 설명 팝오버 ---------- */
.head-title { display: inline-flex; align-items: baseline; gap: var(--space-1); min-width: 0; }
/* 표 접기(3차 2단계-1): 폰에서만. 데스크톱은 단추·요약을 숨기고 본문은 늘 펼침 */
.fold, .fold-sum, .fold-all { display: none; }
@media print { .panel-body[hidden] { display: block !important; content-visibility: visible !important; } .fold, .fold-sum, .fold-all { display: none !important; } }
.info {
  display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; padding: 0;
  border: 0; border-radius: var(--radius-control); background: transparent; color: var(--faint);
  font: inherit; line-height: 1; cursor: pointer; align-self: center;
  transition: color var(--t-fast) var(--ease), background-color var(--t-fast) var(--ease);
}
.info:hover, .info[aria-expanded="true"] { color: var(--text); background: var(--raised); }
.help-pop {
  position: fixed; inset: auto; margin: 0; z-index: 30; width: max-content; max-width: min(340px, calc(100vw - 32px));
  padding: var(--space-3) var(--space-4); border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); font-size: var(--fs-small); line-height: 18px;
  opacity: 1; transition: opacity var(--t-fast) var(--ease), display var(--t-fast) allow-discrete, overlay var(--t-fast) allow-discrete;
}
@starting-style { .help-pop:popover-open { opacity: 0; } }
.help-pop:not(:popover-open) { opacity: 0; }
.no-popover .help-pop { display: none; }
.no-popover .help-pop.open { display: block; }
.help-pop:focus { outline: none; }
.help-pop dl { display: grid; gap: 4px; }
.help-pop dt { font-weight: 500; }
.help-pop dt:not(:first-child) { margin-top: var(--space-3); }
.help-pop dd { color: var(--muted); }
.footer { margin-top: 24px; color: var(--faint); font-size: var(--fs-small); line-height: 18px; max-width: 760px; }

.phone-only { display: none; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; height: var(--control-height); padding: 0 12px;
  border: 1px solid var(--ink); border-radius: var(--radius-control); background: var(--ink); color: var(--surface); font-weight: 500; cursor: pointer;
}

/* ---------- tablet ---------- */
@media (max-width: 1180px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi + .kpi { border-left: 0; }
  .kpi:nth-child(2n) { border-left: 1px solid var(--rule); }
  .kpi:nth-child(n + 3) { border-top: 1px solid var(--rule); }
  .hero { grid-template-columns: minmax(0, 1fr) minmax(0, 1.5fr); }
  .hero-spark { grid-column: 1 / -1; }
  .span-8, .span-4, .span-7, .span-6, .span-5 { grid-column: 1 / -1; }
  .chart-box { flex: none; height: clamp(300px, 42vh, 420px); } /* 화면 높이에 비례, 최소 300px */
  .levels { grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 24px; }
  .level + .level { border-top: 0; }
  .level:nth-child(n + 3) { border-top: 1px solid var(--rule); }
  .level:first-child { padding-top: 12px; }
}

/* ---------- phone: 종목 목록은 접히고, 위쪽 줄과 전체 화면 시트로 바뀐다 ---------- */
@media (max-width: 860px) {
  .app { display: block; }
  .sidebar {
    position: fixed; inset: 0; z-index: 20; height: auto; width: 100%;
    padding: 12px 16px 24px; background: var(--ground); border: 0;
    visibility: hidden; opacity: 0; transform: translateY(8px);
    transition: opacity var(--t-base) var(--ease), transform var(--t-base) var(--ease), visibility 0s linear var(--t-base);
  }
  body.sheet-parked .sidebar { content-visibility: hidden; } /* 닫힌 시트(종목 15행 + 스파크라인)는 레이아웃에서 뺀다. 전환이 끝난 뒤 app.js 가 건다(3차 폰 성능) */
  body.sheet-open { overflow: hidden; }
  body.sheet-open .sidebar { visibility: visible; opacity: 1; transform: none; transition: opacity var(--t-base) var(--ease), transform var(--t-base) var(--ease); }
  .sheet-close { display: inline-flex; margin-left: auto; height: 36px; padding: 0 12px; border: 1px solid var(--control); border-radius: var(--radius-control); background: var(--surface); cursor: pointer; }
  .watch { height: 44px; }

  .phonebar {
    position: sticky; top: 0; z-index: 10;
    display: flex; align-items: center; gap: 10px; height: 52px; padding: 0 16px;
    background: var(--ground); border-bottom: 1px solid var(--border);
  }
  .phonebar .btn { margin-left: auto; height: 36px; }

  .canvas { padding: 20px 16px calc(44px + env(safe-area-inset-bottom) + 24px); }
  #hero, #chart-panel, #levels-panel, #records { scroll-margin-top: 64px; }
  .tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 15; display: flex;
    padding-bottom: env(safe-area-inset-bottom); background: var(--surface); border-top: 1px solid var(--border);
  }
  .tabbar a {
    flex: 1; display: flex; align-items: center; justify-content: center; height: 44px;
    color: var(--muted); text-decoration: none; font-size: var(--fs-small);
    transition: color var(--t-fast) var(--ease);
  }
  .tabbar a.on { color: var(--text); font-weight: 700; }
  body.sheet-open .tabbar { visibility: hidden; }
  .hero { grid-template-columns: minmax(0, 1fr); padding: var(--space-4); }
  .hero h1 { font-size: 22px; line-height: 28px; }
  .hero-id { padding-right: 76px; }
  .hero-num { font-size: 44px; line-height: 50px; }
  .hero-verdict { font-size: 14px; line-height: 20px; }
  /* 표 접기(3차 2단계-1): 머리 어디를 눌러도 접힌다. 첫 줄은 제목 + 꺾쇠, 둘째 줄은 펼쳤을 때 meta · 접혔을 때 결론 요약 */
  .panel[data-fold] .panel-head { cursor: pointer; -webkit-tap-highlight-color: transparent; }
  .panel[data-fold] .panel-head .meta, .panel[data-fold] .panel-head .plan-link { order: 3; }
  .fold { display: inline-flex; align-items: center; justify-content: center; order: 1; align-self: center; width: 36px; height: 36px; margin: -8px -8px -8px auto; padding: 0; border: 0; background: none; color: var(--muted); cursor: pointer; }
  .fold-caret { width: 8px; height: 8px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: translateY(2px) rotate(-135deg); }
  .panel.folded .fold-caret { transform: translateY(-2px) rotate(45deg); }
  .panel.folded .panel-head .plan-link { display: none; }
  /* 모두 펼치기/접기(3차 2단계-2): 첫 접힌 패널 위 오른쪽 끝의 글자 단추 */
  .fold-all { display: flex; justify-content: flex-end; align-items: center; min-height: 36px; margin: calc(-1 * var(--space-2)) 0 calc(-1 * var(--space-2)); padding: 0 var(--space-2); border: 0; background: none; color: var(--muted); font-size: 13px; cursor: pointer; }
  .fold-sum { order: 4; flex-basis: 100%; color: var(--text); font-size: 14px; line-height: 20px; }
  .panel.folded .fold-sum:not(:empty) { display: block; }
  .panel.folded .panel-head { margin-bottom: 0; }
  .panel.folded .panel-head .meta { display: none; }
  /* 폰 순서: 이름 → 숫자·결론 → 낙폭 자 → 작은 줄 → 스파크 */
  .ruler { order: 3; }
  .hero-foot { order: 4; margin-top: calc(-1 * var(--space-1)); }
  .hero-spark { order: 5; }
  .spark-wrap { height: 48px; }
  .dates input { width: 132px; }
  /* 조회 조건은 두 줄까지: 날짜 직접 입력은 '직접'을 눌렀을 때만 */
  .filters, .filters-side { gap: 8px 12px; }
  .filters-main, .filters-side { width: 100%; }
  .filters-main { min-height: 40px; }
  .filters-side { min-height: 44px; }
  .hero-now { min-height: 174px; }
  .hero-id { min-height: 58px; }
  .hero-foot { min-height: 74px; } /* 발견 두 줄 + 도장 두 줄 자리 */
  .filters-side { margin-left: 0; flex-wrap: nowrap; }
  .filters-side .segmented[hidden] { display: none; }
  .filters-side > * { white-space: nowrap; flex: none; }
  .filters-side > .compare-box { flex: 1 1 0; min-width: 0; }
  .compare-box select, .compare-box input { flex: 1 1 0; width: 0; min-width: 0; max-width: none; }
  .phone-only { display: inline-block; }
  .filters .dates { display: none; width: 100%; }
  body.dates-open .filters .dates { display: flex; }

  .kpi { padding: var(--space-3); }
  .kpi:first-child { padding-left: var(--space-3); }
  .kpi-value { font-size: 22px; line-height: 28px; }

  .panel { padding: 16px; }
  .chart-box { height: clamp(220px, 40vh, 360px); min-height: 0; } /* 화면 높이에 비례, 최소 220px */
  .levels { grid-template-columns: minmax(0, 1fr); }
  .level:nth-child(n + 2) { border-top: 1px solid var(--rule); }
  .level:first-child { padding-top: 2px; }

  /* 넓은 표는 카드 안에서만 옆으로 밀리고, 첫 열은 고정 */
  .table td { height: 32px; }
  .table th:first-child, .table td:first-child { position: sticky; left: 0; background: var(--surface); }
  .table tr.current td:first-child { background: var(--active); }
  .table tr.linked td:first-child { background: var(--raised); }
}

/* 첫 로드 카드 페이드: JS 가 한 번 .intro 를 붙였다 떼며, 지연은 요소마다 인라인으로 준다 */
@keyframes card-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
#result.intro > .kpis, #result.intro .panel { animation: card-in var(--t-base) var(--ease) both; }

/* 테마 전환: 바뀌는 동안만 배경·글자색을 부드럽게(상시 transition 은 두지 않는다) */
@media (prefers-reduced-motion: no-preference) {
  html.theme-switching, html.theme-switching *, html.theme-switching *::before, html.theme-switching *::after {
    transition: background-color var(--t-base) var(--ease), color var(--t-base) var(--ease), border-color var(--t-base) var(--ease) !important;
  }
}

@media (max-width: 860px) {
  /* 숫자 열 최소 폭(줄바꿈 방지), 첫 열은 날짜가 들어갈 폭 */
  .table th, .table td { white-space: nowrap; }
  .table th, .table td { padding-left: 6px; padding-right: 6px; }
  .table th:not(:first-child), .table td:not(:first-child) { min-width: 6ch; }
  .table th:first-child, .table td:first-child { min-width: 9ch; }
  /* 스크롤되는 표에는 첫 한 번만 머리글 위에 "옆으로" 안내 */
  .scroll-hint.more-right:not(.seen)::before {
    content: '→ 옆으로'; display: block; padding: 0 8px 2px; text-align: right; color: var(--faint); font-size: 12px; line-height: 16px;
  }
  .scroll-hint::after { width: 40px; }
  /* 분할매수 시뮬레이션: 핵심 열만, 나머지는 행을 눌러 펼침 */
  #ladder-table th:nth-child(n+4):nth-child(-n+6), #ladder-table td:nth-child(n+4):nth-child(-n+6),
  #ladder-table th:nth-child(n+8), #ladder-table td:nth-child(n+8) { display: none; }
  #ladder-table th, #ladder-table td { padding-left: 4px; padding-right: 4px; }
  #ladder-table tbody tr[data-detail] { cursor: pointer; }
  /* 행 펼침 단추: 보이는 건 + / − 한 글자, 히트 영역은 24px. tr 의 aria-expanded 대신 이 단추가 상태를 가진다 */
  .row-toggle { display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; margin: -4px 2px -4px -4px; padding: 0; border: 0; background: none; color: var(--faint); font: inherit; cursor: pointer; vertical-align: middle; }
  .row-toggle::before { content: '+'; }
  tr.open .row-toggle::before { content: '−'; }
  .row-toggle:focus-visible { outline: 2px solid var(--accent-color); outline-offset: -2px; border-radius: 4px; }
  #ladder-table .sim-detail { display: table-row; }
  #ladder-table .sim-detail td { padding: 0; height: auto; text-align: left; white-space: normal; border-bottom: 1px solid var(--rule); min-width: 0; position: static; }
  #ladder-table tr:last-child td { border-bottom: 0; }
  #ladder-table tr.open > td { border-bottom-color: transparent; }
  .sim-detail-body { display: grid; grid-template-rows: 0fr; transition: grid-template-rows var(--t-fast) var(--ease); }
  tr.open + .sim-detail .sim-detail-body { grid-template-rows: 1fr; }
  .sim-detail-body > dl { overflow: hidden; min-height: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 8px 16px; padding: 0 8px; }
  tr.open + .sim-detail .sim-detail-body > dl { padding: 4px 8px 12px; }
  .sim-detail dt { color: var(--faint); font-size: var(--fs-small); }
  .sim-detail dd { color: var(--text); font-variant-numeric: tabular-nums; }
  .sim-detail dd .gain { color: var(--positive); }
  .sim-detail dd .loss { color: var(--negative); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}

/* ---------- 분할매수 시뮬레이션 ---------- */
.ladder-inputs { display: flex; flex-wrap: wrap; gap: 8px 20px; }
.ladder-inputs .field { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); white-space: nowrap; }
.ladder-inputs input {
  height: var(--control-height); width: 72px; padding: 0 8px; border: 1px solid var(--control);
  border-radius: var(--radius-control); background: var(--surface); color: var(--text); font: inherit; text-align: right;
}
.ladder-inputs #ladder-budget { width: 130px; }
.ladder-msg.error { color: var(--warning); }
.gain { color: var(--positive); }
.loss { color: var(--negative); }
.ladder-foot { line-height: 1.6; }
#ladder-table td, #ladder-table th { white-space: nowrap; }

/* 공유 링크 복사 */
.mini-btn {
  margin-top: 6px; height: 26px; padding: 0 10px; border: 1px solid var(--control); border-radius: var(--radius-control);
  background: var(--surface); color: var(--muted); font: inherit; font-size: var(--fs-small); cursor: pointer;
}
.mini-btn:hover { color: var(--text); }
.mini-btn, .btn, .sheet-close { transition: background-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease); }
.mini-btn:active, .sheet-close:active { background: var(--raised); }
.btn:active { background: var(--text); border-color: var(--text); }
.watch:active { background: var(--raised); }
.mini-btn[hidden] { display: none; }

.offline-badge { margin-top: 2px; color: var(--warning); font-weight: 500; }
.offline-badge[hidden] { display: none; }

/* 두 종목 비교 */
/* 비교 칩(2차 디자인 5단계-3): 알약 모양 셀렉트, 비교 중이면 앞에 주황 점(차트의 비교 선 색) */
.compare-box { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: var(--fs-small); }
.compare-box select, .compare-box input {
  height: var(--control-height, 32px); width: 150px; max-width: 150px; padding: 0 10px; border: 1px solid var(--border); border-radius: 999px; /* 너비 고정: 항목이 채워질 때 자라며 옆을 밀지 않게 */
  background: none; color: var(--text); font: inherit;
}
.compare-box select:hover, .compare-box input:hover { border-color: var(--control); }
.compare-dot { display: none; width: 8px; height: 8px; border-radius: 50%; background: var(--chart-2); }
.compare-box.on .compare-dot { display: inline-block; }
.compare-box.on select, .compare-box.on input { border-color: var(--control); }
.compare-box [hidden] { display: none; }

/* ---------- 스켈레톤(첫 로드만): 실제 요소와 같은 박스 안을 --raised 블록으로 채운다 ---------- */
.sk {
  display: block; border-radius: var(--radius); background-color: var(--raised);
  background-image: linear-gradient(90deg, transparent 0%, color-mix(in srgb, var(--surface) 55%, transparent) 50%, transparent 100%);
  background-size: 200% 100%; animation: sk-shimmer 1.2s linear infinite;
}
@keyframes sk-shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }
.sk-label { height: 13px; margin: 0 0 4px; }
.sk-value { height: 28px; margin: 3px 0; }
.sk-line { height: 12px; }
.sk-row { pointer-events: none; }
body.skel #result { opacity: 1; }
body.skel #finding, body.skel #symbol-meta { border-radius: var(--radius); background: var(--raised); }
body.skel #finding { width: 45%; height: 18px; } /* 실제 한 줄(13px 글자) 높이와 같게 — 22px 이면 공개 때 아래가 4px 올라간다 */
body.skel #symbol-meta { width: 30%; height: 16px; }
body.skel #result .grid > :not(.chart-panel):not(.levels-panel), body.staging #result .grid > :not(.chart-panel):not(.levels-panel) { display: none; } /* staging: 첫 로드에서 표 넷이 다음 태스크에 그려지는 동안(3차 6단계) */
body.skel #result .panel { pointer-events: none; }
.chart-box.pending::after, body.skel .chart-box::after { content: ""; position: absolute; inset: 0; border-radius: var(--radius); background-color: var(--raised); background-image: linear-gradient(90deg, transparent, color-mix(in srgb, var(--surface) 55%, transparent), transparent); background-size: 200% 100%; animation: sk-shimmer 1.2s linear infinite; }
body.skel .level-price { width: 72px; height: 18px; margin: 3px 0; border-radius: var(--radius-control); background-color: var(--raised); background-image: linear-gradient(90deg, transparent, color-mix(in srgb, var(--surface) 55%, transparent), transparent); background-size: 200% 100%; animation: sk-shimmer 1.2s linear infinite; }
body.skel .level-sub { width: 60%; height: 48px; margin: 6px 0 0; border-radius: var(--radius-control); background-color: var(--raised); } /* 실제 설명 세 줄(48px) + margin-top 6 과 같게 */
@media (max-width: 860px) { .sk-value { height: 24px; } }
@media (prefers-reduced-motion: reduce) {
  .sk, .chart-box.pending::after, body.skel .chart-box::after, body.skel .level-price { animation: none; background-image: none; }
}
body.skel .hero { min-height: 164px; }
body.skel .hero-now > *, body.skel .hero-spark > *, body.skel .hero-share { visibility: hidden; }
/* 스켈레톤 블록은 빈 자식 위에 겹쳐 그린다(absolute) — 블록이 높이를 더하면 내용이 올 때 아래가 밀린다(3차 폰 성능: 스파크 +68/+84px 였다) */
body.skel .hero-now, body.skel .hero-spark { position: relative; }
body.skel .hero-now::after, body.skel .hero-spark::after { content: ""; position: absolute; left: 0; top: 0; border-radius: var(--radius); background-color: var(--raised); }
body.skel .hero-now::after { width: 70%; height: 90px; }
body.skel .hero-spark::after { right: 0; bottom: 0; }
body.skel .kpi { box-sizing: border-box; height: 106px; overflow: hidden; } /* 실제 KPI 카드 높이(데스크톱 106 · 폰 120)에 맞춘다 */
@media (max-width: 860px) { body.skel .hero { min-height: 260px; } body.skel .kpi { height: 120px; } }
.kpi-label:has(> .sk), .kpi-value:has(> .sk), .kpi-sub:has(> .sk) { display: flow-root; } /* 블록 마진이 부모 밖으로 새지 않게 */
body.skel #base-hint { min-height: 32px; }
body.skel .status { position: absolute; width: 1px; height: 1px; margin: 0; padding: 0; overflow: hidden; clip-path: inset(50%); } /* 안내는 유지하되 자리는 차지하지 않게 */

/* 2차 디자인 1단계-2: 카드 층 그림자(--edge·--shadow-*)와 호버 들림을 뺐다. 활성 종목 표식은 .watch[aria-current] 의 왼쪽 2px 테두리만 */

/* ---------- 노치·홈 인디케이터(viewport-fit=cover): 가장자리 안전 영역만큼 안쪽으로 ---------- */
@media (max-width: 860px) {
  .phonebar { padding-top: env(safe-area-inset-top); height: calc(52px + env(safe-area-inset-top)); }
  .canvas { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
  .sidebar { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
  .tabbar { padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
}

/* ---------- 터치 화면: 누를 수 있는 것은 최소 40px. 작은 아이콘·체크박스는 보이는 크기는 두고 누르는 영역만 44px ---------- */
@media (pointer: coarse) {
  :root { --control-height: 40px; }
  .filters { --control-height: 40px; }
  .segmented button, .btn, .mini-btn, .sheet-close, .card-link, .watch-edit, .level-copy, .phonebar .btn { min-height: 40px; }
  .watch-btn { width: 40px; height: 40px; }
  .level-name input, .panel-foot input, .ladder-inputs input, #q, #compare-input, select { min-height: 40px; }
  .info { position: relative; }
  .info::after { content: ''; position: absolute; left: 50%; top: 50%; width: 44px; height: 44px; transform: translate(-50%, -50%); }
  .check { min-height: 44px; }
}

/* ---------- 폰 표: 하락 사다리는 핵심 열만(나머지는 행을 눌러 펼침), 하락장 기록은 날짜 칸을 두 줄로 접어 네 열이 다 보이게 ---------- */
@media (max-width: 860px) {
  #dist th:nth-child(n+4), #dist td:nth-child(n+4) { display: none; }
  #dist th, #dist td { padding-left: 4px; padding-right: 4px; }
  #dist tbody tr[data-detail] { cursor: pointer; }
  #dist .sim-detail { display: table-row; }
  #dist .sim-detail td { display: table-cell; padding: 0; height: auto; text-align: left; white-space: normal; border-bottom: 1px solid var(--rule); min-width: 0; position: static; }
  #dist tr:last-child td { border-bottom: 0; }
  #dist tr.open > td { border-bottom-color: transparent; }
  #episodes td:first-child { white-space: normal; max-width: 12ch; line-height: 1.3; }
}

/* ---------- 낙폭 자 (2차 디자인 3단계-1) ----------
   0%(고점)부터 가장 깊은 값까지 한 줄. 지금 점·채움만 청록, 기준·저점매수는 회색 눈금(버튼: 누르면 매수 기준가 카드로).
   위 줄: 지금 이름표 / 가운데: 선 / 아래 줄: 눈금 이름표(겹치면 JS 가 뒤의 것을 숨긴다) */
.ruler { grid-column: 1 / -1; position: relative; height: 46px; margin-top: var(--space-1); }
.ruler-line { position: absolute; left: 0; right: 0; top: 24px; height: 2px; background: var(--rule); }
.ruler-fill { position: absolute; left: 0; top: 24px; height: 2px; background: var(--accent-color); }
.ruler-end { position: absolute; top: 31px; font-size: 11px; line-height: 14px; color: var(--faint); white-space: nowrap; }
.ruler-end.l { left: 0; }
.ruler-end.r { right: 0; }
/* 3차 6단계 접근성: 눈금 단추의 히트 영역 20 → 28px(보이는 눈금 2×14 는 그대로 가운데) */
.ruler-tick { position: absolute; top: 11px; width: 28px; height: 28px; margin-left: -14px; padding: 0; border: 0; background: none; cursor: pointer; }
.ruler-tick::before { content: ""; position: absolute; left: 13px; top: 7px; width: 2px; height: 14px; background: var(--control); }
.ruler-tick.bold::before { background: var(--muted); }
.ruler-tick.passive { pointer-events: none; cursor: default; } /* 이웃과 겹쳐 단추에서 뺀 눈금(layoutRuler) */
.ruler-tick:hover::before { background: var(--text); }
.ruler-tick:focus-visible { outline: 2px solid var(--accent-color); outline-offset: 1px; border-radius: 3px; }
.ruler-tick-label { position: absolute; top: 31px; transform: translateX(-50%); font-size: 11px; line-height: 14px; color: var(--faint); white-space: nowrap; pointer-events: none; }
.ruler-tick-label.bold { color: var(--muted); font-weight: 500; }
.ruler-tick-label[hidden] { display: none; }
.ruler-now { position: absolute; top: 25px; width: 14px; height: 14px; margin: -7px 0 0 -7px; border: 2px solid var(--surface); border-radius: 50%; background: var(--accent-color); background-clip: padding-box; } /* 3차 6단계: 링은 그림자 대신 테두리 */
.ruler-now-label { position: absolute; top: 2px; transform: translateX(-50%); font-size: 13px; line-height: 16px; font-weight: 600; color: var(--text); white-space: nowrap; }
.ruler-now-label.edge-l { transform: none; }
.ruler-now-label.edge-r { transform: translateX(-100%); }
.level.is-flash { animation: level-flash 1.2s ease-out; }
@keyframes level-flash { from { background: color-mix(in srgb, var(--accent-color) 18%, transparent); } to { background: transparent; } }
@media (prefers-reduced-motion: reduce) { .level.is-flash { animation: none; } }

/* ---------- 기간 칩 (2차 디자인 5단계) ----------
   기간 이름 + 그 기간 수익률(한국식 색)을 한 칩에. 누르면 조회 기간이 바뀐다(KPI·표·차트 모두). 좁으면 가로 스크롤.
   날짜 직접 입력은 데스크톱에서도 '직접'을 눌렀을 때만 */
.periods { display: flex; align-items: center; gap: 6px; min-width: 0; max-width: 100%; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; padding: 2px 0; }
.periods::-webkit-scrollbar { display: none; }
.period {
  flex: none; display: inline-flex; align-items: center; gap: 4px; height: 30px; padding: 0 9px;
  border: 1px solid var(--border); border-radius: 999px; background: none; color: var(--muted);
  font: inherit; font-size: 12px; line-height: 16px; cursor: pointer; white-space: nowrap;
}
.period[hidden] { display: none; } /* '직접' 은 칩이 그려질 때 함께 나타난다(index.html 의 hidden) — .period 의 display 가 UA 의 [hidden] 을 덮으므로 */
.period:hover { color: var(--text); border-color: var(--control); }
.period[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--surface); font-weight: 500; }
.period[aria-pressed="true"] .period-ret { color: inherit; }
.period-ret { font-weight: 600; font-variant-numeric: tabular-nums; }
.period-ret.gain { color: var(--positive); }
.period-ret.loss { color: var(--negative); }
.period:focus-visible { outline: 2px solid var(--accent-color); outline-offset: 2px; }
.filters .dates { display: none; }
body.dates-open .filters .dates { display: flex; }
@media (pointer: coarse) { .period { height: 36px; } }

/* ---------- 미니 히어로 (2차 디자인 6단계-1, 폰) ----------
   히어로가 상단 바 아래로 사라지면(.phonebar.mini) 브랜드 이름 자리에 종목명 + 고점 대비 숫자. 토스·네이버의 붙는 머리와 같은 관습 */
.phonebar-mini { display: none; align-items: baseline; gap: 8px; min-width: 0; padding: 0; border: 0; background: none; color: var(--text); font: inherit; text-align: left; cursor: pointer; }
.phonebar.mini .brand-name { display: none; }
.phonebar.mini .phonebar-mini { display: inline-flex; }
.mini-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; font-weight: 600; }
.mini-dd { flex: none; font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }
.phonebar-mini:focus-visible { outline: 2px solid var(--accent-color); outline-offset: 2px; border-radius: 4px; }

/* 3차 6단계 CLS: 내용이 화면보다 길어져 세로 스크롤바가 생길 때 본문이 15px 좁아지며 밀리던 것 — 스크롤바 자리를 늘 예약한다(겹침 스크롤바인 폰·맥은 영향 없음) */
html { scrollbar-gutter: stable; }
