:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --bg: #f1f5f9;
  --surface: #fff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --r-md: 14px;
  --r-sm: 8px;
  --shadow: 0 2px 16px rgba(15, 23, 42, .08);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans KR', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

/* ── Header ── */
.header {
  background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 100%);
  color: #fff;
  padding: 20px 16px;
}
.header-inner {
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
}
.header-icon { width: 28px; height: 28px; flex-shrink: 0; }
.header h1 { font-size: 1.2rem; font-weight: 700; letter-spacing: -.02em; }

/* ── Main ── */
main { max-width: 720px; margin: 0 auto; padding: 24px 16px 56px; }

/* ── 지역별 보기 ── */
.regions-section { margin-top: 20px; }

.regions-card {
  background: var(--surface);
  border: 1.5px solid #bfdbfe;
  border-radius: var(--r-md);
  padding: 24px;
}

.regions-header {
  margin-bottom: 20px;
}
.regions-title {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -.02em;
}

.regions-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.region-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 18px;
  background: #fff;
  border: 1.5px solid var(--border);
  border-radius: 30px;
  cursor: pointer;
  transition: all .15s;
  text-align: left;
  gap: 8px;
}
.region-link:hover {
  background: #eff6ff;
  border-color: var(--primary);
}
.region-link-name {
  font-size: .88rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}
.region-link-move {
  font-size: .75rem;
  color: #94a3b8;
  white-space: nowrap;
  flex-shrink: 0;
}
.region-link:hover .region-link-name { color: var(--primary); }
.region-link:hover .region-link-move { color: var(--primary); }

/* ── Loading ── */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 60px 0;
  color: var(--muted);
  font-size: .88rem;
}
.spinner {
  width: 34px; height: 34px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Error ── */
.error-msg {
  margin-top: 14px;
  padding: 13px 16px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: var(--r-sm);
  color: #dc2626;
  font-size: .88rem;
}

/* ── Results ── */
#results { margin-top: 28px; }
.results-summary { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 12px; gap: 8px; }
.sum-route { font-size: .98rem; font-weight: 700; }
.sum-sub { font-size: .8rem; color: var(--muted); white-space: nowrap; }
.results-list { display: flex; flex-direction: column; gap: 10px; }
.no-result { text-align: center; padding: 60px 0; color: var(--muted); font-size: .93rem; }

/* ── Bus card ── */
.bus-card { background: var(--surface); border-radius: var(--r-md); box-shadow: var(--shadow); overflow: hidden; }
.card-times { display: flex; align-items: center; padding: 20px 22px 16px; gap: 10px; }
.t-dep, .t-arr { font-size: 1.45rem; font-weight: 800; letter-spacing: -.03em; min-width: 56px; white-space: nowrap; }
.t-arr { color: var(--muted); }
.t-mid { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; }
.t-dur { font-size: .7rem; color: var(--muted); font-weight: 500; white-space: nowrap; }
.t-rule { width: 100%; display: flex; align-items: center; }
.t-rule::before { content: ''; flex: 1; height: 1.5px; background: linear-gradient(to right, var(--primary), #93c5fd); border-radius: 2px; }
.t-arrowhead { font-size: .7rem; color: #93c5fd; margin-left: 1px; line-height: 1; }
.card-footer { display: flex; align-items: center; justify-content: space-between; padding: 11px 22px; border-top: 1px solid var(--border); background: #fafafa; }
.grade { font-size: .72rem; font-weight: 700; padding: 3px 10px; border-radius: 20px; }
.g-express { background: #dbeafe; color: #1e40af; }
.g-normal  { background: #dcfce7; color: #166534; }
.g-premium { background: #ede9fe; color: #6d28d9; }
.g-night   { background: #1e293b; color: #e2e8f0; }
.fare { font-size: .98rem; font-weight: 700; color: var(--text); }

/* ── Modal overlay ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, .5);
  z-index: 200;
  display: flex; align-items: flex-end; justify-content: center;
}
@media (min-width: 600px) { .modal-overlay { align-items: center; } }

/* ── Modal ── */
.modal {
  background: var(--surface);
  width: 100%; max-width: 580px;
  border-radius: 20px 20px 0 0;
  height: 80dvh;
  display: flex; flex-direction: column;
  overflow: hidden;
}
@media (min-width: 600px) { .modal { border-radius: var(--r-md); height: 540px; } }

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0; gap: 8px;
}
.modal-header h2 { flex: 1; font-size: .95rem; font-weight: 700; text-align: center; }

.btn-back {
  display: flex; align-items: center; gap: 4px;
  background: none; border: none; cursor: pointer;
  font-size: .8rem; font-weight: 600; color: var(--primary);
  padding: 4px 0; white-space: nowrap;
}
.btn-back svg { width: 15px; height: 15px; }
.btn-back:hover { opacity: .75; }

.btn-modal-close {
  width: 30px; height: 30px;
  background: var(--bg); border: none; border-radius: 50%;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  color: var(--muted); flex-shrink: 0;
}
.btn-modal-close svg { width: 14px; height: 14px; }
.btn-modal-close:hover { background: var(--border); color: var(--text); }

/* ── Modal content ── */
.modal-content { flex: 1; overflow-y: auto; }

/* ── Modal Step 1: 지역 그리드 ── */
.modal-region-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  padding: 20px;
}
.modal-region-card {
  display: flex; align-items: center; justify-content: center;
  height: 58px;
  background: #f8fafc;
  border: 1.5px solid var(--border);
  border-radius: var(--r-sm);
  font-size: .88rem; font-weight: 700; color: var(--text);
  cursor: pointer; transition: all .15s; user-select: none;
}
.modal-region-card:hover {
  background: #eff6ff; border-color: var(--primary); color: var(--primary);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(37, 99, 235, .15);
}
.modal-region-card:active { transform: translateY(0); }

/* ── Modal Step 2: 터미널 목록 ── */
.terminal-item {
  display: block; width: 100%;
  padding: 15px 20px;
  background: none; border: none; border-bottom: 1px solid var(--border);
  font-size: .93rem; color: var(--text);
  cursor: pointer; text-align: left;
  transition: background .1s, color .1s;
}
.terminal-item:last-child { border-bottom: none; }
.terminal-item:hover { background: #eff6ff; color: var(--primary); font-weight: 600; }

/* ── 공통 상태 ── */
.content-center {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 200px; gap: 12px;
  color: var(--muted); font-size: .88rem; padding: 24px; text-align: center;
}
.mini-spinner {
  width: 26px; height: 26px;
  border: 2.5px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .75s linear infinite;
}

/* ── Responsive ── */
@media (max-width: 540px) {
  .regions-grid { grid-template-columns: repeat(2, 1fr); }
  .modal-region-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 14px; }
  .t-dep, .t-arr { font-size: 1.25rem; min-width: 46px; }
  .card-times { padding: 16px 16px 12px; }
  .card-footer { padding: 10px 16px; }
}
