:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #f0eee9;
  --text: #17181b;
  --muted: #6a6c72;
  --line: #e4e1da;
  --accent: #1d3fb8;
  --accent-soft: #e8edfb;
  --up: #d1302a;
  --down: #2459d6;
  --flat: #8a8d93;
  --warn-soft: #fff4dc;
  --warn-text: #8a5a00;
  --star: #e8a400;
  --shadow: 0 1px 2px rgba(20, 20, 30, .04), 0 4px 16px rgba(20, 20, 30, .05);
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1e222b;
    --text: #ecedf0;
    --muted: #9aa0ab;
    --line: #272b35;
    --accent: #7c9cff;
    --accent-soft: #1e2742;
    --up: #ff5d55;
    --down: #5e8eff;
    --flat: #8a8f99;
    --warn-soft: #2e2614;
    --warn-text: #f0c060;
    --star: #f5c040;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1e222b;
  --text: #ecedf0;
  --muted: #9aa0ab;
  --line: #272b35;
  --accent: #7c9cff;
  --accent-soft: #1e2742;
  --up: #ff5d55;
  --down: #5e8eff;
  --flat: #8a8f99;
  --warn-soft: #2e2614;
  --warn-text: #f0c060;
  --star: #f5c040;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  word-break: keep-all;
  overflow-wrap: anywhere;
}

body.no-scroll { overflow: hidden; }

a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }

/* ---------- 레이아웃 ---------- */
.app {
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 24px 14px;
  border-right: 1px solid var(--line);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 18px;
  padding: 0 8px;
  letter-spacing: -0.02em;
}

.brand-mark {
  width: 30px; height: 30px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  display: grid; place-items: center;
  font-size: 15px;
}

.side-nav { display: flex; flex-direction: column; gap: 2px; }
.side-nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px;
  border-radius: 10px;
  color: var(--muted);
  font-weight: 500;
  font-size: 15px;
}
.side-nav a:hover { background: var(--surface-2); color: var(--text); }
.side-nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.side-nav .ico { width: 20px; text-align: center; }

.main {
  padding: 32px 32px 64px;
  width: 100%;
  max-width: 920px;
  outline: none;
}

.tabbar { display: none; }

@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { display: none; }
  .main { padding: 20px 16px calc(96px + env(safe-area-inset-bottom)); }
  .tabbar {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 20;
    background: var(--surface);
    border-top: 1px solid var(--line);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .tabbar a {
    display: flex; flex-direction: column; align-items: center; gap: 1px;
    font-size: 11px; color: var(--muted); padding: 4px 0;
  }
  .tabbar a span { font-size: 19px; filter: grayscale(1); opacity: .7; }
  .tabbar a.active { color: var(--accent); font-weight: 700; }
  .tabbar a.active span { filter: none; opacity: 1; }
}

/* ---------- 공통 ---------- */
.loading, .empty { color: var(--muted); padding: 24px 0; }

.page-head { margin-bottom: 24px; }
.page-head h1 { font-size: 26px; font-weight: 800; letter-spacing: -0.03em; line-height: 1.3; }
.page-head p { color: var(--muted); margin-top: 6px; font-size: 15px; }

.eyebrow { font-size: 13px; font-weight: 600; color: var(--muted); letter-spacing: 0.01em; }

