/* 부자: 세로 모바일 웹. 한 줄 컬럼(최대 480px) + 하단 탭 + 지역 바텀시트
   색 규칙: 상승·호재는 빨강, 하락·악재는 파랑 (국내 시세 표기 관례). 점수 지도는 남색 단계, 강조는 금색. */
:root {
  --bg: #f2f4f7;
  --surface: #ffffff;
  --sunk: #e9edf2;
  --ink: #0f1b2d;
  --muted: #5d6879;
  --line: #e0e5ec;
  --navy: #1f3d72;
  --gold: #a87a22;
  --gold-soft: #f6ecd6;
  --up: #d23b3b;
  --up-soft: #fbe7e5;
  --down: #2c66d0;
  --down-soft: #e3ecfb;
  --ctx: #dde2e9;
  --s1: #e1e8f3; --s2: #b9cae6; --s3: #85a2d3; --s4: #4f74b6; --s5: #22447f;
  --map-stroke: #ffffff;
  --shadow: 0 10px 30px rgba(15, 27, 45, 0.12);
  --f-display: 'Black Han Sans', 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  --f-body: 'IBM Plex Sans KR', 'Apple SD Gothic Neo', 'Malgun Gothic', 'Noto Sans KR', system-ui, sans-serif;
  --tabs-h: 64px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b111b; --surface: #141c29; --sunk: #1b2535; --ink: #e7ecf4; --muted: #96a2b5; --line: #263244;
    --navy: #8fb1ec; --gold: #dcae52; --gold-soft: #2e2615; --up: #ff6a66; --up-soft: #3a1c1e; --down: #5d95f6; --down-soft: #172840;
    --ctx: #1a2230; --s1: #1e2a3e; --s2: #2a4068; --s3: #3d609b; --s4: #5d86ca; --s5: #94b5ee; --map-stroke: #0b111b;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.5); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b111b; --surface: #141c29; --sunk: #1b2535; --ink: #e7ecf4; --muted: #96a2b5; --line: #263244;
  --navy: #8fb1ec; --gold: #dcae52; --gold-soft: #2e2615; --up: #ff6a66; --up-soft: #3a1c1e; --down: #5d95f6; --down-soft: #172840;
  --ctx: #1a2230; --s1: #1e2a3e; --s2: #2a4068; --s3: #3d609b; --s4: #5d86ca; --s5: #94b5ee; --map-stroke: #0b111b;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.5); color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); font-family: var(--f-body); font-size: 15px; line-height: 1.5;
  -webkit-tap-highlight-color: transparent; -webkit-text-size-adjust: 100%;
}
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 10; background: var(--bg); }
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--navy); outline-offset: 2px; }
.num { font-variant-numeric: tabular-nums; }

.app { max-width: 480px; margin: 0 auto; min-height: 100%; padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom, 0px) + 12px); }

/* 상단 */
.top {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding-block: 12px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  background: var(--bg);
}
.brand { display: flex; align-items: baseline; gap: 8px; }
.logo { font-family: var(--f-display); font-size: 30px; line-height: 1; color: var(--ink); letter-spacing: -0.5px; }
.logo::after { content: ""; display: inline-block; width: 7px; height: 7px; margin-left: 3px; border-radius: 50%; background: var(--gold); vertical-align: top; }
.tagline { font-size: 13px; color: var(--muted); }
.tagline b { color: var(--ink); font-weight: 700; }

.pad { padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.stack { display: flex; flex-direction: column; gap: 14px; }

/* 하단 탭 */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; justify-content: center;
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px); padding-left: env(safe-area-inset-left, 0px); padding-right: env(safe-area-inset-right, 0px);
}
.tabs button { flex: 1; max-width: 120px; height: var(--tabs-h); border: 0; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 11.5px; color: var(--muted); }
.tabs svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round; }
.tabs button.on { color: var(--ink); font-weight: 700; }
.tabs button.on svg { stroke-width: 2.3; }

/* 공통 블록 */
.card { background: var(--surface); border-radius: 18px; padding: 16px; }
.h-sec { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin: 0 0 10px; }
.h-sec h3 { margin: 0; font-size: 17px; font-weight: 700; text-wrap: balance; }
.h-sec small { color: var(--muted); font-size: 12px; }
.seg { display: inline-flex; background: var(--sunk); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: none; padding: 6px 12px; border-radius: 8px; font-size: 13px; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--ink); font-weight: 700; box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.chip { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 700; padding: 2px 8px; border-radius: 6px; background: var(--sunk); color: var(--muted); white-space: nowrap; }
.chip.up { background: var(--up-soft); color: var(--up); }
.chip.down { background: var(--down-soft); color: var(--down); }
.chip.gold { background: var(--gold-soft); color: var(--gold); }
.up-t { color: var(--up); } .down-t { color: var(--down); }
.src { margin: 10px 0 0; font-size: 11.5px; color: var(--muted); }
.foot-note { font-size: 12px; color: var(--muted); line-height: 1.6; margin: 4px 0 0; }

