:root {
  --bg: #0E1116;
  --card: #171B22;
  --card-hi: #1D232C;
  --line: #262D38;
  --text: #F2F4F7;
  --muted: #8D96A5;
  --accent: #C6F432;
  --accent-ink: #0E1116;
  --warm: #FF9F6B;
  --fuel-gas: #6B9A2E; /* 휘발유 추이선 (색약 검증: dataviz validate_palette 통과) */
  --fuel-diesel: #4C8AD1; /* 경유 추이선 */
  --bg-rgb: 14, 17, 22;
  --radius: 18px;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #F6F8F3; --card: #FFFFFF; --card-hi: #EEF3E4; --line: #DCE3D2;
    --text: #171B14; --muted: #5B6555; --accent: #5C8A28; --accent-ink: #FFFFFF;
    --bg-rgb: 246, 248, 243;
    color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #F6F8F3; --card: #FFFFFF; --card-hi: #EEF3E4; --line: #DCE3D2;
  --text: #171B14; --muted: #5B6555; --accent: #5C8A28; --accent-ink: #FFFFFF;
  --bg-rgb: 246, 248, 243;
  color-scheme: light;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
  background: var(--bg) radial-gradient(60% 260px at 50% -40px, rgba(198, 244, 50, .16), transparent 72%) no-repeat;
  color: var(--text);
  word-break: keep-all; /* 한글은 어절 단위로 줄바꿈 */
  overflow-wrap: break-word;
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", system-ui, sans-serif;
}
body > * { max-width: 480px; margin-inline: auto; padding-inline: 20px; }
a { color: var(--accent); }
h1 { margin: 0; font-size: 30px; line-height: 1.25; letter-spacing: -.03em; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.theme-toggle {
  position: fixed; z-index: 20; top: calc(14px + env(safe-area-inset-top, 0px)); right: max(14px, calc((100% - 480px) / 2 + 14px));
  width: 38px; height: 38px; border: 1px solid var(--line); border-radius: 50%;
  background: var(--card); font-size: 16px; line-height: 1; cursor: pointer;
  box-shadow: 0 6px 16px -6px rgba(0, 0, 0, .4);
}
.theme-toggle:hover { border-color: var(--accent); }

/* 헤더 */
.hero { padding-top: 40px; padding-bottom: 20px; }
.eyebrow { display: inline-flex; align-items: center; gap: 8px; margin: 0 0 14px; font-size: 13px; font-weight: 600; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 12px var(--accent); }
.accent { color: var(--accent); }
.lead { margin: 10px 0 0; color: var(--muted); text-wrap: balance; }
.hero-links { margin: 10px 0 0; font-size: 13px; }
.hero-links a { font-weight: 700; text-decoration: none; }
.hero-links a:hover { text-decoration: underline; }

/* 필터 (스크롤해도 상단에 고정) */
.filters { position: sticky; top: 0; z-index: 5; padding-block: 12px; background: rgba(var(--bg-rgb), .82); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px); }
.selects { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
select {
  width: 100%; height: 48px; padding: 0 40px 0 14px;
  appearance: none; -webkit-appearance: none;
  border: 1px solid var(--line); border-radius: 14px;
  background: var(--card) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238D96A5' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 14px center / 16px;
  color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
  transition: border-color .2s;
}
select:hover { border-color: #3A4452; }
option { background: var(--card); color: var(--text); }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; margin-top: 10px; padding: 5px; border: 1px solid var(--line); border-radius: 16px; background: var(--card); }
.seg button {
  height: 44px; border: 0; border-radius: 12px; background: transparent;
  color: var(--muted); font: inherit; font-weight: 700; cursor: pointer;
  transition: background .2s, color .2s, box-shadow .2s, transform .1s;
}
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); box-shadow: 0 6px 24px -8px rgba(198, 244, 50, .6); }
.seg button:active { transform: scale(.97); }

