/* ── 디자인 토큰(Flutter 테마로 옮기기 쉽게 한 블록에 모음) ── */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --line: #e3e6eb;
  --text: #15181d;
  --text-2: #5b6370;
  --text-3: #8a919c;
  --brand: #e8a400;
  --brand-ink: #1a1400;
  --pos: #e0262f;      /* 호재성 = 빨강(한국 관례) */
  --neg: #1f63e0;      /* 악재성 = 파랑 */
  --tag-red: #e0262f;
  --tag-purple: #7c3aed;
  --tag-orange: #ea6a00;
  --tag-gray: #6b7280;
  --mark: rgba(255, 214, 0, 0.45);
  --flash: rgba(232, 164, 0, 0.18);
  --live: #12b76a;
  --warn: #f79009;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --radius: 12px;
  --radius-sm: 8px;
  --gap: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR", "Malgun Gothic", system-ui, sans-serif;
  --fs: 15px;
  --header-h: 52px;
  --ticker-h: 36px;
  --tabs-h: 46px;
  color-scheme: light;
}
:root[data-font="large"] { --fs: 17px; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1014; --surface: #151a20; --surface-2: #1c222a; --line: #262e38;
    --text: #e8ecf1; --text-2: #a3acb9; --text-3: #6f7987;
    --brand: #f5b70a; --pos: #ff4d55; --neg: #4d8dff;
    --tag-red: #ff4d55; --tag-purple: #a78bfa; --tag-orange: #ff8a2a; --tag-gray: #8b93a1;
    --mark: rgba(255, 214, 0, 0.28); --flash: rgba(245, 183, 10, 0.16);
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1014; --surface: #151a20; --surface-2: #1c222a; --line: #262e38;
  --text: #e8ecf1; --text-2: #a3acb9; --text-3: #6f7987;
  --brand: #f5b70a; --pos: #ff4d55; --neg: #4d8dff;
  --tag-red: #ff4d55; --tag-purple: #a78bfa; --tag-orange: #ff8a2a; --tag-gray: #8b93a1;
  --mark: rgba(255, 214, 0, 0.28); --flash: rgba(245, 183, 10, 0.16);
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 400 var(--fs)/1.5 var(--font); letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
input, select { font: inherit; color: inherit; }
.hidden { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ── 헤더 ── */
.top {
  position: sticky; top: 0; z-index: 30; height: var(--header-h);
  display: flex; align-items: center; gap: 4px; padding: 0 8px 0 16px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.logo { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 19px; letter-spacing: -0.03em; margin-right: auto; }
.logo-mark { width: 26px; height: 26px; border-radius: 7px; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; font-size: 15px; font-weight: 900; }
.conn { width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); }
.conn.live { background: var(--live); box-shadow: 0 0 0 3px color-mix(in srgb, var(--live) 25%, transparent); }
.conn.retry { background: var(--warn); }
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 10px; color: var(--text-2); position: relative; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn[aria-pressed="true"] { color: var(--brand); }
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn .dot { position: absolute; top: 10px; right: 10px; width: 7px; height: 7px; border-radius: 50%; background: var(--live); }
.searchbar { display: flex; align-items: center; gap: 8px; padding: 8px 16px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: var(--header-h); z-index: 29; }
.searchbar input { flex: 1; min-width: 0; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); padding: 0 12px; }

/* ── 티커 ── */
.ticker {
  position: sticky; top: var(--header-h); z-index: 28; height: var(--ticker-h);
  overflow: hidden; background: var(--surface-2); border-bottom: 1px solid var(--line);
  display: flex; align-items: center;
}
.ticker-label { flex: none; height: 100%; display: flex; align-items: center; padding: 0 10px 0 14px; font-size: 12px; font-weight: 800; color: var(--brand); background: var(--surface-2); z-index: 1; }
.ticker-view { flex: 1; overflow: hidden; height: 100%; -webkit-mask-image: linear-gradient(90deg, transparent, #000 24px, #000 calc(100% - 24px), transparent); mask-image: linear-gradient(90deg, transparent, #000 24px, #000 calc(100% - 24px), transparent); }
.ticker-track { display: inline-flex; height: 100%; align-items: center; white-space: nowrap; will-change: transform; }
.ticker-track.run { animation: tick var(--ticker-dur, 60s) linear infinite; }
.ticker:hover .ticker-track, .ticker.paused .ticker-track { animation-play-state: paused; }
@keyframes tick { from { transform: translateX(0); } to { transform: translateX(-50%); } }
.ticker-item { font-size: 13.5px; padding: 0 22px 0 0; color: var(--text); }
.ticker-item b { font-weight: 700; margin-right: 4px; }
.ticker-item .t-red { color: var(--tag-red); } .ticker-item .t-purple { color: var(--tag-purple); } .ticker-item .t-orange { color: var(--tag-orange); }
.ticker-item::after { content: "•"; color: var(--text-3); margin-left: 22px; }
.ticker.fade .ticker-track { animation: none; }
.ticker-empty { font-size: 13px; color: var(--text-3); padding-left: 4px; }

/* ── 탭 ── */
.tabs {
  position: sticky; top: calc(var(--header-h) + var(--ticker-h)); z-index: 27; height: var(--tabs-h);
  display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; padding: 0 8px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.tabs::-webkit-scrollbar { display: none; }
.tab { flex: none; height: 100%; padding: 0 12px; display: flex; align-items: center; font-weight: 600; color: var(--text-2); border-bottom: 2.5px solid transparent; }
.tab[aria-current="page"] { color: var(--text); border-bottom-color: var(--brand); }
body.no-ticker .tabs { top: var(--header-h); }

/* ── 레이아웃 ── */
.layout { max-width: 1120px; margin: 0 auto; padding: 12px 16px 80px; display: grid; gap: 20px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 768px) { .layout { max-width: 752px; } }
@media (min-width: 1024px) {
  .layout { max-width: 1120px; grid-template-columns: minmax(0, 760px) 320px; justify-content: center; }
  .rail { display: block !important; }
}
.rail { display: none; position: sticky; top: calc(var(--header-h) + var(--ticker-h) + var(--tabs-h) + 12px); align-self: start; max-height: calc(100vh - 160px); overflow: auto; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; box-shadow: var(--shadow); }
.panel h3 { margin: 0 0 10px; font-size: 14px; font-weight: 800; display: flex; justify-content: space-between; align-items: baseline; }
.panel h3 small { font-weight: 500; color: var(--text-3); font-size: 12px; }
.rank { list-style: none; margin: 0; padding: 0; counter-reset: r; }
.rank li { counter-increment: r; display: flex; align-items: center; gap: 8px; padding: 6px 0; font-size: 14px; border-top: 1px solid var(--line); }
.rank li:first-child { border-top: 0; }
.rank li::before { content: counter(r); width: 18px; color: var(--text-3); font-weight: 700; font-size: 12px; text-align: center; }
.rank li a { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank li small { color: var(--text-3); font-size: 12px; }

/* ── 필터 칩 ── */
.filters { display: flex; gap: 6px; flex-wrap: wrap; margin: 2px 0 12px; align-items: center; }
.view-title { display: flex; align-items: center; gap: 8px; margin: 4px 0 10px; }
.view-title h2 { margin: 0; font-size: 19px; font-weight: 800; }
.view-title .sub { color: var(--text-3); font-size: 13px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; height: 32px; padding: 0 12px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); font-size: 13.5px; font-weight: 600; color: var(--text-2); white-space: nowrap;
}
.chip[aria-pressed="true"] { background: var(--text); color: var(--surface); border-color: var(--text); }
.chip.sm { height: 26px; padding: 0 9px; font-size: 12.5px; font-weight: 600; }
.chip.stock { color: var(--text); background: var(--surface-2); border-color: transparent; }
.chip.theme { color: var(--text-2); background: transparent; }
.chip .star { color: var(--text-3); font-size: 13px; margin-left: 2px; }
.chip .star.on { color: var(--brand); }
.toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 13.5px; color: var(--text-2); cursor: pointer; }

/* ── 카드 ── */
.feed { display: flex; flex-direction: column; gap: 10px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 13px 14px 8px;
  box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.card.strong { border-color: color-mix(in srgb, var(--brand) 55%, var(--line)); }
.card.pos::before, .card.neg::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; }
.card.pos::before { background: var(--pos); } .card.neg::before { background: var(--neg); }
.card.flash { animation: flash 1.4s ease-out; }
.card.focus { outline: 2px solid var(--brand); outline-offset: 1px; }
@keyframes flash { from { background: var(--flash); } to { background: var(--surface); } }
.card-meta { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-3); min-height: 22px; }
.card-meta .pub { color: var(--text-2); font-weight: 600; }
.card-meta .more { color: var(--text-2); text-decoration: underline; text-underline-offset: 2px; }
.card-meta .right { margin-left: auto; display: flex; gap: 6px; align-items: center; }
.score { font-size: 12px; font-weight: 800; padding: 1px 7px; border-radius: 6px; background: var(--surface-2); color: var(--text-2); }
.score.pick { background: color-mix(in srgb, var(--brand) 18%, transparent); color: color-mix(in srgb, var(--brand) 70%, var(--text)); }
.score.strong { background: var(--brand); color: var(--brand-ink); }
.senti { font-size: 12px; font-weight: 700; }
.senti.pos { color: var(--pos); } .senti.neg { color: var(--neg); }
.card-title { display: block; margin: 4px 0 2px; font-size: 1.07em; font-weight: 700; line-height: 1.42; letter-spacing: -0.02em; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; }
.card-title:hover { text-decoration: underline; text-underline-offset: 3px; }
.badge { display: inline-block; font-size: 0.78em; font-weight: 800; padding: 0 5px; margin-right: 5px; border-radius: 4px; vertical-align: 1px; line-height: 1.55; color: #fff; }
.badge.red { background: var(--tag-red); } .badge.purple { background: var(--tag-purple); } .badge.orange { background: var(--tag-orange); } .badge.gray { background: var(--tag-gray); }
.card-sum { margin: 2px 0 0; color: var(--text-2); font-size: 0.92em; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.card-chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.card-why { display: none; flex-wrap: wrap; gap: 5px; margin-top: 7px; }
.card-why.open { display: flex; }
@media (min-width: 1024px) { .card-why { display: flex; } .chip.why-btn { display: none; } }
.why { font-size: 12px; padding: 2px 8px; border-radius: 6px; background: var(--surface-2); color: var(--text-2); }
.why.pos { color: var(--pos); } .why.neg { color: var(--neg); }
.card-ai { margin-top: 7px; font-size: 13px; color: var(--text-2); }
.card-ai b { color: var(--brand); margin-right: 4px; }
.card-acts { display: flex; gap: 2px; margin: 6px -6px 0; border-top: 1px dashed var(--line); padding-top: 4px; }
.act { height: 34px; padding: 0 9px; border-radius: 8px; font-size: 12.5px; color: var(--text-3); display: inline-flex; align-items: center; gap: 4px; }
.act:hover { background: var(--surface-2); color: var(--text); }
.act.on { color: var(--brand); }
.act svg { width: 16px; height: 16px; }
.act.out { margin-left: auto; }
.card-sources { margin: 8px 0 2px; padding: 8px 10px; border-radius: var(--radius-sm); background: var(--surface-2); font-size: 13px; }
.card-sources a { display: block; padding: 3px 0; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-sources a b { color: var(--text); margin-right: 6px; }
mark { background: var(--mark); color: inherit; border-radius: 2px; padding: 0 1px; }

.empty, .loading { text-align: center; color: var(--text-3); padding: 48px 12px; font-size: 14px; }
.empty b { display: block; color: var(--text-2); font-size: 16px; margin-bottom: 6px; }
.load-more { display: block; width: 100%; height: 44px; margin-top: 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--text-2); font-weight: 600; }
.notice { background: color-mix(in srgb, var(--brand) 12%, var(--surface)); border: 1px solid color-mix(in srgb, var(--brand) 35%, var(--line)); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px; font-size: 14px; }

/* ── 새 뉴스 알약 ── */
.newpill {
  position: fixed; left: 50%; top: calc(var(--header-h) + var(--ticker-h) + var(--tabs-h) + 10px); transform: translateX(-50%); z-index: 40;
  height: 36px; padding: 0 16px; border-radius: 999px; background: var(--text); color: var(--surface); font-weight: 700; font-size: 14px; box-shadow: 0 6px 18px rgba(0,0,0,.2);
}

/* ── 테마 격자 ── */
.theme-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.tcard { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 13px 14px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 8px; }
.tcard-head { display: flex; align-items: baseline; justify-content: space-between; }
.tcard-head a { font-weight: 800; font-size: 16px; }
.tcard-head small { color: var(--text-3); font-size: 12.5px; }
.ratio { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; display: flex; }
.ratio i { display: block; height: 100%; }
.ratio .p { background: var(--pos); } .ratio .n { background: var(--neg); }
.tcard ol { margin: 0; padding-left: 18px; font-size: 13px; color: var(--text-2); }
.tcard ol li { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── 팝업 키워드 ── */
.popup { position: fixed; inset: 0; z-index: 90; background: rgba(5, 8, 12, 0.92); color: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px; text-align: center; }
.popup-kw { font-size: 15px; font-weight: 800; color: #ffd400; margin-bottom: 18px; letter-spacing: 0.02em; }
.popup-title { font-size: clamp(28px, 6vw, 64px); font-weight: 800; line-height: 1.25; letter-spacing: -0.03em; max-width: 1100px; word-break: keep-all; }
.popup-title mark { background: #ffd400; color: #111; }
.popup-meta { margin-top: 18px; color: #c7cdd6; font-size: 15px; }
.popup-btns { margin-top: 28px; display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.popup-btns button, .popup-btns a { height: 46px; padding: 0 18px; border-radius: 10px; background: rgba(255,255,255,.12); color: #fff; font-weight: 700; display: inline-flex; align-items: center; }
.popup-btns .primary { background: #ffd400; color: #111; }
.popup-count { position: absolute; top: 18px; right: 22px; color: #c7cdd6; font-weight: 700; }
.popup-bar { position: absolute; left: 0; bottom: 0; height: 4px; background: #ffd400; }

/* ── 시트(설정) ── */
.scrim { position: fixed; inset: 0; z-index: 70; background: rgba(0,0,0,.4); }
.sheet {
  position: fixed; z-index: 71; top: 0; right: 0; bottom: 0; width: min(440px, 100%); background: var(--bg);
  overflow-y: auto; box-shadow: -8px 0 30px rgba(0,0,0,.18); overscroll-behavior: contain;
}
.sheet-head { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; height: var(--header-h); padding: 0 8px 0 16px; background: var(--surface); border-bottom: 1px solid var(--line); }
.sheet-head h2 { margin: 0 auto 0 0; font-size: 17px; }
.sheet-body { padding: 12px 16px 40px; }
.sec { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.sec h3 { margin: 0 0 4px; font-size: 15px; font-weight: 800; }
.sec p.help { margin: 0 0 10px; font-size: 13px; color: var(--text-3); }
.row { display: flex; align-items: center; gap: 10px; min-height: 44px; border-top: 1px solid var(--line); font-size: 14px; }
.row:first-of-type { border-top: 0; }
.row label, .row .lbl { flex: 1; }
.row select, .row input[type="time"], .row input[type="number"] { height: 36px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface-2); padding: 0 8px; }
.row input[type="range"] { flex: 1; max-width: 180px; }
.addbox { display: flex; gap: 6px; margin-bottom: 10px; position: relative; }
.addbox input { flex: 1; min-width: 0; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); padding: 0 12px; }
.btn { height: 40px; padding: 0 14px; border-radius: 10px; background: var(--text); color: var(--surface); font-weight: 700; font-size: 14px; white-space: nowrap; }
.btn.ghost { background: var(--surface-2); color: var(--text); }
.btn.brand { background: var(--brand); color: var(--brand-ink); }
.btn:disabled { opacity: .5; cursor: default; }
.kw-list { display: flex; flex-direction: column; gap: 6px; }
.kw { display: flex; align-items: center; gap: 4px; padding: 6px 6px 6px 10px; border-radius: 10px; background: var(--surface-2); }
.kw-name { flex: 1; font-weight: 700; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kw-name small { color: var(--text-3); font-weight: 500; margin-left: 4px; }
.mini { height: 28px; padding: 0 8px; border-radius: 7px; font-size: 12px; font-weight: 700; color: var(--text-3); border: 1px solid var(--line); background: var(--surface); }
.mini[aria-pressed="true"] { color: var(--brand-ink); background: var(--brand); border-color: var(--brand); }
.mini.del { border: 0; background: none; font-size: 16px; width: 28px; padding: 0; }
.suggest { position: absolute; left: 0; right: 60px; top: 44px; z-index: 5; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.15); overflow: hidden; }
.suggest button { display: flex; width: 100%; justify-content: space-between; padding: 10px 12px; text-align: left; font-size: 14px; }
.suggest button:hover, .suggest button.on { background: var(--surface-2); }
.suggest small { color: var(--text-3); }
.code-box { font: 800 28px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: 0.12em; text-align: center; padding: 14px; border-radius: 10px; background: var(--surface-2); margin: 8px 0; }
.status { font-size: 13px; color: var(--text-3); }
.status.ok { color: var(--live); }
.disclaimer { font-size: 12.5px; color: var(--text-3); line-height: 1.6; }

/* ── 토스트·하단 배너 ── */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 95; background: var(--text); color: var(--surface); padding: 10px 16px; border-radius: 10px; font-size: 14px; font-weight: 600; box-shadow: 0 8px 24px rgba(0,0,0,.25); max-width: calc(100% - 32px); }
.appbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 60; display: flex; align-items: center; gap: 8px; padding: 10px 12px 10px 16px; background: var(--surface); border-top: 1px solid var(--line); font-size: 14px; }
.appbar span { flex: 1; }

footer.foot { max-width: 1120px; margin: 0 auto; padding: 0 16px 40px; }

@media (prefers-reduced-motion: reduce) {
  .card.flash { animation: none; }
  .ticker-track.run { animation: none; }
}
