:root {
  color-scheme: light;
  --page: #f2f4f6;
  --surface: #ffffff;
  --text: #191f28;
  --text-2: #4e5968;
  --muted: #8b95a1;
  --grid: #e5e8eb;
  --axis: #d1d6db;
  --border: rgba(2, 32, 71, 0.08);
  --card-border: transparent;
  --shadow: 0 1px 2px rgba(2, 32, 71, 0.04), 0 8px 24px rgba(2, 32, 71, 0.06);
  --shadow-lift: 0 2px 4px rgba(2, 32, 71, 0.05), 0 16px 36px rgba(2, 32, 71, 0.10);
  --accent: #3182f6;
  --accent-soft: rgba(49, 130, 246, 0.12);
  --accent-text: #1b64da;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  /* 국내 관례: 상승 빨강, 하락 파랑 */
  --up: #e42939;
  --up-soft: rgba(240, 68, 82, 0.11);
  --down: #1b64da;
  --down-soft: rgba(49, 130, 246, 0.11);
  --good: #0ca30c;
  --good-soft: rgba(12, 163, 12, 0.11);
  --notable: #008300;   /* 주주 표에서 강조하는 기관명 */
  --famous: #7c3aed;    /* 기업정보에서 유명한 회장·CEO 이름 */
  --positive: #1b64da;  /* 뉴스 제목의 호재 표현 */
  --warning: #fab219;
  --warning-soft: rgba(250, 178, 25, 0.16);
  --critical: #d03b3b;
  --critical-soft: rgba(208, 59, 59, 0.10);
  --wash: rgba(2, 32, 71, 0.05);
  --wash-strong: rgba(2, 32, 71, 0.08);
  --radius: 20px;
}
/* 어두운 색 묶음. 기기 설정이 어두울 때, 또는 설정에서 어두운 배경색을 골랐을 때(data-theme) 쓴다. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #101113;
    --surface: #1b1c1f;
    --text: #ffffff;
    --text-2: #b0b8c1;
    --muted: #8b95a1;
    --grid: #2b2d33;
    --axis: #3a3d45;
    --border: rgba(255, 255, 255, 0.10);
    --card-border: rgba(255, 255, 255, 0.06);
    --shadow: none;
    --shadow-lift: 0 16px 36px rgba(0, 0, 0, 0.5);
    --accent: #3d8bfd;
    --accent-soft: rgba(61, 139, 253, 0.18);
    --accent-text: #7fb3ff;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --up: #ff6b76;
    --up-soft: rgba(255, 107, 118, 0.16);
    --down: #6aa8ff;
    --down-soft: rgba(106, 168, 255, 0.16);
    --good-soft: rgba(12, 163, 12, 0.20);
    --notable: #34c759;
    --famous: #b69cff;
    --positive: #6aa8ff;
    --warning-soft: rgba(250, 178, 25, 0.18);
    --critical-soft: rgba(230, 103, 103, 0.18);
    --wash: rgba(255, 255, 255, 0.06);
    --wash-strong: rgba(255, 255, 255, 0.10);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #101113;
  --surface: #1b1c1f;
  --text: #ffffff;
  --text-2: #b0b8c1;
  --muted: #8b95a1;
  --grid: #2b2d33;
  --axis: #3a3d45;
  --border: rgba(255, 255, 255, 0.10);
  --card-border: rgba(255, 255, 255, 0.06);
  --shadow: none;
  --shadow-lift: 0 16px 36px rgba(0, 0, 0, 0.5);
  --accent: #3d8bfd;
  --accent-soft: rgba(61, 139, 253, 0.18);
  --accent-text: #7fb3ff;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --up: #ff6b76;
  --up-soft: rgba(255, 107, 118, 0.16);
  --down: #6aa8ff;
  --down-soft: rgba(106, 168, 255, 0.16);
  --good-soft: rgba(12, 163, 12, 0.20);
  --notable: #34c759;
  --famous: #b69cff;
  --positive: #6aa8ff;
  --warning-soft: rgba(250, 178, 25, 0.18);
  --critical-soft: rgba(230, 103, 103, 0.18);
  --wash: rgba(255, 255, 255, 0.06);
  --wash-strong: rgba(255, 255, 255, 0.10);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font: 15px/1.5 "Pretendard Variable", Pretendard, system-ui, -apple-system, "Segoe UI", "Malgun Gothic", sans-serif;
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p { margin: 0; }
button, input, select { font: inherit; color: inherit; letter-spacing: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

button {
  border: 0;
  background: var(--wash-strong);
  border-radius: 12px;
  padding: 10px 16px;
  min-height: 44px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s, opacity 0.15s;
}
button:hover { background: var(--axis); }
button:active { transform: scale(0.97); }
button:disabled { opacity: 0.5; cursor: default; transform: none; }
button.primary { background: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-text); }
button.danger { background: var(--critical-soft); color: var(--critical); }
.icon { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- 상단 바와 탭 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: calc(10px + env(safe-area-inset-top)) max(16px, calc((100% - 1120px) / 2)) 10px;
}
/* 넓은 화면: 종목스캔·새로고침 버튼(과 그 아래 현재가 갱신 시각)은 창 오른쪽 끝에 붙인다. 앱 이름은 그대로 둔다. */
@media (min-width: 1100px) {
  .topbar { padding-right: 24px; }
}
/* 흐림 효과를 가상 요소에 둬야 아래의 고정 탭(position: fixed)이 화면 기준으로 붙는다 */
.topbar::before {
  content: ""; position: absolute; inset: 0; z-index: -1;
  background: color-mix(in srgb, var(--page) 78%, transparent);
  -webkit-backdrop-filter: saturate(1.6) blur(16px); backdrop-filter: saturate(1.6) blur(16px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; }
.brand img { width: 42px; height: 42px; border-radius: 12px; }
.brand span { font-size: 31px; font-weight: 900; letter-spacing: -0.04em; line-height: 1.1; color: var(--text); }
.brand b { font-weight: inherit; }
.brand-soso { color: #f58220; }   /* 주황 */
.brand-invest { color: #e42939; } /* 빨강 */
.top-actions { display: flex; gap: 8px; }
.top-actions button { display: flex; align-items: center; gap: 6px; border-radius: 999px; padding: 8px 18px 8px 14px; min-height: 40px; white-space: nowrap; }
/* 버튼 이름 아래에 작은 글씨 한 줄 (자동 새로고침 상태와 남은 시간) */
.stacked { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.15; }
.stacked small { font-size: 10px; font-weight: 600; opacity: 0.85; font-variant-numeric: tabular-nums; }
.stacked small:empty { display: none; }
#scan-btn.busy .icon { animation: pulse 0.7s ease-in-out infinite alternate; }
#refresh-btn.busy .icon { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { to { opacity: 0.25; } }

/* 넓은 화면: 메뉴를 상단 바 한가운데에 고정해 올려 둔다 (상단 바 높이 62px 안에 40px 버튼) */
.tabs {
  position: fixed; z-index: 11; top: calc(11px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  display: flex; gap: 4px;
}
.tabs button {
  display: flex; align-items: center; gap: 6px;
  background: none; color: var(--text-2); border-radius: 999px; padding: 8px 16px; min-height: 40px; font-size: 15px; font-weight: 700;
  white-space: nowrap;
}
/* 상단 메뉴가 들어가기 빠듯한 폭(1100~1399px)에서는 여백을 줄여 앱 이름·버튼과 겹치지 않게 한다 */
@media (min-width: 1100px) and (max-width: 1399px) {
  .tabs button { padding: 8px 10px; font-size: 14px; gap: 4px; }
}
.tabs button:hover { background: var(--wash-strong); color: var(--text); }
/* 선택된 메뉴는 진한 바탕에 밝은 글자로 뚜렷하게 */
.tabs button[aria-selected="true"] { color: var(--page); background: var(--text); font-weight: 800; }

/* 상단에 앱 이름·메뉴·버튼 두 개가 한 줄로 들어가지 않는 폭에서는 메뉴를 화면 아래로 내린다 */
@media (max-width: 1099px) {
  .tabs {
    position: fixed; left: 0; right: 0; top: auto; bottom: 0; transform: none; z-index: 10; gap: 0;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    /* 반투명·흐림 효과를 쓰지 않는다. 아이폰에서 그 효과가 걸린 고정 요소가 스크롤 중에 제자리를 벗어나는 일이 있다. */
    background: var(--surface);
    border-top: 1px solid var(--border);
  }
  /* 메뉴 아래로 같은 바탕색을 길게 이어 붙인다. 브라우저의 아래쪽 도구 막대가 나타나거나 사라지면서
     메뉴가 화면 맨 아래에서 잠깐 떠도, 그 틈으로 뒤의 종목 정보가 비치지 않는다. */
  .tabs::after { content: ""; position: absolute; left: 0; right: 0; top: 100%; height: 200px; background: var(--surface); }
  .tabs button { flex: 1; flex-direction: column; gap: 3px; padding: 6px 0; font-size: 13px; font-weight: 800; border-radius: 12px; color: var(--text-2); }
  .tabs button:hover { background: none; }
  .tabs button[aria-selected="true"] { background: none; color: var(--accent-text); }
  .tabs .icon { width: 24px; height: 24px; }
  .tabs button[aria-selected="true"] .icon { stroke-width: 2.6; }
  /* 좁은 화면: 앱 이름과 버튼 두 개가 한 줄에 들어가도록 조금씩 줄인다 */
  .topbar { gap: 8px; }
  .brand { gap: 7px; min-width: 0; }
  .brand img { width: 30px; height: 30px; border-radius: 9px; }
  .brand span { font-size: 25px; }
  .top-actions { gap: 5px; }
  .top-actions button { gap: 4px; padding: 6px 10px 6px 8px; min-height: 38px; font-size: 13px; }
  .top-actions .icon { width: 16px; height: 16px; }
  main { padding-bottom: calc(96px + env(safe-area-inset-bottom)) !important; }
}

.offline { max-width: 1120px; margin: 12px auto 0; padding: 10px 14px; border-radius: 12px; background: var(--warning-soft); font-size: 14px; font-weight: 600; }
@media (max-width: 1152px) { .offline { margin: 12px 16px 0; } }

@media (max-width: 374px) {
  .brand img { display: none; }
}

/* 현재가 자동 새로고침이 켜져 있을 때 마지막으로 받은 시각 */
/* 현재가 갱신 시각: 위쪽 버튼 바로 아래에 떠 있어 상단 바 높이를 바꾸지 않는다.
   넓은 화면은 종목스캔 버튼의 왼쪽 끝에, 휴대폰은 화면 폭이 좁아 버튼 묶음의 오른쪽 끝에 맞춘다. */
.top-actions { position: relative; }
.quote-time {
  position: absolute; top: calc(100% + 18px); right: 0; /* 상단 바 아래 경계선보다 아래에 오도록 */ margin: 0; white-space: nowrap; text-align: right;
  font-size: 12px; font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums;
}
@media (min-width: 1100px) {
  .quote-time { left: 0; right: auto; text-align: left; }
}
.seconds { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text-2); }
.seconds input { width: 6.5em; padding: 8px 10px; border: 0; border-radius: 10px; background: var(--wash-strong); color: var(--text); font-size: 16px; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.seconds input:focus { outline: 2px solid var(--accent); }
.seconds.off { opacity: 0.45; }

main { max-width: 1152px; margin: 0 auto; padding: 8px 16px 56px; }
main > section { animation: rise 0.25s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

/* ---------- 탭 머리말 ---------- */
.hero { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; padding: 20px 4px 14px; }
.eyebrow { font-size: 13px; font-weight: 600; color: var(--accent-text); min-height: 20px; }
.hero-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: 8px; min-width: 0; }
/* 투자기준: 초기화 버튼들에서 조금 띄워 놓는, 미리 정해 둔 설정을 고르는 콤보박스 */
.hero-actions select {
  margin-left: 4px; min-height: 44px; padding: 8px 34px 8px 16px; border: 0; border-radius: 14px; background-color: var(--surface); box-shadow: inset 0 0 0 1px var(--border);
  font-size: 15px; font-weight: 700; color: var(--text); cursor: pointer; -webkit-appearance: none; appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat;
}
.hero-actions select:focus { outline: 2px solid var(--accent); }
/* 좁은 화면에서 버튼들이 두 줄이 되어도 화면 이름은 줄바꿈하지 않는다 */
#tab-rules .hero h2 { white-space: nowrap; }
.hero h2 { font-size: 28px; font-weight: 800; letter-spacing: -0.035em; line-height: 1.25; }
.hero h2 em { font-style: normal; color: var(--accent-text); }
.status { color: var(--text-2); font-size: 14px; margin-top: 2px; min-height: 21px; }
.status.error { color: var(--critical); }
#favorites-status:empty { display: none; } /* 알릴 것이 없을 때는 빈 줄을 남기지 않는다 */
.status.running { color: var(--text); font-weight: 600; }
.progress { height: 8px; border-radius: 4px; background: var(--wash-strong); overflow: hidden; margin: 0 4px 12px; }
.progress div { height: 100%; width: 0; border-radius: 4px; background: var(--accent); transition: width 0.6s; }
.progress.waiting div { width: 30%; animation: progress-slide 1.2s ease-in-out infinite alternate; }
@keyframes progress-slide { from { margin-left: 0; } to { margin-left: 70%; } }

.filter { display: flex; gap: 8px; overflow-x: auto; padding: 2px 4px 12px; scrollbar-width: none; }
.filter[hidden] { display: none; } /* 스캔 결과가 없을 때 */
.filter::-webkit-scrollbar { display: none; }
.filter button {
  display: flex; align-items: center; gap: 6px; white-space: nowrap;
  border-radius: 999px; min-height: 38px; padding: 6px 14px; font-size: 14px;
  background: var(--surface); color: var(--text-2); box-shadow: inset 0 0 0 1px var(--border);
}
.filter button b { font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; }
.filter button[aria-pressed="true"] { background: var(--text); color: var(--page); box-shadow: none; }
.filter button[aria-pressed="true"] b { color: inherit; opacity: 0.7; }
/* 휴대폰 폭에서는 여백을 줄여 네 개가 한 줄에 다 보이게 한다 */
@media (max-width: 480px) {
  .filter { gap: 6px; padding-left: 0; padding-right: 0; flex-wrap: wrap; }
  .filter button { flex: 1 1 auto; justify-content: center; gap: 4px; padding: 6px 8px; min-height: 36px; font-size: 12.5px; }
}
@media (max-width: 374px) {
  .filter { gap: 4px; }
  .filter button { padding: 6px 5px; font-size: 12px; }
}

/* 정렬 메뉴: 목록 바로 위 오른쪽 */
.sort { display: flex; justify-content: flex-end; align-items: center; gap: 8px; margin: 0 4px 10px; font-size: 13px; font-weight: 600; color: var(--text-2); }
.sort select {
  padding: 7px 30px 7px 12px; border: 0; border-radius: 999px; background-color: var(--surface); box-shadow: inset 0 0 0 1px var(--border);
  font-size: 14px; font-weight: 700; color: var(--text); cursor: pointer; -webkit-appearance: none; appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat;
}
/* 정렬해서 보는 중에는 순서를 직접 바꿀 수 없으므로 화살표를 숨기고 끌기 커서를 없앤다 */
.grid[data-sorted] > .card { cursor: auto; }
.grid[data-sorted] .tool { display: none; }

/* ---------- 카드 ---------- */
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr)); }
.card {
  background: var(--surface); border: 1px solid var(--card-border); border-radius: var(--radius);
  padding: 20px; min-width: 0; box-shadow: var(--shadow); transition: transform 0.2s, box-shadow 0.2s;
}
@media (hover: hover) {
  .grid > .card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lift); }
}
/* 끌어서 순서 바꾸기 */
.grid > .card, .settings > .card { cursor: grab; scroll-margin-top: 84px; } /* 고정된 상단 바에 가리지 않을 만큼 띄운다 */
/* 설정 화면은 끄는 동안 항목의 제목만 남긴다 */
.settings.sorting > .card > :not(h3):not(.card-title):not(.setting-name) { display: none; }
.settings.sorting > .card h3 { margin: 0; }
.card.dragging { position: relative; z-index: 20; pointer-events: none; transition: none; box-shadow: var(--shadow-lift); opacity: 0.94; outline: 2px solid var(--accent); }
/* 끄는 동안에는 카드를 머리 부분(도구 줄, 종목과 가격)만 남기고 접어서, 여러 카드가 한 화면에 들어오게 한다 */
.grid.sorting > .card > :not(.card-tools):not(.card-head) { display: none; }
body.drag-active, body.drag-active * { cursor: grabbing !important; user-select: none; -webkit-user-select: none; }
body.drag-active .grid > .card:not(.dragging) { transform: none; }
@media (hover: none) {
  /* 꾹 눌러 끌 때 글자 선택 창이나 미리보기 창이 뜨지 않게 한다 */
  .grid > .card, .settings > .card { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
}
.card-head { display: flex; align-items: flex-start; gap: 12px; }
.title { flex: 1; min-width: 0; }
/* 카드 맨 위 오른쪽의 도구 줄: 순서 화살표와 즐겨찾기 별표 */
.card-tools { display: flex; justify-content: flex-end; gap: 2px; margin: -10px -10px 0 0; }
.tool, .star { flex: none; min-height: 34px; width: 34px; padding: 0; display: grid; place-items: center; border-radius: 50%; background: none; color: var(--muted); }
.tool:hover, .star:hover { background: var(--wash); color: var(--text); }
.tool .icon { width: 20px; height: 20px; }
/* 맨 앞 카드의 "앞으로", 맨 뒤 카드의 "뒤로"는 옮길 곳이 없으니 흐리게 */
.card:first-child .tool[data-move="-1"], .card:last-child .tool[data-move="1"] { opacity: 0.3; }
/* 즐겨찾기 별표. 켜면 노란색으로 채워진다. */
.star { color: var(--axis); }
.star .icon { width: 22px; height: 22px; }
.star[aria-pressed="true"] { color: #f5a623; }
.star[aria-pressed="true"] .icon { fill: currentColor; }
.inline-form { display: flex; gap: 8px; flex: none; }
.inline-form input { width: 8.5em; padding: 8px 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text); font-size: 16px; font-weight: 600; text-transform: uppercase; }
.inline-form input::placeholder { font-weight: 500; text-transform: none; }
@media (max-width: 559px) {
  /* 좁은 화면에서는 제목 아래에 입력칸을 한 줄로 둔다 */
  #tab-favorites .hero { flex-direction: column; align-items: stretch; }
  /* 백테스트·투자기준: 화면 이름 바로 아래 줄에 버튼들을 오른쪽으로 붙여 둔다 */
  #tab-backtest .hero, #tab-rules .hero { flex-direction: column; align-items: stretch; gap: 8px; }
  /* 화면 이름과 같은 줄의 오른쪽 끝에 보이기/숨기기 */
  .hero .hero-title { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
  .hero .hero-fold { margin-left: 0; }
  /* 투자기준: 초기화·초기화 지정이 첫 줄, 설정 적용·저장이 둘째 줄 */
  #tab-rules .hero-actions { row-gap: 4px; } /* 줄을 나누는 빈 칸의 위아래로 한 번씩 들어가 8px이 된다 */
  #tab-rules .hero-actions::after { content: ""; flex-basis: 100%; order: 1; }
  #tab-rules .hero-actions select, #rules-preset-save { order: 2; }
  .inline-form input { flex: 1; width: auto; min-width: 0; }
}
.sym { display: block; font-size: 20px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.3; }
.exchange { margin-left: 8px; font-size: 12px; font-weight: 600; letter-spacing: 0; color: var(--muted); }
/* 종목명은 자르지 않고, 길면 다음 줄로 넘긴다 */
.name { display: block; color: var(--text); font-size: 14px; font-weight: 600; line-height: 1.4; margin-top: 2px; overflow-wrap: anywhere; }
.price { text-align: right; font-size: 20px; font-weight: 800; letter-spacing: -0.02em; white-space: nowrap; line-height: 1.3; font-variant-numeric: tabular-nums; }
.delta { display: inline-block; margin-top: 2px; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--wash); color: var(--text-2); }
.delta.up { background: var(--up-soft); color: var(--up); }
.delta.down { background: var(--down-soft); color: var(--down); }
/* 가격 아래 한 줄: 프리마켓·애프터마켓 가격 (그 시간대의 자료가 있을 때만 보인다) */
/* 현재가 바로 아래: 전일 종가와 그에 견준 등락률. 비어 있어도 줄을 나눠 그 아래 표시가 다음 줄에 오게 한다. */
.day { display: block; font-size: 12px; font-weight: 600; letter-spacing: 0; color: var(--text-2); }
.day b { font-weight: 800; color: var(--text); }
.day .up { color: var(--up); }
.day .down { color: var(--down); }
/* 스캔이 필수 조건을 판정할 때 쓴 값 */
.passed { margin: 8px 0 0; font-size: 12px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.passed b { font-weight: 700; color: var(--muted); margin-right: 4px; }
.ext { display: block; margin-top: 4px; font-size: 12px; font-weight: 600; letter-spacing: 0; color: var(--text-2); }
.ext b { font-weight: 800; color: var(--text); }
.up { color: var(--up); }
.down { color: var(--down); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 14px 0; }
.chip { font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-text); }
.chip.plain { background: var(--wash); color: var(--text-2); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px 8px; margin: 14px 0; padding: 12px 14px; border-radius: 14px; background: var(--wash); }
.stats div { min-width: 0; }
.stats span { display: block; font-size: 12px; color: var(--muted); white-space: nowrap; }
.stats span i { font-style: normal; font-weight: 700; } /* 평가손익 옆의 매수가 대비 수익률 */
.stats b { display: block; font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }

.card-actions { display: flex; gap: 8px; margin-top: 14px; }
/* 기업정보·뉴스·삭제·기록 네 버튼을 같은 너비로 나눈다 */
.card-actions button { flex: 1 1 0; min-width: 0; padding-left: 2px; padding-right: 2px; font-size: 14px; white-space: nowrap; }
.news { list-style: none; margin: 14px 0 0; padding: 4px 14px; font-size: 14px; border-radius: 14px; background: var(--wash); }
.news li { padding: 10px 0; }
.news li + li { border-top: 1px solid var(--border); }
.news a { color: var(--text); text-decoration: none; font-weight: 500; }
.news a:hover { text-decoration: underline; }
.news small { display: block; color: var(--muted); margin-top: 2px; }
.news b.positive { color: var(--positive); font-weight: 800; } /* 뉴스 제목의 호재 표현 */

/* ---------- 차트 ---------- */
.chart { position: relative; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; color: var(--text-2); margin-bottom: 2px; }
.legend i { display: inline-block; width: 14px; height: 2px; border-radius: 1px; vertical-align: middle; margin-right: 4px; }
.ranges { display: flex; gap: 2px; padding: 3px; margin-bottom: 10px; border-radius: 12px; background: var(--wash); }
.ranges button { flex: 1; min-height: 30px; padding: 4px 0; border-radius: 9px; background: none; color: var(--text-2); font-size: 12px; font-weight: 700; white-space: nowrap; }
.ranges button:hover { background: var(--wash-strong); }
.ranges button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), inset 0 0 0 1px var(--border); }
.chart-note { display: grid; place-items: center; min-height: 272px; color: var(--muted); font-size: 14px; }
.legend .entry-key { height: 1px; background: var(--muted); }
.legend .now-key { height: 8px; border-radius: 3px; background: var(--series-1); }
.chart svg { display: block; width: 100%; touch-action: pan-y; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 10px; font-variant-numeric: tabular-nums; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
/* 5Y·전체처럼 긴 기간은 선이 서로 붙어 다니므로 가늘게 그려야 구분된다 */
.chart svg.long .line { stroke-width: 1; }
.chart .entry { stroke: var(--muted); stroke-width: 1; }
.chart .cross { stroke: var(--axis); stroke-width: 1; }
.chart .dot { stroke: var(--surface); stroke-width: 2; }
.chart .now-tag { fill: var(--series-1); }
.chart .now-text { fill: #fff; font-size: 10px; font-weight: 700; font-variant-numeric: tabular-nums; }
.chart .vol { fill: var(--axis); }
.chart .vol.latest { fill: var(--muted); }
.tooltip .vol-key { height: 8px; background: var(--muted); }
.chart .extreme-dot { fill: var(--text); stroke: var(--surface); stroke-width: 2; }
.chart .extreme { fill: var(--text); font-size: 11px; font-weight: 700; font-variant-numeric: tabular-nums; paint-order: stroke; stroke: var(--surface); stroke-width: 3px; }
.tooltip {
  position: absolute; top: 20px; pointer-events: none; z-index: 2;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 8px 10px; font-size: 12px; white-space: nowrap; box-shadow: var(--shadow-lift);
}
.tooltip b { display: block; font-weight: 700; margin-bottom: 2px; }
.tooltip span { display: flex; justify-content: space-between; gap: 12px; font-variant-numeric: tabular-nums; }
.tooltip i { display: inline-block; width: 10px; height: 2px; vertical-align: middle; margin-right: 4px; }

/* ---------- 보유 종목 ---------- */
.slots { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin: 0 0 16px; }
.slot { border-radius: 16px; padding: 12px 6px; text-align: center; font-size: 12px; font-weight: 600; background: var(--surface); box-shadow: var(--shadow); border: 1px solid var(--card-border); min-width: 0; color: var(--text-2); }
.slot b { display: block; font-size: 15px; font-weight: 800; color: var(--text); overflow: hidden; text-overflow: ellipsis; }
.slot.empty { background: none; box-shadow: none; border: 1.5px dashed var(--axis); color: var(--muted); }
.slot.empty b { color: var(--muted); }
.slot.cash { background: var(--wash); box-shadow: none; }

.alerts { list-style: none; margin: 14px 0; padding: 0; display: grid; gap: 8px; font-size: 14px; }
.alerts li { display: flex; gap: 8px; align-items: flex-start; padding: 10px 12px; border-radius: 12px; background: var(--wash); }
.alerts li.critical { background: var(--critical-soft); }
.alerts li.warning { background: var(--warning-soft); }
.alerts li.profit { background: var(--accent-soft); }
.alerts li.good { background: var(--good-soft); }
.alerts strong { white-space: nowrap; font-weight: 800; }


.closed { margin-top: 20px; font-size: 14px; }
.closed h3 { font-size: 16px; font-weight: 800; margin-bottom: 8px; }
.closed table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.closed th, .closed td { text-align: right; padding: 10px 4px; border-top: 1px solid var(--grid); }
.closed th:first-child, .closed td:first-child { text-align: left; font-weight: 700; }
.closed tr:first-child th { border-top: 0; color: var(--muted); font-weight: 600; font-size: 12px; }

/* ---------- 규칙 · 설정 ---------- */
.rules { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr)); }
.rules-stack { display: grid; gap: 16px; align-content: start; }
/* 좁은 화면: 묶음마다 상자 하나씩, 매수 공통조건 → 매수 신호 → 매도 신호 → 분산투자 순서로 놓는다 */
.rules-main { display: contents; }
.rules-stack { order: 1; }
.rules-main > .diversify { order: 2; }
/* 넓은 화면: 묶음마다 상자를 띄우지 않고, 흰 판 하나를 세로선으로 나눈다. 왼쪽에는 조건이 많은 매수 공통조건을 두 줄(단)로 놓고
   그 아래에 분산투자를 두며, 매수 신호·매도 신호는 오른쪽 한 줄에 위아래로 놓아 1920×1080 화면에 한 번에 다 보이게 한다.
   휴대폰 화면은 묶음마다 상자인 지금 모양 그대로다. */
