/* ===== Reset & Base ===== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #f0f2f7;
  --surface: #ffffff;
  --surface2: #f5f6fa;
  --border: #e2e5ef;
  --text: #1a1d2e;
  --text-dim: #5a5f7a;
  --text-muted: #9da3bc;
  --accent: #5b4ff5;
  --accent-light: #7b6fff;
  --accent-bg: #ede9ff;
  --subway: #0052cc;
  --bus-red: #e03030;
  --bus-blue: #1f7ae0;
  --bus-green: #18a35c;
  --bus-yellow: #e08a00;
  --arrival-soon: #d93030;
  --arrival-normal: #c07800;
  --arrival-far: #1a9150;
  --shadow: 0 2px 12px rgba(0,0,0,0.07);
  --shadow-sm: 0 1px 4px rgba(0,0,0,0.06);
  --radius: 16px;
  --radius-sm: 10px;
  --font-sans: 'Noto Sans KR', -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', monospace;
  --font-display: 'Bebas Neue', sans-serif;
}

html {
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overflow-x: hidden;
}

#app {
  max-width: 430px;
  margin: 0 auto;
  min-height: 100dvh;
  position: relative;
  padding-bottom: 80px;
}

/* ===== Header ===== */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px 8px;
}

.logo {
  font-family: var(--font-display);
  font-size: 1.6rem;
  letter-spacing: 2px;
  color: var(--accent);
  font-weight: 400;
}

.header-right {
  text-align: right;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0;
}

.header-settings-btn {
  background: none;
  border: none;
  font-size: 1rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 0;
  margin-top: 2px;
  transition: color 0.15s;
  line-height: 1;
}

.header-settings-btn:hover {
  color: var(--text-dim);
}

.current-time {
  display: block;
  font-family: var(--font-mono);
  font-size: 1.8rem;
  font-weight: 600;
  line-height: 1;
  color: var(--text);
}

.current-date {
  display: block;
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-top: 2px;
}

/* ===== Tab Bar ===== */
.tab-bar {
  display: flex;
  gap: 6px;
  padding: 8px 20px;
  margin-bottom: 4px;
}

.tab {
  flex: 1;
  padding: 10px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-dim);
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.tab .tab-icon {
  margin-right: 4px;
}

