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

:root {
  --bg:        #080c1a;
  --bg2:       #0d1228;
  --bg3:       #121830;
  --card:      rgba(255,255,255,0.04);
  --card-h:    rgba(255,255,255,0.07);
  --border:    rgba(255,255,255,0.08);
  --border-a:  rgba(79,158,255,0.35);
  --txt:       #e8eaf6;
  --txt2:      #8892b0;
  --txt3:      #4a5568;
  --blue:      #4f9eff;
  --purple:    #a855f7;
  --amber:     #f59e0b;
  --red:       #ef4444;
  --teal:      #22d3ee;
  --green:     #10b981;
  --hdr:       56px;
  --cards-w:   400px;  /* right panel width */
}

html { height: 100%; }

body {
  font-family: 'Noto Sans KR', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--txt);
  font-size: 14px;
  line-height: 1.6;
  min-height: 100%;
  overflow-y: auto;   /* scrollable — app-shell fills viewport, below-shell reached by scroll */
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ============================================================
   HEADER
   ============================================================ */
.header {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 1000;
  height: var(--hdr);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  background: rgba(8,12,26,0.94);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.header-logo { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.logo-icon   { width: 36px; height: 36px; }
.logo-text   { display: flex; flex-direction: column; line-height: 1.2; }
.logo-main   { font-size: 15px; font-weight: 700; letter-spacing: -.3px; }
.logo-sub    { font-size: 10px; color: var(--txt2); letter-spacing: .5px; text-transform: uppercase; }

.header-center { flex: 1; display: flex; justify-content: center; }
.header-time   { text-align: center; }
.time-value    { font-family: 'JetBrains Mono', monospace; font-size: 20px; font-weight: 600; color: var(--teal); letter-spacing: 2px; line-height: 1; }
.time-label    { font-size: 10px; color: var(--txt2); margin-top: 2px; }

.header-right  { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.observer-badge {
  display: flex; align-items: center; gap: 5px;
  font-size: 11px; color: var(--txt2);
  background: var(--card); border: 1px solid var(--border);
  border-radius: 20px; padding: 4px 10px;
  font-family: inherit;
  cursor: pointer;
  transition: border-color .2s, color .2s, background .2s;
}
.observer-badge:hover {
  border-color: var(--border-a);
  color: var(--blue);
  background: rgba(79,158,255,.08);
}
.observer-badge.geo-active {
  border-color: rgba(34,211,238,.35);
  color: var(--teal);
}
.observer-badge.geo-loading {
  opacity: .7;
  cursor: wait;
  pointer-events: none;
}
.observer-badge.geo-pulse {
  animation: geo-invite 2.5s ease-in-out 3;
}
@keyframes geo-invite {
  0%,100% { border-color: var(--border); }
  50%      { border-color: var(--border-a); box-shadow: 0 0 8px rgba(79,158,255,.25); }
}
.status-pill {
  display: flex; align-items: center; gap: 6px;
  font-size: 11px; color: var(--txt2);
  background: var(--card); border: 1px solid var(--border);
  border-radius: 20px; padding: 4px 10px;
}
.status-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--txt3); transition: background .3s; }
.status-pill.ready   .status-dot { background: var(--green); box-shadow: 0 0 6px var(--green); animation: pulse 2s infinite; }
.status-pill.loading .status-dot { background: var(--amber); animation: pulse 1s infinite; }
.status-pill.error   .status-dot { background: var(--red); }

@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.4} }

/* ============================================================
   APP SHELL — two-pane grid
   ============================================================ */
.app-shell {
  display: grid;
  grid-template-columns: 1fr var(--cards-w);
  height: calc(100vh - var(--hdr));
  margin-top: var(--hdr);
  overflow: hidden;
}

/* ── LEFT PANE ── */
.pane-map {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-right: 1px solid var(--border);
}

/* Map wrapper — grows to fill entire pane height (minus stats bar) */
.map-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
}

#map { width: 100%; height: 100%; background: #0a0e1c; }