/* 지도 화면 */
.brief { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.brief div { background: var(--surface); border-radius: 14px; padding: 10px 12px; min-width: 0; }
.brief small { display: block; font-size: 11.5px; color: var(--muted); }
.brief b { display: block; font-size: 15px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brief em { font-style: normal; font-size: 12px; font-weight: 700; }

.map-card { background: var(--surface); border-radius: 18px; padding: 12px; }
.map-tools { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.map-mode { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 6px 8px; font: inherit; font-size: 13px; color: var(--ink); }
.map-wrap { position: relative; margin-top: 10px; border-radius: 12px; overflow: hidden; background: var(--sunk); touch-action: none; user-select: none; -webkit-user-select: none; }
.map-wrap { aspect-ratio: 1 / 1; max-width: 100%; }
.map-wrap svg { display: block; width: 100%; height: 100%; }
.map-wrap path.rg { stroke: var(--map-stroke); stroke-width: 0.5; vector-effect: non-scaling-stroke; transition: opacity .15s; cursor: pointer; }
.map-wrap path.ctx { fill: var(--ctx); stroke: var(--map-stroke); stroke-width: 1; vector-effect: non-scaling-stroke; }
.map-wrap path.rg.sel { stroke: var(--ink); stroke-width: 2.6; }
.map-wrap path.gu-line { fill: none; stroke: var(--map-stroke); stroke-width: 1.8; vector-effect: non-scaling-stroke; pointer-events: none; }
.map-wrap path.gu-line.focus { stroke: var(--ink); stroke-width: 2.2; }
.focus-bar { display: flex; align-items: center; gap: 8px; margin-top: 10px; padding: 8px 10px; border-radius: 10px; background: var(--sunk); font-size: 13.5px; }
.focus-bar span { flex: 1; min-width: 0; }
.link { border: 0; background: none; padding: 2px 0; color: var(--navy); font-weight: 700; font-size: 13px; }
.x-sm { border: 0; background: none; width: 28px; height: 28px; font-size: 20px; line-height: 1; color: var(--muted); }
.brief div[data-open] { cursor: pointer; }
.gtx-st span[data-open] { cursor: pointer; }
.gtx-st small { color: var(--muted); font-size: 12px; }
.dong-rank { list-style: none; margin: 0; padding: 0; max-height: 360px; overflow-y: auto; }
.dong-rank button { width: 100%; display: grid; grid-template-columns: 24px minmax(0, 1fr) auto 32px; gap: 8px; align-items: center; border: 0; border-top: 1px solid var(--line); background: none; padding: 9px 0; text-align: left; font-size: 14px; }
.dong-rank li:first-child button { border-top: 0; }
.dong-rank .no { color: var(--muted); font-size: 12px; text-align: center; font-variant-numeric: tabular-nums; }
.dong-rank .num { font-size: 12.5px; }
.dong-rank b { text-align: right; }
.r-title .link { display: block; margin-bottom: 2px; }
.map-wrap.has-sel path.rg:not(.sel) { opacity: .55; }
.map-wrap text { font-family: var(--f-body); font-weight: 700; paint-order: stroke; stroke: var(--surface); stroke-width: 3px; fill: var(--ink); pointer-events: none; text-anchor: middle; dominant-baseline: middle; }
.map-wrap text.city { fill: var(--muted); }
.zoom { position: absolute; right: 8px; bottom: 8px; display: flex; flex-direction: column; gap: 6px; }
.zoom button { width: 34px; height: 34px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); font-size: 18px; line-height: 1; box-shadow: 0 2px 6px rgba(0,0,0,.08); }
.legend { display: flex; align-items: center; gap: 6px; margin-top: 10px; font-size: 11.5px; color: var(--muted); flex-wrap: wrap; }
.legend .sw { display: inline-flex; border-radius: 4px; overflow: hidden; }
.legend .sw i { width: 22px; height: 10px; display: block; }
.search { position: relative; }
.search input { width: 100%; border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 12px; padding: 11px 14px; font: inherit; font-size: 15px; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips button { flex: none; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 12px; font-size: 13px; }
.chips button b { margin-left: 4px; font-variant-numeric: tabular-nums; }

/* 바텀 시트 */
.sheet-dim { position: fixed; inset: 0; background: rgba(5, 10, 20, 0.45); z-index: 30; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 31; max-width: 480px; margin: 0 auto; height: 88%;
  background: var(--bg); border-radius: 22px 22px 0 0; box-shadow: var(--shadow); display: flex; flex-direction: column;
  transform: translateY(0); transition: transform .28s cubic-bezier(.2,.8,.2,1);
}
.sheet.closing { transform: translateY(100%); }
.sheet-grip { display: flex; justify-content: center; padding: 8px 0 4px; }
.grip { width: 56px; height: 18px; border: 0; background: none; position: relative; }
.grip::before { content: ""; position: absolute; left: 12px; right: 12px; top: 7px; height: 4px; border-radius: 2px; background: var(--line); }
.sheet-body { overflow-y: auto; overscroll-behavior: contain; padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; gap: 12px; }

.r-head { display: flex; align-items: center; gap: 14px; }
.score-ring { position: relative; width: 84px; height: 84px; flex: none; }
.score-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.score-ring .v { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.score-ring .v b { font-family: var(--f-display); font-size: 28px; line-height: 1; font-weight: 400; }
.score-ring .v small { font-size: 11px; color: var(--muted); }
.r-title { min-width: 0; }
.r-title h2 { margin: 0; font-size: 22px; line-height: 1.2; text-wrap: balance; }
.r-title p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.grade { display: inline-block; font-family: var(--f-display); font-size: 15px; width: 26px; height: 26px; line-height: 26px; text-align: center; border-radius: 8px; color: var(--surface); background: var(--navy); margin-right: 6px; vertical-align: 2px; }
.grade.S { background: var(--gold); }

.kv { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.kv div { min-width: 0; }
.kv small { display: block; font-size: 11.5px; color: var(--muted); }
.kv b { font-size: 16px; font-variant-numeric: tabular-nums; }

.bars { display: flex; flex-direction: column; gap: 9px; }
.bar-row { display: grid; grid-template-columns: 72px minmax(0, 1fr) 30px; gap: 10px; align-items: center; font-size: 13px; }
.bar-row .track { height: 8px; border-radius: 4px; background: var(--sunk); overflow: hidden; }
.bar-row .track i { display: block; height: 100%; border-radius: 4px; background: var(--s4); }
.bar-row b { text-align: right; font-variant-numeric: tabular-nums; }
.bar-row small { grid-column: 2 / 4; margin-top: -6px; font-size: 11.5px; color: var(--muted); }
.formula { font-size: 12px; color: var(--muted); background: var(--sunk); border-radius: 10px; padding: 8px 10px; margin-top: 10px; }

.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .ax { fill: var(--muted); font-size: 11px; font-family: var(--f-body); }
.chart .ln { fill: none; stroke-width: 2.4; stroke-linejoin: round; stroke-linecap: round; }
.chart .end { font-size: 12px; font-weight: 700; font-family: var(--f-body); }

.news { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.news li { border-top: 1px solid var(--line); }
.news li > a { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 10px; padding: 11px 0; color: inherit; text-decoration: none; }
.news li > a:active .t { color: var(--navy); }
.news .go { color: var(--navy); font-weight: 700; white-space: nowrap; }
.news li:first-child { border-top: 0; }
.news .t { font-size: 14.5px; font-weight: 500; line-height: 1.45; }
.news .m { grid-column: 2; font-size: 12px; color: var(--muted); }

.gtx-st { display: flex; flex-wrap: wrap; gap: 8px; }
.gtx-st span { display: inline-flex; align-items: center; gap: 6px; padding: 7px 10px; border-radius: 10px; background: var(--sunk); font-size: 13px; }
.line-dot { width: 22px; height: 22px; border-radius: 6px; color: #fff; font-size: 11px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; flex: none; }
.lA { background: #8a4fb0; } .lB { background: #14897a; } .lC { background: #b06b16; }

.redev { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 14px; }
.redev .row1 { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.redev .row1 b { font-size: 15px; }
.redev .row1 small { color: var(--muted); font-size: 12px; white-space: nowrap; }
.steps { display: grid; grid-template-columns: repeat(8, 1fr); gap: 3px; margin-top: 6px; }
.steps i { height: 6px; border-radius: 3px; background: var(--sunk); }
.steps i.done { background: var(--s4); }
.steps i.now { background: var(--gold); }
.redev .row2 { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 4px; }

.gauge { height: 12px; border-radius: 6px; background: linear-gradient(90deg, var(--s3) 0 60%, var(--gold) 60% 80%, var(--up) 80%); position: relative; margin: 18px 0 6px; }
.gauge i { position: absolute; top: -6px; width: 4px; height: 24px; border-radius: 2px; background: var(--ink); transform: translateX(-2px); }
.gauge-l { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); }

.school { display: flex; flex-direction: column; gap: 10px; }
.school div { display: flex; flex-direction: column; padding: 10px 12px; background: var(--sunk); border-radius: 12px; }
.school b { font-size: 14.5px; }
.school small { color: var(--muted); font-size: 12px; }
.empty { font-size: 13px; color: var(--muted); padding: 6px 0; }

/* 랭킹 */
.rank-list { list-style: none; margin: 0; padding: 0; background: var(--surface); border-radius: 18px; }
.rank-list li button { width: 100%; display: grid; grid-template-columns: 26px minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 12px 14px; border: 0; background: none; text-align: left; border-top: 1px solid var(--line); }
.rank-list li:first-child button { border-top: 0; }
.rank-list .no { font-family: var(--f-display); font-size: 17px; color: var(--muted); text-align: center; }
.rank-list li:nth-child(-n+3) .no { color: var(--gold); }
.rank-list .nm b { display: block; font-size: 15px; }
.rank-list .nm small { color: var(--muted); font-size: 12px; }
.rank-list .sc { text-align: right; }
.rank-list .sc b { font-family: var(--f-display); font-size: 20px; font-weight: 400; }
.rank-list .sc small { display: block; font-size: 12px; font-weight: 700; }

/* GTX 화면 */
.line-card .stations { list-style: none; margin: 12px 0 0; padding: 0 0 0 4px; }
.line-card .stations li { position: relative; padding: 0 0 14px 26px; font-size: 14px; display: flex; justify-content: space-between; gap: 8px; }
.line-card .stations li::before { content: ""; position: absolute; left: 6px; top: 6px; bottom: -6px; width: 4px; background: var(--lc); border-radius: 2px; }
.line-card .stations li:last-child::before { display: none; }
.line-card .stations li::after { content: ""; position: absolute; left: 1px; top: 3px; width: 10px; height: 10px; border-radius: 50%; background: var(--surface); border: 3px solid var(--lc); }
.line-card .stations li.planned::after { border-style: dashed; }
.line-card .stations button { border: 0; background: none; padding: 0; text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--line); }
.line-card .stations small { color: var(--muted); font-size: 12px; white-space: nowrap; }

@media (prefers-reduced-motion: reduce) { .sheet { transition: none; } .map-wrap path.rg { transition: none; } }

/* 시·도 탭 */
.sido-tabs button.on { background: var(--ink); color: var(--surface); border-color: var(--ink); font-weight: 700; }
.area-now { font-size: 17px; font-weight: 700; }
.area-now small { font-size: 12.5px; font-weight: 400; color: var(--muted); margin-left: 4px; }
.map-wrap path.ctx.go { cursor: pointer; }

/* GTX 노선도 */
.map-wrap .gtx-line { fill: none; stroke-width: 3.5; stroke-linecap: round; vector-effect: non-scaling-stroke; pointer-events: none; }
.map-wrap .gtx-line.plan { stroke-dasharray: 6 5; }
.map-wrap .gtx-dot { fill: none; stroke-width: 11; stroke-linecap: round; vector-effect: non-scaling-stroke; cursor: pointer; }
.map-wrap .gtx-dot-in { fill: none; stroke: var(--surface); stroke-width: 5; stroke-linecap: round; vector-effect: non-scaling-stroke; cursor: pointer; }
.map-wrap text.st { stroke: var(--surface); }
.gtx-toggle { border: 1px solid var(--line); background: var(--surface); color: var(--muted); border-radius: 10px; padding: 6px 10px; font-size: 13px; font-weight: 700; margin-left: auto; }
.gtx-toggle.on { border-color: #8a4fb0; color: #8a4fb0; background: color-mix(in srgb, #8a4fb0 10%, var(--surface)); }
.gtx-legend { margin-top: 6px; }
.gtx-legend .ln { display: inline-block; width: 16px; height: 4px; border-radius: 2px; margin-right: 4px; vertical-align: middle; }