/* ===== Dashboard Cards ===== */
.dashboard {
  padding: 8px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  position: relative;
  transition: transform 0.15s, box-shadow 0.15s;
  box-shadow: var(--shadow);
  /* 모바일 롱프레스 선택/콜아웃 방지 */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.card:hover {
  box-shadow: 0 4px 20px rgba(0,0,0,0.1);
}

.card:active {
  transform: scale(0.98);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 10px;
}

.card-type {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 3px 8px;
  border-radius: 4px;
  color: #fff;
}

/* 버스 타입 색상 */
.card-type.bus-red { background: var(--bus-red); }
.card-type.bus-blue { background: var(--bus-blue); }
.card-type.bus-green { background: var(--bus-green); }
.card-type.bus-yellow { background: var(--bus-yellow); }
/* 지하철 호선별 색상 — 호선 클래스(line-N)가 background를 직접 지정 */

.card-header-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

.card-menu-btn {
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  letter-spacing: -1px;
}

.card-menu-btn:hover {
  background: var(--surface2);
  color: var(--text-dim);
}

.card-name {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 2px;
}

.card-direction {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-bottom: 12px;
}

.card-arrivals {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ===== 가로형 도착 그리드 ===== */
.arrival-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.arrival-chip {
  background: var(--surface2);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.arrival-chip.imminent {
  background: #fff0f0;
  border-color: rgba(208, 48, 48, 0.2);
}

.arrival-chip-header {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
}

.arrival-dir-badge {
  font-size: 0.58rem;
  font-weight: 700;
  color: var(--text-muted);
  background: var(--border);
  padding: 2px 5px;
  border-radius: 3px;
  white-space: nowrap;
  flex-shrink: 0;
}

.arrival-chip-dest {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.arrival-chip-time {
  font-family: var(--font-mono);
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1;
  margin: 2px 0 1px;
}

.arrival-chip-time.soon   { color: var(--arrival-soon); }
.arrival-chip-time.normal { color: var(--arrival-normal); }
.arrival-chip-time.far    { color: var(--arrival-far); }

.arrival-unit {
  font-size: 0.7rem;
  font-weight: 400;
  margin-left: 1px;
}

.arrival-chip-pos {
  font-size: 0.72rem;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.arrival-chip-status {
  font-size: 0.68rem;
  color: var(--text-muted);
}

/* 근접(90초 이하) 열차의 위치 텍스트 표시 */
.arrival-near-status {
  font-family: var(--font-sans);
  font-size: 0.88rem;
  font-weight: 700;
  line-height: 1.35;
  margin: 4px 0 2px;
}

.arrival-near-status.soon   { color: var(--arrival-soon); }
.arrival-near-status.normal { color: var(--arrival-normal); }
.arrival-near-status.far    { color: var(--arrival-far); }

.card-updated {
  font-size: 0.65rem;
  color: var(--text-muted);
  text-align: right;
  margin-top: 8px;
}

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  padding: 80px 40px;
}

.empty-icon {
  font-size: 3rem;
  margin-bottom: 16px;
  opacity: 0.4;
}

.empty-text {
  font-size: 1rem;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.empty-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ===== FAB ===== */
.fab {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 1.8rem;
  font-weight: 300;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(91, 79, 245, 0.35);
  transition: all 0.2s;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.fab:active {
  transform: translateX(-50%) scale(0.92);
}

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: none;
  justify-content: center;
  align-items: flex-end;
}

.modal-overlay.open {
  display: flex;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-width: 430px;
  max-height: 85dvh;
  overflow-y: auto;
  padding: 0 0 24px;
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}

.modal-back,
.modal-close {
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 1.2rem;
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-back:hover,
.modal-close:hover {
  background: var(--surface2);
}

.modal-title {
  flex: 1;
  text-align: center;
  font-size: 1rem;
  font-weight: 600;
}

.modal-close {
  margin-left: auto;
}

/* Step 1: Search */
.modal-step {
  padding: 16px 20px;
}

.search-type-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.search-type {
  flex: 1;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-dim);
  font-family: var(--font-sans);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.15s;
}

.search-type.active {
  background: var(--surface2);
  border-color: var(--accent);
  color: var(--text);
}

.search-box {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.search-box input {
  flex: 1;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface2);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.15s;
}

.search-box input:focus {
  border-color: var(--accent);
}

.search-box input::placeholder {
  color: var(--text-muted);
}

.search-btn {
  padding: 12px 18px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.search-btn:active {
  opacity: 0.8;
}

.search-results {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 45dvh;
  overflow-y: auto;
}

.result-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.1s;
}

.result-item:hover,
.result-item:active {
  background: var(--surface2);
}

.result-badge {
  font-size: 0.65rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 4px;
  color: #fff;
  white-space: nowrap;
  min-width: 48px;
  text-align: center;
}

.result-info {
  flex: 1;
  min-width: 0;
}

.result-name {
  font-size: 0.9rem;
  font-weight: 600;
}

.result-sub {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-top: 2px;
}

.result-arrow {
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* Step 2: Detail selection */
.step2-info {
  padding: 12px 16px;
  background: var(--surface2);
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
}

.step2-info .info-name {
  font-size: 1rem;
  font-weight: 700;
}

.step2-info .info-sub {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-top: 2px;
}

.step2-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 50dvh;
  overflow-y: auto;
}

.step2-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.1s;
}

.step2-item:hover,
.step2-item:active {
  background: var(--surface2);
}

.step2-item-name {
  font-size: 0.9rem;
  font-weight: 500;
}

.step2-item-sub {
  font-size: 0.75rem;
  color: var(--text-dim);
}

/* Step 3: Group */
.step3-summary {
  padding: 16px;
  background: var(--surface2);
  border-radius: var(--radius-sm);
  margin-bottom: 20px;
}

.step3-summary .summary-type {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--accent);
  margin-bottom: 4px;
}

.step3-summary .summary-name {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 2px;
}

.step3-summary .summary-detail {
  font-size: 0.8rem;
  color: var(--text-dim);
}

.group-selector {
  margin-bottom: 24px;
}

.group-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text-dim);
}

.group-options {
  display: flex;
  gap: 10px;
}

.group-option {
  flex: 1;
  cursor: pointer;
}

.group-option input {
  display: none;
}

.group-chip {
  display: block;
  text-align: center;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  color: var(--text-dim);
  transition: all 0.15s;
}

.group-option input:checked + .group-chip {
  border-color: var(--accent);
  background: var(--accent-bg);
  color: var(--accent);
  font-weight: 600;
}

.register-btn {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-family: var(--font-sans);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}

.register-btn:active {
  opacity: 0.8;
}

/* ===== Skeleton Loading ===== */
.card.loading .card-arrivals {
  opacity: 0.5;
}

.sk-line {
  height: 14px;
  background: linear-gradient(90deg, var(--surface2) 25%, var(--border) 50%, var(--surface2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 4px;
  margin-bottom: 10px;
}

.sk-w60 { width: 60%; }
.sk-w80 { width: 80%; }
.sk-w40 { width: 40%; }

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ===== Loading spinner for cards ===== */
.card-loading {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  color: var(--text-muted);
  font-size: 0.8rem;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ===== Search Loading ===== */
.search-loading {
  text-align: center;
  padding: 32px;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.search-empty {
  text-align: center;
  padding: 32px;
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* ===== Refresh indicator ===== */
.refresh-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 20px;
}

.refresh-info {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.refresh-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  border: 1.5px solid var(--accent);
  background: var(--accent-bg);
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  transition: all 0.15s;
  letter-spacing: 0.2px;
}

.refresh-btn:hover {
  background: var(--accent);
  color: #fff;
}

.refresh-btn:active {
  opacity: 0.75;
  transform: scale(0.96);
}

.refresh-icon {
  font-size: 1rem;
  display: inline-block;
  transition: transform 0.3s;
}

.refresh-btn:active .refresh-icon {
  transform: rotate(180deg);
}

/* ===== Wobble Edit Mode (롱프레스) ===== */
@keyframes wobble {
  0%   { transform: rotate(-1.5deg); }
  100% { transform: rotate(1.5deg); }
}

.wobble-active .card {
  animation: wobble 0.18s ease-in-out infinite alternate;
  cursor: default;
  user-select: none;
}

/* 카드 짝수 번째는 반대 방향으로 시작 — 더 자연스러운 흔들림 */
.wobble-active .card:nth-child(even) {
  animation-direction: alternate-reverse;
}

/* wobble 모드에서는 :active 스케일 효과 제거 */
.wobble-active .card:active {
  transform: none;
}

/* wobble 모드에서 ⋮ 메뉴 버튼 숨기고 이동 버튼 표시 */
.wobble-active .card-menu-btn {
  display: none;
}

/* ===== 카드 순서 이동 버튼 (wobble 전용) ===== */
.card-wobble-actions {
  display: none;
  gap: 4px;
  align-items: center;
}

.wobble-active .card-wobble-actions {
  display: flex;
}

.card-move-btn {
  width: 30px;
  height: 30px;
  border: 1.5px solid var(--border);
  background: var(--surface2);
  color: var(--text-dim);
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.12s;
  padding: 0;
}

.card-move-btn:hover {
  background: var(--accent-bg);
  border-color: var(--accent);
  color: var(--accent);
}

.card-move-btn:active {
  transform: scale(0.85);
}

/* ===== 카드 삭제 버튼 (wobble 전용) ===== */
.card-delete-btn {
  position: absolute;
  top: -9px;
  left: -9px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #e03030;
  color: #fff;
  border: 2px solid #fff;
  font-size: 0.65rem;
  font-weight: 900;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 10;
  box-shadow: 0 2px 8px rgba(0,0,0,0.35);
  padding: 0;
  line-height: 1;
  transition: transform 0.1s;
}

.card-delete-btn:active {
  transform: scale(0.85);
}

.wobble-active .card-delete-btn {
  display: flex;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
  width: 4px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

/* ===== 호선 색상 ===== */
.line-1 { background: #0052A4; }
.line-2 { background: #009B3E; }
.line-3 { background: #EF7C1C; }
.line-4 { background: #00A5DE; }
.line-5 { background: #996CAC; }
.line-6 { background: #CD7C2F; }
.line-7 { background: #747F00; }
.line-8 { background: #E6186C; }
.line-9 { background: #BDB092; }
.line-gyeongui { background: #77C4A3; }
.line-airport { background: #0090D2; }
.line-gyeongchun { background: #32C6A6; }
.line-suinbundang { background: #FABE00; }
.line-gtx { background: #9A6292; }
.line-uisinseol { background: #B7C452; }
.line-sinlim { background: #6789CA; }
.line-gyeonggang { background: #0054A6; }

/* ===== Action Sheet ===== */
.action-sheet-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(3px);
  z-index: 300;
  display: none;
  justify-content: center;
  align-items: flex-end;
}

.action-sheet-overlay.open {
  display: flex;
}

.action-sheet {
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-width: 430px;
  padding: 0 0 16px;
  animation: slideUp 0.25s ease;
}

.action-sheet-handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 10px auto 8px;
}

.action-sheet-title {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  text-align: center;
  padding: 4px 20px 12px;
  border-bottom: 1px solid var(--border);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.action-sheet-body {
  padding: 8px 16px 0;
}

.action-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 14px 12px;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  border-radius: var(--radius-sm);
  text-align: left;
  transition: background 0.1s;
}

.action-item:hover,
.action-item:active {
  background: var(--surface2);
}

.action-item.disabled {
  opacity: 0.3;
  pointer-events: none;
}

.action-item-icon {
  font-size: 1.1rem;
  width: 24px;
  text-align: center;
  flex-shrink: 0;
}

.action-item-danger {
  color: var(--bus-red);
}

.action-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

.action-sheet-cancel {
  display: block;
  width: calc(100% - 32px);
  margin: 12px 16px 0;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface2);
  color: var(--text-dim);
  font-family: var(--font-sans);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.1s;
}

.action-sheet-cancel:active {
  background: var(--border);
}

/* Edit Tab 내부 */
.edit-tab-section {
  padding: 4px 0 16px;
}

.edit-tab-label {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-bottom: 12px;
  font-weight: 500;
}

.edit-save-btn {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-family: var(--font-sans);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  margin-top: 4px;
  transition: opacity 0.15s;
}

.edit-save-btn:active {
  opacity: 0.8;
}
