/* 엑스테라 속도계
   배터리: OLED 화면은 검은 점이 전기를 쓰지 않으므로 주간·야간 모두 검은 바탕을 기본으로 합니다.
   주간 — 검은 바탕 + 흰 숫자 + 신호 노랑 (햇빛 아래 대비 최대)
   야간 — 검은 바탕 + 주황 숫자 (눈부심·청색광을 줄이고 밝기도 낮춤)
   한낮 햇빛 — 흰 바탕 + 검은 숫자 (강한 직사광선에서만) */
:root, [data-theme="day"] {
  --bg: #000;
  --panel: #0d0f0e;
  --panel-2: #1a1d1b;
  --fg: #ffffff;
  --label: #a3aba7;
  --muted: #8b938f;
  --line: #262b28;
  --accent: #ffd23f;
  --accent-ink: #1a1400;
  --route: #ffd23f;
  --route-done: #4a4630;
  --track: #3ec7ff;
  --warn: #ff5f45;
  --ok: #3ddc84;
  color-scheme: dark;
}
[data-theme="night"] {
  --bg: #000;
  --panel: #0a0603;
  --panel-2: #160e07;
  --fg: #ff9d3c;
  --label: #9a5f2a;
  --muted: #8a5a2e;
  --line: #24170b;
  --accent: #ff6a2b;
  --accent-ink: #1a0800;
  --route: #c45a1c;
  --route-done: #3a1f0c;
  --track: #b7792f;
  --warn: #ff3b2f;
  --ok: #a3c23a;
  color-scheme: dark;
}
[data-theme="bright"] {
  --bg: #ffffff;
  --panel: #f3f3f0;
  --panel-2: #e6e6e1;
  --fg: #000000;
  --label: #3a3f3c;
  --muted: #555c58;
  --line: #cfd2cc;
  --accent: #c27a00;
  --accent-ink: #ffffff;
  --route: #b06e00;
  --route-done: #d9cfb8;
  --track: #0062c4;
  --warn: #c8281a;
  --ok: #157a3c;
  color-scheme: light;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--fg); }
body {
  font-family: -apple-system, "Pretendard", "Noto Sans KR", "Apple SD Gothic Neo", Roboto, system-ui, sans-serif;
  font-size: 16px; line-height: 1.45;
  padding-top: var(--safe-area-inset-top, env(safe-area-inset-top, 0px));
  user-select: none; -webkit-user-select: none; overscroll-behavior: none;
}
input, textarea, select { user-select: text; -webkit-user-select: text; }
button { font: inherit; color: inherit; }
svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
h1 { font-size: 24px; margin: 4px 0; }
h2 { font-size: 17px; margin: 0; }
p { margin: 0; }
.small { font-size: 13px; }
.muted { color: var(--muted); }
.err { color: var(--warn); font-size: 14px; }
.err:empty { display: none; }
.grow { flex: 1; min-width: 0; }
.spacer { flex: 1; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 14px; }

