:root {
  --bg: #0c1120;
  --panel: #131a28;
  --card: #18202f;
  --card2: #1c2536;
  --line: #273246;
  --ink: #e9eef6;
  --muted: #8d98ab;
  --green: #4fe0a0;
  --green-d: #2fbf86;
  --blue: #6aa2ff;
  --amber: #f6c453;
  --orange: #ff9f6e;
  --red: #ff7a7a;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background:
    radial-gradient(120% 50% at 50% -10%, #1d2650 0%, rgba(29,38,80,0) 60%),
    var(--bg);
  background-attachment: fixed;
  color: var(--ink);
  font-family: "Pretendard Variable", Pretendard, -apple-system, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  font-size: 16px; line-height: 1.45;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  padding-top: env(safe-area-inset-top, 0px);
}
button, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }

/* ---------- 상단 ---------- */
.top { position: relative; display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 14px 16px 6px; max-width: 640px; margin: 0 auto; }
.pill { border: 1px solid var(--line); border-radius: 999px; background: rgba(24,32,47,.75); }
.brand {
  display: flex; align-items: center; gap: 8px; padding: 9px 18px 9px 14px; cursor: pointer;
  color: var(--green); font-weight: 750; font-size: 19px; letter-spacing: -.01em;
  box-shadow: 0 0 24px rgba(79,224,160,.12) inset;
}
.brand svg { width: 22px; height: 22px; color: var(--blue); }
.updated { padding: 7px 18px; text-align: right; font-size: 13px; line-height: 1.3; }
.updated span { display: block; color: var(--ink); }
.updated b { font-weight: 700; }
.menu { position: absolute; left: 16px; top: 64px; z-index: 50; background: var(--card2); border: 1px solid var(--line); border-radius: 14px; padding: 6px; }
.menu button { display: block; background: none; border: 0; padding: 10px 16px; cursor: pointer; border-radius: 10px; }
.menu button:hover { background: var(--card); }

main { max-width: 640px; margin: 0 auto; padding: 8px 12px calc(110px + env(safe-area-inset-bottom, 0px)); }