/* Map controls (top-right) */
.map-controls {
  position: absolute; top: 12px; right: 12px; z-index: 500;
  display: flex; flex-direction: column; gap: 6px;
}
.ctrl-btn {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 7px 10px; min-width: 46px;
  background: rgba(8,12,26,.88); border: 1px solid var(--border);
  border-radius: 8px; color: var(--txt2);
  font-size: 9px; font-family: inherit; cursor: pointer;
  transition: all .2s; backdrop-filter: blur(8px);
}
.ctrl-btn svg { width: 16px; height: 16px; }
.ctrl-btn:hover { background: var(--card-h); color: var(--txt); }
.ctrl-btn.active { border-color: var(--border-a); color: var(--blue); background: rgba(79,158,255,.08); }

/* Visible count badge (bottom-left of map) */
.map-vis-badge {
  position: absolute; bottom: 14px; left: 14px; z-index: 500;
  display: flex; flex-direction: column; align-items: center;
  background: rgba(8,12,26,.88); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 14px; backdrop-filter: blur(8px);
}
.vis-num  { font-family: 'JetBrains Mono', monospace; font-size: 24px; font-weight: 700; color: var(--teal); line-height: 1; }
.vis-lbl  { font-size: 10px; color: var(--txt2); margin-top: 2px; }

/* Pass overlay (bottom-center of map) */
.map-pass-overlay {
  position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%);
  z-index: 500;
  display: flex; align-items: center; gap: 8px;
  background: rgba(34,211,238,.15); border: 1px solid rgba(34,211,238,.4);
  border-radius: 20px; padding: 6px 16px;
  backdrop-filter: blur(8px); white-space: nowrap;
}
.pass-icon { font-size: 14px; }
.pass-text { font-size: 11px; font-weight: 600; color: var(--teal); }

/* ── STATS BAR ── */
.stats-bar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  height: 52px;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  gap: 0;
}
.stat-item {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  flex: 1; gap: 1px;
}
.stat-num  { font-family: 'JetBrains Mono', monospace; font-size: 16px; font-weight: 700; color: var(--blue); line-height: 1; }
.stat-lbl  { font-size: 9px; color: var(--txt2); white-space: nowrap; }
.stat-divider { width: 1px; height: 28px; background: var(--border); flex-shrink: 0; margin: 0 4px; }
.stat-pass .stat-num,
.stat-pass-num { color: var(--amber); font-size: 13px; }

/* ── BELOW-SHELL (ranking + footer — scroll to reveal) ── */
.below-shell {
  border-top: 2px solid var(--border);
  background: var(--bg);
}

/* ── RANKING SECTION ── */
.ranking-section { }
.ranking-inner { max-width: 1400px; margin: 0 auto; padding: 28px 32px; }

.section-header { margin-bottom: 14px; }
.section-title  { font-size: 14px; font-weight: 700; }
.section-sub    { font-size: 11px; color: var(--txt2); margin-top: 2px; }

.ranking-wrap { overflow-x: auto; }
.ranking-table {
  width: 100%; border-collapse: collapse; font-size: 12px; min-width: 480px;
}
.ranking-table th {
  padding: 6px 8px; text-align: left; color: var(--txt2);
  font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px;
  border-bottom: 1px solid var(--border);
}
.ranking-table td { padding: 10px 8px; border-bottom: 1px solid rgba(255,255,255,.04); vertical-align: middle; }
.rank-row { cursor: pointer; transition: background .15s; }
.rank-row:hover { background: var(--card); }