/* 결과 */
main { padding-top: 6px; }
.status { min-height: 1.5em; margin: 10px 0 12px; font-size: 13px; color: var(--muted); }
.list { display: grid; gap: 12px; margin: 0; padding: 0; list-style: none; }
.card {
  padding: 16px 18px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card);
  animation: rise .45s cubic-bezier(.2, .7, .2, 1) both; animation-delay: calc(var(--i, 0) * 45ms);
}
.card.best {
  border-color: rgba(198, 244, 50, .45);
  background: linear-gradient(180deg, rgba(198, 244, 50, .1), rgba(198, 244, 50, 0) 62%), var(--card);
  box-shadow: 0 10px 40px -18px rgba(198, 244, 50, .55);
}
.card-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.rank { padding: 3px 10px; border-radius: 99px; background: var(--card-hi); color: var(--muted); font-size: 12px; font-weight: 800; }
.best .rank { background: var(--accent); color: var(--accent-ink); }
.chip { padding: 2px 10px; border: 1px solid var(--line); border-radius: 99px; color: var(--muted); font-size: 12px; }
.price { display: flex; align-items: baseline; gap: 4px; margin: 10px 0 4px; font-variant-numeric: tabular-nums; }
.price strong { font-size: 30px; line-height: 1.1; letter-spacing: -.02em; }
.best .price strong { font-size: 40px; color: var(--accent); }
.price span { color: var(--muted); font-weight: 600; }
.diff { margin-left: auto; color: var(--warm); font-size: 13px; font-style: normal; font-weight: 700; }
.name { margin: 0; font-size: 16px; font-weight: 700; }
.addr { margin: 2px 0 0; color: var(--muted); font-size: 14px; }
.actions { display: flex; gap: 8px; margin-top: 12px; }
.btn {
  display: inline-flex; flex: 1; align-items: center; justify-content: center; height: 36px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--card-hi);
  color: var(--text); font: inherit; font-size: 14px; font-weight: 600; text-decoration: none; cursor: pointer;
  transition: border-color .2s, transform .1s;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: scale(.98); }

/* 로딩·빈 상태 */
.skel { height: 136px; border: 1px solid var(--line); border-radius: var(--radius); background: linear-gradient(100deg, var(--card) 30%, var(--card-hi) 50%, var(--card) 70%) 0 0 / 200% 100%; animation: shimmer 1.3s linear infinite; }
.notice { display: grid; justify-items: center; gap: 4px; padding: 40px 20px; border: 1px dashed var(--line); border-radius: var(--radius); color: var(--muted); text-align: center; }
.notice strong { color: var(--text); font-size: 17px; }
.notice .btn { flex: none; margin-top: 14px; padding: 0 20px; }

/* 하단 · 안내 페이지 공통 */
.foot { padding-block: 32px 40px; color: var(--muted); font-size: 13px; }
.foot a { color: var(--muted); }
.foot p { margin: 6px 0 0; }
body > main:not(:has(.list)) { padding-block: 32px; }
body > main:not(:has(.list)) h2 { margin: 28px 0 8px; font-size: 18px; }
body > main:not(:has(.list)) p { color: #C9CFD9; }

@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
@keyframes shimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* 접속 통계 페이지 */
.stats-auth { display: flex; gap: 8px; margin: 16px 0; }
.stats-auth input { flex: 1; min-width: 0; height: 44px; padding: 0 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--card); color: var(--text); font: inherit; }
.stats-auth .btn { flex: none; height: 44px; padding: 0 18px; }
.stats-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.stats-table th, .stats-table td { padding: 10px 8px; border-bottom: 1px solid var(--line); text-align: right; }
.stats-table th:first-child, .stats-table td:first-child { text-align: left; }
.stats-table th { color: var(--muted); font-size: 13px; font-weight: 600; }
.stats-table tr.current td { color: var(--accent); font-weight: 700; }
.stats-note { margin-top: 16px; color: var(--muted); font-size: 13px; }