#app { padding: 14px 16px calc(84px + var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px))); max-width: 640px; margin: 0 auto; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px; }
.card.sel { border-color: var(--accent); }
.card.warn { border-color: var(--warn); }
button.card { text-align: left; width: 100%; }
.btn { border: 1px solid var(--line); background: var(--panel-2); color: var(--fg); border-radius: 10px; padding: 11px 16px; font-weight: 700; cursor: pointer; }
.btn.sm { padding: 7px 12px; font-size: 14px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { background: var(--warn); border-color: var(--warn); color: #fff; }
.btn.ghost { background: transparent; }
.btn.danger.ghost { color: var(--warn); background: transparent; }
.btn:disabled { opacity: .55; }
.chip-btn { border: 1px solid var(--line); background: var(--panel); border-radius: 99px; padding: 6px 12px; font-size: 14px; }
.i { width: 100%; background: var(--panel-2); color: var(--fg); border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; font: inherit; }
.i.num { width: 90px; text-align: right; }
textarea.i { min-height: 70px; resize: vertical; }
.f { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--label); }
.f.row { flex-direction: row; align-items: center; color: var(--fg); }
.f.row select { width: auto; max-width: 60%; }
.f small { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.tog input { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }
.tag { font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 99px; border: 1px solid var(--line); white-space: nowrap; }
.tag.review, .tag.error { color: var(--warn); border-color: var(--warn); }
.tag.done { color: var(--ok); border-color: var(--ok); }
.tag.ready, .tag.uploading { color: var(--accent); border-color: var(--accent); }
.banner { display: flex; flex-direction: column; gap: 2px; padding: 12px 14px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); }
.banner span { font-size: 13px; color: var(--muted); }
.banner .btn { align-self: flex-start; margin-top: 6px; }
.banner.warn { border-color: var(--warn); }
.banner.warn b { color: var(--warn); }
.banner.accent { border-color: var(--accent); }
.banner.accent b { color: var(--accent); }

/* 홈 */
.home-head { display: flex; align-items: center; gap: 10px; }
/* 운동 종목 고르기 */
.sport-bar { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 6px; }
.sport-bar button { border: 1px solid var(--line); background: var(--panel); color: var(--fg); border-radius: 10px; padding: 11px 0; font-size: 16px; font-weight: 700; }
.sport-bar button.on { background: var(--accent); border-color: var(--accent); color: var(--bg); }
/* 자전거(별명) 고르기 — 라이딩일 때만 */
.bike-bar { display: flex; flex-wrap: wrap; gap: 6px; }
.bike-bar[hidden] { display: none; }
.bike-bar button { border: 1px solid var(--line); background: var(--panel); color: var(--fg); border-radius: 999px; padding: 7px 13px; font-size: 14px; font-weight: 600; }
.bike-bar button.on { border-color: var(--accent); color: var(--accent); }
.bike-bar button.add { border-style: dashed; color: var(--muted, inherit); }
.brand { display: flex; align-items: center; gap: 8px; font-size: 17px; }
.brand img { width: 30px; height: 30px; border-radius: 50%; }
.start { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; width: min(64vw, 260px); aspect-ratio: 1; margin: 18px auto 4px; border-radius: 50%;
  border: 0; background: var(--accent); color: var(--accent-ink); font-size: 22px; font-weight: 800; cursor: pointer; box-shadow: 0 0 0 8px var(--panel-2); }
.start svg { width: 54px; height: 54px; fill: currentColor; stroke: none; }
.gps-line { display: flex; align-items: center; justify-content: center; gap: 8px; font-size: 14px; color: var(--muted); text-align: center; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; display: inline-block; }
.dot.ok { background: var(--ok); }
.dot.weak { background: var(--warn); }

/* 라이딩 화면 */
.ride { position: fixed; inset: 0; top: var(--safe-area-inset-top, env(safe-area-inset-top, 0px)); display: flex; flex-direction: column; background: var(--bg); }
.r-status { display: flex; align-items: center; gap: 12px; padding: 8px 14px; font-size: 14px; color: var(--label); font-variant-numeric: tabular-nums; }
.r-status b { color: var(--fg); font-size: 16px; }
.st { display: inline-flex; align-items: center; gap: 6px; font-weight: 800; }
.st i { width: 10px; height: 10px; border-radius: 50%; background: currentColor; }
.st.rec { color: var(--ok); }
.st.pause, .st.weak { color: var(--warn); }
.st.idle { color: var(--accent); }
.r-page { flex: 1; min-height: 0; display: flex; }
.r-grid { flex: 1; display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--line); }
.r-grid.n1 { grid-template-columns: 1fr; }
.r-cell { background: var(--bg); display: flex; flex-direction: column; justify-content: center; align-items: center; padding: 4px 6px; min-width: 0; overflow: hidden; }
.r-cell.big { grid-column: 1 / -1; }
.r-grid:not(.fixed) .r-cell:last-child:nth-child(even) { grid-column: 1 / -1; } /* 칸 수가 맞지 않으면 마지막 칸을 넓게 */
/* 붙임 그림 모양: 가로 2칸 · 세로 8줄. 글자 크기는 main.js fitVal 이 칸에 맞춤 */
.r-grid.fixed { grid-template-rows: repeat(8, minmax(0, 1fr)); }
.r-grid.fixed .r-cell { padding: 2px 6px; gap: 1px; }
.r-grid.fixed .r-cell > span { line-height: 1.2; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.r-cell.map { position: relative; padding: 0; }
.r-cell.map .nav-zoom { right: 6px; bottom: 6px; gap: 6px; }
.r-cell.map .nav-zoom button { width: 36px; height: 36px; font-size: 20px; }
.cell-turn { position: absolute; left: 6px; top: 6px; right: 6px; width: fit-content; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 3px 8px; font-weight: 800; font-size: 17px; }
.cell-turn:empty { display: none; }
.cell-turn.now { color: var(--accent); }
.cell-turn.off { background: var(--warn); color: #fff; }
.r-cell > span { font-size: clamp(13px, 3.6vw, 18px); color: var(--label); font-weight: 600; white-space: nowrap; }
.r-val { display: flex; align-items: baseline; gap: 4px; font-variant-numeric: tabular-nums; line-height: 1; white-space: nowrap; }
.r-val b { font-weight: 800; letter-spacing: -0.02em; font-size: min(12.5vw, 8.5vh); }
.r-cell.big .r-val b { font-size: min(30vw, 19vh); }
.r-grid.n2 .r-val b, .r-grid.n3 .r-val b { font-size: min(18vw, 13vh); }
.r-grid.n8 .r-val b, .r-grid.n9 .r-val b, .r-grid.n10 .r-val b { font-size: min(10vw, 6.5vh); }
.r-grid.n8 .r-cell.big .r-val b, .r-grid.n9 .r-cell.big .r-val b, .r-grid.n10 .r-cell.big .r-val b { font-size: min(22vw, 13vh); }
.r-val small { font-size: clamp(12px, 3.4vw, 17px); color: var(--label); font-weight: 600; }
.r-dots { display: flex; justify-content: center; gap: 4px; padding: 6px; }
.r-dots button { width: 26px; height: 18px; border: 0; background: transparent; position: relative; }
.r-dots button::after { content: ''; position: absolute; inset: 6px 7px; border-radius: 4px; background: var(--line); }
.r-dots button.on::after { background: var(--fg); }
.r-ctrls { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; padding: 8px 10px calc(10px + var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px))); border-top: 1px solid var(--line); }
.r-btn { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 9px 0; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); font-size: 13px; font-weight: 700; }
.r-btn svg { width: 26px; height: 26px; }
.r-btn.on { color: var(--accent); border-color: var(--accent); }
.r-btn.stop { color: var(--warn); }
.r-btn.stop svg { fill: currentColor; }

