:root {
  --bg: #f3f5f9;
  --card: #ffffff;
  --text: #121826;
  --muted: #6b7280;
  --line: #e5e8ef;
  --accent: #1f5bd8;
  --accent-soft: #e8efff;
  --soon: #e5484d;
  --warn-bg: #fff6e0;
  --warn-text: #7a5300;
  --radius: 16px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116;
    --card: #181c24;
    --text: #eef1f6;
    --muted: #98a1b2;
    --line: #2a303b;
    --accent: #6d9bff;
    --accent-soft: #1d2a44;
    --soon: #ff6b70;
    --warn-bg: #3a2f12;
    --warn-text: #ffd98a;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Malgun Gothic", "Noto Sans KR", sans-serif;
  font-size: 16px;
  line-height: 1.4;
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
input { font: inherit; color: inherit; }

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
}
.top h1 { font-size: 22px; margin: 0; letter-spacing: -0.02em; }
.top-actions { display: flex; gap: 4px; align-items: center; }
.icon { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; color: var(--accent); }
.icon:active { background: var(--accent-soft); }
.icon.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.ghost { padding: 8px 12px; border-radius: 10px; color: var(--accent); font-weight: 600; }
.ghost:active { background: var(--accent-soft); }
.primary { padding: 10px 16px; border-radius: 12px; background: var(--accent); color: #fff; font-weight: 700; }
.primary:disabled { opacity: .5; }

.banner {
  margin: 0 16px 12px; padding: 10px 14px; border-radius: 12px;
  background: var(--warn-bg); color: var(--warn-text); font-size: 14px;
}

main { padding: 0 16px; display: grid; gap: 12px; }

.empty {
  text-align: center; color: var(--muted); padding: 56px 16px;
}
.empty strong { display: block; color: var(--text); font-size: 18px; margin-bottom: 6px; }

.card { background: var(--card); border-radius: var(--radius); padding: 14px 16px 6px; box-shadow: 0 1px 2px rgb(0 0 0 / .05); }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; margin-bottom: 4px; }
.card-title { font-size: 18px; font-weight: 700; letter-spacing: -0.01em; }
.card-sub { font-size: 13px; color: var(--muted); }
.chip { display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 6px; background: var(--accent-soft); color: var(--accent); margin-left: 6px; vertical-align: 2px; }
.chip.demo { background: var(--warn-bg); color: var(--warn-text); }
.edit-tools { display: none; gap: 2px; }
.editing .edit-tools { display: flex; }
.edit-tools button { width: 36px; height: 36px; border-radius: 10px; background: var(--bg); font-size: 15px; }
.edit-tools .del { color: var(--soon); }

.rows { list-style: none; margin: 0; padding: 0; }
.row {
  display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center;
  padding: 10px 0; border-top: 1px solid var(--line);
}
.row:first-child { border-top: 0; }
.badge {
  min-width: 52px; padding: 4px 8px; border-radius: 8px; text-align: center;
  font-weight: 800; font-size: 15px; color: #fff; background: var(--c, #555);
  white-space: nowrap;
}
.dir { font-size: 13px; color: var(--muted); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.times { text-align: right; }
.t1 { font-size: 17px; font-weight: 800; white-space: nowrap; font-variant-numeric: tabular-nums; }
.t1.soon { color: var(--soon); }
.t-note { font-size: 12px; color: var(--muted); white-space: nowrap; }
.t2 { font-size: 13px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.card-msg { color: var(--muted); font-size: 14px; padding: 10px 0 12px; }
.card-msg.err { color: var(--soon); }

.updated { text-align: center; color: var(--muted); font-size: 12px; margin: 16px; }

.fab {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(20px + env(safe-area-inset-bottom));
  padding: 14px 22px; border-radius: 999px; background: var(--accent); color: #fff;
  font-weight: 700; box-shadow: 0 6px 20px rgb(31 91 216 / .35);
}

/* bottom sheet */
.sheet {
  border: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 560px;
  max-height: 88dvh; border-radius: 20px 20px 0 0; background: var(--card); color: var(--text);
}
.sheet::backdrop { background: rgb(0 0 0 / .4); }
.sheet-inner { padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 12px; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.sheet-head h2 { margin: 0; font-size: 19px; }

.seg { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--bg); border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { padding: 9px 4px; border-radius: 9px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgb(0 0 0 / .1); }

.search { display: flex; gap: 8px; margin-top: 12px; }
.search input, .field input {
  flex: 1; min-width: 0; padding: 11px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg);
}
.hint { margin: 6px 2px 0; font-size: 13px; color: var(--muted); }
.hint.err { color: var(--soon); }

.results, .routes { list-style: none; margin: 8px 0 0; padding: 0; overflow-y: auto; max-height: 50dvh; }
.results li button { width: 100%; text-align: left; padding: 12px 4px; border-bottom: 1px solid var(--line); }
.results li button:active { background: var(--accent-soft); }
.results .r-name { font-weight: 600; }
.results .r-sub { font-size: 13px; color: var(--muted); }

.field { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
.station-sub { margin: 0; font-size: 13px; color: var(--muted); }
.routes-head { display: flex; justify-content: space-between; align-items: center; font-weight: 700; margin-top: 4px; }
.routes label { display: flex; align-items: center; gap: 10px; padding: 9px 4px; border-bottom: 1px solid var(--line); }
.routes input { width: 20px; height: 20px; accent-color: var(--accent); }
.routes .dir { flex: 1; }
.sheet-foot { display: flex; justify-content: space-between; gap: 8px; padding-top: 4px; }
.sheet-foot .primary { flex: 1; }