@media (min-width: 1100px) {
  main:has(#tab-rules:not([hidden])) { max-width: 1400px; }
  .rules {
    grid-template-columns: 2fr 1fr; gap: 0; align-items: stretch;
    padding: 20px 0; border-radius: var(--radius, 20px); background: var(--surface); box-shadow: var(--shadow);
  }
  .rules-main { display: block; min-width: 0; }
  .rules-main > .card, .rules-stack > .card { margin: 0; padding: 0 28px; border-radius: 0; background: none; box-shadow: none; }
  .rules > * + * { border-left: 1px solid var(--grid); }
  .rules-stack { gap: 0; }
  /* 묶음 사이의 위아래 여백은 좁게 두어 한 화면에 들어오게 한다 */
  .rules-stack > .card + .card, .rules-main > .card + .card { margin-top: 10px; padding-top: 12px; border-top: 1px solid var(--grid); }
  .rules-main .diversify h3 { margin-bottom: 6px; }
  .rules-stack h3 { margin-bottom: 6px; }
  /* 매수 공통조건: 조건을 두 단으로 흘려 놓는다. 제목은 두 단 위에 걸치고, 한 조건이 단 사이에서 잘리지 않게 한다 */
  .rules-main > .card.wide { columns: 2; column-gap: 56px; column-rule: 1px solid var(--grid); }
  .rules-main > .card.wide h3 { column-span: all; }
  .rules-main > .card.wide .rule { break-inside: avoid; }
  /* 분산투자: 위의 두 단과 줄이 맞게 자본금과 주식을 반씩 나란히 놓는다 */
  .rules-main > .diversify { display: grid; grid-template-columns: 1fr 1fr; column-gap: 56px; }
  .rules-main > .diversify h3 { grid-column: 1 / -1; }
  .rules-main > .diversify .rule { border-top: 0; }
  .rules .rule { min-height: 38px; padding: 2px 0; }
  .rules .rule.stack { padding: 5px 0; }
  .rules .rule input[type="number"], .rules .rule input[type="text"] { padding: 2px 8px; margin: 1px 0; }
  .rules h3 { margin-bottom: 14px; } /* 제목과 조건 목록이 떨어져 보이게 */
}
.rules h3, .settings h3, .bt-rules h3 { font-size: 17px; font-weight: 800; letter-spacing: -0.02em; margin-bottom: 8px; }
.rules h3 { margin-bottom: 12px; } /* 투자기준: 묶음 제목과 그 아래 조건 사이를 띄운다 */
/* 제목 옆의 "공통조건만 사용" 체크박스 */
.rules h3 .only { display: inline-flex; align-items: center; gap: 5px; margin-left: 12px; font-size: 13px; font-weight: 700; letter-spacing: 0; color: var(--text-2); cursor: pointer; vertical-align: middle; }
.rules h3 .only input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }
/* 공통조건만 쓰는 동안 매수 신호는 흐리게 (체크하는 즉시 바뀌도록 화면을 다시 그리지 않고 CSS로 처리한다) */
.rules:has(input[name="common_only"]:checked) .card.buy .rule { opacity: 0.4; }
.rules:has(input[name="common_only"]:checked) .card.buy h3 small::after { content: " · 적용 안 함"; }
/* 공통조건을 빼는 동안 공통조건은 흐리게. 주가 조건과, 스캔 대상을 정하는 ETF 포함, 레버리지·인버스 ETF 제외는 그대로 쓴다 */
.rules:has(input[name="skip_common"]:checked) .card.wide .rule:not(:has(input[name="use_price"], input[name="include_etf"], input[name="exclude_leveraged"])) { opacity: 0.4; }
.rules h3 .only + .only { margin-left: 10px; }
.rules h3 small, .bt-rules h3 small { margin-left: 6px; font-size: 13px; font-weight: 600; color: var(--muted); letter-spacing: 0; }
/* 한 줄에 스위치 · 이름 · 기준 숫자. 이름은 왼쪽, 숫자는 오른쪽에 붙이고, 폭이 모자라면 숫자가 다음 줄 오른쪽으로 내려간다. */
.rule { display: flex; gap: 12px; align-items: center; min-height: 52px; padding: 6px 0; border-top: 1px solid var(--grid); }
.rules h3 + .rule { border-top: 0; }
.rule > div { flex: 1; min-width: 0; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 2px 10px; transition: opacity 0.15s; }
.rule b { font-size: 15px; }
.rule p { margin-left: auto; display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: 0 10px; color: var(--text-2); font-size: 14px; line-height: 1.5; }
/* 두 줄 배치: 첫 줄 스위치 + 이름(왼쪽), 둘째 줄 기준 숫자(다른 조건처럼 오른쪽 정렬) */
.rule.stack { flex-wrap: wrap; row-gap: 4px; padding: 10px 0; }
.rule.stack p { margin-left: 0; flex-basis: 100%; justify-content: flex-end; transition: opacity 0.15s; }
.rule.stack:has(.switch input:not(:checked)) > p { opacity: 0.45; }
/* 조건 이름 옆의 "?" 설명 버튼 (필수 조건 제목 옆에도 있다) */
.rules h3 .help, .bt-rules h3 .help { margin-left: 6px; vertical-align: 2px; }
.rule-name { display: inline-flex; align-items: center; gap: 6px; }
.rules .help, .bt-rules .help, .backtest-form .help, #backtest-result .help {
  flex: none; width: 22px; height: 22px; min-width: 0; min-height: 0; padding: 0; border: 0; border-radius: 50%;
  background: var(--wash-strong); color: var(--text-2); font-size: 13px; font-weight: 800; line-height: 22px; cursor: pointer;
}
/* 마우스를 올리면 앱 아이콘과 같은 노랑. 노랑 위에서는 흰 글자가 안 보여 진한 글자를 쓴다 */
.rules .help:hover, .rules .help:focus-visible, .bt-rules .help:hover, .bt-rules .help:focus-visible, .backtest-form .help:hover, .backtest-form .help:focus-visible,
#backtest-result .help:hover, #backtest-result .help:focus-visible { background: #ffd400; color: #1a1a1a; }
.help-figure { display: block; width: 100%; max-width: 420px; margin: 0 auto; }
.help-figure text { fill: var(--text-2); font-size: 11px; }
.help-figure .guide { stroke: var(--muted); stroke-width: 1.5; stroke-dasharray: 4 4; }
.help-figure .axis { stroke: var(--grid); stroke-width: 1; }
.help-numbers div { padding: 8px 0; border-top: 1px solid var(--grid); }
.help-numbers div:first-child { border-top: 0; }
.help-numbers dt { font-weight: 800; }
.help-numbers dd { margin: 2px 0 0; color: var(--text-2); line-height: 1.6; }
.help-presets td:first-child { white-space: normal; }
/* 조건을 한 줄에 하나씩: 오른쪽 끝을 맞춰 세로로 쌓는다 */
.rule.stack.column p { flex-direction: column; align-items: flex-end; gap: 4px; }
.rule p > span { white-space: nowrap; } /* "꺾임 [3] % 이상" 같은 덩어리는 중간에서 끊지 않는다 */
/* 꺼 둔 조건은 흐리게 */
.rule:has(.switch input:not(:checked)) > div { opacity: 0.45; }
/* 매수기준·매도기준: 제목과 같은 줄의 오른쪽에 매매 방식(추세 추종 / 반등 매매)과 그 설명 버튼을 둔다 */
.rules .mode-head, .bt-rules .mode-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 12px; margin-bottom: 8px; }
.rules .mode-head h3, .bt-rules .mode-head h3 { margin: 0; }
.rules .mode-head + .rule, .bt-rules .mode-head + .rule { border-top: 0; }
.mode-head .mode { display: inline-flex; align-items: center; gap: 8px; margin-left: auto; }
.mode-head .currency-toggle { font-size: 14px; }
@media (max-width: 640px) {
  /* 좁은 화면에서도 제목과 매매 방식이 한 줄에 들어가게 글자와 간격을 조금 줄인다 */
  .rules .mode-head, .bt-rules .mode-head { gap: 4px 6px; } /* 글꼴을 크게 해 두어 들어가지 않으면 매매 방식이 다음 줄 오른쪽으로 내려간다 */
  .rules .mode-head h3, .bt-rules .mode-head h3 { white-space: nowrap; font-size: 16px; }
  .rules .mode-head h3 small, .bt-rules .mode-head h3 small { margin-left: 3px; font-size: 12px; }
  .rules .mode-head h3 .help, .bt-rules .mode-head h3 .help { margin-left: 3px; }
  .mode-head .mode { gap: 4px; }
  .mode-head .currency-toggle { gap: 3px; font-size: 12px; white-space: nowrap; }
  .mode-head .currency-toggle .switch { transform: scale(0.85); margin: 0 -3px; }
}
/* 글자가 16px보다 작으면 아이폰이 입력할 때 화면을 확대한다 */
.rule input[type="number"], .rule input[type="text"] {
  padding: 4px 8px; border: 0; border-radius: 8px; background: var(--wash-strong); color: var(--text);
  font-size: 16px; font-weight: 700; line-height: 1.4; text-align: right; font-variant-numeric: tabular-nums;
  margin: 3px 0; vertical-align: middle;
}
.rule input:focus { outline: 2px solid var(--accent); }
.rules .hint { padding-top: 10px; border-top: 1px solid var(--grid); }
.switch { flex: none; position: relative; width: 46px; height: 28px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--axis); transition: background 0.15s; pointer-events: none; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25); transition: transform 0.15s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
/* 투자기준 알림("자동 저장됨", 오류): 화면 아래쪽 가운데에 잠깐 떠오른다. 휴대폰에서는 아래 메뉴 위에 뜬다. */
.rules-toast {
  position: fixed; z-index: 12; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 12px);
  max-width: min(92vw, 520px); margin: 0; padding: 10px 18px; border-radius: 999px;
  background: var(--text); color: var(--page); font-size: 14px; font-weight: 700; text-align: center;
  box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s;
}
.rules-toast.show { opacity: 1; transform: translate(-50%, 0); }
.rules-toast.error { background: var(--critical); color: #fff; border-radius: 16px; }
@media (max-width: 1099px) {
  .rules-toast { bottom: calc(96px + env(safe-area-inset-bottom)); }
}

.settings { display: grid; gap: 16px; max-width: 600px; }
.settings h3 { margin-bottom: 2px; }
.settings .hint { margin-bottom: 14px; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.swatch { display: flex; align-items: center; gap: 8px; padding: 8px 14px 8px 10px; font-size: 14px; border-radius: 999px; background: var(--wash); }
.swatch i { width: 20px; height: 20px; border-radius: 50%; box-shadow: inset 0 0 0 1px var(--axis); background: var(--swatch); }
label.swatch { min-height: 44px; font-weight: 600; cursor: pointer; }
.swatch[aria-pressed="true"], .swatch.on, .sizes button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent-text); box-shadow: inset 0 0 0 1.5px var(--accent); }
.swatch input[type="color"] { width: 22px; height: 22px; padding: 0; border: 0; background: none; cursor: pointer; }
.sizes { display: flex; gap: 6px; padding: 4px; border-radius: 16px; background: var(--wash); }
.sizes button { flex: 1; white-space: nowrap; background: none; padding: 8px 4px; }
/* 고른 것은 강조색 바탕에 흰 글자로. 어두운 배경에서도 뚜렷이 구분된다 (설정의 글꼴 크기, 백테스트의 기간) */
.sizes button[aria-pressed="true"] { background: var(--accent); color: #fff; box-shadow: none; }

/* 간결한 설정 줄: 이름은 왼쪽, 고르는 칸은 오른쪽 */
.settings .setting-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; padding-top: 16px; padding-bottom: 16px; }
.setting-row h3 { margin: 0; }
.setting-row > :last-child { margin-left: auto; }
.setting-row .swatch { padding: 6px 12px 6px 8px; }
.setting-row label.swatch { min-height: 36px; }
.setting-row .sizes { flex: 0 1 300px; }
.setting-row .sizes button { min-height: 36px; padding: 6px 4px; font-size: 14px; }
.setting-row .seconds input { width: 5.5em; padding: 6px 10px; }
.setting-name { display: flex; align-items: center; gap: 12px; }
/* 계정: 로그인한 아이디 바로 옆에 로그아웃, 그 옆에 계정 변경 */
#account-name { margin-right: 4px; font-size: 15px; font-weight: 700; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-actions { display: flex; align-items: center; gap: 8px; min-width: 0; }
.account-actions button { flex: none; }
.account-actions button { min-height: 36px; padding: 6px 16px; }
.card-title { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 4px; }
.card-title h3 { margin: 0; }
.card-title button { min-height: 36px; padding: 6px 16px; }
.sites { list-style: none; margin: 0; padding: 0; }
.sites li { display: flex; align-items: center; gap: 8px; padding: 12px 0; border-top: 1px solid var(--grid); }
.sites li > div { flex: 1; min-width: 0; }
.sites a { font-size: 16px; font-weight: 800; color: var(--accent-text); text-decoration: none; }
.sites a:hover { text-decoration: underline; }
.sites small { display: block; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sites p { color: var(--text-2); font-size: 14px; margin-top: 2px; }
.sites button { min-height: 36px; padding: 6px 12px; font-size: 14px; white-space: nowrap; }
.sites .empty { color: var(--text-2); font-size: 14px; }

/* ---------- 백테스트 ---------- */
.backtest-form { display: grid; gap: 0; }
/* 입력 묶음: 왼쪽에 무엇을 정하는 칸인지 적고 오른쪽에 입력을 둔다. 묶음 사이는 가는 선으로 나눈다 */
.bt-field { display: grid; grid-template-columns: 6.5em minmax(0, 1fr); gap: 4px 12px; align-items: center; padding: 3px 0; border-top: 1px solid var(--grid); }
.bt-field:first-child { padding-top: 0; border-top: 0; }
.bt-field[hidden] { display: none; }
.bt-field:last-child { padding-bottom: 0; }
.bt-label { font-size: 14px; font-weight: 800; color: var(--text); }
.bt-label small { margin-left: 4px; font-size: 12px; font-weight: 600; color: var(--muted); }
.bt-body { display: grid; gap: 6px; min-width: 0; }
.bt-body.backtest-buy, .bt-body.backtest-costs, .bt-body.backtest-invest, .bt-body.backtest-dca { display: flex; }
#tab-backtest .backtest-form { padding-block: 8px; }
/* 종목: 기간 줄과 같은 세 칸에 종목 코드·실행 | 화면 콤보박스 | 그 화면의 종목 콤보박스. 화면 콤보박스가 아래 줄의 달러/원화와 나란히 선다 */
/* 첫 칸은 줄의 1/3, 둘째 칸은 좁게 잡아 화면 콤보박스와 종목 콤보박스 사이를 가깝게 둔다 (기간 줄과 같은 칸 나눔) */
.bt-body.backtest-symbol { display: grid; grid-template-columns: calc((100% - 40px) / 3) max-content minmax(0, 1fr); align-items: center; justify-items: start; gap: 6px 20px; }
/* 화면 콤보박스와 종목 콤보박스는 이어지는 한 쌍이라 바짝 붙인다 */
.backtest-symbol select[name="pick"] { margin-left: -12px; }
.backtest-symbol .bt-run { display: flex; align-items: center; gap: 8px; min-width: 0; max-width: 100%; }
.backtest-symbol input {
  flex: 0 1 6.5em; width: 6.5em; min-width: 0; min-height: 34px; padding: 4px 12px; border: 0; border-radius: 12px; background: var(--wash-strong); color: var(--text);
  font-size: 16px; font-weight: 700; text-transform: uppercase;
}
.backtest-symbol input::placeholder { font-weight: 500; text-transform: none; }
.backtest-symbol input:focus { outline: 2px solid var(--accent); }
.backtest-symbol button { flex: none; min-height: 34px; padding: 4px 32px; white-space: nowrap; }
.backtest-symbol select { flex: 0 1 auto; min-width: 0; }
.backtest-symbol select:disabled { opacity: 0.5; cursor: default; }
.backtest-form .sizes button { min-height: 38px; }
/* 고른 기간은 강조색 바탕에 흰 글자로. 어두운 배경에서도 다른 기간과 뚜렷이 구분된다 */
.backtest-form .sizes button[aria-pressed="true"] { background: var(--accent); color: #fff; box-shadow: none; }
.backtest-costs { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; font-size: 14px; color: var(--text-2); }
.backtest-costs input { width: 4.5em; padding: 4px 8px; border: 0; border-radius: 8px; background: var(--wash-strong); color: var(--text); font-size: 15px; font-weight: 700; text-align: center; }
/* 처음 매수일·수량과, 찾아 온 종가·매수금액 */
.backtest-buy { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; font-size: 14px; color: var(--text-2); }
.backtest-buy input { padding: 4px 8px; border: 0; border-radius: 8px; background: var(--wash-strong); color: var(--text); font-size: 15px; font-weight: 700; }
.backtest-buy input[name="shares"] { width: 5.5em; text-align: center; }
.backtest-buy button { min-height: 32px; padding: 4px 12px; font-size: 13px; }
/* 처음 매수일: 날짜가 적힌 버튼을 누르면 그 아래에 달력이 뜬다 */
.date-field { position: relative; display: inline-flex; align-items: center; gap: 6px; }
.backtest-buy .date-btn, .backtest-dca .date-btn { min-height: 34px; padding: 4px 12px; border-radius: 8px; background: var(--wash-strong); color: var(--text); font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.backtest-buy .date-btn.empty, .backtest-dca .date-btn.empty { color: var(--muted); font-weight: 500; }
.calendar { position: absolute; z-index: 30; top: calc(100% + 6px); left: 0; width: 288px; padding: 12px; border-radius: 16px; background: var(--surface); box-shadow: var(--shadow-lift), inset 0 0 0 1px var(--border); color: var(--text); }
.calendar button { min-height: 0; padding: 0; background: none; font-size: 14px; }
.calendar button:hover:not(:disabled) { background: var(--wash-strong); }
.calendar button:disabled { opacity: 0.3; cursor: default; }
.cal-head { display: flex; align-items: center; gap: 2px; margin-bottom: 8px; }
.cal-head b { flex: 1; text-align: center; font-size: 16px; font-weight: 800; }
.calendar .cal-head button { width: 34px; height: 34px; border-radius: 50%; font-size: 18px; color: var(--text-2); }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; }
.cal-grid span { padding: 4px 0; font-size: 12px; font-weight: 600; color: var(--muted); }
.calendar .cal-grid button { aspect-ratio: 1; border-radius: 50%; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--text); }
/* 주말은 흐리게 (장이 열리지 않는 날) */
.calendar .cal-grid button:nth-child(7n+1), .calendar .cal-grid button:nth-child(7n) { color: var(--muted); }
.calendar .cal-grid button.today { box-shadow: inset 0 0 0 1.5px var(--accent); }
.calendar .cal-grid button.on { background: var(--accent); color: #fff; }
.cal-foot { display: flex; justify-content: space-between; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--grid); }
.calendar .cal-foot button { padding: 6px 12px; border-radius: 10px; font-size: 13px; font-weight: 700; color: var(--accent-text); }
.backtest-buy .buy-info { flex-basis: 100%; margin: 0; color: var(--text); font-weight: 600; }
.backtest-buy .buy-info small { color: var(--muted); font-weight: 500; }
.backtest-buy .buy-info.error { color: var(--critical); }
/* 거치식(매수일을 적었을 때)과 적립식에서는 기간을 쓰지 않지만, 고른 기간은 흐리게 하지 않고 그대로 진하게 보여 준다 */
#backtest-periods { color: var(--text); font-weight: 800; }
/* 기간 콤보박스와, 그 옆의 달러/원화·환율 변동 포함 */
.bt-body.backtest-period { display: grid; grid-template-columns: calc((100% - 40px) / 3) 147px minmax(0, 1fr); align-items: center; justify-items: start; gap: 6px 20px; }
.backtest-period > * { min-width: 0; }
.backtest-period select, .backtest-symbol select, .backtest-dca select {
  min-height: 34px; padding: 4px 34px 4px 14px; border: 0; border-radius: 12px; background-color: var(--wash-strong);
  font-size: 15px; font-weight: 700; color: var(--text); cursor: pointer; -webkit-appearance: none; appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat;
}
.backtest-period select:focus, .backtest-symbol select:focus { outline: 2px solid var(--accent); }
.backtest-period .with-help { display: inline-flex; align-items: center; gap: 8px; }
.backtest-period .currency-toggle { font-size: 14px; }
.backtest-costs .with-help { display: inline-flex; align-items: center; gap: 6px; }
/* 환율 변동 포함 스위치와 그 설명 */
.fx-toggle { display: flex; align-items: center; gap: 8px; margin: 0; font-size: 14px; font-weight: 700; color: var(--text); cursor: pointer; white-space: nowrap; }
.fx-toggle .switch { display: inline-block; margin: 0; }
.backtest-buy .buy-info:empty { display: none; }
/* 투자 방식: 신호만 / 거치식 / 적립식 가운데 하나를 고른다 */
.bt-body.backtest-invest { align-items: center; gap: 8px; }
.backtest-form .invest-modes { flex: 0 1 300px; padding: 3px; border-radius: 12px; }
.backtest-form .invest-modes button { min-height: 30px; padding: 3px 8px; border-radius: 9px; font-size: 14px; }
/* 적립식: 기간, 주기, 한 번에 넣는 금액이나 수량. 그 아래에 어림한 횟수와, 직접 적는 매도일 */
.bt-body.backtest-dca { flex-wrap: wrap; align-items: center; gap: 8px 16px; font-size: 14px; color: var(--text-2); }
.backtest-dca > span, .backtest-dca label, .dca-sell { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.backtest-dca select { padding: 4px 28px 4px 10px; border-radius: 10px; background-position: calc(100% - 15px) 50%, calc(100% - 10px) 50%; }
.backtest-dca input[type="number"] { width: 6.5em; padding: 4px 8px; border: 0; border-radius: 8px; background: var(--wash-strong); color: var(--text); font-size: 15px; font-weight: 700; text-align: center; }
.backtest-dca .buy-info { flex-basis: 100%; margin: 0; color: var(--text); font-weight: 600; }
.backtest-dca .buy-info small, .dca-sells > small { color: var(--muted); font-weight: 500; }
.backtest-dca .buy-info.error { color: var(--critical); }
.dca-sells { flex-basis: 100%; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; }
.dca-sell input[type="number"] { width: 4.2em; }
.dca-sells > button, .dca-sell > button { min-height: 32px; padding: 4px 12px; font-size: 13px; }
/* 매수조건·매도조건: 넓은 화면에서는 두 상자를 나란히, 좁은 화면에서는 위아래로 놓는다. 줄의 모양은 투자기준과 같다 */
.bt-rules { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); gap: 16px; align-items: start; margin-top: 16px; }
.bt-rules > * { min-width: 0; }
.bt-rules[hidden] { display: none; }
/* 화면 이름 줄의 설정 보이기/설정 숨기기. 넓은 화면에서는 화면 이름 · 초기화 버튼들 · 설정 숨기기가 한 줄에 놓인다 (좁은 화면은 탭 머리말 쪽에서 정한다) */
.hero-title { display: contents; }
.hero-title h2 { margin-right: auto; }
.hero-title + .hero-actions { order: 1; }
.hero-fold { order: 2; margin-left: -8px; color: var(--accent-text); }
/* 숨기면 화면 이름 옆(좁은 화면에서는 아래)의 버튼들이 사라진다 */
.folded > .hero .hero-actions { display: none; }
/* 매수조건·매도조건을 보이거나 숨기는 줄. 숨겨 두어도 지금 고른 매매 방식은 여기에 적어 둔다 */
.bt-rules-toggle { display: flex; align-items: center; gap: 4px 10px; width: 100%; margin-top: 16px; padding: 8px 16px 8px 20px; border: 1px solid var(--card-border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); text-align: left; }
.bt-rules-toggle:hover { background: var(--surface); }
.bt-rules-toggle span { font-size: 15px; font-weight: 800; color: var(--text); white-space: nowrap; }
.bt-rules-toggle small { flex: 1; min-width: 0; font-size: 13px; font-weight: 600; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bt-rules-toggle b { flex: none; padding: 5px 12px; border-radius: 10px; background: var(--wash-strong); font-size: 13px; font-weight: 700; color: var(--accent-text); }
.bt-rules .rule { min-height: 44px; padding: 3px 0; }
/* 제목 옆의 "?" */
#backtest-result h3 .help { margin-left: 8px; vertical-align: 2px; }
#backtest-result, #backtest-saved { display: grid; gap: 16px; margin-top: 16px; }
#backtest-result > *, #backtest-saved > * { min-width: 0; }
.backtest-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; padding: 0 4px; color: var(--text-2); font-size: 14px; }
.backtest-head b { color: var(--text); font-size: 17px; }
/* 결과의 종목 코드: 크게 쓰고, 누르면 큰 차트가 열린다 */
.backtest-symbol-link { min-height: 0; padding: 0; background: none; box-shadow: none; color: var(--text); font-size: 28px; font-weight: 800; letter-spacing: -0.02em; cursor: pointer; }
.backtest-symbol-link:hover { color: var(--accent); text-decoration: underline; background: none; }
.backtest-name { margin-left: 10px; color: var(--text); font-size: 16px; font-weight: 600; }
.backtest-head .saved-note { font-weight: 600; color: var(--accent-text); }
#backtest-save input { width: 14em; text-transform: none; }
#backtest-result .card h3, #backtest-saved .card h3 { font-size: 17px; font-weight: 800; margin-bottom: 10px; }
#backtest-result h3 small { margin-left: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.backtest-chosen { padding: 6px 4px 0; font-size: 19px; font-weight: 800; letter-spacing: -0.02em; }
/* 좁은 화면: 칸이 화면 밖으로 밀려 실행 버튼이 잘리지 않게 한다. 기간 여덟 개는 두 줄(네 개씩)로 놓는다 */
.backtest-form > * { min-width: 0; }
@media (max-width: 640px) {
  /* 화면 옆 여백과 상자 안 여백을 줄여, 입력 칸과 표·그래프가 더 넓게 보이게 한다 */
  #tab-backtest .backtest-form, .bt-rules, #backtest-result, #backtest-saved { margin-inline: -10px; }
  .bt-rules-toggle { width: calc(100% + 20px); margin-inline: -10px; padding-inline: 12px; }
  #tab-backtest .card { padding: 16px 12px; }
  #tab-backtest .tiles { gap: 8px; grid-template-columns: repeat(2, minmax(0, 1fr)); } /* 요약 칸은 두 개씩 */
  #tab-backtest .tiles b { font-size: 19px; }
  #tab-backtest .tiles > div { padding: 12px; }
  .backtest-form .sizes { flex-wrap: wrap; }
  .backtest-form .sizes button { flex: 1 0 22%; }
  #backtest-save { flex: 1 1 100%; }
  #backtest-save input { flex: 1; width: auto; min-width: 0; }
}
/* 요약 숫자 칸 */
.tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 190px), 1fr)); }
.tiles > div { padding: 14px 16px; border-radius: 16px; background: var(--surface); border: 1px solid var(--card-border); box-shadow: var(--shadow); min-width: 0; }
.tiles span { display: block; font-size: 12px; font-weight: 600; color: var(--muted); }
.tiles b { display: block; margin: 2px 0; font-size: 22px; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.tiles small { display: block; font-size: 12px; color: var(--text-2); line-height: 1.4; }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-scroll .holders { margin: 0; }
.compare-full { min-width: 760px; }
.compare th, .compare td { padding: 10px 6px; }
.compare td:first-child small { font-weight: 500; line-height: 1.4; }
/* 지금 아래에 자세히 보여 주는 줄 */
.compare:not(.compare-full) tr[aria-selected="true"] td:first-child b::after {
  content: "보는 중"; margin-left: 6px; padding: 2px 7px; border-radius: 999px; background: var(--accent); color: #fff; font-size: 11px; font-weight: 700; vertical-align: 1px; white-space: nowrap;
}
.compare tr[data-variant] { cursor: pointer; }
.compare tr[data-variant]:hover td { background: var(--wash); }
.compare tr[aria-selected="true"] td { background: var(--accent-soft); }
/* 견줄 기준인 단순 보유는 맨 위에 굵은 글씨로 둔다. 숫자는 다른 줄처럼 오르면 빨강, 내리면 파랑, 보합이면 검정 */
.compare .hold-row td, .compare .hold-row td small { font-weight: 800; }
.compare .hold-row td:not(.up):not(.down) { color: var(--text); }
.compare .hold-row + tr td { border-top: 2px solid var(--grid); }
.yearly { max-width: 420px; }
.trades.with-money { min-width: 520px; }
.trades th:last-child, .trades td.why { padding-left: 14px; text-align: left; white-space: normal; }
.trades + .hint, .table-scroll + .hint { margin-top: 10px; }
.saved-backtests { min-width: 720px; }
.saved-backtests .note { white-space: normal; text-align: left; color: var(--text-2); }
.row-actions button { min-height: 32px; padding: 4px 10px; margin-left: 4px; font-size: 13px; }
.chart.trade-chart svg { cursor: crosshair; }
.trade-chart .baseline { stroke: var(--axis); stroke-width: 1; }
.trade-chart .line.thin { stroke-width: 1.5; }
/* 매수는 위를 향한 빨강 세모, 매도는 아래를 향한 파랑 세모 */
.trade-chart .mark { stroke: var(--surface); stroke-width: 1.5; stroke-linejoin: round; }
.trade-chart .mark.buy { fill: var(--up); }
.trade-chart .mark.sell { fill: var(--down); }
.trade-chart .legend .up, .trade-chart .legend .down { font-weight: 700; }
.tooltip .trade-line { font-weight: 600; }
.backtest-limits { padding: 0 4px; font-size: 13px; line-height: 1.6; color: var(--text-2); }
.backtest-limits summary { cursor: pointer; font-weight: 600; }
.backtest-limits summary u { color: var(--accent-text); text-underline-offset: 2px; }
.backtest-limits ul { margin: 8px 0 0; padding-left: 18px; }
/* 한눈에 보기: 결론 한 줄과, 신호대로 사고판 결과·단순 보유를 견주는 막대 두 개 */
.bt-verdict { display: grid; gap: 12px; }
#backtest-result .bt-verdict h3 { margin-bottom: 0; }
.bt-chip { justify-self: start; margin: 0; padding: 8px 14px; border-radius: 12px; background: var(--wash); color: var(--text); font-size: 17px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.4; }
.bt-chip.good { background: var(--accent-soft); color: var(--accent-text); }
.bt-bars { display: grid; gap: 14px; }
.bt-bar { display: grid; grid-template-columns: 11.5em minmax(0, 1fr) 9.5em; grid-template-areas: "who track result"; align-items: center; gap: 4px 14px; }
.bt-bar .who { grid-area: who; font-size: 15px; font-weight: 700; }
.bt-bar .result { grid-area: result; text-align: right; }
.bt-bar .result b { font-size: 22px; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.bt-bar small { display: block; font-size: 12px; font-weight: 500; color: var(--text-2); font-variant-numeric: tabular-nums; }
.bt-bar .track { grid-area: track; position: relative; height: 22px; border-radius: 6px; background: var(--wash); }
.bt-bar .track i { display: block; height: 100%; min-width: 2px; border-radius: 6px; background: var(--muted); }
.bt-bar.mine .track i { background: var(--series-1); }
/* 처음 넣은 돈의 자리 */
.bt-bar .track::after { content: ""; position: absolute; top: -5px; bottom: -5px; left: var(--start); border-left: 2px dashed var(--text); opacity: 0.55; }
.bt-also { margin: 0; padding-top: 12px; border-top: 1px solid var(--grid); font-size: 14px; color: var(--text-2); line-height: 1.6; }
.bt-also b { color: var(--text); font-variant-numeric: tabular-nums; }
/* 요약 칸 이름 옆의 "?" */
#tab-backtest .tiles span { display: flex; align-items: center; gap: 6px; min-height: 22px; font-size: 13px; }
/* 전문 지표 더 보기 */
.bt-more summary { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; cursor: pointer; list-style: none; }
.bt-more summary::-webkit-details-marker { display: none; }
.bt-more summary::before { content: "▸"; color: var(--muted); }
.bt-more[open] summary::before { content: "▾"; }
.bt-more summary b { font-size: 16px; font-weight: 800; }
.bt-more h4 { margin: 18px 0 6px; font-size: 14px; font-weight: 800; }
.bt-terms { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); gap: 0 24px; margin: 12px 0 0; }
.bt-terms > div { padding: 10px 0; border-top: 1px solid var(--grid); }
.bt-terms dt { display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.bt-terms dd { margin: 2px 0 0; }
.bt-terms dd b { font-size: 18px; font-weight: 800; font-variant-numeric: tabular-nums; }
.bt-terms dd small { display: block; font-size: 12px; color: var(--text-2); line-height: 1.5; }
@media (max-width: 640px) {
  .bt-field { grid-template-columns: minmax(0, 1fr); gap: 4px; padding: 8px 0; }
  /* 좁은 화면의 종목: 두 줄로 놓는다. 첫 줄에 종목 코드와 큼직한 실행 버튼, 둘째 줄에 화면 콤보박스와 종목 콤보박스를 반씩 */
  .bt-body.backtest-symbol { grid-template-columns: repeat(2, minmax(0, 1fr)); justify-items: stretch; gap: 8px; }
  .backtest-symbol .bt-run { grid-column: 1 / -1; }
  .backtest-symbol input { min-height: 40px; }
  .backtest-symbol button { min-height: 40px; padding: 6px 30px; font-size: 16px; }
  .backtest-symbol select { width: 100%; min-height: 40px; }
  .backtest-symbol select[name="pick"] { margin-left: 0; }
  /* 좁은 화면의 기간: 기간, 달러/원화, 환율 변동 포함을 한 줄에 놓는다. 들어가도록 글자와 스위치를 조금 줄인다 */
  .bt-body.backtest-period { display: flex; flex-wrap: nowrap; justify-content: space-between; gap: 8px; }
  .backtest-period select { min-height: 40px; padding: 8px 26px 8px 10px; font-size: 14px; background-position: calc(100% - 14px) 50%, calc(100% - 9px) 50%; }
  .backtest-period .currency-toggle, .backtest-period .fx-toggle { gap: 3px; font-size: 12px; white-space: nowrap; }
  .backtest-period label .switch { transform: scale(0.85); margin: 0 -3px; }
  .backtest-period .with-help { gap: 4px; }
  /* 좁은 화면의 적립식: 한 줄에 다 들어가지 않으므로 기간의 종료 쪽과 매도 줄이 다음 줄로 넘어가게 한다 */
  .backtest-dca > span, .dca-sell { flex-wrap: wrap; }
  .backtest-dca select { padding: 6px 20px 6px 8px; font-size: 14px; background-position: calc(100% - 11px) 50%, calc(100% - 6px) 50%; }
  .bt-body.backtest-dca { gap: 8px 10px; }
  .backtest-dca > span, .backtest-dca label, .dca-sell { gap: 4px; }
  .dca-sell input[type="number"] { width: 3.4em; }
  .backtest-form .invest-modes { flex: 1 1 0; }
  .bt-chip { font-size: 16px; }
  .bt-bar { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "who result" "track track"; align-items: end; }
  .bt-bar .track { height: 16px; margin-top: 4px; }
  .compare th, .compare td { padding: 10px 3px; }
  .compare:not(.compare-full) { font-size: 13px; }
  .trades { font-size: 13px; }
  .trades th:last-child, .trades td.why { padding-left: 10px; }
}
@media (max-width: 1099px) {
  /* 메뉴가 여섯 개라 휴대폰에서는 글자를 조금 줄인다 */
  .tabs button { font-size: 11px; letter-spacing: -0.03em; }
}

.empty-state { grid-column: 1 / -1; text-align: center; padding: 56px 16px; color: var(--text-2); border-radius: var(--radius); border: 1.5px dashed var(--axis); }
.empty-state b { display: block; font-size: 17px; font-weight: 800; color: var(--text); margin-bottom: 4px; }

/* ---------- 대화상자 ---------- */
dialog {
  border: 0; border-radius: 24px; background: var(--surface); color: var(--text);
  padding: 24px; width: min(92vw, 400px); box-shadow: var(--shadow-lift);
}
dialog[open] { animation: rise 0.2s ease-out; }
dialog::backdrop { background: rgba(0, 0, 0, 0.45); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
dialog h2 { font-size: 20px; font-weight: 800; letter-spacing: -0.03em; margin-bottom: 16px; }
dialog label { display: block; font-size: 13px; font-weight: 600; color: var(--text-2); margin-bottom: 12px; }
dialog input, dialog select {
  display: block; width: 100%; margin-top: 6px; padding: 12px 14px; min-height: 48px;
  border: 0; border-radius: 12px; background: var(--wash); font-size: 16px; font-weight: 500;
}
dialog input:focus, dialog select:focus { outline: 2px solid var(--accent); outline-offset: 0; }
/* 로그인 창: 계정 만들기일 때만 나오는 칸이 있다. 안내 글이 있을 때는 입력 칸과 띄운다 */
#login-dialog [hidden] { display: none; }
#login-dialog .hint:not(:empty) { margin-bottom: 14px; line-height: 1.5; }
/* 큰 차트 */
.chart svg { cursor: zoom-in; }
.chart-dialog { width: min(96vw, 1240px); height: min(92dvh, 900px); max-height: none; padding: 0 24px 20px; }
.chart-dialog[open] { display: flex; flex-direction: column; }
.chart-dialog .dialog-head { position: static; padding: 20px 0 10px; }
.chart-dialog .dialog-head h2 { font-size: 24px; margin: 0; }
.chart-dialog .dialog-head h2 .exchange { font-size: 13px; }
/* 종목 코드: 누르면 기업정보가 뜬다. 제목 글자 모양 그대로 두고, 올리면 밑줄만 긋는다 */
.chart-dialog .dialog-head h2 .ticker-open { min-height: 0; margin: 0; padding: 0; background: none; box-shadow: none; color: inherit; font: inherit; letter-spacing: inherit; cursor: pointer; }
.chart-dialog .dialog-head h2 .ticker-open:hover { color: var(--accent); text-decoration: underline; background: none; }
/* 현재가 묶음은 종목 코드 바로 옆에 한 줄로 놓는다 (닫기 버튼과 떨어뜨린다). 자리가 모자라면 다음 줄로 넘어간다 */
.chart-dialog .dialog-head { justify-content: flex-start; gap: 12px 28px; }
.chart-dialog .dialog-head > div:first-child { flex: 0 1 auto; min-width: 0; }
.chart-dialog .dialog-head > button { margin-left: auto; }
.pro-quote { flex: 0 1 auto; display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; align-self: center;
  text-align: left; font-size: 20px; white-space: normal; }
.pro-quote p { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 12px; margin: 0; }
.pro-quote .day, .pro-quote .ext { display: inline; margin: 0; font-size: 13px; }
.pro-quote .delta { margin: 0; }
@media (min-width: 641px) {
  /* 넓은 화면: 종목 이름 칸을 넓혀, 현재가 묶음이 아래 기간 버튼의 "1Q" 글자 위치쯤에서 시작하게 한다 */
  .chart-dialog .dialog-head > div:first-child { flex: 0 0 calc(38% - 28px); }
}
@media (max-width: 640px) {
  /* 좁은 화면: 종목 이름과 닫기 버튼을 첫 줄에, 현재가 묶음을 그 아래 줄에 놓는다 */
  .chart-dialog .dialog-head { flex-wrap: wrap; }
  .chart-dialog .dialog-head > div:first-child { flex: 1; }
  .pro-quote { order: 3; flex-basis: 100%; font-size: 19px; }
}
.chart-dialog .dialog-head > button { flex: none; white-space: nowrap; } /* 좁은 화면에서 "닫기"가 두 줄로 꺾이지 않게 */
.chart-dialog .ranges { margin-bottom: 8px; }
/* 종가는 굵은 글씨로 (크기와 색은 주변의 본문 글자와 같게) */
.pro-legend .close { font-weight: 800; color: var(--text); }
/* 고른 기간은 강조색 바탕에 흰 글자로. 어두운 배경에서도 뚜렷이 구분된다 */
.chart-dialog .ranges button[aria-pressed="true"] { background: var(--accent); color: #fff; box-shadow: none; }
.tools { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 8px; }
.tools .interval { font-size: 12px; font-weight: 800; color: var(--text-2); margin-right: 2px; }
.tools button { min-height: 30px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--wash); color: var(--text-2); }
.tools button[aria-pressed="true"] { background: var(--text); color: var(--page); }
/* 설명이 있는 도구: 마우스를 올리거나 누르면(포커스) 버튼 아래에 설명이 뜬다 */
/* 설명 상자는 도구 줄의 왼쪽 끝에 맞춰 띄운다. 버튼이 오른쪽에 있거나 화면이 좁아도 화면 밖으로 나가지 않는다 */
.tools { position: relative; }
.tools button[data-tip] { text-decoration: underline dotted; text-underline-offset: 3px; }
.tools button[data-tip]:hover::after, .tools button[data-tip]:focus::after {
  content: attr(data-tip); position: absolute; left: 0; top: calc(100% + 4px); z-index: 20;
  width: min(380px, 100%); padding: 12px 14px; border-radius: 12px; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); box-shadow: var(--shadow-lift); white-space: pre-line; text-align: left;
  font-size: 13px; font-weight: 500; line-height: 1.6; pointer-events: none;
}
.pro-legend { min-height: 36px; font-size: 12px; line-height: 1.5; color: var(--text-2); font-variant-numeric: tabular-nums; }
.pro-legend b { color: var(--text); }
.pro-legend[hidden] { display: none; }
@media (max-width: 640px) {
  /* 휴대폰: 그래프를 짚을 때만 나오고, 자리를 차지하지 않게 그래프 위에 겹쳐 띄운다 */
  .chart-dialog .pro-legend {
    position: absolute; left: 8px; right: 8px; z-index: 5; min-height: 0; padding: 6px 8px; border-radius: 10px;
    background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); pointer-events: none;
  }
}
.pro-legend .key { white-space: nowrap; margin-left: 6px; }
.pro-legend .key i { display: inline-block; width: 10px; height: 2px; vertical-align: middle; margin-right: 3px; }
.pro-chart { flex: 1; min-height: 0; position: relative; }
.pro-chart .chart-note { min-height: 100%; }
@media (max-width: 559px) {
  /* 휴대폰에서는 화면 폭을 다 쓴다 (다른 창처럼 아래에서 올라오는 판). 96vw로 두면 왼쪽으로 붙어 오른쪽이 빈다 */
  .chart-dialog { width: 100%; max-width: 100%; height: 94dvh; padding: 0 8px calc(12px + env(safe-area-inset-bottom)); }
}

/* 기업정보 */
dialog.wide { width: min(94vw, 600px); max-height: min(88vh, 900px); overflow-y: auto; padding-top: 0; }
.dialog-head { position: sticky; top: 0; z-index: 1; display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 24px 0 12px; background: var(--surface); }
.dialog-head h2 { margin-bottom: 0; font-size: 24px; }
.dialog-tools { display: flex; align-items: center; gap: 8px; flex: none; }
/* 달러 ↔ 원화 토글. 지금 고른 쪽 글자를 진하게 한다. */
.currency-toggle { display: flex; align-items: center; gap: 6px; margin: 0; font-size: 13px; font-weight: 600; color: var(--muted); cursor: pointer; }
.currency-toggle .switch { display: inline-block; margin: 0; }
.currency-toggle .on { color: var(--text); font-weight: 800; }
/* 켜짐·꺼짐이 아니라 둘 중 하나를 고르는 토글이라, 어느 쪽이든 같은 색으로 둔다 */
.currency-toggle .switch input + span { background: var(--accent); }
dialog.wide section { padding: 16px 0; border-top: 1px solid var(--grid); }
dialog.wide h3 { font-size: 16px; font-weight: 800; margin-bottom: 8px; }
dialog.wide section > p:not(.hint) { color: var(--text-2); line-height: 1.6; margin-bottom: 12px; }
dialog.wide a { color: var(--accent-text); }
/* 링크처럼 보이는 버튼 (기업정보의 "최근 뉴스 보기") */
dialog.wide button.link { min-height: 0; padding: 0; background: none; box-shadow: none; color: var(--accent-text); font: inherit; text-decoration: underline; cursor: pointer; }
#news-dialog .news { margin: 0; padding: 12px 0 0; }
/* 뉴스 팝업: 제목은 검정, 호재 단어만 보라 굵은 글씨로 */
#news-dialog .news a { color: var(--text); }
#news-dialog .news b.positive { color: var(--famous); font-weight: 800; }
dialog.wide section > p.fetch-failed { padding: 10px 12px; border-radius: 10px; background: var(--grid); color: var(--text); font-weight: 600; }
/* 업종 내 시가총액 1~3위 표시: 굵은 빨강 */
dialog.wide section > p.top-rank { color: var(--up); font-size: 16px; font-weight: 800; margin-bottom: 0; }
/* 업종 1·2위와 이 회사를 나란히 놓은 표. 이 회사 줄은 굵게, 1~3위이면 빨강 */
.peers { margin: 4px 0 8px; }
.peers + .hint { margin-bottom: 14px; }
.peers tr.own td { font-weight: 800; }
.peers tr.own.top td, .peers tr.own.top td small { color: var(--up); }
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px 16px; margin: 0; }
.facts div { min-width: 0; }
.facts dt { font-size: 12px; color: var(--muted); }
.facts dd { margin: 0; font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.holders { width: 100%; border-collapse: collapse; margin: 14px 0 8px; font-size: 14px; font-variant-numeric: tabular-nums; }
.holders th, .holders td { text-align: right; padding: 8px 4px; border-top: 1px solid var(--grid); white-space: nowrap; }
.holders th { border-top: 0; font-size: 12px; font-weight: 600; color: var(--muted); }
.holders th:first-child, .holders td:first-child { text-align: left; white-space: normal; }
.facts + .hint { margin-top: 12px; }
dialog.wide h4 { font-size: 14px; font-weight: 800; margin: 20px 0 8px; }
.income-chart svg { display: block; width: 100%; }
.income-chart .gridline { stroke: var(--grid); stroke-width: 1; }
.income-chart .baseline { stroke: var(--axis); stroke-width: 1; }
.income-chart .tick { fill: var(--muted); font-size: 10px; font-variant-numeric: tabular-nums; }
.income-chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.income-chart .dot { stroke: var(--surface); stroke-width: 2; }
.income-chart .extreme { fill: var(--text); font-size: 11px; font-weight: 700; font-variant-numeric: tabular-nums; paint-order: stroke; stroke: var(--surface); stroke-width: 3px; }
.income td i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; }
.income td i.line-key { height: 2px; width: 14px; border-radius: 1px; vertical-align: middle; }
.holders td.notable { font-weight: 800; color: var(--notable); }
/* 기업정보 창 제목의 종목 코드: 누르면 네이버 증권 */
.dialog-head h2 a.ticker-link { color: inherit; text-decoration: none; }
.dialog-head h2 a.ticker-link::after { content: " ↗"; font-size: 15px; color: var(--muted); }
.dialog-head h2 a.ticker-link:hover { color: var(--accent-text); text-decoration: underline; }
/* 유명한 회장·CEO: 보라색 이름, 누르면 그 사람의 뉴스 */
dialog.wide .holders a.famous { color: var(--famous); text-decoration: none; }
dialog.wide .holders a.famous::after { content: " ↗"; font-size: 12px; }
dialog.wide .holders a.famous:hover { text-decoration: underline; }
.holders td small { display: block; color: var(--text-2); font-size: 13px; }
.hint { font-size: 13px; color: var(--text-2); }
.error { font-size: 13px; color: var(--critical); min-height: 18px; }
.dialog-actions { display: flex; gap: 8px; margin-top: 12px; }
.dialog-actions button { flex: 1; min-height: 50px; }
.dialog-actions button.primary { flex: 2; }
@media (max-width: 559px) {
  /* 휴대폰에서는 아래에서 올라오는 시트 */
  dialog, dialog.wide { margin: auto 0 0; width: 100%; max-width: 100%; border-radius: 24px 24px 0 0; padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
  dialog[open] { animation: sheet 0.25s ease-out; }
}
@keyframes sheet { from { transform: translateY(100%); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