.section { margin-top: 36px; }
.section-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  margin-bottom: 12px;
}
.section-head h2 { font-size: 18px; font-weight: 800; letter-spacing: -0.02em; }
.section-head a { font-size: 14px; color: var(--accent); font-weight: 600; white-space: nowrap; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.sample-banner {
  display: flex; gap: 8px; align-items: flex-start;
  background: var(--warn-soft); color: var(--warn-text);
  border-radius: 10px; padding: 10px 14px;
  font-size: 13.5px; font-weight: 500;
  margin-bottom: 20px;
}

.chip-row { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  color: var(--muted);
}
.chip:hover { color: var(--text); }
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); font-weight: 700; }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; font-weight: 600;
  padding: 2px 8px; border-radius: 6px;
  background: var(--surface-2); color: var(--muted);
  white-space: nowrap;
}
.badge.korea { background: #ffe9e7; color: #b42318; }
.badge.global { background: var(--accent-soft); color: var(--accent); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .badge.korea { background: #3a1f1d; color: #ff8a80; }
}
:root[data-theme="dark"] .badge.korea { background: #3a1f1d; color: #ff8a80; }

.star { color: var(--star); }

.up { color: var(--up); }
.down { color: var(--down); }
.flat { color: var(--flat); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--surface);
  border-radius: 10px; padding: 9px 16px;
  font-weight: 600; font-size: 14px; cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .55; cursor: default; }

input[type="text"], input[type="search"], textarea {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 14px;
  outline: none;
}
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; min-height: 88px; line-height: 1.55; }

/* ---------- 홈 ---------- */
.headline-card { padding: 22px 24px; }
.headline-card .eyebrow { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.headline-card h1 { font-size: 23px; font-weight: 800; line-height: 1.45; letter-spacing: -0.03em; margin-top: 8px; }

.ind-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}
.ind-mini { padding: 12px 14px; display: block; }
.ind-mini .name { font-size: 13px; color: var(--muted); font-weight: 500; }
.ind-mini .asof { font-size: 11px; opacity: .75; }
.ind-mini .val { font-size: 18px; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; margin-top: 2px; }
.ind-mini .chg { font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
@media (max-width: 860px) {
  .ind-strip {
    display: flex; overflow-x: auto; scroll-snap-type: x mandatory;
    margin-left: -16px; margin-right: -16px; padding: 0 16px 4px;
    scrollbar-width: none;
  }
  .ind-strip::-webkit-scrollbar { display: none; }
  .ind-mini { flex: 0 0 132px; scroll-snap-align: start; }
}

.top-list { display: flex; flex-direction: column; gap: 12px; }

.story {
  padding: 18px 20px;
  cursor: pointer;
  text-align: left;
  width: 100%;
  display: block;
  transition: border-color .15s, transform .15s;
}
.story:hover { border-color: var(--accent); }
.story:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.story .meta { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.story h3 { font-size: 17.5px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.45; margin-top: 8px; }
.story .lede { color: var(--muted); font-size: 15px; margin-top: 6px; }
.story .why-teaser {
  margin-top: 10px; font-size: 13.5px; color: var(--text);
  background: var(--surface-2); border-radius: 8px; padding: 7px 10px;
}
.story .why-teaser b { color: var(--accent); }
.story.compact { padding: 14px 16px; }
.story.compact h3 { font-size: 16px; margin-top: 6px; }

.rank {
  display: inline-grid; place-items: center;
  width: 22px; height: 22px; border-radius: 6px;
  background: var(--text); color: var(--bg);
  font-size: 12px; font-weight: 800;
}

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

.event-list { display: flex; flex-direction: column; }
.event {
  display: grid; grid-template-columns: 64px minmax(0, 1fr); gap: 14px;
  padding: 14px 18px; border-top: 1px solid var(--line);
}
.event:first-child { border-top: 0; }
.event .d { font-weight: 800; font-size: 15px; line-height: 1.3; }
.event .d small { display: block; font-size: 12px; color: var(--muted); font-weight: 500; }
.event .t { font-weight: 700; font-size: 15.5px; }
.event .w { font-size: 14px; color: var(--muted); margin-top: 2px; }
.event .tags { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.event.today { background: var(--accent-soft); }

/* 퀴즈 */
.quiz { padding: 20px; }
.quiz-q + .quiz-q { margin-top: 22px; padding-top: 20px; border-top: 1px dashed var(--line); }
.quiz-q .q { font-weight: 700; font-size: 16px; }
.quiz-q .q small { color: var(--muted); font-weight: 600; margin-right: 6px; }
.choices { display: grid; gap: 8px; margin-top: 10px; }
.choice {
  text-align: left; padding: 10px 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-size: 15px;
}
.choice:hover:not(:disabled) { border-color: var(--accent); }
.choice:disabled { cursor: default; }
.choice.correct { border-color: #1f9d55; background: #e7f7ee; color: #146c3b; font-weight: 700; }
.choice.wrong { border-color: var(--up); background: #fdecea; color: #a1231d; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .choice.correct { background: #12301f; color: #6be29a; }
  :root:not([data-theme="light"]) .choice.wrong { background: #3a1716; color: #ff8a80; }
}
:root[data-theme="dark"] .choice.correct { background: #12301f; color: #6be29a; }
:root[data-theme="dark"] .choice.wrong { background: #3a1716; color: #ff8a80; }
.explain { margin-top: 10px; font-size: 14px; color: var(--muted); background: var(--surface-2); padding: 10px 12px; border-radius: 8px; }
.quiz-score { font-weight: 700; color: var(--accent); }

/* ---------- 뉴스 ---------- */
.filters { display: flex; flex-direction: column; gap: 10px; margin-bottom: 18px; }
.news-list { display: flex; flex-direction: column; gap: 10px; }

/* ---------- 지표 ---------- */
.ind-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.ind-card { padding: 16px 18px; }
.ind-card .top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.ind-card .name { font-weight: 700; font-size: 15px; }
.ind-card .src { font-size: 12px; color: var(--muted); }
.ind-card .val { font-size: 26px; font-weight: 800; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; margin-top: 4px; }
.ind-card .val small { font-size: 15px; font-weight: 600; margin-left: 2px; color: var(--muted); }
.ind-card .chg { font-weight: 700; font-size: 14px; font-variant-numeric: tabular-nums; }
.ind-card svg { display: block; width: 100%; height: 44px; margin-top: 10px; }
.ind-card .desc { font-size: 13.5px; color: var(--muted); margin-top: 8px; }

/* ---------- 타임라인 ---------- */
.tl-list { display: grid; gap: 12px; }
.tl-card { padding: 18px 20px; display: block; }
.tl-card h3 { font-size: 17px; font-weight: 800; }
.tl-card p { color: var(--muted); font-size: 14.5px; margin-top: 4px; }
.tl-card .latest { margin-top: 10px; font-size: 14px; }

.tl { position: relative; padding-left: 26px; margin-top: 8px; }
.tl::before { content: ""; position: absolute; left: 7px; top: 6px; bottom: 6px; width: 2px; background: var(--line); }
.tl-item { position: relative; padding: 0 0 22px; }
.tl-item::before {
  content: ""; position: absolute; left: -25px; top: 6px;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--surface); border: 3px solid var(--line);
}
.tl-item.now::before { border-color: var(--accent); background: var(--accent); }
.tl-item .date { font-size: 13px; font-weight: 700; color: var(--muted); }
.tl-item .txt { font-size: 15.5px; margin-top: 2px; }
.tl-item .link { font-size: 13.5px; color: var(--accent); font-weight: 600; cursor: pointer; background: none; border: 0; padding: 0; margin-top: 4px; }

/* ---------- 사전 ---------- */
.gl-search { position: relative; }
.gl-group { margin-top: 22px; }
.gl-group h3 { font-size: 14px; color: var(--muted); font-weight: 700; margin-bottom: 8px; }
.gl-items { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 8px; }
.gl-item { padding: 12px 14px; cursor: pointer; text-align: left; width: 100%; }
.gl-item:hover { border-color: var(--accent); }
.gl-item b { font-size: 15.5px; }
.gl-item p { font-size: 13.5px; color: var(--muted); margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.gl-item .new { font-size: 11px; color: var(--accent); font-weight: 700; margin-left: 6px; }
.request-box { padding: 16px 18px; margin-top: 12px; }
.request-box p { font-size: 14.5px; }

/* ---------- 본문 안 용어 ---------- */
.term {
  background: none; border: 0; padding: 0; cursor: pointer;
  font: inherit; color: inherit;
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}
.term:hover { color: var(--accent); }
.term.term-new { text-decoration-style: dotted; }

/* ---------- 레이어 (상세, 용어) ---------- */
.layer { position: fixed; inset: 0; z-index: 50; }
.layer[hidden] { display: none; }
.layer-term { z-index: 60; }
.layer-backdrop { position: absolute; inset: 0; background: rgba(10, 12, 18, .45); }

.sheet {
  position: absolute; top: 0; right: 0; bottom: 0;
  width: min(600px, 100%);
  background: var(--bg);
  overflow-y: auto;
  padding: 28px 28px 48px;
  box-shadow: -8px 0 32px rgba(0, 0, 0, .15);
  animation: slideIn .22s ease-out;
}
@keyframes slideIn { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }

.sheet-close {
  position: sticky; top: 0; float: right;
  width: 36px; height: 36px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--surface);
  cursor: pointer; font-size: 15px; z-index: 2;
}

@media (max-width: 860px) {
  .sheet {
    top: 6vh; left: 0; width: 100%;
    border-radius: 18px 18px 0 0;
    padding: 20px 16px calc(40px + env(safe-area-inset-bottom));
    animation: slideUp .25s ease-out;
  }
  @keyframes slideUp { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
}

.detail h2 { font-size: 22px; font-weight: 800; letter-spacing: -0.03em; line-height: 1.4; margin-top: 10px; padding-right: 44px; }
.detail .block { margin-top: 24px; }
.detail .block-title { font-size: 14px; font-weight: 800; color: var(--muted); margin-bottom: 10px; display: flex; align-items: center; gap: 6px; }
.detail ul.summary { margin: 0; padding-left: 20px; display: grid; gap: 6px; font-size: 16px; }

.why { padding: 18px; background: var(--accent-soft); border-radius: var(--radius); }
.chain { display: flex; flex-direction: column; gap: 0; }
.chain-step {
  background: var(--surface); border-radius: 10px; padding: 9px 14px;
  font-weight: 600; font-size: 15px; border: 1px solid var(--line);
}
.chain-arrow { text-align: center; color: var(--accent); font-weight: 800; line-height: 1.4; font-size: 15px; }
.korea-impact { margin-top: 12px; font-size: 15px; }
.korea-impact b { color: var(--up); }

.fo { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 560px) { .fo { grid-template-columns: 1fr; } }
.fo > div { padding: 14px 16px; }
.fo h4 { margin: 0 0 6px; font-size: 13.5px; }
.fo ul { margin: 0; padding-left: 18px; font-size: 14.5px; display: grid; gap: 4px; }
.fo .fact h4 { color: #1f8a4c; }
.fo .outlook h4 { color: #b26a00; }

.sources a { color: var(--accent); font-weight: 600; font-size: 14.5px; }
.sources { display: flex; flex-wrap: wrap; gap: 6px 14px; }

.note-status { font-size: 13px; color: var(--muted); margin-top: 6px; min-height: 1em; }

.term-card {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(440px, calc(100% - 32px));
  max-height: 80vh; overflow-y: auto;
  background: var(--surface); border-radius: 18px;
  padding: 22px 22px 24px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, .25);
}
@media (max-width: 860px) {
  .term-card {
    top: auto; bottom: 0; left: 0; transform: none; width: 100%;
    border-radius: 18px 18px 0 0;
    padding-bottom: calc(28px + env(safe-area-inset-bottom));
  }
}
.term-card h3 { font-size: 21px; font-weight: 800; padding-right: 44px; }
.term-card .def { font-size: 16px; margin-top: 10px; }
.term-card .ex { margin-top: 12px; background: var(--surface-2); padding: 12px 14px; border-radius: 10px; font-size: 15px; }
.term-card .ex b { color: var(--accent); }
.term-card .usage { margin-top: 14px; font-size: 14px; }
.term-card .usage button { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font: inherit; font-weight: 600; text-align: left; }
.term-card .related { margin-top: 14px; }

/* ---------- 노트, 설정, 더보기 ---------- */
.note-item { padding: 16px 18px; }
.note-item + .note-item { margin-top: 10px; }
.note-item .t { font-weight: 700; cursor: pointer; }
.note-item .t:hover { color: var(--accent); }
.note-item .txt { margin-top: 8px; font-size: 15px; white-space: pre-wrap; border-left: 3px solid var(--accent); padding-left: 12px; }

.kw-form { display: flex; gap: 8px; }
.kw-form input { flex: 1; }
.kw-chip { display: inline-flex; align-items: center; gap: 6px; }
.kw-chip button { background: none; border: 0; cursor: pointer; color: var(--muted); padding: 0 0 0 2px; font-size: 13px; }

.settings-card { padding: 20px; }
.settings-card + .settings-card { margin-top: 12px; }
.settings-card h3 { font-size: 16px; font-weight: 800; }
.settings-card > p { font-size: 14px; color: var(--muted); margin-top: 4px; margin-bottom: 12px; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; font-size: 14.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; }

.more-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.more-grid a { padding: 18px; display: flex; flex-direction: column; gap: 4px; }
.more-grid a span { font-size: 24px; }
.more-grid a b { font-size: 15.5px; }
.more-grid a small { color: var(--muted); font-size: 13px; }

.wk-list { display: grid; gap: 10px; }
.wk-item { padding: 14px 18px; display: grid; grid-template-columns: 28px 1fr; gap: 10px; }
.wk-item h4 { margin: 0; font-size: 16px; }
.wk-item p { font-size: 14.5px; color: var(--muted); }
.wk-table { width: 100%; border-collapse: collapse; font-size: 15px; }
.wk-table td { padding: 10px 16px; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.wk-table tr:first-child td { border-top: 0; }
.wk-table td:last-child { text-align: right; font-weight: 700; }

/* ---------- Claude에게 물어보기 ---------- */
.ask-box { padding: 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.ask-box .chip { color: var(--accent); border-color: var(--accent-soft); background: var(--accent-soft); font-weight: 600; }
.ask-form { display: flex; gap: 8px; margin-top: 12px; }
.ask-form input { flex: 1; min-width: 0; }
.ask-form .btn { white-space: nowrap; }
.ask-note { font-size: 12.5px; color: var(--muted); margin-top: 8px; }
.more-ask { color: var(--accent); font-weight: 600; font-size: 14px; }
.sel-ask {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 70;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 14.5px;
  padding: 11px 18px; border-radius: 999px; box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
  white-space: nowrap; max-width: calc(100% - 32px); overflow: hidden; text-overflow: ellipsis;
}
.sel-ask[hidden] { display: none; }

.footnote { margin-top: 40px; font-size: 12.5px; color: var(--muted); }