/* 경로 화면 */
.nav-wrap { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.nav-turn { display: flex; align-items: center; gap: 14px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); min-height: 86px; }
.nav-turn .turn-ic { width: 64px; height: 64px; stroke-width: 2.6; color: var(--accent); flex: none; }
.nav-turn b { display: block; font-size: min(11vw, 46px); line-height: 1.05; font-variant-numeric: tabular-nums; }
.nav-turn span { font-size: 18px; color: var(--label); font-weight: 700; }
.nav-turn.now .turn-ic, .nav-turn.now b { color: var(--accent); }
.nav-turn.off { background: var(--warn); color: #fff; }
.nav-turn.off span, .nav-turn.off .turn-ic { color: #fff; }
.nav-turn.none b { font-size: 20px; }
.nav-turn.none span { font-size: 14px; font-weight: 500; }
.nav-map { flex: 1; position: relative; min-height: 0; }
.nav-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.nav-zoom { position: absolute; right: 10px; bottom: 34px; display: flex; flex-direction: column; gap: 8px; }
.nav-zoom button { width: 46px; height: 46px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); font-size: 24px; font-weight: 800; }
.nav-zoom button.sm { font-size: 13px; }
.nav-mini { display: grid; grid-template-columns: repeat(3, 1fr); border-top: 1px solid var(--line); }
.nav-mini div { display: flex; flex-direction: column; align-items: center; padding: 6px 0; }
.nav-mini span { font-size: 13px; color: var(--label); font-weight: 600; }
.nav-mini b { font-size: min(9vw, 36px); font-variant-numeric: tabular-nums; line-height: 1.1; }
.nav-mini small { font-size: 13px; color: var(--label); margin-left: 3px; }

/* 기록 */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; background: var(--line); border-radius: 12px; overflow: hidden; border: 1px solid var(--line); }
.stats div { background: var(--panel); padding: 10px; display: flex; flex-direction: column; }
.stats span { font-size: 12px; color: var(--label); }
.stats b { font-size: 21px; font-variant-numeric: tabular-nums; }
.stats small { font-size: 12px; color: var(--label); margin-left: 2px; font-weight: 500; }
canvas.preview { width: 100%; height: 240px; border-radius: 12px; border: 1px solid var(--line); display: block; }
.ride-row { display: flex; align-items: center; gap: 12px; }
.ride-row b { display: block; }
.ride-row .grow { display: flex; flex-direction: column; }
canvas.mini { width: 56px; height: 56px; border-radius: 8px; flex: none; }
.seg-row { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-top: 1px solid var(--line); }
.seg-row input { width: 22px; height: 22px; accent-color: var(--warn); margin-top: 2px; flex: none; }
.seg-row div { display: flex; flex-direction: column; }
.ph-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); gap: 6px; }
.ph { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: var(--panel-2); }
.ph img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.tbl th { text-align: left; font-size: 12px; color: var(--label); font-weight: 600; padding: 4px 6px; border-bottom: 1px solid var(--line); }
.tbl td { padding: 6px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl .bar { display: inline-block; height: 7px; border-radius: 4px; background: var(--accent); margin-right: 6px; vertical-align: 1px; }
.warn-txt { color: var(--warn); }
.gps-line[hidden] { display: none; }
.ph i { position: absolute; right: 4px; bottom: 4px; background: var(--ok); color: #000; border-radius: 99px; font-size: 11px; font-style: normal; font-weight: 800; padding: 0 6px; }

/* 설정 */
.set h2 { color: var(--accent); }
.page-edit { border: 1px solid var(--line); border-radius: 10px; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--panel-2); border-radius: 99px; padding: 5px 10px; font-size: 13px; color: var(--fg); }
.chip.add { color: var(--accent); border-color: var(--accent); background: transparent; }
/* 설정: 쪽 모양 미리보기 (칸을 눌러 바꿈) */
.pe-grid { display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: repeat(8, 30px); gap: 1px; background: var(--line); border: 1px solid var(--line); }
.pe-cell { background: var(--panel); border: 0; color: var(--fg); font-size: 13px; font-weight: 600; padding: 0 4px; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.pe-cell:active { background: var(--panel-2); }
.pe-cell.map { color: var(--accent); }
.pe-grid.nav { display: flex; align-items: center; justify-content: center; height: 120px; background: var(--panel); color: var(--label); font-size: 13px; }

/* 아래 탭 */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(4, 1fr); background: var(--panel); border-top: 1px solid var(--line);
  padding-bottom: var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px)); z-index: 5; }
