:root {
  --bg: #f2f4f7;
  --card: #ffffff;
  --ink: #14202e;
  --ink-sub: #5a6675;
  --line: #d8dee6;
  --accent: #16324f;
  --accent-ink: #ffffff;
  --hot: #c8461a;
  --ok: #17693f;
  --shadow: 0 2px 8px rgba(20, 32, 46, .10);
  --tabbar-h: 62px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10151c;
    --card: #1b232e;
    --ink: #eef3f8;
    --ink-sub: #9daabb;
    --line: #2e3a48;
    --accent: #4d8fd6;
    --accent-ink: #0d1219;
    --hot: #ff9166;
    --ok: #5fd39a;
    --shadow: 0 2px 8px rgba(0, 0, 0, .45);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", sans-serif;
  font-size: 17px;
  font-weight: 700;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
}

/* ---------- ヘッダー ---------- */
.app-header {
  flex: 0 0 auto;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: var(--accent);
  color: var(--accent-ink);
}
.app-header h1 { margin: 0; font-size: 19px; letter-spacing: .04em; }
.clock { display: flex; align-items: baseline; gap: 8px; }
#clock-time { font-size: 26px; font-variant-numeric: tabular-nums; letter-spacing: .02em; }
.clock-date { font-size: 14px; opacity: .85; }

/* ---------- 本体 ---------- */
main {
  flex: 1 1 auto;
  position: relative;
  min-height: 0;
}
.view {
  display: none;
  position: absolute;
  inset: 0;
  overflow-y: auto;
  overscroll-behavior: none;
  -webkit-overflow-scrolling: touch;
  padding: 12px 12px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
}
.view.is-active { display: block; }

.empty {
  margin: 48px 16px;
  text-align: center;
  color: var(--ink-sub);
  font-size: 16px;
  line-height: 1.9;
}
.hidden { display: none !important; }

/* ---------- 発車カード ---------- */
.depart-list { display: flex; flex-direction: column; gap: 12px; }

.card {
  background: var(--card);
  border-radius: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-left: 7px solid var(--accent);
}
.card-head .place { font-size: 20px; }
.card-head .meta { font-size: 14px; color: var(--ink-sub); }
.card-head .go { margin-left: auto; font-size: 15px; color: var(--ink-sub); }