.rank-num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 6px;
  font-size: 11px; font-weight: 700;
}
.rank-1 { background: rgba(245,158,11,.2); color: #f59e0b; }
.rank-2 { background: rgba(148,163,184,.2); color: #94a3b8; }
.rank-3 { background: rgba(180,120,80,.2); color: #b47850; }
.rank-4 { background: rgba(74,85,104,.15); color: var(--txt2); }
.rank-5 { background: rgba(74,85,104,.10); color: var(--txt3); }

.sat-tag { font-size: 11px; font-weight: 600; color: var(--c); white-space: nowrap; }
.sbar {
  display: inline-block; width: 44px; height: 4px;
  background: rgba(255,255,255,.06); border-radius: 2px; overflow: hidden;
  vertical-align: middle; margin-right: 4px;
}
.sfill { height: 100%; background: var(--c); border-radius: 2px; opacity: .8; }
.total { font-family: 'JetBrains Mono', monospace; font-size: 14px; font-weight: 700; }
.verdict { font-size: 10px; color: var(--txt2); white-space: nowrap; }

/* ── FOOTER ── */
.footer { border-top: 1px solid var(--border); }
.footer-inner { max-width: 1400px; margin: 0 auto; padding: 20px 32px 28px; }
.footer-row {
  display: flex; flex-wrap: wrap; gap: 12px;
  font-size: 11px; color: var(--txt2); margin-bottom: 6px;
}
.footer-note { font-size: 10px; color: var(--txt3); margin-top: 4px; }
.ver-badge {
  display: inline-block; font-size: 9px; font-family: 'JetBrains Mono', monospace;
  background: rgba(79,158,255,.12); color: var(--blue); border: 1px solid rgba(79,158,255,.25);
  border-radius: 4px; padding: 1px 5px; vertical-align: middle; margin-left: 4px;
}

/* ============================================================
   RIGHT PANE — satellite cards
   ============================================================ */
.pane-cards {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg2);
}

.cards-header {
  flex-shrink: 0;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
}

/* Tabs */
.tab-bar {
  flex-shrink: 0;
  display: flex; gap: 2px;
  padding: 8px 12px 0;
  border-bottom: 1px solid var(--border);
  overflow-x: auto; scrollbar-width: none;
  background: var(--bg2);
}
.tab-bar::-webkit-scrollbar { display: none; }
.tab {
  flex-shrink: 0;
  padding: 6px 12px;
  background: transparent; border: none;
  border-bottom: 2px solid transparent;
  color: var(--txt2); font-size: 12px; font-family: inherit; font-weight: 500;
  cursor: pointer; transition: all .2s; border-radius: 6px 6px 0 0;
}
.tab:hover { color: var(--txt); background: rgba(255,255,255,.04); }
.tab.active { color: var(--blue); border-bottom-color: var(--blue); background: rgba(79,158,255,.06); }

/* Cards container — scrollable */
.sat-cards {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Loading */
.loading-state {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 16px;
  padding: 60px 20px; color: var(--txt2); font-size: 13px;
}
.loading-spinner {
  width: 32px; height: 32px;
  border: 2px solid var(--border); border-top-color: var(--blue);
  border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Satellite Card ── */
.sat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  cursor: pointer;
  transition: all .2s;
  position: relative;
  overflow: hidden;
  flex-shrink: 0;
}
.sat-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0;
  height: 2px; background: var(--card-clr, var(--blue));
}
.sat-card:hover { background: var(--card-h); border-color: var(--border-a); transform: translateY(-1px); }
.sat-card.is-visible { box-shadow: 0 0 0 1px var(--card-clr), 0 4px 20px rgba(0,0,0,.4); }

/* Card header */
.sat-card-header {
  display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 10px;
}
.sat-card-title { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.sat-card-name  { font-size: 14px; font-weight: 700; display: block; }
.sat-card-en    { font-size: 10px; color: var(--txt2); display: block; margin-top: 1px; }
.sat-card-rank  { display: flex; flex-direction: column; align-items: center; gap: 1px; flex-shrink: 0; }
.rank-label     { font-size: 9px; color: var(--txt3); }
.rank-badge {
  width: 26px; height: 26px; border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 900; flex-shrink: 0;
}

/* vis-status row */
.vis-status { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }

/* Score pills */
.sat-card-scores {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 10px;
}
.score-pill {
  background: rgba(255,255,255,.04); border: 1px solid var(--border);
  border-radius: 6px; padding: 5px 4px; text-align: center;
}
.score-pill.total { background: rgba(79,158,255,.07); border-color: rgba(79,158,255,.25); }
.score-pill-val { font-family: 'JetBrains Mono', monospace; font-size: 15px; font-weight: 700; display: block; line-height: 1; }
.score-pill-lbl { font-size: 9px; color: var(--txt2); display: block; margin-top: 2px; }

/* Live data grid */
.sat-live {
  display: grid; grid-template-columns: 1fr 1fr; gap: 5px; margin-bottom: 10px;
}
.live-item { background: rgba(0,0,0,.2); border-radius: 6px; padding: 5px 8px; }
.live-label { font-size: 9px; color: var(--txt2); display: block; margin-bottom: 1px; }
.live-value { font-family: 'JetBrains Mono', monospace; font-size: 12px; color: var(--teal); display: block; font-weight: 600; }

/* Elevation bar */
.el-bar { position: relative; height: 6px; background: rgba(255,255,255,.06); border-radius: 3px; overflow: hidden; margin-bottom: 3px; }
.el-fill { height: 100%; border-radius: 3px; background: var(--card-clr, var(--blue)); transition: width .5s ease; box-shadow: 0 0 8px var(--card-clr, var(--blue)); }
.el-labels { display: flex; justify-content: space-between; font-size: 9px; color: var(--txt3); margin-bottom: 8px; }

/* Visibility badge */
.vis-badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 10px; padding: 3px 8px; border-radius: 20px; font-weight: 600;
}
.vis-badge::before { content: ''; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.vis-badge.visible   { background: rgba(16,185,129,.15); color: var(--green); border: 1px solid rgba(16,185,129,.3); }
.vis-badge.visible::before { box-shadow: 0 0 4px currentColor; animation: pulse 2s infinite; }
.vis-badge.invisible { background: rgba(74,85,104,.15); color: var(--txt3); border: 1px solid var(--border); }

/* Next pass */
.next-pass {
  margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border);
  font-size: 10px; color: var(--txt2);
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
}
.next-pass-time { font-family: 'JetBrains Mono', monospace; color: var(--amber); font-size: 11px; font-weight: 600; flex-shrink: 0; }

/* Train notice */
.train-notice {
  font-size: 11px; color: var(--amber);
  background: rgba(245,158,11,.08); border: 1px solid rgba(245,158,11,.2);
  border-radius: 6px; padding: 7px 10px; margin-top: 8px; line-height: 1.5;
}

/* Leaflet overrides */
.leaflet-control-zoom { border: 1px solid var(--border) !important; }
.leaflet-control-zoom a { background: var(--bg2) !important; color: var(--txt) !important; border-color: var(--border) !important; }
.leaflet-control-zoom a:hover { background: var(--bg3) !important; }
.leaflet-control-attribution { background: rgba(8,12,26,.8) !important; color: var(--txt3) !important; font-size: 9px !important; }
.leaflet-control-attribution a { color: var(--txt3) !important; }
.leaflet-popup-content-wrapper { background: var(--bg2) !important; border: 1px solid var(--border) !important; border-radius: 10px !important; box-shadow: 0 8px 32px rgba(0,0,0,.5) !important; color: var(--txt) !important; }
.leaflet-popup-tip { background: var(--bg2) !important; }
.leaflet-popup-content { margin: 12px 16px !important; font-family: 'Noto Sans KR', sans-serif !important; }
.popup-title  { font-weight: 700; font-size: 13px; margin-bottom: 8px; }
.popup-grid   { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; font-size: 11px; }
.popup-label  { color: var(--txt2); }
.popup-value  { font-family: 'JetBrains Mono', monospace; font-size: 11px; color: var(--teal); }

/* Satellite markers — legacy circle (fallback) */
.sat-marker { display: flex; align-items: center; justify-content: center; width: 28px; height: 28px; border-radius: 50%; border: 2px solid; transition: transform .2s; position: relative; }
.sat-marker:hover { transform: scale(1.3); z-index: 9999 !important; }
.sat-marker-dot { width: 9px; height: 9px; border-radius: 50%; }
.sat-marker-dot:hover { transform: scale(1.4); }
.sat-main-dot { width: 14px; height: 14px; border-radius: 50%; flex-shrink: 0; transition: transform .2s; }
.sat-icon-wrap:hover .sat-main-dot { transform: scale(1.5); }

/* SVG satellite icon wrapper (main markers) */
.sat-icon-wrap {
  position: relative;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  transition: transform .18s, filter .18s;
}
.sat-icon-wrap:hover { transform: scale(1.28); z-index: 9999 !important; }
.sat-icon-wrap svg { display: block; overflow: visible; }

/* Label above the satellite SVG */
.sat-label {
  position: absolute;
  bottom: calc(100% + 3px);
  left: 50%; transform: translateX(-50%);
  white-space: nowrap;
  font-size: 10px; font-family: 'Noto Sans KR', sans-serif;
  color: #fff;
  background: rgba(8,12,26,.88);
  padding: 2px 7px; border-radius: 4px;
  pointer-events: none;
}
/* Observer (my location) marker — large, prominent, pulsing */
.observer-marker {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  filter: drop-shadow(0 0 10px rgba(34,211,238,.9));
}
.obs-ring {
  position: absolute;
  top: 14px; left: 50%;
  transform: translate(-50%, -50%);
  width: 44px; height: 44px;
  border: 2px solid rgba(34,211,238,.6);
  border-radius: 50%;
  animation: obs-pulse 2.2s ease-out infinite;
  pointer-events: none;
}
.obs-ring2 {
  position: absolute;
  top: 14px; left: 50%;
  transform: translate(-50%, -50%);
  width: 44px; height: 44px;
  border: 2px solid rgba(34,211,238,.35);
  border-radius: 50%;
  animation: obs-pulse 2.2s ease-out infinite .7s;
  pointer-events: none;
}
.obs-icon  { font-size: 28px; line-height: 1; position: relative; z-index: 1; }
.obs-label {
  font-size: 11px; font-weight: 700; color: var(--teal);
  font-family: 'JetBrains Mono', monospace; white-space: nowrap;
  background: rgba(8,12,26,.85); border: 1px solid rgba(34,211,238,.3);
  padding: 2px 7px; border-radius: 5px; position: relative; z-index: 1;
}
@keyframes obs-pulse {
  0%   { transform: translate(-50%,-50%) scale(.7); opacity: .9; }
  100% { transform: translate(-50%,-50%) scale(2.4); opacity: 0; }
}

/* ============================================================
   TABLET  (900 – 1199px)
   ============================================================ */
@media (max-width: 1199px) {
  :root { --cards-w: 340px; }
  .time-value { font-size: 17px; }
}

/* ============================================================
   MOBILE  (≤ 768px) — single column, body scrollable
   ============================================================ */
@media (max-width: 768px) {
  :root { --hdr: 50px; }

  body { overflow: auto; }   /* restore normal scroll */

  .app-shell {
    display: flex;
    flex-direction: column;
    height: auto;
    overflow: visible;
  }

  /* MAP pane */
  .pane-map { overflow: visible; border-right: none; }
  .map-wrap { flex: none; height: 280px; }

  /* CARDS pane */
  .pane-cards { overflow: visible; min-height: 0; }
  .sat-cards   { overflow: visible; max-height: none; flex-direction: column; }
  .pane-cards  { border-top: 1px solid var(--border); }

  /* Header */
  .header { padding: 0 12px; gap: 8px; }
  .logo-sub { display: none; }
  .observer-badge { padding: 4px 7px; }  /* compact — icon only */
  #observer-badge-text { display: none; }
  .time-value { font-size: 16px; }
  .status-text { display: none; }

  /* Stats */
  .stats-bar { height: auto; flex-wrap: wrap; padding: 8px 12px; gap: 4px; }
  .stat-item { flex: 1 0 40%; }
  .stat-divider { display: none; }
  .stat-num { font-size: 14px; }

  /* Ranking */
  .ranking-inner { padding: 16px; }
  .ranking-table th:nth-child(4),
  .ranking-table td:nth-child(4) { display: none; }  /* hide 주기 on mobile */

  /* Footer */
  .footer-inner { padding: 16px; }
  .footer-row { gap: 8px; }
}

@media (max-width: 480px) {
  .time-value { font-size: 14px; letter-spacing: 1px; }
  .map-wrap { height: 240px; }
  .ranking-inner { padding: 12px; }
  .footer-inner  { padding: 12px; }

  .ranking-table th:nth-child(3),
  .ranking-table td:nth-child(3),
  .ranking-table th:nth-child(5),
  .ranking-table td:nth-child(5) { display: none; }
}

/* ============================================================
   SCROLLBAR
   ============================================================ */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,.1); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,.2); }

/* ============================================================
   ANIMATIONS
   ============================================================ */
.sat-card { animation: fadeUp .3s ease both; }
.sat-card:nth-child(1){animation-delay:.05s}
.sat-card:nth-child(2){animation-delay:.10s}
.sat-card:nth-child(3){animation-delay:.15s}
.sat-card:nth-child(4){animation-delay:.20s}
.sat-card:nth-child(5){animation-delay:.25s}

@keyframes fadeUp { from{opacity:0;transform:translateY(10px)} to{opacity:1;transform:translateY(0)} }