/* 최근 일주일 전국 평균가 추이 */
.trend { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; padding: 14px 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); width: calc(100% - 40px); max-width: 440px; }
.trend[hidden] { display: none; }
.trend-legend { display: grid; gap: 6px; min-width: 0; font-size: 12px; }
.trend-title { margin: 0; color: var(--muted); font-size: 11px; font-weight: 700; }
.trend-legend .row { display: flex; align-items: baseline; gap: 6px; white-space: nowrap; }
.trend-legend .dot { flex: none; width: 8px; height: 8px; border-radius: 50%; align-self: center; }
.trend-legend .name { color: var(--muted); font-weight: 600; }
.trend-legend .price { color: var(--text); font-weight: 800; font-variant-numeric: tabular-nums; }
.trend-legend .delta { font-size: 11px; font-weight: 700; }
.trend-legend .delta.up { color: var(--warm); }
.trend-legend .delta.down { color: #7DB8FF; }
.trend-chart { flex: none; width: 132px; height: 40px; }
.trend-chart polyline { fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.trend-chart circle { stroke: var(--card); stroke-width: 2; }

/* 정렬 */
.sorts { display: flex; gap: 6px; margin-top: 4px; }
.sorts button { height: 32px; padding: 0 14px; border: 1px solid var(--line); border-radius: 99px; background: transparent; color: var(--muted); font: inherit; font-size: 13px; font-weight: 700; cursor: pointer; transition: border-color .2s, color .2s, background .2s, transform .1s; }
.sorts button[aria-pressed="true"] { border-color: rgba(198, 244, 50, .6); background: rgba(198, 244, 50, .1); color: var(--accent); }
.sorts button:active { transform: scale(.96); }

/* 카드 보강: 거리 · 배지 · 버튼 */
.card-left { display: flex; align-items: center; gap: 6px; min-height: 22px; }
.dist { padding: 3px 9px; border-radius: 99px; background: rgba(125, 184, 255, .12); color: #7DB8FF; font-size: 12px; font-weight: 800; font-variant-numeric: tabular-nums; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.tag { padding: 2px 9px; border: 1px solid var(--line); border-radius: 99px; color: var(--muted); font-size: 12px; font-weight: 700; }
.tag.self { border-color: rgba(198, 244, 50, .5); color: var(--accent); }
.tag.quality { border-color: rgba(125, 184, 255, .45); color: #7DB8FF; }
.tag.open24 { border-color: rgba(255, 159, 107, .5); color: var(--warm); }
.actions .btn { min-width: 0; padding: 0 8px; white-space: nowrap; }

/* 더 보기 · 광고 */
.more { width: 100%; margin-top: 12px; height: 44px; flex: none; }
.more[hidden], .ad[hidden] { display: none; }
.ad { margin: 56px 0 4px; padding-top: 20px; border-top: 1px solid var(--line); min-height: 100px; text-align: center; } /* 버튼과 충분히 떨어뜨려 실수 클릭을 막는다 */
.ad::before { content: "광고"; display: block; margin-bottom: 6px; color: var(--muted); font-size: 11px; }

@media (max-width: 360px) { .actions .btn { padding: 0 4px; font-size: 13px; } }

/* 내 위치로 찾기 · 내 주변 도구 */
.locate-row { margin-bottom: 12px; }
.locate-row[hidden] { display: none; }
.locate { width: 100%; height: 46px; border: 1px solid rgba(198, 244, 50, .45); border-radius: 14px; background: rgba(198, 244, 50, .08); color: var(--accent); font: inherit; font-weight: 800; cursor: pointer; transition: background .2s, transform .1s; }
.locate:hover:not(:disabled) { background: rgba(198, 244, 50, .14); }
.locate:active:not(:disabled) { transform: scale(.98); }
.locate:disabled { opacity: .6; cursor: progress; }
.near-tools { display: flex; flex-wrap: wrap; gap: 8px 14px; margin-top: 10px; }
.near-tools[hidden] { display: none; }
.near-group { display: flex; gap: 6px; }
.near-group button { height: 30px; padding: 0 12px; border: 1px solid var(--line); border-radius: 99px; background: transparent; color: var(--muted); font: inherit; font-size: 12px; font-weight: 700; cursor: pointer; }
.near-group button[aria-pressed="true"] { border-color: rgba(125, 184, 255, .6); background: rgba(125, 184, 255, .12); color: #7DB8FF; }

/* 관련 뉴스·종목 */
.related { padding-block: 28px; border-top: 1px solid var(--line); scroll-margin-top: 140px; } /* 위로 고정된 필터 바에 제목이 가리지 않게 */
.related h2 { margin: 0 0 4px; font-size: 17px; }
.related-lead { margin: 0 0 14px; color: var(--muted); font-size: 13px; }
.stock-list, .news-list { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.stock-list a { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; padding: 12px 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--card); color: var(--text); text-decoration: none; transition: border-color .2s; }
.stock-list a:hover { border-color: var(--accent); }
.stock-list .code { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.stock-list .why { flex-basis: 100%; color: var(--muted); font-size: 13px; }
.news-item { padding: 10px 0; border-bottom: 1px solid var(--line); }
.news-item:last-child { border-bottom: 0; }
.news-item a { color: var(--text); font-size: 14px; font-weight: 600; text-decoration: none; }
.news-item a:hover { color: var(--accent); }
.news-meta { display: block; margin-top: 4px; color: var(--muted); font-size: 12px; }
.news-list .skel { height: 44px; border-radius: 10px; }

/* 포털로 돌아가는 링크 · 맨 위로 버튼 */
.crumb { margin: 14px 0 0; font-size: 13px; }
.crumb a { color: var(--muted); text-decoration: none; }
.crumb a:hover { color: var(--accent); }
.top {
  position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); z-index: 10;
  width: 44px; height: 44px; border: 1px solid var(--line); border-radius: 50%;
  background: var(--card-hi); color: var(--text); font-size: 18px; line-height: 1; cursor: pointer;
  box-shadow: 0 8px 24px -8px rgba(0, 0, 0, .5);
  transition: background .2s, transform .1s;
}
.top[hidden] { display: none; }
.top:hover { background: var(--card); border-color: var(--accent); }
.top:active { transform: scale(.94); }