.dep-row {
  display: grid;
  grid-template-columns: 88px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-top: 1px solid var(--line);
}
.dep-row.past { opacity: .38; }
.dep-time { font-size: 26px; font-variant-numeric: tabular-nums; letter-spacing: .01em; }
.dep-mid { min-width: 0; }
.dep-dest { font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dep-type { font-size: 14px; color: var(--ink-sub); }
.dep-left { font-size: 18px; text-align: right; white-space: nowrap; }
.dep-left.soon { color: var(--hot); }
.dep-note { padding: 10px 14px; border-top: 1px solid var(--line); font-size: 15px; color: var(--ink-sub); }

/* ---------- 時刻表 ---------- */
.chip-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  overscroll-behavior: none;
  padding-bottom: 8px;
}
.chip {
  flex: 0 0 auto;
  padding: 8px 14px;
  border-radius: 999px;
  border: 2px solid var(--line);
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-size: 15px;
}
.chip.is-active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.seg-row { display: flex; gap: 8px; margin: 4px 0 10px; }
.seg {
  flex: 1 1 0;
  padding: 9px 0;
  border-radius: 10px;
  border: 2px solid var(--line);
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-size: 15px;
}
.seg.is-active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.table-wrap { background: var(--card); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; }
.hour-row { display: grid; grid-template-columns: 54px 1fr; border-top: 1px solid var(--line); }
.hour-row:first-child { border-top: 0; }
.hour-row.now { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.hour-num {
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-variant-numeric: tabular-nums;
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}
.hour-mins { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 10px; }
.min {
  font-size: 18px; font-variant-numeric: tabular-nums;
  padding: 2px 6px; border-radius: 6px;
  background: color-mix(in srgb, var(--ink) 6%, transparent);
}
.min .sup { font-size: 13px; color: var(--ink-sub); margin-left: 2px; }
.min.next { background: var(--hot); color: #fff; }
.min.next .sup { color: #fff; }
.table-legend { padding: 10px 14px; font-size: 14px; color: var(--ink-sub); border-top: 1px solid var(--line); }

/* ---------- 設定 ---------- */
.section-title {
  margin: 18px 4px 8px;
  font-size: 15px;
  color: var(--ink-sub);
  letter-spacing: .05em;
}
.section-title:first-child { margin-top: 4px; }

.settings-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.settings-row {
  display: flex; align-items: center; gap: 8px;
  background: var(--card); border-radius: 12px; box-shadow: var(--shadow);
  padding: 10px 12px;
}
.settings-row .info { flex: 1 1 auto; min-width: 0; }
.settings-row .name { font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.settings-row .sub { font-size: 14px; color: var(--ink-sub); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  flex: 0 0 auto;
  width: 40px; height: 40px;
  border-radius: 10px;
  border: 2px solid var(--line);
  background: transparent; color: var(--ink);
  font: inherit; font-size: 17px;
}
.icon-btn.danger { color: var(--hot); border-color: color-mix(in srgb, var(--hot) 40%, var(--line)); }

.btn {
  display: block; width: 100%;
  padding: 14px; border-radius: 12px;
  border: 2px solid var(--line);
  background: var(--card); color: var(--ink);
  font: inherit; font-size: 17px;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-block { margin-top: 4px; }

.row-setting {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--card); border-radius: 12px; box-shadow: var(--shadow);
  padding: 12px 14px; margin-bottom: 8px; font-size: 16px;
}
.row-setting select { font: inherit; font-size: 16px; padding: 6px 8px; border-radius: 8px; border: 2px solid var(--line); background: var(--bg); color: var(--ink); }
.row-setting input[type=checkbox] { width: 26px; height: 26px; accent-color: var(--accent); }

.note { font-size: 14px; color: var(--ink-sub); margin: 10px 4px 0; line-height: 1.8; }

/* ---------- タブバー ---------- */
.tabbar {
  flex: 0 0 auto;
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 20;
}
.tab {
  flex: 1 1 0;
  height: var(--tabbar-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border: 0; background: transparent;
  color: var(--ink-sub); font: inherit; font-size: 14px;
}
.tab.is-active { color: var(--accent); }
.tab-ico { font-size: 22px; line-height: 1; }

/* ---------- 追加シート ---------- */
.sheet {
  position: fixed; inset: 0; z-index: 40;
  background: var(--bg);
  display: flex; flex-direction: column;
  padding-top: env(safe-area-inset-top);
}
.sheet-head {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px;
  background: var(--accent); color: var(--accent-ink);
}
.sheet-title { flex: 1 1 auto; text-align: center; font-size: 17px; }
.sheet-btn {
  border: 0; background: transparent; color: var(--accent-ink);
  font: inherit; font-size: 16px; padding: 6px 10px; min-width: 64px;
}
.sheet-crumb { padding: 8px 14px; font-size: 14px; color: var(--ink-sub); }
.sheet-search {
  margin: 0 12px 10px;
  padding: 12px 14px;
  font: inherit; font-size: 17px;
  border: 2px solid var(--line); border-radius: 12px;
  background: var(--card); color: var(--ink);
}
.sheet-body {
  flex: 1 1 auto; min-height: 0;
  overflow-y: auto; overscroll-behavior: none;
  -webkit-overflow-scrolling: touch;
  padding: 0 12px calc(env(safe-area-inset-bottom) + 24px);
}
.pick {
  display: flex; align-items: center; gap: 10px;
  width: 100%; text-align: left;
  padding: 14px; margin-bottom: 8px;
  border: 0; border-radius: 12px;
  background: var(--card); color: var(--ink);
  box-shadow: var(--shadow);
  font: inherit; font-size: 17px;
}
.pick .bar { flex: 0 0 auto; width: 6px; align-self: stretch; border-radius: 3px; background: var(--accent); }
.pick .txt { flex: 1 1 auto; min-width: 0; }
.pick .sub { font-size: 14px; color: var(--ink-sub); }
.pick .arrow { color: var(--ink-sub); font-size: 16px; }
.sheet-msg { padding: 24px 8px; text-align: center; color: var(--ink-sub); font-size: 16px; line-height: 1.9; }

/* ---------- トースト ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 20px);
  transform: translateX(-50%);
  max-width: 88vw;
  background: var(--ink); color: var(--bg);
  padding: 12px 18px; border-radius: 12px;
  font-size: 16px; z-index: 60;
  box-shadow: 0 6px 20px rgba(0,0,0,.3);
}