/* ---------- 하단 탭 ---------- */
.tabs {
  position: fixed; z-index: 40; left: 12px; right: 12px; bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  max-width: 616px; margin: 0 auto;
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 2px; padding: 7px;
  background: rgba(17,23,35,.92); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--line); border-radius: 999px;
  box-shadow: 0 10px 30px rgba(0,0,0,.45);
}
.tabs button { background: none; border: 0; padding: 12px 0; border-radius: 999px; font-weight: 650; font-size: 14px; letter-spacing: -.01em; color: #c3cad6; cursor: pointer; }
.tabs button[aria-current="page"] {
  background: linear-gradient(180deg, #5ef0ae, #2fbf86); color: #08251a;
  box-shadow: 0 0 18px rgba(79,224,160,.45);
}

/* ---------- 공통 블록 ---------- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 26px; padding: 20px 16px 18px; }
.label { color: var(--green); font-weight: 700; font-size: 15px; margin: 0 0 10px; }
.label + .sub { margin-top: -6px; }
.sub { color: var(--muted); font-size: 15px; margin: 0 0 14px; }
.section-gap { margin-top: 26px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 16px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }

/* 상태 화면 머리 */
.car-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 16px 6px 4px; }
.car-head h1 { margin: 0; font-size: 34px; font-weight: 800; letter-spacing: -.03em; line-height: 1.15; }
.badge { padding: 7px 16px; border-radius: 999px; font-weight: 700; font-size: 15px; border: 1px solid; white-space: nowrap; }
.badge[data-s="offline"], .badge[data-s="unknown"] { color: var(--orange); border-color: rgba(255,159,110,.4); background: rgba(255,159,110,.08); }
.badge[data-s="asleep"] { color: var(--blue); border-color: rgba(106,162,255,.4); background: rgba(106,162,255,.08); }
.badge[data-s="online"], .badge[data-s="driving"] { color: var(--green); border-color: rgba(79,224,160,.4); background: rgba(79,224,160,.08); }
.badge[data-s="charging"] { color: var(--amber); border-color: rgba(246,196,83,.4); background: rgba(246,196,83,.08); }
.car-meta { color: var(--muted); font-size: 14px; margin: 0 6px 16px; }

/* 배터리 막대 */
.bat { position: relative; height: 108px; border-radius: 24px; background: var(--card); border: 1px solid var(--line); overflow: hidden; }
.bat-fill { position: absolute; inset: 0 auto 0 0; width: 0; border-radius: 24px; background: linear-gradient(100deg, #3d6ff0, #5ab6f2); transition: width 1s cubic-bezier(.2,.7,.2,1); }
.bat[data-low] .bat-fill { background: linear-gradient(100deg, #e0603c, #f6a04d); }
.bat[data-charging] .bat-fill { background: linear-gradient(100deg, #26b47c, #5ef0ae); }
.bat-t { position: absolute; left: 20px; top: 12px; font-weight: 700; font-size: 16px; }
.bat-v { position: absolute; left: 20px; right: 16px; top: 38px; bottom: 10px; }
.bat-v b { display: block; font-size: 30px; font-weight: 750; letter-spacing: -.02em; white-space: nowrap; text-shadow: 0 1px 6px rgba(0,0,0,.35); }
.bat-v b small { font-size: 17px; font-weight: 600; margin-left: 4px; }
.bat-v span { position: absolute; right: 0; bottom: 0; font-size: 14px; font-weight: 650; white-space: nowrap; text-shadow: 0 1px 6px rgba(0,0,0,.45); }

.eff h3 { margin: 0 0 12px; font-weight: 500; font-size: 15px; color: var(--muted); }
.eff p { margin: 0; font-size: 26px; font-weight: 750; letter-spacing: -.02em; }
.eff p small { font-size: 14px; font-weight: 600; margin-left: 3px; }
.eff p + p { margin-top: 6px; }
.eff .foot { font-size: 12px; color: var(--muted); font-weight: 400; margin-top: 4px; letter-spacing: 0; }

.tire h3, .posn h3 { margin: 0 0 12px; color: var(--green); font-size: 15px; font-weight: 700; }
.tire-car { position: relative; aspect-ratio: 3 / 4; max-width: 160px; margin: 0 auto; }
.tire-car svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.tire-car b { position: absolute; font-size: 18px; font-weight: 700; }
.tire-car b.low { color: var(--orange); }
.tire-car .fl { left: 10%; top: 26%; } .tire-car .fr { right: 10%; top: 26%; }
.tire-car .rl { left: 10%; bottom: 20%; } .tire-car .rr { right: 10%; bottom: 20%; }
.mini-map { height: 130px; border-radius: 18px; overflow: hidden; position: relative; z-index: 0; isolation: isolate; background: var(--card2); }
.posn p { margin: 10px 0 0; color: var(--muted); font-size: 14px; }

/* 충전 중 */
.now-charging { margin-top: 12px; display: flex; gap: 18px; align-items: center; border-color: rgba(79,224,160,.35); }
.now-charging b { display: block; font-size: 22px; }
.now-charging span { color: var(--muted); font-size: 13px; }

/* ---------- 기록 카드 ---------- */
.ev { background: var(--card); border: 1px solid var(--line); border-radius: 22px; overflow: hidden; margin-top: 14px; }
.ev-top { display: flex; align-items: center; gap: 12px; padding: 16px 16px 4px; }
.ico { flex: none; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: rgba(79,224,160,.12); color: var(--green); }
.ico svg { width: 18px; height: 18px; }
.ev-dist { font-size: 26px; font-weight: 750; color: var(--green); letter-spacing: -.02em; }
.ev-dur { color: var(--muted); font-size: 14px; }
.map-btn { margin-left: auto; width: 46px; height: 46px; border-radius: 14px; border: 1px solid var(--line); background: var(--card2); color: var(--muted); display: grid; place-items: center; cursor: pointer; }
.map-btn[aria-expanded="true"] { color: var(--green); border-color: rgba(79,224,160,.5); background: rgba(79,224,160,.12); }
.map-btn svg { width: 20px; height: 20px; }
.od { padding: 6px 16px 12px; }
.od div { display: grid; grid-template-columns: 1fr auto; column-gap: 10px; padding-left: 18px; position: relative; margin-top: 6px; }
.od div::before { content: ""; position: absolute; left: 2px; top: 8px; width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 8px var(--green); }
.od div.dst::before { background: var(--blue); box-shadow: 0 0 8px var(--blue); }
.od span { color: var(--muted); font-size: 14px; }
.od time { color: var(--muted); font-size: 13px; text-align: right; }
.od p { grid-column: 1 / -1; margin: 0; font-size: 16px; font-weight: 600; }
.stats4 { display: grid; grid-template-columns: repeat(4, 1fr); border-top: 1px solid var(--line); }
.stats4 div { text-align: center; padding: 12px 4px; }
.stats4 div + div { border-left: 1px solid var(--line); }
.stats4 span { display: block; color: var(--muted); font-size: 12px; }
.stats4 b { display: block; font-size: 19px; font-weight: 650; margin-top: 2px; }
.stats4 small { display: block; color: var(--muted); font-size: 11px; }
.ev-map { height: 220px; position: relative; z-index: 0; isolation: isolate; background: var(--card2); }

.chg { display: grid; grid-template-columns: 84px 1fr auto; gap: 4px 12px; padding: 16px; align-items: start; }
.chg-l { grid-row: 1 / span 2; text-align: center; }
.chg-l .ico { margin: 0 auto; width: 52px; height: 52px; flex-direction: column; font-size: 11px; font-weight: 800; gap: 0; line-height: 1; }
.chg-l .ico svg { width: 16px; height: 16px; }
.chg-l b { display: block; margin-top: 8px; color: var(--green); font-size: 14px; white-space: nowrap; }
.chg.dc .chg-l .ico { background: rgba(255,122,122,.12); color: var(--red); }
.chg.dc .chg-l b { color: var(--red); }
.chg-place { font-weight: 650; font-size: 16px; line-height: 1.3; }
.chg-meta { grid-column: 2 / -1; color: var(--muted); font-size: 13px; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 10px; }
.chg-meta .lines p { margin: 2px 0; }
.soc-pill { border: 1px solid var(--line); border-radius: 999px; padding: 3px 12px; font-weight: 700; color: var(--ink); background: var(--card2); white-space: nowrap; }
.chg .map-btn { grid-row: 1; grid-column: 3; }
.chg-map { height: 220px; margin: 0 16px 16px; border-radius: 18px; overflow: hidden; position: relative; z-index: 0; isolation: isolate; }

/* ---------- 통계 머리 ---------- */
.stat-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 16px; }
.stat-head .label { margin: 0; line-height: 1.3; }
.period { display: flex; align-items: center; gap: 4px; border: 1px solid var(--line); border-radius: 999px; padding: 4px 6px 4px 16px; background: var(--card); }
.period span { color: var(--muted); font-size: 14px; }
.period select { background: transparent; border: 0; padding: 6px 8px; font-weight: 650; font-size: 15px; cursor: pointer; }
.period select option { background: var(--card2); }
.stat { text-align: center; padding: 18px 8px; display: flex; flex-direction: column; justify-content: center; min-height: 120px; }
.stat h3 { margin: 0 0 8px; font-size: 14px; color: #c3cad6; font-weight: 600; }
.stat b { font-size: 26px; font-weight: 750; letter-spacing: -.02em; line-height: 1.15; }
.stat small { display: block; margin-top: 6px; color: var(--muted); font-size: 12px; }
.grid3 .stat b { font-size: 21px; }
.c-green { color: var(--green); } .c-blue { color: var(--blue); } .c-amber { color: var(--amber); } .c-orange { color: var(--orange); }

/* ---------- 배터리 화면 ---------- */
.cap { border-radius: 22px; padding: 16px 20px 14px; margin-top: 12px; border: 1px solid var(--line); }
.cap.new { background: linear-gradient(135deg, #253259, #1d2640); }
.cap.now { background: linear-gradient(135deg, #1f3542, #1a2635); }
.cap.deg { background: linear-gradient(135deg, #3a2a2e, #24283a); }
.cap span { color: #b5bfcf; font-size: 14px; }
.cap b { display: block; text-align: center; font-size: clamp(24px, 7.4vw, 34px); white-space: nowrap; font-weight: 750; letter-spacing: -.02em; margin: 4px 0; }
.cap small { display: block; text-align: right; color: var(--muted); font-size: 13px; }
.sel { border: 1px solid var(--line); border-radius: 18px; padding: 10px 16px; margin: 4px 0 12px; }
.sel span { display: block; color: var(--muted); font-size: 13px; }
.sel b { font-size: 18px; }
.big { border-radius: 20px; padding: 14px 20px; margin-top: 10px; border: 1px solid var(--line); }
.big.a { background: linear-gradient(135deg, #253259, #1d2640); }
.big.b { background: linear-gradient(135deg, #1f3542, #1a2635); }
.big b { display: block; font-size: 32px; font-weight: 750; letter-spacing: -.02em; }
.big span { color: #b5bfcf; font-size: 15px; }
.chart { margin-top: 14px; background: #0f1522; border: 1px solid var(--line); border-radius: 24px; padding: 14px 10px 8px; }
.chart svg { width: 100%; height: auto; display: block; touch-action: none; }
.chart-foot { display: flex; justify-content: space-between; align-items: flex-end; margin: 12px 4px 6px; }
.chart-foot span { color: var(--muted); font-size: 14px; }
.chart-foot div { text-align: right; }
.chart-foot b { font-size: 18px; }
input[type=range] { width: 100%; accent-color: var(--blue); margin: 10px 0 4px; }

.more { display: block; width: 100%; margin: 16px 0 0; padding: 13px; background: var(--card); border: 1px solid var(--line); border-radius: 16px; color: #c3cad6; cursor: pointer; }
.empty, .error { text-align: center; color: var(--muted); padding: 40px 12px; }
.skeleton { height: 160px; border-radius: 26px; background: var(--panel); border: 1px solid var(--line); margin-top: 12px; }

/* ---------- 로그인 ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login form { width: 100%; max-width: 340px; }
.login h1 { color: var(--green); font-size: 32px; margin: 0 0 4px; letter-spacing: -.02em; }
.login p { color: var(--muted); margin: 0 0 22px; }
.login input { width: 100%; font: inherit; font-size: 17px; padding: 14px 18px; border-radius: 16px; border: 1px solid var(--line); background: var(--card); color: var(--ink); }
.login button { width: 100%; margin-top: 12px; padding: 14px; font-size: 17px; font-weight: 700; border: 0; border-radius: 999px; background: linear-gradient(180deg, #5ef0ae, #2fbf86); color: #08251a; cursor: pointer; }
.login .msg { color: var(--orange); font-size: 14px; min-height: 20px; margin: 12px 0 0; }

@media (max-width: 370px) {
  .stats4 b { font-size: 16px; }
  .car-head h1 { font-size: 28px; }
}
@media (prefers-reduced-motion: reduce) { .bat-fill { transition: none; } }
.updated { cursor: pointer; }

/* ---------- Trip (전체 주행 지도) ---------- */
body.trip-mode { overflow: hidden; }
.tab.trip { position: fixed; left: 0; right: 0; bottom: 0; top: var(--top-h, 76px); }
#trip-map { position: absolute; inset: 0; z-index: 0; background: #dfe3e8; }
#trip-map .leaflet-bottom { bottom: calc(78px + env(safe-area-inset-bottom, 0px)); }
.trip-bar { position: absolute; z-index: 500; top: 10px; left: 12px; right: 12px; display: flex; justify-content: space-between; align-items: center; gap: 8px; pointer-events: none; }
.trip-bar > * { pointer-events: auto; }
.trip-bar .period { background: rgba(17,23,35,.9); box-shadow: 0 4px 14px rgba(0,0,0,.35); }
.trip-stat { background: rgba(17,23,35,.9); border: 1px solid var(--line); border-radius: 999px; padding: 9px 16px; font-size: 14px; font-weight: 650; box-shadow: 0 4px 14px rgba(0,0,0,.35); white-space: nowrap; }
.trip-stat b { color: var(--green); }
.trip-pop { font-family: inherit; font-size: 14px; color: #17202b; }
.trip-pop b { display: block; font-size: 16px; }
@media (max-width: 370px) { .tabs button { font-size: 12.5px; } }

/* ---------- 앱 화면 고정: 문서 대신 main 만 스크롤 (iOS Safari 툴바가 움직여 하단 메뉴가 오르내리는 문제 방지) ---------- */
html:has(body.app) { height: 100%; overflow: hidden; }
body.app { height: 100%; height: 100dvh; overflow: hidden; display: flex; flex-direction: column; }
body.app .top { flex: none; width: 100%; }
body.app main {
  flex: 1 1 auto; min-height: 0; width: 100%; max-width: none; margin: 0;
  overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  padding: 8px max(12px, calc((100% - 616px) / 2)) calc(110px + env(safe-area-inset-bottom, 0px));
}

[hidden] { display: none !important; }
