:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --text: #14191d;
  --muted: #68737d;
  --panel: rgba(255, 255, 255, 0.93);
  --border: rgba(20, 25, 29, 0.10);
  --shadow: 0 10px 28px rgba(18, 26, 33, 0.14);
  --gmb: #159447;
  --kmb: #d92f38;
  --ctb: #f0c51e;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body,
#app,
#map {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
}

html,
body {
  overflow: hidden;
  background: #eef1f2;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Microsoft JhengHei", Arial, sans-serif;
}

button,
select {
  font: inherit;
}

#app {
  position: relative;
  isolation: isolate;
}

#map {
  position: absolute;
  inset: 0;
  background: #edf0f1;
}

/* Requirement: OpenFreeMap visual strength ~50%. Only the map canvas is faded,
   while station markers and controls remain fully opaque. */
#map .maplibregl-canvas {
  opacity: 0.5;
}

#map .maplibregl-control-container {
  display: none;
}

.topbar {
  position: absolute;
  z-index: 30;
  top: calc(var(--safe-top) + 12px);
  left: 12px;
  right: 12px;
  min-height: 66px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 10px 9px 12px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px) saturate(1.2);
  -webkit-backdrop-filter: blur(18px) saturate(1.2);
}

.brand {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-logo {
  position: relative;
  width: 36px;
  height: 46px;
  flex: 0 0 36px;
}

.brand-logo-sign {
  position: absolute;
  top: 0;
  left: 1px;
  width: 34px;
  height: 25px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  overflow: hidden;
  border: 2px solid #171c20;
  border-radius: 7px;
  background: #fff;
}

.brand-logo-sign i:nth-child(1) { background: var(--gmb); }
.brand-logo-sign i:nth-child(2) { background: var(--kmb); }
.brand-logo-sign i:nth-child(3) { background: var(--ctb); }

.brand-logo-post {
  position: absolute;
  top: 24px;
  left: 17px;
  width: 3px;
  height: 15px;
  transform: translateX(-50%);
  border-radius: 2px;
  background: #171c20;
}

.brand-logo-dot {
  position: absolute;
  bottom: 0;
  left: 17px;
  width: 8px;
  height: 8px;
  transform: translateX(-50%);
  border: 2px solid #fff;
  border-radius: 50%;
  background: #171c20;
  box-shadow: 0 0 0 1px rgba(0,0,0,.15);
}

.brand-copy {
  min-width: 0;
}

.brand-name {
  font-size: 20px;
  line-height: 1.05;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.brand-status {
  max-width: 190px;
  margin-top: 5px;
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.15;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.range-select-wrap {
  min-width: 112px;
  display: grid;
  gap: 2px;
  padding: 7px 9px 6px 11px;
  border: 1px solid rgba(20, 25, 29, 0.09);
  border-radius: 14px;
  background: rgba(244, 246, 247, 0.95);
}

.range-select-wrap > span {
  color: #6b737a;
  font-size: 10px;
  line-height: 1;
}

.range-select-wrap select {
  min-width: 92px;
  appearance: none;
  -webkit-appearance: none;
  padding: 1px 20px 1px 0;
  border: 0;
  outline: 0;
  background:
    linear-gradient(45deg, transparent 50%, #20262b 50%) right 7px center / 5px 5px no-repeat,
    linear-gradient(135deg, #20262b 50%, transparent 50%) right 3px center / 5px 5px no-repeat;
  color: var(--text);
  font-size: 14px;
  font-weight: 750;
}

.legend {
  position: absolute;
  z-index: 25;
  top: calc(var(--safe-top) + 90px);
  left: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 5px 18px rgba(20, 25, 29, 0.10);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: #3c454c;
  font-size: 11px;
  font-weight: 650;
}

.legend > span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.legend-dot,
.operator-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.08);
}
.legend-dot.gmb { background: var(--gmb); }
.legend-dot.kmb { background: var(--kmb); }
.legend-dot.ctb { background: var(--ctb); }

.map-actions {
  position: absolute;
  z-index: 30;
  right: 12px;
  bottom: calc(var(--safe-bottom) + 54px);
  display: grid;
  gap: 8px;
}

.map-action {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(255,255,255,.94);
  box-shadow: 0 8px 20px rgba(18,26,33,.14);
  color: #151a1e;
  font-size: 24px;
  font-weight: 500;
  cursor: pointer;
}

.map-action:active,
.copyright-pill:active {
  transform: scale(.96);
}

.gps-action {
  font-size: 0;
}

.gps-ring {
  position: relative;
  width: 18px;
  height: 18px;
  display: block;
  border: 2px solid #1c6ed7;
  border-radius: 50%;
}

.gps-ring::before,
.gps-ring::after {
  content: "";
  position: absolute;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  background: #1c6ed7;
}

.gps-ring::before { width: 6px; height: 6px; border-radius: 50%; }
.gps-ring::after { width: 26px; height: 2px; opacity: .22; }

.copyright-pill {
  position: absolute;
  z-index: 28;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 12px);
  transform: translateX(-50%);
  padding: 7px 12px;
  border: 1px solid rgba(20,25,29,.08);
  border-radius: 999px;
  background: rgba(255,255,255,.80);
  box-shadow: 0 4px 15px rgba(18,26,33,.08);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: rgba(20,25,29,.70);
  font-size: 10px;
  font-weight: 600;
  cursor: pointer;
}

.copyright-pill:active {
  transform: translateX(-50%) scale(.96);
}

.transport-stop-marker {
  position: relative;
  transform: translateY(-1px);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

.transport-stop-sign {
  position: relative;
  z-index: 2;
  min-width: 43px;
  max-width: 108px;
  min-height: 27px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px 7px;
  border: 2px solid #13181c;
  border-radius: 5px;
  box-shadow: 0 2px 6px rgba(0,0,0,.20);
  color: #11161a;
  font-size: 12px;
  line-height: 1.05;
  font-weight: 850;
  text-align: center;
  white-space: nowrap;
}

.transport-stop-marker.operator-gmb .transport-stop-sign { background: var(--gmb); color: #fff; }
.transport-stop-marker.operator-kmb .transport-stop-sign { background: var(--kmb); color: #fff; }
.transport-stop-marker.operator-ctb .transport-stop-sign { background: var(--ctb); color: #101418; }

.transport-stop-post {
  position: relative;
  z-index: 1;
  width: 2px;
  height: 13px;
  margin: -1px auto 0;
  background: #15191d;
  box-shadow: 0 1px 2px rgba(255,255,255,.7);
}

.transport-stop-point {
  width: 7px;
  height: 7px;
  margin: -1px auto 0;
  border: 1.5px solid #fff;
  border-radius: 50%;
  background: #12171b;
  box-shadow: 0 0 0 1px rgba(0,0,0,.24);
}

.transport-stop-marker:hover .transport-stop-sign,
.transport-stop-marker:focus-visible .transport-stop-sign {
  transform: translateY(-2px);
}

.user-location-marker {
  width: 18px;
  height: 18px;
  border: 3px solid #fff;
  border-radius: 50%;
  background: #2474e8;
  box-shadow: 0 0 0 2px rgba(36,116,232,.22), 0 3px 9px rgba(0,0,0,.22);
}

.user-location-marker::after {
  content: "";
  position: absolute;
  inset: -10px;
  border: 1px solid rgba(36,116,232,.28);
  border-radius: 50%;
  animation: gpsPulse 2s ease-out infinite;
}

@keyframes gpsPulse {
  0% { transform: scale(.6); opacity: .75; }
  70%, 100% { transform: scale(1.25); opacity: 0; }
}

.toast {
  position: absolute;
  z-index: 55;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 58px);
  max-width: min(88vw, 420px);
  transform: translate(-50%, 12px);
  padding: 9px 13px;
  border-radius: 12px;
  background: rgba(20,25,29,.90);
  box-shadow: 0 8px 24px rgba(0,0,0,.18);
  color: #fff;
  font-size: 12px;
  line-height: 1.35;
  opacity: 0;
  pointer-events: none;
  transition: .2s ease;
}

.toast.show {
  transform: translate(-50%, 0);
  opacity: 1;
}

.stop-sheet {
  position: absolute;
  z-index: 60;
  left: 10px;
  right: 10px;
  bottom: calc(var(--safe-bottom) + 10px);
  max-height: min(48vh, 390px);
  overflow: auto;
  padding: 10px 18px 18px;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: rgba(255,255,255,.96);
  box-shadow: 0 18px 50px rgba(14,23,31,.23);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  transform: translateY(calc(100% + 30px));
  opacity: 0;
  pointer-events: none;
  transition: transform .24s ease, opacity .2s ease;
}

.stop-sheet.open {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
}

.sheet-handle {
  width: 38px;
  height: 4px;
  margin: 0 auto 13px;
  border-radius: 99px;
  background: #d5dade;
}

.sheet-close {
  position: absolute;
  top: 12px;
  right: 14px;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: #f0f2f3;
  color: #4e575f;
  font-size: 20px;
  cursor: pointer;
}

.sheet-head {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding-right: 36px;
}

.operator-dot {
  width: 12px;
  height: 12px;
  flex: 0 0 12px;
  margin-top: 4px;
}

.sheet-operator {
  color: #66727b;
  font-size: 11px;
  font-weight: 700;
}

.sheet-title {
  margin: 2px 0 0;
  font-size: 19px;
  line-height: 1.25;
}

.sheet-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  margin-top: 10px;
  color: #6b747c;
  font-size: 11px;
}

.sheet-route-title {
  margin-top: 15px;
  color: #5b646c;
  font-size: 11px;
  font-weight: 700;
}

.sheet-routes {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 8px;
}

.sheet-route-chip {
  min-width: 40px;
  padding: 6px 9px;
  border: 1px solid #d7dcdf;
  border-radius: 9px;
  background: #f7f8f8;
  color: #192026;
  font-size: 12px;
  font-weight: 800;
  text-align: center;
}

.loading-overlay {
  position: absolute;
  z-index: 100;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(239,242,243,.96);
  transition: opacity .25s ease, visibility .25s ease;
}

.loading-overlay.hide {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loading-card {
  display: grid;
  justify-items: center;
  gap: 10px;
  color: #1e252b;
}

.loading-card strong {
  font-size: 24px;
}

.loading-card span {
  color: #6e7880;
  font-size: 12px;
}

.loading-logo {
  width: 38px;
  height: 38px;
  border: 4px solid #cbd2d6;
  border-top-color: #242b31;
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

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

@media (max-width: 440px) {
  .topbar {
    gap: 7px;
    min-height: 62px;
    border-radius: 18px;
  }

  .brand-logo {
    width: 32px;
    height: 42px;
    flex-basis: 32px;
    transform: scale(.9);
    transform-origin: left center;
  }

  .brand-name { font-size: 18px; }
  .brand-status { max-width: 132px; font-size: 10px; }
  .range-select-wrap { min-width: 104px; }
  .range-select-wrap select { min-width: 84px; font-size: 13px; }
  .legend { top: calc(var(--safe-top) + 86px); }
}

@media (max-width: 350px) {
  .brand-status { display: none; }
  .brand-logo { display: none; }
  .legend { gap: 6px; font-size: 10px; }
}