.tabbar[hidden] { display: none; }
.tabbar button { border: 0; background: transparent; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 7px; font-size: 12px; color: var(--muted); font-weight: 700; }
.tabbar svg { width: 24px; height: 24px; }
.tabbar button.on { color: var(--accent); }

/* 시트 · 알림 */
.sheet-bg { position: fixed; inset: 0; background: rgba(0, 0, 0, .65); display: flex; align-items: flex-end; z-index: 20; }
.sheet { width: 100%; max-width: 640px; margin: 0 auto; background: var(--panel); border-top: 1px solid var(--line); border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px)));
  display: flex; flex-direction: column; gap: 12px; max-height: 86vh; overflow-y: auto; }
.sheet.tall { height: 86vh; }
.sheet p { color: var(--label); }
.sheet-btns { display: flex; flex-direction: column; gap: 8px; }
.sheet-btns .btn { padding: 14px; font-size: 17px; }
.pick { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.pick h3 { grid-column: 1 / -1; margin: 10px 0 0; font-size: 14px; color: var(--label); }
.pick h3:first-child { margin-top: 0; }
.pick .btn small { display: block; font-size: 11px; font-weight: 400; color: var(--label); }
.toast { position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 700; font-size: 14px;
  max-width: calc(100% - 32px); z-index: 30; text-align: center; pointer-events: none; }
.toast[hidden] { display: none; }
